microsoft/semantic-kernel · error · AgentInvokeException

FunctionChoiceBehavior.Auto(auto_invoke=False) is not suppor

Error message

FunctionChoiceBehavior.Auto(auto_invoke=False) is not supported for agent invocations. The agent run loop manages tool invocation; disabling auto_invoke is not compatible.

What it means

Raised when FunctionChoiceBehavior.Auto is supplied to an AzureAIAgent invocation but auto_invoke_kernel_functions is False. The Azure AI service run loop owns tool invocation server-side; disabling client-side auto_invoke conflicts with that contract.

Source

Thrown at python/semantic_kernel/agents/azure_ai/agent_thread_actions.py:998

            tool["function"]["name"] for tool in existing_tools if "function" in tool and "name" in tool["function"]
        }
        return [tool for tool in new_tools if tool.get("function", {}).get("name") not in existing_names]

    @staticmethod
    def _validate_function_choice_behavior(
        function_choice_behavior: FunctionChoiceBehavior | None,
    ) -> None:
        """Validate the function choice behavior is compatible with agent invocations."""
        if function_choice_behavior is None:
            return
        if function_choice_behavior.type_ != FunctionChoiceType.AUTO:
            raise AgentInvokeException(
                f"FunctionChoiceBehavior with type '{function_choice_behavior.type_}' is not supported for agent "
                "invocations. Use FunctionChoiceBehavior.Auto(filters=...) to control which kernel functions "
                "are available."
            )
        if not function_choice_behavior.auto_invoke_kernel_functions:
            raise AgentInvokeException(
                "FunctionChoiceBehavior.Auto(auto_invoke=False) is not supported for agent invocations. "
                "The agent run loop manages tool invocation; disabling auto_invoke is not compatible."
            )
        valid_filter_keys: set[str] = {
            "excluded_plugins",
            "included_plugins",
            "excluded_functions",
            "included_functions",
        }
        if function_choice_behavior.filters is not None:
            if not function_choice_behavior.filters:
                raise AgentInvokeException(
                    "FunctionChoiceBehavior filters must not be empty. Provide at least one filter key "
                    f"from {sorted(valid_filter_keys)}, or omit filters entirely to include all "
                    "kernel functions."
                )
            unknown_keys = {str(k) for k in function_choice_behavior.filters} - valid_filter_keys
            if unknown_keys:

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Use FunctionChoiceBehavior.Auto() with auto_invoke left at its default (True) and rely on FunctionInvocationFilter / function_invoking hooks to intercept/approve calls.
  2. Remove the behavior argument so the agent manages tool invocation by default.
  3. If manual-only invocation is mandatory, use a different agent type (e.g. ChatCompletionAgent) that supports the manual loop.

Example fix

// before
behavior = FunctionChoiceBehavior.Auto(auto_invoke=False)

// after
behavior = FunctionChoiceBehavior.Auto()
kernel.add_filter(
    FilterTypes.FUNCTION_INVOCATION,
    MyApprovalFilter(),  # approve/veto per call
)
Defensive patterns

Strategy: validation

Validate before calling

def ensure_auto_invoke(behavior):
    if behavior is None:
        return None
    if behavior.type_ == FunctionChoiceType.AUTO and not behavior.auto_invoke_kernel_functions:
        return FunctionChoiceBehavior.Auto(filters=behavior.filters)
    return behavior

Type guard

def is_auto_invoke(b: object) -> bool:
    return b is None or (
        getattr(b, "type_", None) == FunctionChoiceType.AUTO
        and getattr(b, "auto_invoke_kernel_functions", True) is True
    )

Try / catch

try:
    await agent.invoke(thread, function_choice_behavior=fcb)
except AgentInvokeException as e:
    if "auto_invoke=False" in str(e):
        fcb = FunctionChoiceBehavior.Auto()
        await agent.invoke(thread, function_choice_behavior=fcb)
    raise

Prevention

When it happens

Trigger: Constructing FunctionChoiceBehavior.Auto(auto_invoke=False) explicitly and passing it to the agent's invoke flow, or reusing a behavior configured for a manual tool-calling chat completion path.

Common situations: Developer wants to intercept and manually approve each tool call before execution, a pattern valid for kernel.invoke_async but unsupported by the AzureAIAgent hosted run loop.

Related errors


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