Claude API AutoGen Multi-Agent Setup Guide
Setting up Claude with AutoGen means configuring AutoGen's llm_config to talk to Anthropic's Messages API instead of OpenAI's, then wiring your agents into a GroupChat or sequential conversation pattern. The tricky part isn't AutoGen itself — it's that AutoGen was built OpenAI-first, so you need to either use its native Anthropic client support or write a thin adapter that translates AutoGen's expectations into Claude's request/response shape.
This guide walks through both approaches: the quick path using AutoGen's built-in api_type: "anthropic" config, and a custom client for cases where you need more control over streaming or tool calls. It also covers the practical side of running multi-agent systems on Claude — key management, cost tracking per agent, and rate limits — which matters more once you have five agents calling the API instead of one.
Installing the pieces
You'll need the AutoGen package and the Anthropic SDK:
pip install pyautogen anthropic
Set your Anthropic key as an environment variable:
export ANTHROPIC_API_KEY="sk-ant-..."
If you're routing through SubToAPI instead of a raw Anthropic key (useful for team usage tracking and seat-based billing), you'd set SUBTOAPI_KEY and point the base_url at https://api.subtoapi.app/v1 — more on that below.
Native Anthropic config in AutoGen
Recent versions of pyautogen support Anthropic models directly in the config list:
import os
from autogen import AssistantAgent, UserProxyAgent
config_list = [
{
"model": "claude-sonnet-4-5",
"api_key": os.environ["ANTHROPIC_API_KEY"],
"api_type": "anthropic",
}
]
llm_config = {"config_list": config_list, "temperature": 0.2}
assistant = AssistantAgent(
name="researcher",
llm_config=llm_config,
system_message="You research technical questions and cite sources.",
)
user_proxy = UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER",
code_execution_config={"work_dir": "coding", "use_docker": False},
)
user_proxy.initiate_chat(
assistant,
message="Summarize the trade-offs between REST and gRPC for internal APIs.",
)
This is enough for a basic single-agent loop. The real value of AutoGen shows up once you add more agents with distinct roles.
Multi-agent group chat with Claude
A common pattern is a researcher, a critic, and a writer agent coordinated through GroupChat:
from autogen import AssistantAgent, GroupChat, GroupChatManager
researcher = AssistantAgent(
name="researcher",
llm_config=llm_config,
system_message="Gather facts and technical details. Be concise.",
)
critic = AssistantAgent(
name="critic",
llm_config=llm_config,
system_message="Point out gaps, risks, or incorrect assumptions in prior messages.",
)
writer = AssistantAgent(
name="writer",
llm_config=llm_config,
system_message="Turn the discussion into a clear final answer.",
)
groupchat = GroupChat(
agents=[researcher, critic, writer],
messages=[],
max_round=8,
)
manager = GroupChatManager(groupchat=groupchat, llm_config=llm_config)
researcher.initiate_chat(
manager,
message="Draft a migration plan from a monolith to microservices for a 20-person team.",
)
Each agent gets its own system prompt but shares the same underlying model config. You can mix Claude models here too — a cheaper, faster model for the critic and a stronger one for the writer — by giving each agent a different config_list.
When native support isn't enough
If you need Claude-specific features AutoGen doesn't expose cleanly — strict tool-use schemas, streaming token-by-token to a UI, or extended thinking — write a custom model client class and register it with register_model_client. The client just needs to implement create() and message_retrieval() against the Anthropic Messages API (or an Anthropic-compatible endpoint). This is also where routing through SubToAPI instead of Anthropic directly becomes useful: you keep the same Messages-style request format, but get a sub_live_... application key, per-agent usage metadata, and streaming support without rewriting the adapter for each environment. See the quickstart and messages docs for the request shape, and streaming if your agents need incremental output.
Tool use across multiple agents
Multi-agent setups often need one agent to call a function (search, database query, calculator) and pass results to another agent. Claude's tool-use format works the same way regardless of how many agents are involved — define the tool schema once, attach it to the agent that needs it, and let AutoGen's function-execution hooks handle the loop:
assistant = AssistantAgent(
name="data_agent",
llm_config={
"config_list": config_list,
"tools": [
{
"name": "query_db",
"description": "Run a read-only SQL query",
"input_schema": {
"type": "object",
"properties": {"sql": {"type": "string"}},
"required": ["sql"],
},
}
],
},
)
If you're building this on top of SubToAPI, the tools docs cover the exact schema and response handling for tool calls, which matches what you'd wire into AutoGen's function map.
Managing keys and costs across agents
Once you have three or more agents in a loop, token usage adds up fast — every round-trip in a GroupChat is a full API call per agent. A few practical steps:
- Separate keys per environment. Use different application keys for dev, staging, and production AutoGen runs so a runaway loop in testing doesn't burn production quota.
- Cap
max_round. AutoGen will happily loop agents indefinitely if termination conditions aren't set; always define amax_roundor ais_termination_msgcheck. - Track usage per agent. If multiple team members are running agent experiments, a shared dashboard with per-key usage is far easier to audit than scattered
.envfiles. SubToAPI's plans (pricing) include team seats specifically for this — each developer or agent pipeline gets its own key under one billing account, and you can sign up for a free trial to test the setup before committing.
A minimal termination pattern
def is_termination(msg):
return "FINAL ANSWER" in msg.get("content", "")
groupchat = GroupChat(
agents=[researcher, critic, writer],
messages=[],
max_round=10,
)
manager = GroupChatManager(
groupchat=groupchat,
llm_config=llm_config,
is_termination_msg=is_termination,
)
Having the writer agent output a fixed phrase like FINAL ANSWER when done gives you a clean, predictable stopping point instead of relying only on round counts.
Questions
Does AutoGen support Claude natively, or do I need a wrapper? Recent pyautogen releases support Anthropic models through "api_type": "anthropic" in the config list, covering standard chat completions. For streaming, extended thinking, or custom tool schemas, a lightweight custom model client is more reliable than the built-in integration.
Can different agents in the same GroupChat use different Claude models? Yes. Each AssistantAgent takes its own llm_config, so you can assign a faster/cheaper model to agents doing simple tasks (like a critic) and a stronger model to agents producing final output.
How do I avoid runaway token usage in multi-agent loops? Always set max_round and a termination condition (is_termination_msg), use separate API keys per environment, and monitor usage per key — especially important once several agents or team members are generating traffic against the same account.