microsoft/autogen · error · ArgumentException

All agents must have a name.

Error message

All agents must have a name.

What it means

When a GroupChat is constructed, its Validation() method verifies every member agent exposes a non-null, non-empty Name. If any member returns null or "" from its Name property, construction fails with ArgumentException('All agents must have a name.'). The chat needs names to route messages, attribute speakers, and build role-play prompts, so an unnamed agent is unrecoverable at this point.

Source

Thrown at dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs:79

    /// <param name="initializeMessages"></param>
    public GroupChat(
        IEnumerable<IAgent> members,
        IOrchestrator orchestrator,
        IEnumerable<IMessage>? initializeMessages = null)
    {
        this.agents = members.ToList();
        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.");
            }

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Give every agent passed into GroupChat a unique non-empty Name (e.g. set the name parameter when constructing GPTAgent/AssistantAgent).
  2. Check members before construction: reject any agent where string.IsNullOrEmpty(agent.Name).
  3. If a Name getter throws (like GroupChatManager.Name), replace that member with the real underlying agents.
  4. When loading agents from config, validate the name field exists and fail fast with a clear config error.

Example fix

// before
var chat = new GroupChat(admin: adminAgent, members: new[] { unnamedAgent });

// after
var members = new List<IAgent> { new GPTAgent("writer", ...), new GPTAgent("critic", ...) };
if (members.Any(m => string.IsNullOrEmpty(m.Name)))
    throw new ConfigException("Every group chat member needs a name");
var chat = new GroupChat(admin: adminAgent, members: members);
Defensive patterns

Strategy: validation

Validate before calling

if (members.Any(m => string.IsNullOrWhiteSpace(SafeName(m))))
    throw new ConfigurationException("Every group chat member must have a non-empty Name");
var chat = new GroupChat(admin, members);

Try / catch

try { var chat = new GroupChat(admin, members); }
catch (ArgumentException ex) when (ex.Message.Contains("must have a name"))
{
    // identify and name the offending member, then retry construction
}

Prevention

When it happens

Trigger: new GroupChat(admin, members) where any member's Name is null or empty; custom IAgent implementations that return string.Empty; mocks/stubs used in tests that never set Name; accidentally including a GroupChatManager (whose Name throws) in members.

Common situations: Hand-rolled IAgent classes or test doubles without a Name; building agents from configuration where the name field was omitted; versions/middleware that produce anonymous agent instances.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/8a7ab5379ff7a484. Report an issue: GitHub.