{"record":{"id":"84453ee263031fbd","repo":"microsoft/autogen","slug":"tool-choice-specified-but-no-tools-provided","errorCode":null,"errorMessage":"tool_choice specified but no tools provided","messagePattern":"tool_choice specified but no tools provided","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py","lineNumber":639,"sourceCode":"        # Add system message if present\n        if system_message is not None:\n            request_args[\"system\"] = system_message\n\n        has_tool_results = any(isinstance(msg, FunctionExecutionResultMessage) for msg in messages)\n\n        # Store and add tools if present\n        if len(tools) > 0:\n            converted_tools = convert_tools(tools)\n            self._last_used_tools = converted_tools\n            request_args[\"tools\"] = converted_tools\n        elif has_tool_results:\n            # anthropic requires tools to be present even if there is any tool use\n            request_args[\"tools\"] = self._last_used_tools\n\n        # Process tool_choice parameter\n        if isinstance(tool_choice, Tool):\n            if len(tools) == 0 and not has_tool_results:\n                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\")","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py#L621-L657","documentation":"Error \"tool_choice specified but no tools provided\" thrown in microsoft/autogen.","triggerScenarios":"Thrown at python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py:639 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide tools or remove tool_choice"],"exampleFix":"Pass tools=[...] alongside tool_choice","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"}