Skip to main content
Traces provide complete visibility into agent execution, exposing every decision, tool call, and reasoning step as a primitive for debugging, monitoring, and optimization.

Overview

The Traces primitive gives you real-time insight into agent execution by streaming detailed events about what the agent is thinking, which tools it’s using, and how it’s progressing toward task completion. Traces are the foundation for understanding, debugging, and optimizing agent behavior. Traces are essential for:
  • Debugging: Understand why agents make specific decisions or encounter errors
  • Optimization: Identify inefficiencies and opportunities for improvement
  • Monitoring: Track agent performance and behavior in production
  • Audit: Maintain detailed records of agent actions
  • Learning: Understand agent reasoning patterns and decision-making

Real-Time Streaming

Receive execution events as they happen during agent processing

Complete Visibility

See every thought, tool call, and intermediate result

Structured Events

Well-defined event types make traces easy to parse and analyze

Zero Configuration

Traces available automatically for every agent request

How Traces Work

Event Stream

Traces are delivered as a stream of events:
  1. Agent Starts: Execution begins
  2. Thinking Events: Agent reasons about the task
  3. Tool Use Events: Agent calls tools
  4. Tool Response Events: Tools return results
  5. Step Completion: Agent finishes a reasoning step
  6. Cost Events: Cost incurred for operations
  7. Error Events: Errors encountered during execution
  8. Completion: Agent finishes successfully

Event Structure

Each trace event contains:
  • Event Type: What kind of event occurred
  • Timestamp: When the event happened
  • Context: Session ID, step number, etc.
  • Payload: Event-specific data
  • Metadata: Additional contextual information
Streaming by Default: Set stream: true to receive events in real-time. Without streaming, you only get the final result.

Code Examples

Basic Trace Streaming

Trace Collection and Analysis

Filtering and Focusing Traces

Real-Time Progress Tracking

Trace Event Types

Agent Thinking

Shows agent’s internal reasoning:

Tool Use

Agent calls a tool:

Tool Response

Tool returns results:

Step Completion

Agent completes a reasoning step:

Cost Tracking

Cost incurred:

Errors

Error encountered:

Use Cases

1. Debugging Agent Behavior

Understand why agents make specific decisions:

2. Performance Optimization

Identify and eliminate bottlenecks:

3. Production Monitoring

Monitor agent behavior in real-time:

4. Learning from Agent Behavior

Analyze patterns to improve prompts:

Best Practices

Efficient Trace Processing

Integration with Other Primitives

With Hooks

Combine traces with custom callbacks:
Learn more: Hooks Primitive

With Evals

Use traces to validate agent behavior:
Learn more: Evals Primitive

Performance Considerations

Streaming Overhead

  • Network: Minimal overhead for event streaming
  • Processing: Depends on your event handlers
  • Memory: Incremental processing uses constant memory
  • Latency: No additional latency added to agent execution

Optimization Tips

Troubleshooting

Solution: Ensure streaming is enabled
Solution: Some events may not occur for all requests

Hooks

Custom callbacks for trace events

Evals

Test agents using trace data

Background Tasks

Monitor async task progress

Self-Healing

Debug error recovery with traces

Additional Resources

Event Types Reference

Complete event documentation

Debugging Guide

Advanced debugging techniques

API Reference

Streaming parameters
Remember: Traces are most powerful when processed incrementally. Stream events, filter to what matters, and handle them as they arrive for optimal performance and insights.