Integrations
CrewAI
Trace CrewAI multi-agent crews in Muster via the OpenInference instrumentation.
CrewAI is a framework for orchestrating autonomous AI agents — teams of agents with specific roles collaborating on complex tasks. Muster captures CrewAI executions through the OpenInference instrumentation, giving you per-agent and per-task spans without modifying your crew code.
Setup
1. Install dependencies
%pip install langfuse crewai openinference-instrumentation-crewai -q2. Configure credentials
import os
os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-***"
os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-***"
os.environ["LANGFUSE_BASE_URL"] = "https://app.getmuster.io"
os.environ["OPENAI_API_KEY"] = "sk-proj-***"from langfuse import get_client
langfuse = get_client()
if langfuse.auth_check():
print("Muster client is authenticated and ready!")3. Instrument CrewAI
from openinference.instrumentation.crewai import CrewAIInstrumentor
CrewAIInstrumentor().instrument(skip_dep_check=True)4. Build and run a crew
from crewai import Agent, Task, Crew
coder = Agent(
role="Software developer",
goal="Write clear, concise code on demand",
backstory="An expert coder with a keen eye for software trends.",
)
task1 = Task(
description="Define the HTML for a simple website with the heading 'Hello World! Muster monitors your CrewAI agent!'",
expected_output="A clear and concise HTML snippet",
agent=coder,
)
crew = Crew(agents=[coder], tasks=[task1])
with langfuse.start_as_current_observation(as_type="span", name="crewai-index-trace"):
result = crew.kickoff()
print(result)
langfuse.flush()Open Muster — you will see a trace per crew run with spans for each agent and task, including LLM calls, tool calls, and durations.
Add user/session attributes
For per-user attribution, wrap the run in propagate_attributes:
from langfuse import propagate_attributes
with propagate_attributes(user_id="user_123", session_id="sess_abc", tags=["crewai"]):
crew.kickoff()See the SDK guide for full details on decorators, context managers, and the
@observe() decorator.
Troubleshooting
- Enable debug logging:
export LANGFUSE_DEBUG="True". - In short-lived scripts, call
langfuse.flush()before exit. - Other instrumentations may emit unrelated OTel spans — filter them via OTel span processors.