{"record":{"id":"a491a9ccf8579d51","repo":"microsoft/semantic-kernel","slug":"entry-agent-is-not-defined-a491a9","errorCode":null,"errorMessage":"Entry agent is not defined.","messagePattern":"Entry agent is not defined\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/Orchestration/Sequential/SequentialOrchestration.cs","lineNumber":32,"sourceCode":"/// and sequentially passes each agent result to the next agent.\n/// </summary>\npublic class SequentialOrchestration<TInput, TOutput> : AgentOrchestration<TInput, TOutput>\n{\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"SequentialOrchestration{TInput, TOutput}\"/> class.\n    /// </summary>\n    /// <param name=\"agents\">The agents participating in the orchestration.</param>\n    public SequentialOrchestration(params Agent[] agents)\n        : base(agents)\n    {\n    }\n\n    /// <inheritdoc />\n    protected override async ValueTask StartAsync(IAgentRuntime runtime, TopicId topic, IEnumerable<ChatMessageContent> input, AgentType? entryAgent)\n    {\n        if (!entryAgent.HasValue)\n        {\n            throw new ArgumentException(\"Entry agent is not defined.\", nameof(entryAgent));\n        }\n        await runtime.PublishMessageAsync(input.AsRequestMessage(), entryAgent.Value).ConfigureAwait(false);\n    }\n\n    /// <inheritdoc />\n    protected override async ValueTask<AgentType?> RegisterOrchestrationAsync(IAgentRuntime runtime, OrchestrationContext context, RegistrationContext registrar, ILogger logger)\n    {\n        AgentType outputType = await registrar.RegisterResultTypeAsync<SequentialMessages.Response>(response => [response.Message]).ConfigureAwait(false);\n\n        // Each agent handsoff its result to the next agent.\n        AgentType nextAgent = outputType;\n        for (int index = this.Members.Count - 1; index >= 0; --index)\n        {\n            Agent agent = this.Members[index];\n            nextAgent = await RegisterAgentAsync(agent, index, nextAgent).ConfigureAwait(false);\n\n            logger.LogRegisterActor(this.OrchestrationLabel, nextAgent, \"MEMBER\", index + 1);\n        }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/Orchestration/Sequential/SequentialOrchestration.cs#L14-L50","documentation":"SequentialOrchestration.StartAsync requires a non-null entryAgent because the first agent in the chain must receive the input message. When entryAgent.HasValue is false it throws ArgumentException(nameof(entryAgent)). The entry agent is computed by RegisterOrchestrationAsync, which returns null when there are zero members, so an empty agents array propagates a null entry agent up to StartAsync.","triggerScenarios":"Constructing `new SequentialOrchestration(...)` with an empty `params Agent[]` so RegisterOrchestrationAsync's loop never runs and returns null; calling the protected StartAsync directly with `entryAgent: null`; a custom orchestration overriding registration to return null.","commonSituations":"Dynamically building the agents array from a filter/query that yields nothing; unit tests instantiating the orchestration with no members; config-driven agent lists where none are registered.","solutions":["Ensure at least one Agent is passed to the SequentialOrchestration constructor.","Validate the agents collection is non-empty before invoking: `if (agents.Length == 0) throw ...`.","If building the list dynamically, guard with a fallback/default agent so the chain always has an entry point."],"exampleFix":"// before\nvar orch = new SequentialOrchestration<TIn, TOut>(agents.Where(a => a.Enabled).ToArray());\n\n// after\nvar members = agents.Where(a => a.Enabled).ToArray();\nif (members.Length == 0) throw new InvalidOperationException(\"At least one agent is required.\");\nvar orch = new SequentialOrchestration<TIn, TOut>(members);","handlingStrategy":"validation","validationCode":"Agent[] members = GetAgents();\nif (members is null || members.Length == 0)\n{\n    throw new InvalidOperationException(\"SequentialOrchestration requires at least one agent.\");\n}\nvar orch = new SequentialOrchestration<TIn, TOut>(members);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the agents array is non-empty before constructing the orchestration.","When filtering agents dynamically, assert the result count is >= 1.","In tests, always supply at least one member."],"tags":["orchestration","sequential","validation","agents","dotnet"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}