microsoft/autogen · error · ArgumentException
All agents must have a unique name.
Error message
All agents must have a unique name.
What it means
GroupChat.Validation() requires all member agents to have distinct names. It collects agents.Select(x => x.Name) and, if names.Distinct().Count() != names.Count, throws ArgumentException('All agents must have a unique name.'). Names are the identity used for speaker selection and message attribution, so duplicates would make routing ambiguous.
Source
Thrown at dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs:86
this.initializeMessages = initializeMessages ?? new List<IMessage>();
this.orchestrator = orchestrator;
this.Validation();
}
private void Validation()
{
// check if all agents has a name
if (this.agents.Any(x => string.IsNullOrEmpty(x.Name)))
{
throw new ArgumentException("All agents must have a name.");
}
// check if any agents has the same name
var names = this.agents.Select(x => x.Name).ToList();
if (names.Distinct().Count() != names.Count)
{
throw new ArgumentException("All agents must have a unique name.");
}
// if there's a workflow
// check if the agents in that workflow are in the group chat
if (this.workflow != null)
{
var agentNamesInWorkflow = this.workflow.Transitions.Select(x => x.From.Name!).Concat(this.workflow.Transitions.Select(x => x.To.Name!)).Distinct();
if (agentNamesInWorkflow.Any(x => !this.agents.Select(a => a.Name).Contains(x)))
{
throw new ArgumentException("All agents in the workflow must be in the group chat.");
}
}
}
/// <summary>
/// Select the next speaker based on the conversation history.
/// The next speaker will be decided by a combination effort of the admin and the workflow.
/// Firstly, a group of candidates will be selected by the workflow. If there's only one candidate, then that candidate will be the next speaker.View on GitHub (pinned to 027ecf0a37)
Solutions
- Assign a distinct Name to each member, e.g. suffix loop indices ("worker-0", "worker-1").
- Pre-validate with GroupBy before construction and fail with a clear message showing the duplicates.
- If two agents intentionally play the same role, either rename them ("summarizer-a"/"summarizer-b") or use a single agent.
- Note the comparison is case-sensitive: "Critic" and "critic" both pass validation, but downstream matching lowercases names, so avoid case variants too.
Example fix
// before
var members = Enumerable.Range(0, 3).Select(_ => new GPTAgent("worker", ...));
var chat = new GroupChat(admin, members);
// after
var members = Enumerable.Range(0, 3).Select(i => new GPTAgent($"worker-{i}", ...));
var chat = new GroupChat(admin, members); Defensive patterns
Strategy: validation
Validate before calling
var names = members.Select(m => m.Name).ToList();
var duplicates = names.GroupBy(n => n).Where(g => g.Count() > 1).Select(g => g.Key).ToList();
if (duplicates.Count > 0)
throw new ConfigurationException($"Duplicate agent names: {string.Join(", ", duplicates)}"); Try / catch
try { var chat = new GroupChat(admin, members); }
catch (ArgumentException ex) when (ex.Message.Contains("unique name"))
{
// rename the duplicate members (e.g. suffix an index) and retry
} Prevention
- Generate names programmatically (base + index) when creating agents in loops.
- Run a distinctness pre-check on member names before construction.
- Avoid case-variant names; downstream matching lowercases, which creates subtle routing bugs even though validation passes.
When it happens
Trigger: Passing two agents constructed with the same name string (e.g. two GPTAgent("assistant", ...)); generating members in a loop with a constant name; case-sensitive duplicates like "Agent" vs "Agent" (the check is ordinal, so exact matches only).
Common situations: Copy-pasted agent setup code where the name wasn't changed; factory loops creating N agents with the same label; merging agents from different modules that happen to share a default name.
Related errors
- All agents must have a name.
- All agents in the workflow must be in the group chat.
- GroupChatManager does not have a name
- No next available agents found in the current workflow
- No admin is provided.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/64e93b3c97c7a8bd.
Report an issue: GitHub.