Claude API CrewAI Agent Framework Setup Guide
CrewAI is a Python framework for orchestrating multiple LLM agents that each have a role, a goal, and a set of tools, working together on a shared task. Setting it up with Claude means configuring CrewAI's LLM layer to call Claude's models instead of (or alongside) OpenAI, then defining agents, tasks, and a crew that runs them in sequence or in parallel.
The short version: install crewai and langchain-anthropic (or point CrewAI's LLM wrapper at an Anthropic-compatible endpoint), set your API key as an environment variable, instantiate agents with llm=ChatAnthropic(model="claude-..."), and build a Crew from your agents and tasks. The rest of this guide walks through each piece, including the parts that trip people up — model naming, rate limits, and streaming behavior inside multi-agent loops.
Installing CrewAI and the Anthropic integration
Start with a clean virtual environment:
python -m venv .venv
source .venv/bin/activate
pip install crewai langchain-anthropic
CrewAI itself doesn't ship a native Anthropic client — it relies on LangChain's model wrappers under the hood for most non-OpenAI providers. langchain-anthropic gives you ChatAnthropic, which is what you'll pass into each agent's llm parameter.
Set your key as an environment variable rather than hardcoding it:
export ANTHROPIC_API_KEY="sk-ant-..."
If you're routing through a gateway that reshapes Claude as a standard HTTPS API — for example to centralize usage tracking across a team — you'd swap the base URL and key in the same spot without touching your agent code. SubToAPI issues sub_live_... keys for exactly this: your existing Claude access becomes a drop-in HTTPS endpoint with streaming, tool use, and per-key usage metadata, which is useful once you have several CrewAI agents each burning tokens independently and you want one dashboard to see who's spending what. Setup details are in the quickstart.
Configuring the LLM
from langchain_anthropic import ChatAnthropic
claude = ChatAnthropic(
model="claude-sonnet-4-20250514",
temperature=0.3,
max_tokens=4096,
)
Two things matter here that aren't obvious from CrewAI's docs:
- Model string format. CrewAI passes the model name straight through to the wrapper, so it has to match Anthropic's exact model identifier, not a shorthand like
claude-3. Check the current model list before deploying — typos here fail silently in some CrewAI versions and just fall back to a default. - Token limits per agent. Each agent call consumes
max_tokensindependently. In a crew with four agents doing sequential handoffs, a 4096 ceiling per agent can add up fast across a single task run. Lower it for agents that only need short structured outputs (classifiers, routers) and keep it higher for the one actually writing long-form content.
Defining agents
from crewai import Agent
researcher = Agent(
role="Research Analyst",
goal="Find and summarize recent information on {topic}",
backstory="You are a meticulous analyst who verifies claims before reporting them.",
llm=claude,
verbose=True,
)
writer = Agent(
role="Content Writer",
goal="Turn research findings into a clear, structured draft",
backstory="You write concisely and avoid unsupported claims.",
llm=claude,
verbose=True,
)
The backstory field isn't decorative — it's injected into Claude's system context and genuinely shapes output tone. Treat it like a mini system prompt rather than filler text.
Defining tasks and the crew
from crewai import Task, Crew, Process
research_task = Task(
description="Research {topic} and list the three most important recent developments.",
expected_output="A bulleted list of three developments with one-sentence context each.",
agent=researcher,
)
writing_task = Task(
description="Write a 300-word summary based on the research findings.",
expected_output="A 300-word plain-text summary.",
agent=writer,
context=[research_task],
)
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
process=Process.sequential,
)
result = crew.kickoff(inputs={"topic": "edge AI inference costs"})
print(result)
context=[research_task] is what passes the first agent's output into the second one's prompt. Without it, the writer agent runs blind and just invents content from its goal description alone — a common source of "why is my crew output generic" bug reports.
Adding tools
Claude agents in CrewAI can call tools the same way any LangChain-compatible agent does:
from crewai_tools import SerperDevTool
researcher = Agent(
role="Research Analyst",
goal="Find current information on {topic}",
backstory="...",
llm=claude,
tools=[SerperDevTool()],
)
Claude's native tool-use format is different from OpenAI's function-calling schema, and most of the translation happens inside langchain-anthropic — you generally don't need to touch it. If you're building tool-calling behavior outside CrewAI and want to see the raw request/response shape Claude expects, the tools reference is worth reading once so you understand what's happening under the abstraction.
Common setup problems
- Rate limit errors mid-crew. A crew with parallel agents (
Process.hierarchicalor custom async setups) can fire several Claude calls at once, especially during retries. If you hit 429s, add backoff at the LLM wrapper level or reduce concurrent agents. - Context window bleed. CrewAI passes prior task outputs as context, which grows with each step. On long crews this can quietly push you toward the model's context limit — trim
expected_outputdescriptions and avoid chaining more than 4-5 tasks without summarization steps in between. - Streaming inside a crew. CrewAI's default
kickoff()is blocking; it doesn't stream token-by-token to your terminal by default. If you need real-time visibility into what Claude is generating per agent, you'll need to configure callbacks onChatAnthropicdirectly or inspect streaming if you're building your own wrapper around a gateway. - Key management across agents. Every agent in a crew usually shares one
ANTHROPIC_API_KEY. If you want to track usage per agent or per team member building crews, a single shared key makes that invisible. Routing through SubToAPI and issuing separate keys per project gives you that breakdown without changing agent code — just the base URL and key each agent'sChatAnthropicinstance points to.
Testing the setup
Before running a full multi-agent crew, verify the Claude connection in isolation:
from langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(model="claude-sonnet-4-20250514")
response = llm.invoke("Reply with the word 'connected' only.")
print(response.content)
If this returns connected, your credentials and model name are correct and any further issues are CrewAI-specific, not Claude-specific — a useful first debugging step whenever a crew fails silently.
questions
Does CrewAI support Claude natively, or only through LangChain? CrewAI relies on LangChain-style model wrappers for non-OpenAI providers, so you use langchain-anthropic's ChatAnthropic class as the llm for each agent rather than a CrewAI-native Claude client.
Can different agents in the same crew use different Claude models? Yes. Each Agent takes its own llm instance, so you can assign a cheaper, faster model to routing or classification agents and a stronger model to the agent producing final output.
Why does my crew ignore my Claude system prompt? CrewAI builds the system prompt from the agent's role, goal, and backstory fields rather than a raw string you pass in — edit those fields instead of trying to inject a separate system message directly.