Skip to main content

CrewAI Integration

Build multi-agent systems using CrewAI with Lucid’s verifiable infrastructure. Every agent action generates a cryptographic receipt, creating a full audit trail.

Setup

pip install crewai lucid-crewai

Basic Crew

from crewai import Agent, Task, Crew
from lucid_crewai import LucidLLM

# Use Lucid as the LLM provider — all calls go through TrustGate
llm = LucidLLM(
    api_key="your-lucid-api-key",
    base_url="https://api.lucid.foundation/v1",
)

researcher = Agent(
    role="Researcher",
    goal="Find accurate information about the topic",
    backstory="You are an expert researcher with access to multiple sources.",
    llm=llm,
)

writer = Agent(
    role="Writer",
    goal="Create clear, compelling content",
    backstory="You are a skilled technical writer.",
    llm=llm,
)

research_task = Task(
    description="Research the latest developments in {topic}",
    agent=researcher,
    expected_output="A detailed research summary with sources",
)

write_task = Task(
    description="Write a blog post based on the research",
    agent=writer,
    expected_output="A 500-word blog post",
    context=[research_task],
)

crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, write_task],
    verbose=True,
)

result = crew.kickoff(inputs={"topic": "verifiable AI"})

Verifiable Crews

Every LLM call made by CrewAI agents generates a Lucid receipt. After execution, you can retrieve the full audit trail:
from lucid import Lucid

client = Lucid(api_key="your-lucid-api-key")

# Get all receipts from the last hour
receipts = client.receipts.list(
    since="1h",
    metadata={"source": "crewai"},
)

for receipt in receipts:
    print(f"Agent: {receipt.metadata.get('agent_role')}")
    print(f"Model: {receipt.model}")
    print(f"Tokens: {receipt.usage.total_tokens}")
    print(f"Verified: {receipt.signature_valid}")

Multi-Model Crews

Use different models for different agents via passport routing:
researcher = Agent(
    role="Researcher",
    llm=LucidLLM(api_key=KEY, model="gpt-4o"),
)

writer = Agent(
    role="Writer",
    llm=LucidLLM(api_key=KEY, model="claude-3-sonnet"),
)

coder = Agent(
    role="Developer",
    llm=LucidLLM(api_key=KEY, model="deepseek-coder"),
)
TrustGate handles routing to the correct provider for each model.

With MCPGate Tools

Give CrewAI agents access to MCPGate tools:
from lucid_crewai import MCPGateTool

devops_agent = Agent(
    role="DevOps",
    goal="Monitor and respond to incidents",
    tools=[
        MCPGateTool(server="github", tool="create_issue"),
        MCPGateTool(server="slack", tool="post_message"),
    ],
    llm=llm,
)