Overview
AI agents that use tools require special tracing consideration. This guide shows how to trace agent loops, tool calls, and multi-turn conversations effectively.
Basic Agent Pattern
Here’s a well-traced agent implementation:
What Gets Traced
Each LLM call in the agent loop creates a span:
Tool Execution Tracing
Use span() to trace individual tool executions:
Now your trace shows tool execution:
Multi-Turn Conversations
For chat applications, preserve session context:
ReAct Pattern
For ReAct (Reasoning + Acting) agents, use span() for thought and action steps:
Best Practices
Name your traces after the agent’s purpose, not implementation details. Use “customer-support-agent” not “anthropic-tool-loop”.
- One trace per task — Wrap the entire agent execution in
@observe
- Trace tool execution — Use
span() for custom tool calls
- Include iteration context — Add step numbers to metadata
- Set reasonable limits — Cap iterations to prevent runaway traces
- Tag by agent type — Use tags like
["agent", "react"] for filtering
See Also