Log Agent Graphs

Agent Graphs are a great way to visualize the flow of an agent and simplifies it’s debugging.

Opik supports logging agent graphs for the following frameworks:

  1. LangGraph
  2. Manual Tracking

LangGraph

You can log the agent execution graph by specifying the graph parameter in the OpikTracer callback:

1from opik.integrations.langchain import OpikTracer
2
3opik_tracer = OpikTracer(graph=app.get_graph(xray=True))

Opik will log the agent graph definition in the Opik dashboard which you can access by clicking on Show Agent Graph in the trace sidebar.

Manual Tracking

You can also log the agent graph definition manually by logging the agent graph definition as a mermaid graph definition in the metadata of the trace:

1import opik
2from opik import opik_context
3
4@opik.track
5def chat_agent(input: str):
6 # Update the current trace with the agent graph definition
7 opik_context.update_current_trace(
8 metadata={
9 "_opik_graph_definition": {
10 "format": "mermaid",
11 "data": "graph TD; U[User]-->A[Agent]; A-->L[LLM]; L-->A; A-->R[Answer];"
12 }
13 }
14 )
15 return "Hello, how can I help you today?"
16
17chat_agent("Hi there!")

Opik will log the agent graph definition in the Opik dashboard which you can access by clicking on Show Agent Graph in the trace sidebar.

Next steps

Why not check out: