Open in Google Colab
Run the complete notebook in your browser
All company names (ContentCraft) and scenarios in this cookbook are entirely fictional and used for demonstration purposes only.
What You’ll Learn
Trace Agent Handoffs
Capture the message flow between agents as tasks pass through the pipeline
Track Per-Agent Costs
Monitor token usage and costs for each agent role to identify cost drivers
Debug Multi-Agent Flows
Understand why agents made specific decisions and where quality degrades
Compare Configurations
Run experiments with different model assignments to find the cost/quality sweet spot
Prerequisites:
- Python >=3.10, <3.14
- OpenAI API key
- Netra API key (Get started here)
- CrewAI installed
Why Trace Multi-Agent Systems?
Multi-agent systems introduce complexity that single-agent workflows don’t have:
Without per-agent visibility, you can’t optimize individual roles or identify where the pipeline breaks down.
CrewAI Architecture
CrewAI organizes multi-agent work into three components:
Processes:
- Sequential: Tasks execute one after another (A → B → C)
- Hierarchical: Manager agent delegates to workers
Building an Example Pipeline
Installation
Environment Setup
Define the Agents
Create a 4-agent content pipeline: Researcher → Writer → Editor → SEO:Define the Tasks
Create tasks that chain together:Create the Crew
Adding Netra Observability
Initialize Netra with Auto-Instrumentation
Netra provides auto-instrumentation for CrewAI that captures agent execution automatically:- Agent execution spans with role and backstory
- Task execution with descriptions and outputs
- LLM calls with prompts, completions, and token usage
- Cost calculations per agent
Using the Workflow Decorator
For more control, wrap your pipeline with the@workflow decorator:
Adding Custom Span Attributes
Track additional metadata for each pipeline run:Viewing Traces in Netra
After running the pipeline, navigate to Observability → Traces in Netra.What the Trace Shows

- Pipeline span: Overall execution time
- Agent spans: Each agent’s task execution
- LLM calls: Nested under each agent with prompts and completions
- Token usage: Per-agent and total
Running Configuration Experiments
Test different model configurations to find the optimal cost/quality balance.Define Configurations
Run Experiments
Compare in Dashboard
After running all configurations, compare costs and latency:Debugging Multi-Agent Issues
Common Problems and Solutions
Using Traces to Debug
- Find slow agents: Sort spans by duration
- Trace context flow: Check task outputs passed between agents
- Identify cost drivers: Filter by token usage
- Compare successful vs failed: Look for pattern differences
Summary
You’ve learned how to add comprehensive observability to CrewAI pipelines:- Auto-instrumentation captures agent execution with minimal code
- Per-agent tracing reveals costs, latency, and token usage
- Custom attributes enable filtering by topic, config, and more
- Configuration experiments find the optimal cost/quality balance
Key Takeaways
- Multi-agent systems need per-agent visibility to identify bottlenecks
- Cost allocation by role reveals which agents benefit from premium models
- Trace context flow to debug handoff issues
- Use configuration experiments for data-driven model selection
See Also
CrewAI Integration
Complete CrewAI instrumentation guide
Agents Documentation
Deep dive into agent observability features
Usage APIs
Query cost and usage data programmatically
