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

# CrewAI Integration with Veritrix Agent Observability

> Instrument CrewAI Crews and Flows automatically with Veritrix. Trace every agent, task, tool call, and delegation across your entire crew in real time.

Veritrix gives you complete visibility into your CrewAI applications with zero modifications to your crew definitions. After a single call to `trace.init()`, Veritrix automatically traces every agent action, task execution, tool invocation, and inter-agent delegation across your Crew or Flow — so you can identify bottlenecks, debug unexpected behavior, and measure the cost and latency of each step in production.

## Prerequisites

* Python 3.10 or higher
* An active [Veritrix account](https://app.veritrix.xyz) and API key
* CrewAI installed

## Installation & Setup

<Steps>
  <Step title="Install Veritrix and CrewAI">
    ```bash theme={null}
    pip install veritrix crewai
    ```

    If you need CrewAI's optional tools bundle, install it as well:

    ```bash theme={null}
    pip install "crewai[tools]"
    ```
  </Step>

  <Step title="Initialize Veritrix tracing">
    Call `trace.init()` at the top of your entry point, before you define any agents, tasks, or crews.

    ```python theme={null}
    from veritrix import trace

    trace.init("research-crew")
    ```
  </Step>

  <Step title="Define your Crew as normal">
    No changes are required to your agent or task definitions. Veritrix instruments CrewAI automatically.

    ```python theme={null}
    from crewai import Agent, Task, Crew
    from veritrix import trace

    trace.init("research-crew")
    # Define agents and tasks normally
    ```
  </Step>
</Steps>

## Example: Research Crew

The following example defines a two-agent research crew. Veritrix traces the full execution — including which agent handled each task, what tools were called, and how long each step took.

```python theme={null}
from crewai import Agent, Task, Crew
from crewai_tools import SerperDevTool
from veritrix import trace

trace.init("research-crew")

search_tool = SerperDevTool()

researcher = Agent(
    role="Senior Research Analyst",
    goal="Find accurate and up-to-date information on the given topic.",
    backstory="You are an expert researcher with a talent for finding reliable sources.",
    tools=[search_tool],
    verbose=True,
)

writer = Agent(
    role="Technical Writer",
    goal="Synthesize research findings into a clear, concise summary.",
    backstory="You specialize in turning complex research into accessible writing.",
    verbose=True,
)

research_task = Task(
    description="Research the latest developments in AI agent observability.",
    expected_output="A list of key findings with sources.",
    agent=researcher,
)

writing_task = Task(
    description="Write a two-paragraph summary of the research findings.",
    expected_output="A polished two-paragraph summary.",
    agent=writer,
)

crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, writing_task],
    verbose=True,
)

result = crew.kickoff()
print(result)
```

## Example: CrewAI Flow

For Flow-based orchestration, Veritrix traces each flow method invocation and the state transitions between them.

```python theme={null}
from crewai.flow.flow import Flow, listen, start
from veritrix import trace

trace.init("content-flow")

class ContentFlow(Flow):
    @start()
    def generate_outline(self):
        return "Introduction, Main Body, Conclusion"

    @listen(generate_outline)
    def write_draft(self, outline: str):
        # In a real flow, an LLM or crew would expand the outline
        return f"Draft based on: {outline}"

flow = ContentFlow()
result = flow.kickoff()
print(result)
```

## What Gets Captured Automatically

| Signal                | Details                                                         |
| --------------------- | --------------------------------------------------------------- |
| **LLM calls**         | Model name, prompt, completion, token counts, latency per agent |
| **Tool calls**        | Tool name, input arguments, output, duration                    |
| **Task execution**    | Task description, assigned agent, output, duration              |
| **Agent delegations** | Delegating agent, receiving agent, context passed               |
| **Flow transitions**  | Method name, input state, output state, duration                |
| **Retries**           | Retry count, error type, backoff applied                        |

<Note>
  Each agent in your crew gets its own set of spans, so you can compare performance across agents and identify which one is contributing most to latency or cost.
</Note>

## OpenTelemetry Compatibility

Veritrix is built on [OpenTelemetry](https://opentelemetry.io), so every span it generates for your CrewAI workflows is a standard OTel span. You can route these spans to any OTel-compatible collector alongside your existing infrastructure telemetry.

<Tip>
  To configure a custom OTel exporter or send traces to a third-party backend, see the [OpenTelemetry integration page](/integrations/opentelemetry).
</Tip>
