Working with CrewAI
Add end-to-end tracing to Agno agent workflows with LangDB—monitor model calls, tool usage, and step flows using a single init() call.
LangDB makes it effortless to trace CrewAI workflows end-to-end. With a single init()
call, all agent interactions, task executions, and LLM calls are captured.
Installation
Install the LangDB client with LangChain feature flag:
pip install pylangdb[crewai]
Quick Start
Export Environment Variables
Set your LangDB credentials:
export LANGDB_API_KEY="<your_langdb_api_key>"
export LANGDB_PROJECT_ID="<your_langdb_project_id>"
Initialize Tracing
Import and run the initialize before configuring your CrewAI Code:
from pylangdb.crewai import init
# Initialise LangDB
init()
Configure your CrewAI code
import os
from dotenv import load_dotenv
from crewai import Agent, Task, Crew, LLM
# Configure LLM with LangDB headers
llm = LLM(
model="openai/gpt-4o", # Use LiteLLM Like Model Names
api_key=os.getenv("LANGDB_API_KEY"),
base_url=os.getenv("LANGDB_API_BASE_URL"),
extra_headers={"x-project-id": os.getenv("LANGDB_PROJECT_ID")}
)
# Define agents and tasks as usual
researcher = Agent(
role="researcher",
goal="Research topic thoroughly",
backstory="You are an expert researcher",
llm=llm,
verbose=True
)
task = Task(description="Research the given topic", agent=researcher)
crew = Crew(agents=[researcher], tasks=[task])
# Kick off the workflow
result = crew.kickoff()
print(result)
All CrewAI calls—agent initialization, task execution, and model responses—are automatically linked.
Last updated
Was this helpful?