{"record":{"id":"02b9fbc1b68713a8","repo":"microsoft/semantic-kernel","slug":"agent-failure-strategy-unable-to-select-next-age-02b9fb","errorCode":null,"errorMessage":"Agent Failure - Strategy unable to select next agent: {agent_name}","messagePattern":"Agent Failure - Strategy unable to select next agent: (.+?)","errorType":"exception","errorClass":"AgentExecutionException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/strategies/selection/kernel_function_selection_strategy.py","lineNumber":114,"sourceCode":"        except Exception as ex:\n            logger.error(\"Kernel Function Selection Strategy next method failed\", exc_info=ex)\n            raise AgentExecutionException(\"Agent Failure - Strategy failed to execute function.\") from ex\n\n        logger.info(\n            f\"Kernel Function Selection Strategy next method completed: \"\n            f\"{self.function.plugin_name}, {self.function.name}, result: {result.value if result else None}\",\n        )\n\n        agent_name = self.result_parser(result)\n        if isawaitable(agent_name):\n            agent_name = await agent_name\n\n        if agent_name is None:\n            raise AgentExecutionException(\"Agent Failure - Strategy unable to determine next agent.\")\n\n        agent_turn = next((agent for agent in agents if agent.name == agent_name), None)\n        if agent_turn is None:\n            raise AgentExecutionException(f\"Agent Failure - Strategy unable to select next agent: {agent_name}\")\n\n        return agent_turn\n","sourceCodeStart":96,"sourceCodeEnd":117,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/strategies/selection/kernel_function_selection_strategy.py#L96-L117","documentation":"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.","triggerScenarios":"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.","commonSituations":"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').","solutions":["Ensure every selectable agent is added to the group chat so its .name is in the agents list.","Make result_parser normalize the returned name (strip/lowercase) and map synonyms to the exact agent.name values.","Update the selection function's prompt/instructions to list only the valid agent names.","Log the returned {agent_name} to confirm exactly what the function emitted."],"exampleFix":"// before\ndef parse(result):\n    return result.value.strip()  # may return 'Agent One' but agent.name == 'agent_one'\n\n// after\nALIASES = {\"agent one\": \"agent_one\", \"agent_two\": \"agent_two\"}\ndef parse(result):\n    key = result.value.strip().lower()\n    return ALIASES.get(key, key)","handlingStrategy":"validation","validationCode":"valid_names = {a.name for a in agents}\nname = strategy.result_parser(result)\nif name not in valid_names:\n    raise ValueError(f'parsed name {name!r} not among agents {sorted(valid_names)}')","typeGuard":"def is_known_agent(name: str, agents: list) -> bool:\n    return name in {a.name for a in agents}","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentExecutionException\ntry:\n    agent = await strategy.next(agents, history)\nexcept AgentExecutionException:\n    agent = agents[0]  # graceful fallback","preventionTips":["Make result_parser normalize names (strip, lowercase, alias map)","Ensure all selectable agents are added to the group chat","Keep the prompt's agent list in sync with actual agent.name values"],"tags":["agents","selection-strategy","agent-group-chat","llm-output"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}