Govern, secure, and optimize your CrewAI workflows with LangDB AI Gateway—access 350+ models, automatic routing, cost optimization, and full observability.
LangDB AI Gateway provides OpenAI-compatible APIs to connect with multiple Large Language Models and serves as an observability platform that makes it effortless to trace CrewAI workflows end-to-end while providing access to 350+ language models. With a single init() call, all agent interactions, task executions, and LLM calls are captured, providing comprehensive observability and production-ready AI infrastructure for your applications.
Import and initialize LangDB before configuring your CrewAI code:
from pylangdb.crewai import init# Initialize LangDBinit()
4
Configure CrewAI with LangDB
Set up your LLM with LangDB headers:
from crewai import Agent, Task, Crew, LLMimport os# Configure LLM with LangDB headersllm = LLM( model="openai/gpt-4o", # Replace with the model you want to use 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")})
Here’s a simple example to get you started with LangDB and CrewAI:
import osfrom pylangdb.crewai import initfrom crewai import Agent, Task, Crew, LLM# Initialize LangDB before any CrewAI importsinit()def create_llm(model): return LLM( model=model, api_key=os.environ.get("LANGDB_API_KEY"), base_url=os.environ.get("LANGDB_API_BASE_URL"), extra_headers={"x-project-id": os.environ.get("LANGDB_PROJECT_ID")} )# Define your agentresearcher = Agent( role="Research Specialist", goal="Research topics thoroughly", backstory="Expert researcher with skills in finding information", llm=create_llm("openai/gpt-4o"), # Replace with the model you want to use verbose=True)# Create a tasktask = Task( description="Research the given topic and provide a comprehensive summary", agent=researcher, expected_output="Detailed research summary with key findings")# Create and run the crewcrew = Crew(agents=[researcher], tasks=[task])result = crew.kickoff()print(result)