Skip to content

CrewAI

CrewAI orchestrates role-playing autonomous agents into collaborating “crews”. You can send full traces of every agent, task, tool call, and large language model (LLM) request to Logfire.

CrewAI doesn’t have a dedicated logfire.instrument_crewai() method, but it works out of the box with the OpenInference CrewAI instrumentor. This is possible because logfire.configure() sets up the global OpenTelemetry tracer provider, and the OpenInference instrumentor exports its spans to that provider — so they end up in Logfire automatically.

Installation

Install logfire, crewai, and the OpenInference CrewAI instrumentor:

Terminal
pip install logfire crewai openinference-instrumentation-crewai

Usage

Call logfire.configure() and then CrewAIInstrumentor().instrument() before you build and run your crew:

Set OPENAI_API_KEY in your terminal before starting the script:

Terminal
export OPENAI_API_KEY='<your-openai-key>'
from crewai import Agent, Crew, Process, Task
from crewai.tools import tool
from openinference.instrumentation.crewai import CrewAIInstrumentor

import logfire

logfire.configure()
CrewAIInstrumentor().instrument()


@tool('lookup_incident')
def lookup_incident(incident_id: str) -> str:
    """Look up the current status and owner of an incident by ID."""
    return f'{incident_id} is resolved; owner=platform-observability'


researcher = Agent(
    role='Researcher',
    goal='Resolve incident questions using the available operational tools',
    backstory='You are a reliability engineer who verifies facts with tools.',
    llm='openai/gpt-4o-mini',
    tools=[lookup_incident],
)

task = Task(
    description="Use lookup_incident for incident_id='incident-42', then report its status and owner.",
    expected_output='The status and owner returned by lookup_incident.',
    agent=researcher,
)

crew = Crew(agents=[researcher], tasks=[task], process=Process.sequential)
print(crew.kickoff())

You’ll see a nested trace in Live and Explore with the crew kickoff at the top and a span per task and agent beneath it. CrewAI agents also appear in the specialized Agents view — each run is detected and named after the agent’s role.

The CrewAI OpenInference instrumentation emits agent and chain spans, but not separate model-call spans, so the LLMs view and the Agents view’s token, model, and cost columns stay empty for CrewAI runs. The support matrix shows which columns each view populates.

Managed prompts

You can keep your agents’ prompts (roles, goals, backstories, and task descriptions) in Prompt Management and fetch them at runtime with the Logfire software development kit (SDK), so non-engineers can iterate on them without redeploying.

Install the variables extra:

Terminal
pip install 'logfire[variables]'

Then fetch a versioned prompt and pass it into your agent:

from crewai import Agent
from pydantic import BaseModel

import logfire

logfire.configure()


class BackstoryInputs(BaseModel):
    domain: str


backstory_var = logfire.template_var(
    name='prompt__researcher_backstory',
    type=str,
    default='You are a knowledgeable analyst who values brevity.',
    inputs_type=BackstoryInputs,
)

with backstory_var.get(BackstoryInputs(domain='observability'), label='production') as resolved:
    backstory = resolved.value

researcher = Agent(
    role='Researcher',
    goal='Explain a topic clearly and concisely',
    backstory=backstory,
    llm='openai/gpt-4o-mini',
)

See Use Prompts in Your Application for the full workflow, including promoting versions and rollout targeting.