from agentflare import AgentFlareguard = AgentFlare(api_key="ag_...", agent_id="my-agent")@guard.trackdef run_agent(query: str) -> str: # Your full agent logic lives here # ... call LLMs, use tools, etc. return result
Calling run_agent("some input") is now equivalent to:
guard.send_event(AgentEvent(agent_id="my-agent", event_type="agent_start"))try: result = run_agent("some input") guard.send_event(AgentEvent(agent_id="my-agent", event_type="agent_end")) return resultexcept Exception as exc: guard.send_event(AgentEvent( agent_id="my-agent", event_type="agent_end", metadata={"error": str(exc)}, )) raise
If the wrapped function raises an exception, agent_end is still emitted with metadata={"error": "<exception message>"}. The exception is then re-raised, so your existing error handling is unaffected.
@guard.trackdef risky_agent(): raise ValueError("Something went wrong")# risky_agent() raises ValueError as normal,# but agent_end is still recorded in AgentFlare