microsoft/semantic-kernel · error · AgentExecutionException

Agent Failure - Strategy unable to select next agent

Error message

Agent Failure - Strategy unable to select next agent: {agent_name}

What it means

The parser returned a name, but no agent in the group has a matching `.name` (`next((a for a in agents if a.name == agent_name), None)` is None). The error interpolates the offending name so you can see exactly what the function returned.

Solutions

  1. Ensure every selectable agent is added to the group chat so its .name is in the agents list.
  2. Make result_parser normalize the returned name (strip/lowercase) and map synonyms to the exact agent.name values.
  3. Update the selection function's prompt/instructions to list only the valid agent names.
  4. Log the returned {agent_name} to confirm exactly what the function emitted.

Example fix

// before
def parse(result):
    return result.value.strip()  # may return 'Agent One' but agent.name == 'agent_one'

// after
ALIASES = {"agent one": "agent_one", "agent_two": "agent_two"}
def parse(result):
    key = result.value.strip().lower()
    return ALIASES.get(key, key)
Defensive patterns

Strategy: validation

Validate before calling

valid_names = {a.name for a in agents}
name = strategy.result_parser(result)
if name not in valid_names:
    raise ValueError(f'parsed name {name!r} not among agents {sorted(valid_names)}')

Type guard

def is_known_agent(name: str, agents: list) -> bool:
    return name in {a.name for a in agents}

Try / catch

from semantic_kernel.exceptions.agent_exceptions import AgentExecutionException
try:
    agent = await strategy.next(agents, history)
except AgentExecutionException:
    agent = agents[0]  # graceful fallback

Prevention

When it happens

Trigger: The selection function returns a name that is not among the agents passed to the strategy: a hallucinated name, a casing/whitespace mismatch, or an agent that was never added to the group chat.

Common situations: Agent not registered in the AgentGroupChat; the prompt given to the selection function lists names that differ from agent.name; the LLM returns a slightly different spelling, role label, or extra text; case sensitivity ('Agent1' vs 'agent1').

Related errors


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

Appendix: source

Thrown at python/semantic_kernel/agents/strategies/selection/kernel_function_selection_strategy.py:114

        except Exception as ex:
            logger.error("Kernel Function Selection Strategy next method failed", exc_info=ex)
            raise AgentExecutionException("Agent Failure - Strategy failed to execute function.") from ex

        logger.info(
            f"Kernel Function Selection Strategy next method completed: "
            f"{self.function.plugin_name}, {self.function.name}, result: {result.value if result else None}",
        )

        agent_name = self.result_parser(result)
        if isawaitable(agent_name):
            agent_name = await agent_name

        if agent_name is None:
            raise AgentExecutionException("Agent Failure - Strategy unable to determine next agent.")

        agent_turn = next((agent for agent in agents if agent.name == agent_name), None)
        if agent_turn is None:
            raise AgentExecutionException(f"Agent Failure - Strategy unable to select next agent: {agent_name}")

        return agent_turn

View on GitHub (pinned to c028a0c7dc)