Python SDK
CrewAI Integration
Trace multi-agent systems, collaborative tasks, and tool executions in CrewAI.
Infralo integrates with CrewAI by listening to lifecycle hooks on CrewAI's event bus. It automatically captures tool invocations and nested task executions.
Setup
First, install the CrewAI extra dependencies:
pip install infralo[crewai]To enable tracing, instantiate the InfraloCrewAIListener once at the module level. The listener automatically self-registers to CrewAI's global event bus.
from infralo import Infralo
from infralo.integrations.crewai import InfraloCrewAIListener
infralo = Infralo()
# Register the listener once (typically at startup or module import time)
InfraloCrewAIListener()Usage Example
Run your Crew workflows inside an active trace context. The listener automatically captures events happening in the Crew execution thread and links them to the active trace.
from infralo import Infralo
from infralo.integrations.crewai import InfraloCrewAIListener
from crewai import Agent, Task, Crew
infralo = Infralo()
InfraloCrewAIListener() # Registered globally
# Define agents, tools, and tasks
researcher = Agent(role="Researcher", goal="Fetch details", tools=[my_tool], ...)
task = Task(description="Research details", agent=researcher, expected_output="...")
crew = Crew(agents=[researcher], tasks=[task])
# Execute the Crew within an active trace
with infralo.start_trace(session_id="crewai-run"):
result = crew.kickoff()What is Captured
The CrewAI integration automatically captures:
- Tool Spans: Every tool execution run by any agent is captured.
- Inputs & Outputs: Input parameters and outputs returned by the tools.
- Multithreaded Task Safety: Tasks executing concurrently in different threads (e.g. delegated sub-tasks or parallel agents) are isolated and synchronized correctly.
- Error Tracking: Intercepts tool execution errors and marks the corresponding spans as failed with traceback information.
Complete Examples
You can view or download the complete, ready-to-run examples:
- crewai_integration.py — Standard single-agent integration.
- crewai_complex_nesting.py — Advanced multi-agent delegation and nested crews.