feat(projekt-matching): flow-2 stages with gate, CRM verify, notification, langfuse trace

This commit is contained in:
tlg
2026-07-09 11:06:11 +02:00
parent 11b5675eab
commit 2032305d90
3 changed files with 311 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
"""Post one consolidated Langfuse trace per project (ingestion API).
Reads the LANGFUSE_* env vars that create_pod_langflow.sh already sets on
the Langflow container. Never raises — tracing must not fail a run."""
from __future__ import annotations
import datetime as dt
import os
import uuid
import requests
def post_trace(ctx: dict) -> None:
host = os.environ.get("LANGFUSE_HOST")
pk = os.environ.get("LANGFUSE_PUBLIC_KEY")
sk = os.environ.get("LANGFUSE_SECRET_KEY")
if not (host and pk and sk):
return
now = dt.datetime.now(dt.timezone.utc).isoformat()
body = {
"id": str(uuid.uuid4()),
"timestamp": now,
"name": "projekt-match",
"input": {"canonical": ctx.get("canonical"), "title": ctx.get("title")},
"output": {"decision": ctx.get("decision"),
"status": ctx.get("status"),
"mustMatch": ctx.get("mustMatch"),
"niceMatch": ctx.get("niceMatch"),
"description": ctx.get("description")},
"metadata": {"opportunityId": ctx.get("opportunityId"),
"crmUrl": ctx.get("crmUrl"),
"error": ctx.get("error"),
"projectName": ctx.get("projectName")},
"tags": [ctx.get("status") or "unknown"],
}
event = {"batch": [{"id": str(uuid.uuid4()), "type": "trace-create",
"timestamp": now, "body": body}]}
try:
requests.post(f"{host.rstrip('/')}/api/public/ingestion", json=event,
auth=(pk, sk), timeout=15)
except Exception:
pass