import httpx, threading
def muster_emit(job_id, checks, token_input=None, token_output=None, model=None, latency_ms=None):
"""Fire-and-forget — never blocks your agent."""
def _send():
try:
httpx.post(
f"https://backend.YOUR-INSTANCE.getmuster.io/api/v1/jobs/{job_id}/quality",
json={
"agent_id": "invoice-processor-v2",
"job_id": job_id,
"overall_passed": all(c["passed"] for c in checks),
"checks": checks,
"token_input": token_input,
"token_output": token_output,
"model": model,
"latency_ms": latency_ms,
},
timeout=2.0,
)
except Exception:
pass # never fail your agent
threading.Thread(target=_send, daemon=True).start()
muster_emit(
job_id=job_id,
checks=[
{"check_id": "output_not_empty", "severity": "HIGH", "passed": bool(output)},
{"check_id": "subtotal_arithmetic", "severity": "HIGH",
"passed": abs(computed - declared) < 0.01,
"expected": str(declared), "actual": str(computed)},
],
token_input=1247, token_output=312, model="gpt-4o", latency_ms=1840,
)