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

# CrewAI

> Capture traces from CrewAI crews with OpenLit

## Choose a setup method

| Method              | Use it when                                                                    |
| ------------------- | ------------------------------------------------------------------------------ |
| **Agnost AI skill** | You want your coding agent to inspect the app, make the change, and verify it. |
| **Agnost AI SDK**   | You want explicit control over the interaction boundaries and fields.          |
| **OpenTelemetry**   | The framework already emits useful spans or you operate an OTel pipeline.      |

Start with one method for a call path. Combining SDK tracking with framework
OpenTelemetry on the same call can create duplicate interactions.

## Recommended: Agnost AI skill

<Note>
  **Recommended.** Choose this path when you want your coding agent to inspect the
  project, select a supported transport, make the smallest instrumentation change,
  send a test event, and verify that it reached Agnost AI.
</Note>

Install the skill once in your coding-agent environment:

```bash theme={null}
npx skills add AgnostAI/skills --skill agnost-ai
```

Run the framework-specific prompt below from the application root. Review the
resulting diff before deploying it.

```text theme={null}
Use the agnost-ai skill to add Agnost AI analytics to this CrewAI application.
Org ID: your-org-id
Instrument the real crew.kickoff() path and verify one fresh interaction.
```

## Manual setup: Agnost AI SDK

```bash theme={null}
pip install agnost
```

```python theme={null}
import agnost

agnost.init("your-org-id")
interaction = agnost.begin(user_id="u-42", agent_name="crewai-research", input=prompt)
try:
    result = crew.kickoff(inputs={"prompt": prompt})
    interaction.end(output=str(result))
except Exception as exc:
    interaction.end(output=str(exc), success=False)
    raise
finally:
    agnost.shutdown()
```

## Manual setup: OpenTelemetry

OpenLit is the recommended path: it auto-instruments CrewAI plus the underlying LLM provider.

### Install

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

### Setup

```python theme={null}
import os, openlit
from crewai import Agent, Crew, Task
from openinference.instrumentation import using_attributes

os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://otel.agnost.ai"
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = "X-Agnost-Org-ID=<your-org-id>"

openlit.init(application_name="my-crew", environment="production")

with using_attributes(session_id="sess-123", user_id="u-42"):
    Crew(agents=[...], tasks=[...]).kickoff()
```

Spans use OTel GenAI semconv (`gen_ai.prompt.{n}.content`, `gen_ai.completion.{n}.content`, `gen_ai.usage.*`) plus `gen_ai.agent.name` and `gen_ai.operation.name` on agent/task spans.

### Caveats

* Call `openlit.init()` before constructing any `Crew` / `Agent` objects.
* CrewAI's own anonymized telemetry (sent to CrewAI's servers) is unrelated and can be left enabled.

### Verify

Run one `Crew(...).kickoff()` call, then open **Events** in Agnost AI. Confirm CrewAI and provider spans are present.

### Troubleshooting

* Call `openlit.init()` before constructing crews or agents.
* Confirm `OTEL_EXPORTER_OTLP_HEADERS` contains `X-Agnost-Org-ID=<your-org-id>`.
* Wrap runs with `using_attributes` if you need explicit user/session grouping.

### References

* [Enable OpenTelemetry export](https://docs.crewai.com/en/observability/openlit)
* [Add custom metadata](https://docs.crewai.com/en/api-reference/kickoff)

## Next steps

* [Conversations](/using-conversations): review the complete CrewAI execution.
* [Events](/using-events): inspect crew, task, and model activity.
* [Intents](/using-intents): organize production conversations by what users wanted.
