microsoft/semantic-kernel · error · AgentExecutionException

Agent Failure - Strategy failed to execute function.

Error message

Agent Failure - Strategy failed to execute function.

What it means

KernelFunctionSelectionStrategy invokes a KernelFunction to choose the next agent; any exception raised by `self.function.invoke(kernel, arguments)` is caught and re-raised as AgentExecutionException. The original exception is chained as __cause__ and also logged. This is a generic wrapper, so the real failure is downstream.

Source

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

            **original_arguments,
            **extracted_settings,
            **{k: v for k, v in filtered_arguments.items()},
        }

        arguments = KernelArguments(
            **combined_arguments,
        )

        logger.info(
            f"Kernel Function Selection Strategy next method called, "
            f"invoking function: {self.function.plugin_name}, {self.function.name}",
        )

        try:
            result = await self.function.invoke(kernel=self.kernel, arguments=arguments)
        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)

Solutions

  1. Inspect the chained exception (`except AgentExecutionException as e: cause = e.__cause__`) to find the real error.
  2. Call `await strategy.function.invoke(kernel=kernel, arguments=...)` in isolation with the same arguments to reproduce the underlying fault.
  3. Confirm the AI service and execution settings are configured on the kernel and that the function/plugin is registered.
  4. Verify the variable names the function expects match agent_variable_name/history_variable_name (defaults _agent_ / _history_).

Example fix

// before
strategy = KernelFunctionSelectionStrategy(function=fn, kernel=kernel)
# kernel has no chat completion service configured -> invoke fails -> wrapped error

// after
kernel.add_service(AnthropicChatCompletion(ai_model_id="claude-3-5-sonnet-latest", api_key=...))
strategy = KernelFunctionSelectionStrategy(function=fn, kernel=kernel)
Defensive patterns

Strategy: try-catch

Validate before calling

# Validate the function executes with representative arguments before wiring it into the strategy
result = await strategy.function.invoke(kernel=kernel, arguments=test_args)
if result is None:
    raise ValueError('selection function returned None unexpectedly')

Try / catch

from semantic_kernel.exceptions.agent_exceptions import AgentExecutionException
try:
    agent = await strategy.next(agents, history)
except AgentExecutionException as e:
    cause = e.__cause__  # the real downstream error
    logger.error('selection failed: %r', cause)

Prevention

When it happens

Trigger: The selection function raises during invoke: a missing or misnamed kernel argument (agent_variable_name / history_variable_name), a prompt-template/render error, an AI service HTTP or auth error, a function that is not registered on the kernel, or a malformed result the invoke pipeline cannot process.

Common situations: Wrong or missing execution settings / AI service on the kernel; the function references variables not supplied by the strategy; API key or network problems; incompatible prompt template format; function plugin not added to the kernel.

Related errors


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