{"record":{"id":"8a7ab5379ff7a484","repo":"microsoft/autogen","slug":"all-agents-must-have-a-name","errorCode":null,"errorMessage":"All agents must have a name.","messagePattern":"All agents must have a name\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs","lineNumber":79,"sourceCode":"    /// <param name=\"initializeMessages\"></param>\n    public GroupChat(\n        IEnumerable<IAgent> members,\n        IOrchestrator orchestrator,\n        IEnumerable<IMessage>? initializeMessages = null)\n    {\n        this.agents = members.ToList();\n        this.initializeMessages = initializeMessages ?? new List<IMessage>();\n        this.orchestrator = orchestrator;\n\n        this.Validation();\n    }\n\n    private void Validation()\n    {\n        // check if all agents has a name\n        if (this.agents.Any(x => string.IsNullOrEmpty(x.Name)))\n        {\n            throw new ArgumentException(\"All agents must have a name.\");\n        }\n\n        // check if any agents has the same name\n        var names = this.agents.Select(x => x.Name).ToList();\n        if (names.Distinct().Count() != names.Count)\n        {\n            throw new ArgumentException(\"All agents must have a unique name.\");\n        }\n\n        // if there's a workflow\n        // check if the agents in that workflow are in the group chat\n        if (this.workflow != null)\n        {\n            var agentNamesInWorkflow = this.workflow.Transitions.Select(x => x.From.Name!).Concat(this.workflow.Transitions.Select(x => x.To.Name!)).Distinct();\n            if (agentNamesInWorkflow.Any(x => !this.agents.Select(a => a.Name).Contains(x)))\n            {\n                throw new ArgumentException(\"All agents in the workflow must be in the group chat.\");\n            }","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Core/GroupChat/GroupChat.cs#L61-L97","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Give every agent passed into GroupChat a unique non-empty Name (e.g. set the name parameter when constructing GPTAgent/AssistantAgent).","Check members before construction: reject any agent where string.IsNullOrEmpty(agent.Name).","If a Name getter throws (like GroupChatManager.Name), replace that member with the real underlying agents.","When loading agents from config, validate the name field exists and fail fast with a clear config error."],"exampleFix":"// before\nvar chat = new GroupChat(admin: adminAgent, members: new[] { unnamedAgent });\n\n// after\nvar members = new List<IAgent> { new GPTAgent(\"writer\", ...), new GPTAgent(\"critic\", ...) };\nif (members.Any(m => string.IsNullOrEmpty(m.Name)))\n    throw new ConfigException(\"Every group chat member needs a name\");\nvar chat = new GroupChat(admin: adminAgent, members: members);","handlingStrategy":"validation","validationCode":"if (members.Any(m => string.IsNullOrWhiteSpace(SafeName(m))))\n    throw new ConfigurationException(\"Every group chat member must have a non-empty Name\");\nvar chat = new GroupChat(admin, members);","typeGuard":null,"tryCatchPattern":"try { var chat = new GroupChat(admin, members); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"must have a name\"))\n{\n    // identify and name the offending member, then retry construction\n}","preventionTips":["Always pass an explicit name when constructing agents destined for a group chat.","Validate members with a pre-check before GroupChat construction.","Audit test doubles and custom IAgent implementations for missing Name implementations."],"tags":["autogen","dotnet","group-chat","validation","argumentexception"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}