{"record":{"id":"2eb4b99b8a25e070","repo":"microsoft/semantic-kernel","slug":"functionchoicebehavior-with-type-function-choice","errorCode":null,"errorMessage":"FunctionChoiceBehavior with type '{function_choice_behavior.type_}' is not supported for agent invocations. Use FunctionChoiceBehavior.Auto(filters=...) to control which kernel functions are available.","messagePattern":"FunctionChoiceBehavior with type '(.+?)' is not supported for agent invocations\\. Use FunctionChoiceBehavior\\.Auto\\(filters=\\.\\.\\.\\) to control which kernel functions are available\\.","errorType":"validation","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/azure_ai/agent_thread_actions.py","lineNumber":992,"sourceCode":"            tool[\"openapi\"] = openapi_data\n        return tool\n\n    @staticmethod\n    def _deduplicate_tools(existing_tools: list[dict], new_tools: list[dict]) -> list[dict]:\n        existing_names = {\n            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(","sourceCodeStart":974,"sourceCodeEnd":1010,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/azure_ai/agent_thread_actions.py#L974-L1010","documentation":"Raised when an AzureAIAgent invocation is given a FunctionChoiceBehavior whose type_ is not FunctionChoiceType.AUTO. The Azure AI agent run loop is hardwired to auto-invoke tools, so only the Auto behavior is compatible; other types (None/Required) would hand control to the caller in a way the loop cannot honor.","triggerScenarios":"Passing FunctionChoiceBehavior.Required() or FunctionChoiceBehavior.NoneInvoke() (or any non-AUTO type) as the function_choice_behavior argument to AzureAIAgent.invoke()/invoke_stream, or setting it on the ChatHistory/PromptExecutionSettings used by the agent.","commonSituations":"Developer copies a FunctionChoiceBehavior setup from a non-agent chat flow (e.g. ChatCompletionAgent or kernel.invoke_async) into an AzureAIAgent call, expecting the same behavior mapping. Also occurs after upgrading when FunctionChoiceBehavior replaced the older None auto_invoke kwargs.","solutions":["Switch to FunctionChoiceBehavior.Auto(filters=...) with the desired included_plugins/included_functions/excluded_plugins/excluded_functions to control tool availability.","Remove the FunctionChoiceBehavior argument entirely — the agent run loop defaults to exposing all registered kernel functions.","If you need required/no-tool semantics, do not use AzureAIAgent; those behaviors are not supported by the hosted run loop."],"exampleFix":"// before\nbehavior = FunctionChoiceBehavior.Required()\nawait agent.invoke(thread, messages=..., function_choice_behavior=behavior)\n\n// after\nbehavior = FunctionChoiceBehavior.Auto(\n    filters={\"included_functions\": [\"MyPlugin-MyFunc\"]}\n)\nawait agent.invoke(thread, messages=..., function_choice_behavior=behavior)","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.ai.function_choice_behavior import FunctionChoiceBehavior, FunctionChoiceType\n\ndef is_agent_compatible(behavior) -> bool:\n    return behavior is None or behavior.type_ == FunctionChoiceType.AUTO\n\n# before invoking\nif not is_agent_compatible(fcb):\n    fcb = FunctionChoiceBehavior.Auto()","typeGuard":"from semantic_kernel.connectors.ai.function_choice_behavior import FunctionChoiceBehavior, FunctionChoiceType\n\ndef is_auto_behavior(b: object) -> bool:\n    return (\n        b is None\n        or (isinstance(b, FunctionChoiceBehavior) and b.type_ == FunctionChoiceType.AUTO)\n    )","tryCatchPattern":"from semantic_kernel.exceptions import AgentInvokeException\n\ntry:\n    await agent.invoke(thread, function_choice_behavior=fcb)\nexcept AgentInvokeException as e:\n    if \"not supported for agent invocations\" in str(e):\n        fcb = FunctionChoiceBehavior.Auto()\n        await agent.invoke(thread, function_choice_behavior=fcb)\n    else:\n        raise","preventionTips":["Centralize FunctionChoiceBehavior construction in a helper that always returns Auto for AzureAIAgent calls.","Add a unit test asserting any behavior passed to AzureAIAgent has type_ == FunctionChoiceType.AUTO."],"tags":["azure-ai-agent","function-choice-behavior","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}