The Error
RuntimeError: GroupChat select_speaker failed to resolve the next speaker's name
This crashes mid-conversation when AutoGen's GroupChatManager can't figure out which agent goes next. The LLM was supposed to return one of your registered agent names. Instead it returned something unrecognizable β or nothing at all.
Root Causes
Several distinct things trigger this, and they require different fixes:
- LLM returned a name that doesn't match any agent β the model hallucinated a name, or added formatting like
"Agent: Coder"instead of the plain string"Coder". - Agent names contain spaces or special characters β names like
"Code Writer"or"agent-1"confuse the fuzzy matching AutoGen uses to parse LLM output. - Token limit hit during speaker selection β the selection prompt got truncated, and the model returned an empty or partial response.
- Weak model running the GroupChatManager β GPT-3.5 and most local LLMs fail this task surprisingly often. GPT-4-class models handle it reliably.
- Custom
speaker_selection_methodthrew an exception β if you passed a callable and it errored, AutoGen wraps it in this RuntimeError.
Fix 1: Use simple, single-word agent names
This one fix resolves the error for most people. Rename your agents to plain alphanumeric strings. No spaces. No hyphens. No underscores if you can avoid them.
import autogen
coder = autogen.AssistantAgent(
name="Coder", # Good: simple, single word
llm_config=llm_config,
)
reviewer = autogen.AssistantAgent(
name="Reviewer", # Good
llm_config=llm_config,
)
# Bad examples:
# name="Code Writer" β spaces break matching
# name="code-reviewer" β hyphens trip up the LLM
# name="agent_1" β underscores sometimes misread as spaces
Fix 2: Give the GroupChatManager a stronger model
Speaker selection is a separate LLM call β the manager isn't using whatever model your agents use. If the manager's model is weak, give it its own config pointing to GPT-4o or equivalent. Setting temperature=0 also helps: deterministic output means fewer hallucinated names.
manager_llm_config = {
"config_list": [{"model": "gpt-4o", "api_key": "..."}],
"temperature": 0,
}
group_chat = autogen.GroupChat(
agents=[user_proxy, coder, reviewer],
messages=[],
max_round=12,
)
manager = autogen.GroupChatManager(
groupchat=group_chat,
llm_config=manager_llm_config, # separate, stronger config
)
Fix 3: Skip the LLM entirely with deterministic selection
Don't need dynamic routing? Don't pay for it. Use "round_robin" or a custom callable and the speaker selection call never happens.
# Option A: round_robin β agents take turns in order
group_chat = autogen.GroupChat(
agents=[user_proxy, coder, reviewer],
messages=[],
max_round=10,
speaker_selection_method="round_robin",
)
# Option B: custom callable β full control
def my_speaker_selector(last_speaker, groupchat):
agents = groupchat.agents
last_idx = agents.index(last_speaker)
return agents[(last_idx + 1) % len(agents)]
group_chat = autogen.GroupChat(
agents=[user_proxy, coder, reviewer],
messages=[],
max_round=10,
speaker_selection_method=my_speaker_selector,
)
Fix 4: Increase max_retries_for_selecting_speaker
AutoGen 0.2.x includes a retry parameter built specifically for this failure mode. The default is 2 retries β often not enough when the model occasionally hiccups. Bumping it to 5 recovers most transient failures without any other changes.
group_chat = autogen.GroupChat(
agents=[user_proxy, coder, reviewer],
messages=[],
max_round=10,
max_retries_for_selecting_speaker=5, # default is 2
speaker_selection_method="auto",
)
Fix 5: Handle local LLM context window overflows
Running Ollama or LM Studio? The speaker selection prompt includes the full conversation history. At round 8 or 10, that history can push past a 4K or 8K context window. The model gets truncated input and returns garbage β or nothing.
Two knobs help: cap max_tokens for the speaker response (it only needs one word), and reduce max_round to keep history short.
llm_config = {
"config_list": [{
"model": "llama3",
"base_url": "http://localhost:11434/v1",
"api_key": "ollama",
}],
"max_tokens": 512, # speaker response is just a name
"temperature": 0,
}
group_chat = autogen.GroupChat(
agents=[user_proxy, coder, reviewer],
messages=[],
max_round=6, # fewer rounds = shorter context history
)
Fix 6: Migrated to autogen-agentchat 0.4.x?
The 0.4.x package rewrote the GroupChat API from scratch. Old GroupChatManager patterns don't exist anymore. Use RoundRobinGroupChat for deterministic ordering, or SelectorGroupChat when you need LLM-based routing.
from autogen_agentchat.teams import RoundRobinGroupChat, SelectorGroupChat
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
model_client = OpenAIChatCompletionClient(model="gpt-4o")
coder = AssistantAgent(name="Coder", model_client=model_client)
reviewer = AssistantAgent(name="Reviewer", model_client=model_client)
# Deterministic rotation
team = RoundRobinGroupChat([coder, reviewer], max_turns=10)
# LLM-based selection β use a capable model here
team = SelectorGroupChat(
[coder, reviewer],
model_client=model_client,
)
Verification
Run a minimal two-agent chat with a trivial task. If it completes cleanly, the fix worked.
import autogen
llm_config = {"config_list": [{"model": "gpt-4o", "api_key": "YOUR_KEY"}], "temperature": 0}
user = autogen.UserProxyAgent(name="User", human_input_mode="NEVER", max_consecutive_auto_reply=1)
coder = autogen.AssistantAgent(name="Coder", llm_config=llm_config)
gc = autogen.GroupChat(agents=[user, coder], messages=[], max_round=3)
mgr = autogen.GroupChatManager(groupchat=gc, llm_config=llm_config)
user.initiate_chat(mgr, message="Write a hello world in Python")
# Should complete without RuntimeError
Watch the logs after the run. select_speaker warnings are fine β they mean a retry succeeded. Actual errors mean the problem isn't fixed yet.
Prevention
- Stick to CamelCase single-word agent names:
Planner,Coder,Critic. Boring names don't cause bugs. - Set
temperature=0on the manager's LLM config. Deterministic output = fewer hallucinated speaker names. - For anything running in production, use
round_robinor a custom callable. LLM-driven routing ("auto") adds a failure point that's hard to debug at 2am. - Test speaker selection explicitly before building complex pipelines with local models β most sub-7B models fail this task under real conversation lengths.
- Pin
pyautogeninrequirements.txt. The 0.2.x β 0.4.x migration broke the entire GroupChat API, and it can happen again.

