{"record":{"id":"d60b7ee89ee78f8e","repo":"microsoft/semantic-kernel","slug":"agent-failure-no-agents-present-to-select-d60b7e","errorCode":null,"errorMessage":"Agent Failure - No agents present to select.","messagePattern":"Agent Failure - No agents present to select\\.","errorType":"exception","errorClass":"AgentExecutionException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/strategies/selection/selection_strategy.py","lineNumber":37,"sourceCode":"    has_selected: bool = False\n    initial_agent: Agent | None = None\n\n    async def next(\n        self,\n        agents: list[Agent],\n        history: list[\"ChatMessageContent\"],\n    ) -> Agent:\n        \"\"\"Select the next agent to interact with.\n\n        Args:\n            agents: The list of agents to select from.\n            history: The history of messages in the conversation.\n\n        Returns:\n            The agent who takes the next turn.\n        \"\"\"\n        if not agents and self.initial_agent is None:\n            raise AgentExecutionException(\"Agent Failure - No agents present to select.\")\n\n        # If it's the first selection and we have an initial agent, use it\n        if not self.has_selected and self.initial_agent is not None:\n            agent = self.initial_agent\n        else:\n            agent = await self.select_agent(agents, history)\n\n        self.has_selected = True\n        return agent\n\n    async def select_agent(\n        self,\n        agents: list[Agent],\n        history: list[\"ChatMessageContent\"],\n    ) -> Agent:\n        \"\"\"Determines which agent goes next. Override for custom logic.\n\n        By default, this fallback returns the first agent in the list.","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/strategies/selection/selection_strategy.py#L19-L55","documentation":"SelectionStrategy.next raises AgentExecutionException when the agents list is empty AND initial_agent is None. There is simply no agent to select. If initial_agent is set it is used on the first turn, so the error specifically means both sources are missing.","triggerScenarios":"Starting a group chat selection with an empty agents list and no initial_agent configured on the strategy.","commonSituations":"AgentGroupChat created with no agents added; agents filtered/removed before selection; a custom flow that passes an empty list and forgot to set initial_agent.","solutions":["Add at least one agent to the group chat before invoking selection.","Set SelectionStrategy.initial_agent so the first turn has a fallback even if the list is empty.","Guard upstream: if not agents, short-circuit instead of calling next()."],"exampleFix":"// before\nchat = AgentGroupChat(agents=[], selection_strategy=strat)\nawait chat.invoke()  # no agents and no initial_agent -> error\n\n// after\nchat = AgentGroupChat(agents=[agent1, agent2], selection_strategy=strat)\n# or set: strat.initial_agent = agent1","handlingStrategy":"validation","validationCode":"if not agents and strategy.initial_agent is None:\n    raise ValueError('no agents and no initial_agent configured')\nawait strategy.next(agents, history)","typeGuard":"def has_selectable(agents: list, strategy) -> bool:\n    return bool(agents) or strategy.initial_agent is not None","tryCatchPattern":null,"preventionTips":["Always add at least one agent to the group chat","Set SelectionStrategy.initial_agent as a first-turn fallback","Short-circuit upstream when the agent list is empty"],"tags":["agents","selection-strategy","agent-group-chat","config"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}