microsoft/autogen · error · ArgumentException

All agents in the workflow must be in the group chat.

Error message

All agents in the workflow must be in the group chat.

What it means

If a GroupChat is created with a workflow, Validation() extracts every agent name appearing as From or To in the workflow's transitions and confirms each is a member of the chat. Any transition endpoint not present in the members list causes ArgumentException('All agents in the workflow must be in the group chat.'). A workflow referencing an outsider could never route to it, so the configuration is rejected up front.

Source

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

        {
            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.
    /// Otherwise, the admin will be invoked to decide the next speaker using role-play prompt.
    /// </summary>
    /// <param name="currentSpeaker">current speaker</param>
    /// <param name="conversationHistory">conversation history</param>
    /// <returns>next speaker.</returns>
    [Obsolete("Please use RolePlayOrchestrator or WorkflowOrchestrator")]
    public async Task<IAgent> SelectNextSpeakerAsync(IAgent currentSpeaker, IEnumerable<IMessage> conversationHistory)
    {
        var agentNames = this.agents.Select(x => x.Name).ToList();
        if (this.workflow != null)

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Add every agent referenced by workflow transitions (both From and To endpoints) to the GroupChat members list.
  2. Rebuild the workflow whenever an agent's Name changes, since transitions capture agent identity by name.
  3. Add a pre-check that workflow.Transitions endpoints are a subset of member names before constructing the chat.
  4. Prefer the newer RolePlayOrchestrator/WorkflowOrchestrator APIs if you are restructuring routing anyway.

Example fix

// before
var workflow = new Graph();
workflow.AddTransition(Transition.Create(a, b));
workflow.AddTransition(Transition.Create(b, c)); // c not a member
var chat = new GroupChat(admin, members: new[] { a, b }, workflow: workflow);

// after
var chat = new GroupChat(admin, members: new[] { a, b, c }, workflow: workflow);
Defensive patterns

Strategy: validation

Validate before calling

var memberNames = members.Select(m => m.Name).ToHashSet();
var missing = workflow.Transitions
    .SelectMany(t => new[] { t.From.Name!, t.To.Name! })
    .Where(n => !memberNames.Contains(n))
    .ToList();
if (missing.Count > 0)
    throw new ConfigurationException($"Workflow references non-member agents: {string.Join(", ", missing)}");

Try / catch

try { var chat = new GroupChat(admin, members, workflow); }
catch (ArgumentException ex) when (ex.Message.Contains("must be in the group chat"))
{
    // add missing agents to members, or rebuild workflow without those transitions
}

Prevention

When it happens

Trigger: Building a Graph/Workflow with agents A, B, C but constructing GroupChat with only A and B; renaming an agent after wiring it into workflow transitions; reusing a workflow object built against a different set of agents.

Common situations: Refactoring agent names without rebuilding the workflow; sharing a static workflow definition across chats with varying membership; adding a transition to a new agent but forgetting to add that agent to the group chat constructor.

Related errors


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