{"record":{"id":"65c3925a78302cda","repo":"microsoft/semantic-kernel","slug":"functionchoicebehavior-auto-auto-invoke-false-is","errorCode":null,"errorMessage":"FunctionChoiceBehavior.Auto(auto_invoke=False) is not supported for agent invocations. The agent run loop manages tool invocation; disabling auto_invoke is not compatible.","messagePattern":"FunctionChoiceBehavior\\.Auto\\(auto_invoke=False\\) is not supported for agent invocations\\. The agent run loop manages tool invocation; disabling auto_invoke is not compatible\\.","errorType":"validation","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/azure_ai/agent_thread_actions.py","lineNumber":998,"sourceCode":"            tool[\"function\"][\"name\"] for tool in existing_tools if \"function\" in tool and \"name\" in tool[\"function\"]\n        }\n        return [tool for tool in new_tools if tool.get(\"function\", {}).get(\"name\") not in existing_names]\n\n    @staticmethod\n    def _validate_function_choice_behavior(\n        function_choice_behavior: FunctionChoiceBehavior | None,\n    ) -> None:\n        \"\"\"Validate the function choice behavior is compatible with agent invocations.\"\"\"\n        if function_choice_behavior is None:\n            return\n        if function_choice_behavior.type_ != FunctionChoiceType.AUTO:\n            raise AgentInvokeException(\n                f\"FunctionChoiceBehavior with type '{function_choice_behavior.type_}' is not supported for agent \"\n                \"invocations. Use FunctionChoiceBehavior.Auto(filters=...) to control which kernel functions \"\n                \"are available.\"\n            )\n        if not function_choice_behavior.auto_invoke_kernel_functions:\n            raise AgentInvokeException(\n                \"FunctionChoiceBehavior.Auto(auto_invoke=False) is not supported for agent invocations. \"\n                \"The agent run loop manages tool invocation; disabling auto_invoke is not compatible.\"\n            )\n        valid_filter_keys: set[str] = {\n            \"excluded_plugins\",\n            \"included_plugins\",\n            \"excluded_functions\",\n            \"included_functions\",\n        }\n        if function_choice_behavior.filters is not None:\n            if not function_choice_behavior.filters:\n                raise AgentInvokeException(\n                    \"FunctionChoiceBehavior filters must not be empty. Provide at least one filter key \"\n                    f\"from {sorted(valid_filter_keys)}, or omit filters entirely to include all \"\n                    \"kernel functions.\"\n                )\n            unknown_keys = {str(k) for k in function_choice_behavior.filters} - valid_filter_keys\n            if unknown_keys:","sourceCodeStart":980,"sourceCodeEnd":1016,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/azure_ai/agent_thread_actions.py#L980-L1016","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use FunctionChoiceBehavior.Auto() with auto_invoke left at its default (True) and rely on FunctionInvocationFilter / function_invoking hooks to intercept/approve calls.","Remove the behavior argument so the agent manages tool invocation by default.","If manual-only invocation is mandatory, use a different agent type (e.g. ChatCompletionAgent) that supports the manual loop."],"exampleFix":"// before\nbehavior = FunctionChoiceBehavior.Auto(auto_invoke=False)\n\n// after\nbehavior = FunctionChoiceBehavior.Auto()\nkernel.add_filter(\n    FilterTypes.FUNCTION_INVOCATION,\n    MyApprovalFilter(),  # approve/veto per call\n)","handlingStrategy":"validation","validationCode":"def ensure_auto_invoke(behavior):\n    if behavior is None:\n        return None\n    if behavior.type_ == FunctionChoiceType.AUTO and not behavior.auto_invoke_kernel_functions:\n        return FunctionChoiceBehavior.Auto(filters=behavior.filters)\n    return behavior","typeGuard":"def is_auto_invoke(b: object) -> bool:\n    return b is None or (\n        getattr(b, \"type_\", None) == FunctionChoiceType.AUTO\n        and getattr(b, \"auto_invoke_kernel_functions\", True) is True\n    )","tryCatchPattern":"try:\n    await agent.invoke(thread, function_choice_behavior=fcb)\nexcept AgentInvokeException as e:\n    if \"auto_invoke=False\" in str(e):\n        fcb = FunctionChoiceBehavior.Auto()\n        await agent.invoke(thread, function_choice_behavior=fcb)\n    raise","preventionTips":["Never pass FunctionChoiceBehavior.Auto(auto_invoke=False) to AzureAIAgent; use a FunctionInvocationFilter to intercept calls instead.","Review any shared behavior factory to confirm it does not flip auto_invoke off."],"tags":["azure-ai-agent","function-choice-behavior","auto-invoke"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}