{"record":{"id":"9f0bff258055d942","repo":"microsoft/autogen","slug":"tool-choice-references-tool-name-but-it-s-not","errorCode":null,"errorMessage":"tool_choice references '{tool_name}' but it's not in the available tools","messagePattern":"tool_choice references '(.+?)' but it's not in the available tools","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py","lineNumber":657,"sourceCode":"                raise ValueError(\"tool_choice specified but no tools provided\")\n\n            # Validate that the tool exists in the provided tools\n            tool_names_available: List[str] = []\n            if len(tools) > 0:\n                for tool in tools:\n                    if isinstance(tool, Tool):\n                        tool_names_available.append(tool.schema[\"name\"])\n                    else:\n                        tool_names_available.append(tool[\"name\"])\n            else:\n                # Use last used tools names if available\n                for tool_param in self._last_used_tools:\n                    tool_names_available.append(tool_param[\"name\"])\n\n            # tool_choice is a single Tool object\n            tool_name = tool_choice.schema[\"name\"]\n            if tool_name not in tool_names_available:\n                raise ValueError(f\"tool_choice references '{tool_name}' but it's not in the available tools\")\n\n        # Convert to Anthropic format and add to request_args only if tools are provided\n        # According to Anthropic API, tool_choice may only be specified while providing tools\n        if len(tools) > 0 or has_tool_results:\n            converted_tool_choice = convert_tool_choice_anthropic(tool_choice)\n            if converted_tool_choice is not None:\n                request_args[\"tool_choice\"] = converted_tool_choice\n\n        # Optional parameters\n        for param in [\"top_p\", \"top_k\", \"stop_sequences\", \"metadata\"]:\n            if param in create_args:\n                request_args[param] = create_args[param]\n\n        # Add thinking configuration if available\n        thinking_config = self._get_thinking_config(extra_create_args)\n        if thinking_config:\n            request_args.update(thinking_config)\n","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py#L639-L675","documentation":"Error \"tool_choice references '{tool_name}' but it's not in the available tools\" thrown in microsoft/autogen.","triggerScenarios":"Thrown at python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py:657 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reference an available tool name"],"exampleFix":"Set tool_choice to one of the provided tool names","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}