> For the complete documentation index, see [llms.txt](https://docs.bluerock.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bluerock.io/agent-frameworks-integration/crewai.md).

# CrewAI

The BlueRock runtime provides native, out-of-the-box telemetry tracing for multi-agent orchestrations built using the CrewAI framework. By embedding the `bluerock` Sensor directly into the execution space, BlueRock automatically hooks into CrewAI's lifecycle hooks without requiring codebase alterations or manual analytics callbacks.

#### Core Architecture & Telemetry Pipeline

<figure><img src="/files/Ejl2eq752vKKzuO3YJAv" alt=""><figcaption></figcaption></figure>

#### Environment Setup

1. **Provision the Isolated Project Environment**\
   Initialize the local configuration layout with `uv` to ensure strict, repeatable dependency management across testing environments:<br>

   ```shellscript
   # Initialize clean project workspace
   $ uv init --python python3.13 sample_agent
   $ cd sample_agent

   # Activate virtual runtime environment
   $ source .venv/bin/activate

   # Append required core CrewAI modules
   $ uv add crewai
   ```

2. **Inject and Register BluePython Sensors**\
   Deploy the custom BlueRock telemetry sensor library directly within the activated workspace context:<br>

   ```shellscript
   # Perform localized wheel installation
   $ uv pip install /opt/bluerock/python-dist/bluerock-0.0.1*.whl

   # Activate runtime sensor hooks
   $ python -m bluerock --install
   ```

#### Agent Execution Block

Create the localized controller file as `help_agent.py` to initiate multi-agent execution. Ensure appropriate authorization environment variables (`OPENAI_API_KEY`) are bound to the parent terminal session:

```shellscript
# Execute target CrewAI workspace script
$ uv run sample_agent.py  
```

#### Captured OpenTelemetry (OTEL) Lifecycle Events

During validation phases, the active `bluepython` sensor writes structured payloads tracking the progression of multi-agent orchestration states.

**Phase 1: Crew Initialization (`crew_kickoff_started`)**

Triggers at the entry boundary of the collective execution loop, registering involved roles, input properties, task items, and processing schemas.

```json
{
    "body": {
        "agents": [ "Helpful assistant" ],
        "context": { "process": { "pid": 000000 } },
        "entity_id": "xxxxxxxx-0000-0xxx-xxxx-000000xxxxxx",
        "event": "crew_kickoff_started",
        "inputs": "null",
        "process": "Process.sequential",
        "tasks": [ "why sky is blue?" ]
    },
    "severity_number": 0,
    "severity_text": "INFO",
    "attributes": {
        "domain": "gyro",
        "event_name": "python_crewai_event",
        "hostid": "000.00.00.00",
        "origin": "bluepython",
        "sensor_id": 0000,
        "type": "event"
    },
    "scope": { "name": "bluerockd" },
    "resource": { "service.name": "bluerock" }
}
```

**Phase 2: Task Provisioning (`task_started`)**

Logs properties when an item is dispatched to a specific worker agent, recording intent requirements, expected resolution criteria, and assigned tool layers.

```json
{
    "body": {
        "agent": "Helpful assistant",
        "async_execution": false,
        "context": { "process": { "pid": 000000 } },
        "entity_id": "xxxxxxxx-0000-0xxx-xxxx-000000xxxxxx",
        "event": "task_started",
        "expected_output": "provide more scientic answer",
        "task": "why sky is blue?",
        "tools": []
    },
    "severity_number": 0,
    "severity_text": "INFO",
    "attributes": {
        "domain": "gyro",
        "event_name": "python_crewai_event",
        "origin": "bluepython",
        "sensor_id": 0000
    }
}
```

**Phase 3: Runtime Execution Profile (`agent_execution`)**

Captures structural metadata associated with individual execution states, auditing behavioral guardrails such as target model variants, delegation permission rules, and backstories.

```json
{
    "body": {
        "agent": "Helpful assistant",
        "agent_allow_delegation": false,
        "agent_backstory": "A helpful assistant. can answer any topic",
        "agent_goal": "Helpful assistant. answer user queries",
        "agent_id": "000xxxx0-0xxx-0xxx-0xxx-0xxxx0000000",
        "agent_llm": "gpt-4o",
        "agent_tools": [],
        "context": { "process": { "pid": 000000 } },
        "entity_id": "xxxxxxxx-0000-0xxx-xxxx-000000xxxxxx",
        "event": "agent_execution",
        "task": "why sky is blue?"
    },
    "severity_number": 0,
    "severity_text": "INFO",
    "attributes": {
        "domain": "gyro",
        "event_name": "python_crewai_event",
        "origin": "bluepython",
        "sensor_id": 0000
    }
}
```

**Phase 4: Execution Resolution (`agent_execution_completed`)**

Marks task completion steps, registering structural text output answers, verification states, and usage parameters.

```json
{
    "body": {
        "agent": "Helpful assistant",
        "context": { "process": { "pid": 000000 } },
        "entity_id": "xxxxxxxx-0000-0xxx-xxxx-000000xxxxxx",
        "event": "agent_execution_completed",
        "output": "The sky appears blue to the human eye due to a phenomenon known as Rayleigh scattering. This scattering occurs when sunlight enters Earth's atmosphere and interacts with the gas molecules and smaller particles present...",
        "token_usage": {
            "cached_prompt_tokens": 0,
            "completion_tokens": 0,
            "prompt_tokens": 0,
            "successful_requests": 0,
            "total_tokens": 0
        }
    },
    "severity_number": 0,
    "severity_text": "INFO",
    "attributes": {
        "domain": "gyro",
        "event_name": "python_crewai_event",
        "origin": "bluepython",
        "sensor_id": 0000
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.bluerock.io/agent-frameworks-integration/crewai.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
