Crewai

CrewAI is a cutting-edge framework for orchestrating autonomous AI agents.

Opik integrates with CrewAI to log traces for all CrewAI activity.

You can check out the Colab Notebook if you’d like to jump straight to the code:

Open In Colab

Getting started

First, ensure you have both opik and crewai installed:

$pip install opik crewai crewai-tools

In addition, you can configure Opik using the opik configure command which will prompt you for the correct local server address or if you are using the Cloud platform your API key:

$opik configure

Logging CrewAI calls

To log a CrewAI pipeline run, you can use the track_crewai. This callback will log each CrewAI call to Opik:

1from crewai import Agent, Crew, Task, Process
2
3
4class YourCrewName:
5 def agent_one(self) -> Agent:
6 return Agent(
7 role="Data Analyst",
8 goal="Analyze data trends in the market",
9 backstory="An experienced data analyst with a background in economics",
10 verbose=True,
11 )
12
13 def agent_two(self) -> Agent:
14 return Agent(
15 role="Market Researcher",
16 goal="Gather information on market dynamics",
17 backstory="A diligent researcher with a keen eye for detail",
18 verbose=True
19 )
20
21 def task_one(self) -> Task:
22 return Task(
23 name="Collect Data Task",
24 description="Collect recent market data and identify trends.",
25 expected_output="A report summarizing key trends in the market.",
26 agent=self.agent_one()
27 )
28
29 def task_two(self) -> Task:
30 return Task(
31 name="Market Research Task",
32 description="Research factors affecting market dynamics.",
33 expected_output="An analysis of factors influencing the market.",
34 agent=self.agent_two()
35 )
36
37 def crew(self) -> Crew:
38 return Crew(
39 agents=[self.agent_one(), self.agent_two()],
40 tasks=[self.task_one(), self.task_two()],
41 process=Process.sequential,
42 verbose=True
43 )
44
45
46from opik.integrations.crewai import track_crewai
47
48track_crewai(project_name="crewai-integration-demo")
49
50my_crew = YourCrewName().crew()
51result = my_crew.kickoff()
52
53print(result)

Each run will now be logged to the Opik platform:

Cost Tracking

The track_crewai integration automatically tracks token usage and cost for all supported LLM models used during CrewAI agent execution.

Cost information is automatically captured and displayed in the Opik UI, including:

  • Token usage details
  • Cost per request based on model pricing
  • Total trace cost

View the complete list of supported models and providers on the Supported Models page.