> ## Documentation Index
> Fetch the complete documentation index at: https://www.sentrial.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# CrewAI Integration

> Track multi-agent CrewAI systems with automatic task tracking, agent steps, and tool executions.

## What Gets Tracked Automatically

<CardGroup cols={2}>
  <Card title="Agent Steps">
    Every step each agent takes with reasoning.
  </Card>

  <Card title="Task Completions">
    When tasks complete with outputs.
  </Card>

  <Card title="Tool Calls">
    All tool executions with inputs and outputs.
  </Card>

  <Card title="Agent Thoughts">
    Reasoning and decision making.
  </Card>
</CardGroup>

## Installation

```bash theme={null}
pip install sentrial crewai
```

## Basic Usage with Callbacks

Add `SentrialCrewHandler` callbacks to your Crew:

```python theme={null}
from crewai import Agent, Task, Crew
from sentrial import SentrialClient
from sentrial.crewai import SentrialCrewHandler

# Initialize Sentrial
client = SentrialClient(api_key="sentrial_live_xxx")

# Create session
session_id = client.create_session(
    name="Research Team",
    agent_name="crewai-research",
    user_id="user_123"
)

# Create handler
handler = SentrialCrewHandler(client, session_id, verbose=True)

# Define agents
researcher = Agent(
    role="Senior Researcher",
    goal="Find comprehensive information",
    backstory="Expert researcher with years of experience",
)

writer = Agent(
    role="Content Writer",
    goal="Write engaging content",
    backstory="Skilled writer who creates clear content",
)

# Define tasks
research_task = Task(description="Research {topic}", agent=researcher)
writing_task = Task(description="Write article", agent=writer)

# Create crew with callbacks
crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, writing_task],
    step_callback=handler.on_step,
    task_callback=handler.on_task_complete,
)

# Run
result = crew.kickoff(inputs={"topic": "AI agents"})

# Finish
handler.finish(success=True, output=str(result))
```

## Simple Decorator Usage

Use the `@track_crew` decorator for simpler tracking:

```python theme={null}
from sentrial import SentrialClient
from sentrial.crewai import track_crew

client = SentrialClient(api_key="sentrial_live_xxx")

@track_crew(client, agent_name="research-crew", user_id="user_123")
def run_research(topic: str):
    crew = Crew(agents=[...], tasks=[...])
    return crew.kickoff(inputs={"topic": topic})

# Just call - automatically tracked!
result = run_research("AI Safety")
```

## Wrap Existing Crew

```python theme={null}
handler = SentrialCrewHandler(client, session_id)

# Wrap adds callbacks automatically
crew = handler.wrap_crew(crew)

# Now kickoff is tracked
result = crew.kickoff(inputs={"topic": "AI"})

handler.finish(success=True)
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Python SDK Reference" icon="python" href="/sdk/python">
    Full SDK documentation.
  </Card>

  <Card title="AutoGen Integration" icon="robot" href="/integrations/autogen">
    Track AutoGen multi-agent systems.
  </Card>
</CardGroup>
