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

  1. Add at least one agent to the group chat before invoking selection.
  2. Set SelectionStrategy.initial_agent so the first turn has a fallback even if the list is empty.
  3. 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

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


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/d60b7ee89ee78f8e. Report an issue: GitHub.