Python SDK: CrewAI Integration
Track time and token costs for CrewAI agents using the Keito task callback.
Setup
from keito import Keito
from keito.integrations.crewai import KeitoTaskCallback
client = Keito()
callback = KeitoTaskCallback(
client=client,
project_id="prj_abc",
)
Usage
from crewai import Agent, Task, Crew
researcher = Agent(
role="Senior Researcher",
goal="Find relevant information",
backstory="An experienced research analyst",
llm="claude-sonnet-4-6",
)
task = Task(
description="Research Q4 market trends",
agent=researcher,
callback=callback,
)
crew = Crew(agents=[researcher], tasks=[task])
result = crew.kickoff()
Each task creates a time entry and LLM expense attributed to the agent that executed it.
What Gets Tracked
For each CrewAI task:
- A time entry — duration measured from task start to completion, with
source: "agent"and the agent’s role as the notes. - An LLM expense — total token usage across all LLM calls within the task.
Multi-Agent Crews
When a crew has multiple agents, each task is attributed to the agent that executed it:
researcher = Agent(role="Researcher", llm="claude-sonnet-4-6")
writer = Agent(role="Writer", llm="claude-sonnet-4-6")
research_task = Task(
description="Research AI trends",
agent=researcher,
callback=callback,
)
writing_task = Task(
description="Write report from research",
agent=writer,
callback=callback,
context=[research_task],
)
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
)
result = crew.kickoff()
This creates separate time entries and expenses for each task, making it clear how much time and cost each agent contributed.
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
auto_expense | bool | True | Automatically log LLM expenses |
agent_id_from_role | bool | True | Use agent role as agent_id in metadata |
task_id | str | None | Default task ID for all entries |
Related
- LangChain Integration — LangChain callback handler
- Agent Integration — manual integration patterns