{"record":{"id":"ae7aa4c4286dfada","repo":"microsoft/semantic-kernel","slug":"agent-failure-strategy-unable-to-determine-next-ae7aa4","errorCode":null,"errorMessage":"Agent Failure - Strategy unable to determine next agent.","messagePattern":"Agent Failure - Strategy unable to determine next agent\\.","errorType":"exception","errorClass":"AgentExecutionException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/strategies/selection/kernel_function_selection_strategy.py","lineNumber":110,"sourceCode":"        )\n\n        try:\n            result = await self.function.invoke(kernel=self.kernel, arguments=arguments)\n        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":92,"sourceCodeEnd":117,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/strategies/selection/kernel_function_selection_strategy.py#L92-L117","documentation":"After the selection function succeeds, result_parser(result) must yield an agent name string. If it returns None (after awaiting if it is a coroutine), the strategy cannot proceed and raises AgentExecutionException. Note the default parser returns '' (empty string), which does NOT trigger this branch, so this requires a custom parser that returns None.","triggerScenarios":"A custom result_parser returns None for the given result, e.g. because it could not extract a name from the function output, or a code path returns None instead of a default.","commonSituations":"Parser logic that returns None on unexpected/empty LLM output; a parser that maps only known names and returns None for anything else; the function returned an empty or malformed result that the parser cannot handle.","solutions":["Make result_parser always return a valid agent name string, with an explicit fallback rather than None.","Improve the selection prompt/function so it consistently returns a parseable name.","Return the first agent's name or a known-safe default when parsing fails."],"exampleFix":"// before\ndef parse(result):\n    name = extract(result.value)\n    return name  # returns None when extraction fails\n\n// after\ndef parse(result):\n    name = extract(result.value)\n    return name or agents[0].name  # always a concrete name","handlingStrategy":"validation","validationCode":"name = strategy.result_parser(result)\nif isawaitable(name):\n    name = await name\nassert name is not None, 'result_parser returned None; provide a fallback name'","typeGuard":"def safe_parser(result, fallback: str) -> str:\n    value = parse(result)\n    return value if value is not None else fallback","tryCatchPattern":null,"preventionTips":["Never let result_parser return None; always return a concrete name","Provide a fallback to the first agent's name","Improve the prompt so the function reliably returns a parseable name"],"tags":["agents","selection-strategy","kernel-function","agent-group-chat"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}