microsoft/semantic-kernel · error · AgentExecutionException
Agent Failure - No agents present to select.
Error message
Agent Failure - No agents present to select.
What it means
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.
Source
Thrown at python/semantic_kernel/agents/strategies/selection/selection_strategy.py:37
has_selected: bool = False
initial_agent: Agent | None = None
async def next(
self,
agents: list[Agent],
history: list["ChatMessageContent"],
) -> Agent:
"""Select the next agent to interact with.
Args:
agents: The list of agents to select from.
history: The history of messages in the conversation.
Returns:
The agent who takes the next turn.
"""
if not agents and self.initial_agent is None:
raise AgentExecutionException("Agent Failure - No agents present to select.")
# If it's the first selection and we have an initial agent, use it
if not self.has_selected and self.initial_agent is not None:
agent = self.initial_agent
else:
agent = await self.select_agent(agents, history)
self.has_selected = True
return agent
async def select_agent(
self,
agents: list[Agent],
history: list["ChatMessageContent"],
) -> Agent:
"""Determines which agent goes next. Override for custom logic.
By default, this fallback returns the first agent in the list.View on GitHub (pinned to c028a0c7dc)
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().
Example fix
// before chat = AgentGroupChat(agents=[], selection_strategy=strat) await chat.invoke() # no agents and no initial_agent -> error // after chat = AgentGroupChat(agents=[agent1, agent2], selection_strategy=strat) # or set: strat.initial_agent = agent1
Defensive patterns
Strategy: validation
Validate before calling
if not agents and strategy.initial_agent is None:
raise ValueError('no agents and no initial_agent configured')
await strategy.next(agents, history) Type guard
def has_selectable(agents: list, strategy) -> bool:
return bool(agents) or strategy.initial_agent is not None Prevention
- 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
When it happens
Trigger: Starting a group chat selection with an empty agents list and no initial_agent configured on the strategy.
Common situations: 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.
Related errors
- Agent Failure - Strategy failed to execute function.
- Agent Failure - Strategy unable to determine next agent.
- Agent Failure - Strategy unable to select next agent: {agent
- No agents to select from
- Subclasses should implement this method
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/d60b7ee89ee78f8e.
Report an issue: GitHub.