# Log Agent Graphs

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

:::frame
<img src="../img/apps/opik-documentation/documentation/fern/img/tracing/agent_definition.png" alt="">
:::

Opik supports logging agent graphs for the following frameworks:

1. LangGraph
2. Google Agent Development Kit (ADK)
3. Manual Tracking

## LangGraph

You can log the agent execution graph by specifying the `graph` parameter in the
[OpikTracer](https://www.comet.com/docs/opik/python-sdk-reference/integrations/langchain/OpikTracer) callback:

```python
from opik.integrations.langchain import OpikTracer

opik_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.

## Google Agent Development Kit (ADK)

Opik automatically generates visual representations of your agent workflows for Google ADK without requiring any additional configuration. Simply integrate Opik's OpikTracer callback as shown in the [ADK integration configuration guide](/guides/python-adk#configuring-google-adk), and your agent graphs will be automatically captured and visualized.

The graph automatically shows:

- Agent hierarchy and relationships
- Sequential execution flows
- Parallel processing branches
- Tool connections and dependencies
- Loop structures and iterations

For example, a basic weather and time agent will display its execution flow with all agent steps, LLM calls, and tool invocations:

:::frame
<img src="../img/apps/opik-documentation/documentation/fern/img/tracing/adk/adk_weather_time_graph_screenshot.png" alt="">
:::

For more complex multi-agent architectures, the automatic graph visualization becomes even more valuable, providing clear visibility into nested agent hierarchies and complex execution patterns.

## 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:

```python
import opik
from opik import opik_context

@opik.track
def chat_agent(input: str):
  # Update the current trace with the agent graph definition
  opik_context.update_current_trace(
    metadata={
      "_opik_graph_definition": {
        "format": "mermaid",
            "data": "graph TD; U[User]-->A[Agent]; A-->L[LLM]; L-->A; A-->R[Answer];"
      }
    }
  )
  return "Hello, how can I help you today?"

chat_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:

- [Opik's 50+ integrations](/guides/overview-integrations-overview)
- [Logging traces](https://www.comet.com/tracing/advanced/log_traces)
- [Evaluating agents](https://www.comet.com/evaluation/evaluate_agents)

## Related pages

- [Log traces](./observability-tracing-advanced-log-traces.md)
- [Log conversations](./observability-tracing-advanced-log-chat-conversations.md)
- [Log media & attachments](./observability-tracing-advanced-log-multimodal-traces.md)
- [Log distributed traces](./observability-tracing-advanced-log-distributed-traces.md)
- [Log user feedback](./observability-tracing-advanced-annotate-traces.md)
- [Cost tracking](./observability-tracing-advanced-cost-tracking.md)
- [Export data](./observability-export-data.md)
- [Migrate data](./observability-migrate-data.md)
- [SDK configuration](./observability-tracing-advanced-sdk-configuration.md)
- [Offline fallback and message replay](./observability-tracing-advanced-offline-fallback.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
