mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-07-01 21:28:10 +00:00
* feat: adopt directory-based docs versioning with Edge channel Switch docs.crewai.com from navigation-only versioning (every version selector entry rendered the same docs/<lang>/* source files) to Mintlify's directory-based versioning so each version selector entry renders its own snapshot. Add an "Edge" channel under docs/edge/<lang>/* that always reflects main HEAD for unreleased work, eliminating pre-release leakage onto frozen release labels. External links to canonical /<lang>/* URLs are preserved via wildcard redirects that always land on the current default version. Layout: - docs/edge/<lang>/* rolling source (you edit here) - docs/edge/enterprise-api.*.yaml - docs/v<X.Y.Z>/<lang>/* frozen, immutable snapshots - docs/v<X.Y.Z>/enterprise-api.*.yaml - docs/images/ shared, append-only - docs/docs.json nav + redirects URLs follow the Mintlify-idiomatic shape: /edge/<lang>/<page> for Edge, /v<X.Y.Z>/<lang>/<page> for every frozen snapshot. The wildcard redirects /<lang>/:slug* -> /<default>/<lang>/:slug* keep stale links working, and every freeze rewrites them (plus all per-section/per-page redirects) so destinations always resolve to the current default without depending on a second redirect hop. Release flow integration (devtools release): - New module crewai_devtools.docs_versioning.freeze() materialises docs/v<X.Y.Z>/ from docs/edge/, rewrites openapi: refs inside the snapshot, inserts the version into every language block in docs.json, and refreshes all redirect destinations. - _update_docs_and_create_pr() in cli.py now calls that freeze during Phase 2 of devtools release. Edge changelogs are updated first (so the snapshot freeze picks them up), then the snapshot is staged alongside docs.json, branched as docs/freeze-v<X.Y.Z>, and the PR is titled [docs-freeze] docs: snapshot and changelog for v<X.Y.Z> — the title prefix the new CI guard reads. - The PR still gates tag, GitHub release, PyPI publish, and the enterprise release as before; no new PRs are added. - Pre-releases (1.X.YaN, 1.X.YbN, ...) skip the snapshot — they ride Edge — and the docs PR title omits the [docs-freeze] prefix. - docs_check (AI-generated docs scaffolding) writes to docs/edge/<lang>/* so newly-generated unreleased docs land in Edge and never accidentally touch a frozen snapshot. Migration scripts (one-shot): - scripts/docs/freeze_historical_versions.py reconstructs all 16 historical snapshots (v1.10.0 .. v1.14.7) from git tags via git archive | tar, rewriting openapi: MDX refs so each snapshot reads its own enterprise-api YAML rather than the live one. - scripts/docs/prefix_version_paths.py one-shot-migrates docs.json: rewrites every page path in 16 versioned blocks to point under docs/v<X.Y.Z>/, inserts a new Edge entry per language, tags v1.14.7 as Latest (default), prunes pages whose target file doesn't exist in the snapshot (e.g. docs/ar/ didn't exist before v1.12.0), and writes the wildcard + per-section redirects. - scripts/docs/freeze_current_edge.py is now a thin CLI wrapper around docs_versioning.freeze for manual one-off freezes (e.g. retroactively snapshotting a forgotten release). CI guards (.github/workflows/docs-snapshots.yml): - Frozen snapshots under docs/v[0-9]*/ are immutable; only PRs whose title contains [docs-freeze] (i.e. release-cut PRs generated by devtools release or the manual wrapper) may modify them. - Images under docs/images/ are append-only since snapshots share a single image directory. Deleting or renaming an image breaks every historical snapshot that still references it. Restored docs/images/crewai-otel-export.png from PR #3673; it was deleted in PR #4908 but v1.10.0 / v1.10.1 snapshots still reference it. Restoring instead of editing the snapshots preserves historical rendering fidelity and validates the new append-only rule retroactively. Tests: - lib/devtools/tests/test_docs_versioning.py covers the freeze: file copy, openapi rewrite, version insertion, default demotion, redirect upserts, per-section redirect rewriting, idempotency, and invalid inputs. Verified locally with mintlify broken-links: 0 broken links across the full site (Edge + 16 frozen versions, 4 locales). AGENTS.md (repo root) is the contributor guide for the new model; RELEASING.md is the release-cut runbook; README's Contribution section links to both. Co-authored-by: Cursor <cursoragent@cursor.com> * style: resolve linter issues --------- Co-authored-by: Cursor <cursoragent@cursor.com>
288 lines
9.9 KiB
Plaintext
288 lines
9.9 KiB
Plaintext
---
|
|
title: LangDB Integration
|
|
description: Govern, secure, and optimize your CrewAI workflows with LangDB AI Gateway—access 350+ models, automatic routing, cost optimization, and full observability.
|
|
icon: database
|
|
mode: "wide"
|
|
---
|
|
|
|
# Introduction
|
|
|
|
[LangDB AI Gateway](https://langdb.ai) 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.
|
|
|
|
<Frame caption="LangDB CrewAI Trace Example">
|
|
<img src="/images/langdb-1.png" alt="LangDB CrewAI trace example" />
|
|
</Frame>
|
|
|
|
**Checkout:** [View the live trace example](https://app.langdb.ai/sharing/threads/3becbfed-a1be-ae84-ea3c-4942867a3e22)
|
|
|
|
## Features
|
|
|
|
### AI Gateway Capabilities
|
|
- **Access to 350+ LLMs**: Connect to all major language models through a single integration
|
|
- **Virtual Models**: Create custom model configurations with specific parameters and routing rules
|
|
- **Virtual MCP**: Enable compatibility and integration with MCP (Model Context Protocol) systems for enhanced agent communication
|
|
- **Guardrails**: Implement safety measures and compliance controls for agent behavior
|
|
|
|
### Observability & Tracing
|
|
- **Automatic Tracing**: Single `init()` call captures all CrewAI interactions
|
|
- **End-to-End Visibility**: Monitor agent workflows from start to finish
|
|
- **Tool Usage Tracking**: Track which tools agents use and their outcomes
|
|
- **Model Call Monitoring**: Detailed insights into LLM interactions
|
|
- **Performance Analytics**: Monitor latency, token usage, and costs
|
|
- **Debugging Support**: Step-through execution for troubleshooting
|
|
- **Real-time Monitoring**: Live traces and metrics dashboard
|
|
|
|
## Setup Instructions
|
|
|
|
<Steps>
|
|
<Step title="Install LangDB">
|
|
Install the LangDB client with CrewAI feature flag:
|
|
```bash
|
|
pip install 'pylangdb[crewai]'
|
|
```
|
|
</Step>
|
|
<Step title="Set Environment Variables">
|
|
Configure your LangDB credentials:
|
|
```bash
|
|
export LANGDB_API_KEY="<your_langdb_api_key>"
|
|
export LANGDB_PROJECT_ID="<your_langdb_project_id>"
|
|
export LANGDB_API_BASE_URL='https://api.us-east-1.langdb.ai'
|
|
```
|
|
</Step>
|
|
<Step title="Initialize Tracing">
|
|
Import and initialize LangDB before configuring your CrewAI code:
|
|
```python
|
|
from pylangdb.crewai import init
|
|
# Initialize LangDB
|
|
init()
|
|
```
|
|
</Step>
|
|
<Step title="Configure CrewAI with LangDB">
|
|
Set up your LLM with LangDB headers:
|
|
```python
|
|
from crewai import Agent, Task, Crew, LLM
|
|
import os
|
|
|
|
# Configure LLM with LangDB headers
|
|
llm = 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")}
|
|
)
|
|
```
|
|
</Step>
|
|
</Steps>
|
|
|
|
## Quick Start Example
|
|
|
|
Here's a simple example to get you started with LangDB and CrewAI:
|
|
|
|
```python
|
|
import os
|
|
from pylangdb.crewai import init
|
|
from crewai import Agent, Task, Crew, LLM
|
|
|
|
# Initialize LangDB before any CrewAI imports
|
|
init()
|
|
|
|
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 agent
|
|
researcher = 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 task
|
|
task = 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 crew
|
|
crew = Crew(agents=[researcher], tasks=[task])
|
|
result = crew.kickoff()
|
|
print(result)
|
|
```
|
|
|
|
## Complete Example: Research and Planning Agent
|
|
|
|
This comprehensive example demonstrates a multi-agent workflow with research and planning capabilities.
|
|
|
|
### Prerequisites
|
|
|
|
```bash
|
|
pip install crewai 'pylangdb[crewai]' crewai_tools setuptools python-dotenv
|
|
```
|
|
|
|
### Environment Setup
|
|
|
|
```bash
|
|
# LangDB credentials
|
|
export LANGDB_API_KEY="<your_langdb_api_key>"
|
|
export LANGDB_PROJECT_ID="<your_langdb_project_id>"
|
|
export LANGDB_API_BASE_URL='https://api.us-east-1.langdb.ai'
|
|
|
|
# Additional API keys (optional)
|
|
export SERPER_API_KEY="<your_serper_api_key>" # For web search capabilities
|
|
```
|
|
|
|
### Complete Implementation
|
|
|
|
```python
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import sys
|
|
from pylangdb.crewai import init
|
|
init() # Initialize LangDB before any CrewAI imports
|
|
from dotenv import load_dotenv
|
|
from crewai import Agent, Task, Crew, Process, LLM
|
|
from crewai_tools import SerperDevTool
|
|
|
|
load_dotenv()
|
|
|
|
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")}
|
|
)
|
|
|
|
class ResearchPlanningCrew:
|
|
def researcher(self) -> Agent:
|
|
return Agent(
|
|
role="Research Specialist",
|
|
goal="Research topics thoroughly and compile comprehensive information",
|
|
backstory="Expert researcher with skills in finding and analyzing information from various sources",
|
|
tools=[SerperDevTool()],
|
|
llm=create_llm("openai/gpt-4o"),
|
|
verbose=True
|
|
)
|
|
|
|
def planner(self) -> Agent:
|
|
return Agent(
|
|
role="Strategic Planner",
|
|
goal="Create actionable plans based on research findings",
|
|
backstory="Strategic planner who breaks down complex challenges into executable plans",
|
|
reasoning=True,
|
|
max_reasoning_attempts=3,
|
|
llm=create_llm("openai/anthropic/claude-3.7-sonnet"),
|
|
verbose=True
|
|
)
|
|
|
|
def research_task(self) -> Task:
|
|
return Task(
|
|
description="Research the topic thoroughly and compile comprehensive information",
|
|
agent=self.researcher(),
|
|
expected_output="Comprehensive research report with key findings and insights"
|
|
)
|
|
|
|
def planning_task(self) -> Task:
|
|
return Task(
|
|
description="Create a strategic plan based on the research findings",
|
|
agent=self.planner(),
|
|
expected_output="Strategic execution plan with phases, goals, and actionable steps",
|
|
context=[self.research_task()]
|
|
)
|
|
|
|
def crew(self) -> Crew:
|
|
return Crew(
|
|
agents=[self.researcher(), self.planner()],
|
|
tasks=[self.research_task(), self.planning_task()],
|
|
verbose=True,
|
|
process=Process.sequential
|
|
)
|
|
|
|
def main():
|
|
topic = sys.argv[1] if len(sys.argv) > 1 else "Artificial Intelligence in Healthcare"
|
|
|
|
crew_instance = ResearchPlanningCrew()
|
|
|
|
# Update task descriptions with the specific topic
|
|
crew_instance.research_task().description = f"Research {topic} thoroughly and compile comprehensive information"
|
|
crew_instance.planning_task().description = f"Create a strategic plan for {topic} based on the research findings"
|
|
|
|
result = crew_instance.crew().kickoff()
|
|
print(result)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
```
|
|
|
|
### Running the Example
|
|
|
|
```bash
|
|
python main.py "Sustainable Energy Solutions"
|
|
```
|
|
|
|
## Viewing Traces in LangDB
|
|
|
|
After running your CrewAI application, you can view detailed traces in the LangDB dashboard:
|
|
|
|
<Frame caption="LangDB Trace Dashboard">
|
|
<img src="/images/langdb-2.png" alt="LangDB trace dashboard showing CrewAI workflow" />
|
|
</Frame>
|
|
|
|
### What You'll See
|
|
|
|
- **Agent Interactions**: Complete flow of agent conversations and task handoffs
|
|
- **Tool Usage**: Which tools were called, their inputs, and outputs
|
|
- **Model Calls**: Detailed LLM interactions with prompts image.pngand responses
|
|
- **Performance Metrics**: Latency, token usage, and cost tracking
|
|
- **Execution Timeline**: Step-by-step view of the entire workflow
|
|
|
|
|
|
## Troubleshooting
|
|
|
|
### Common Issues
|
|
|
|
- **No traces appearing**: Ensure `init()` is called before any CrewAI imports
|
|
- **Authentication errors**: Verify your LangDB API key and project ID
|
|
|
|
|
|
## Resources
|
|
|
|
<CardGroup cols={3}>
|
|
<Card title="LangDB Documentation" icon="book" href="https://docs.langdb.ai">
|
|
Official LangDB documentation and guides
|
|
</Card>
|
|
<Card title="LangDB Guides" icon="graduation-cap" href="https://docs.langdb.ai/guides">
|
|
Step-by-step tutorials for building AI agents
|
|
</Card>
|
|
<Card title="GitHub Examples" icon="github" href="https://github.com/langdb/langdb-samples/tree/main/examples/crewai" >
|
|
Complete CrewAI integration examples
|
|
</Card>
|
|
<Card title="LangDB Dashboard" icon="chart-line" href="https://app.langdb.ai">
|
|
Access your traces and analytics
|
|
</Card>
|
|
<Card title="Model Catalog" icon="list" href="https://app.langdb.ai/models">
|
|
Browse 350+ available language models
|
|
</Card>
|
|
<Card title="Enterprise Features" icon="building" href="https://docs.langdb.ai/enterprise">
|
|
Self-hosted options and enterprise capabilities
|
|
</Card>
|
|
</CardGroup>
|
|
|
|
## Next Steps
|
|
|
|
This guide covered the basics of integrating LangDB AI Gateway with CrewAI. To further enhance your AI workflows, explore:
|
|
|
|
- **Virtual Models**: Create custom model configurations with routing strategies
|
|
- **Guardrails & Safety**: Implement content filtering and compliance controls
|
|
- **Production Deployment**: Configure fallbacks, retries, and load balancing
|
|
|
|
For more advanced features and use cases, visit the [LangDB Documentation](https://docs.langdb.ai) or explore the [Model Catalog](https://app.langdb.ai/models) to discover all available models.
|