Skip to main content

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”.
  1. One trace per task — Wrap the entire agent execution in @observe
  2. Trace tool execution — Use span() for custom tool calls
  3. Include iteration context — Add step numbers to metadata
  4. Set reasonable limits — Cap iterations to prevent runaway traces
  5. Tag by agent type — Use tags like ["agent", "react"] for filtering

See Also