microsoft/autogen · error · ValueError

tool_choice references '{tool_name}' but it's not in the ava

Error message

tool_choice references '{tool_name}' but it's not in the available tools

What it means

Error "tool_choice references '{tool_name}' but it's not in the available tools" thrown in microsoft/autogen.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py:657

                raise ValueError("tool_choice specified but no tools provided")

            # Validate that the tool exists in the provided tools
            tool_names_available: List[str] = []
            if len(tools) > 0:
                for tool in tools:
                    if isinstance(tool, Tool):
                        tool_names_available.append(tool.schema["name"])
                    else:
                        tool_names_available.append(tool["name"])
            else:
                # Use last used tools names if available
                for tool_param in self._last_used_tools:
                    tool_names_available.append(tool_param["name"])

            # tool_choice is a single Tool object
            tool_name = tool_choice.schema["name"]
            if tool_name not in tool_names_available:
                raise ValueError(f"tool_choice references '{tool_name}' but it's not in the available tools")

        # Convert to Anthropic format and add to request_args only if tools are provided
        # According to Anthropic API, tool_choice may only be specified while providing tools
        if len(tools) > 0 or has_tool_results:
            converted_tool_choice = convert_tool_choice_anthropic(tool_choice)
            if converted_tool_choice is not None:
                request_args["tool_choice"] = converted_tool_choice

        # Optional parameters
        for param in ["top_p", "top_k", "stop_sequences", "metadata"]:
            if param in create_args:
                request_args[param] = create_args[param]

        # Add thinking configuration if available
        thinking_config = self._get_thinking_config(extra_create_args)
        if thinking_config:
            request_args.update(thinking_config)

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Reference an available tool name

Example fix

Set tool_choice to one of the provided tool names

When it happens

Trigger: Thrown at python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py:657 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/9f0bff258055d942. Report an issue: GitHub.