AnthropicChatCompletionClient ignores the configured `tool_choice` and drops `strict` and `additionalProperties` from tools
What happened?
AnthropicChatCompletionClient changes three tool constraints before the request is sent, without any warning. We found this while testing how SDKs carry tool-call constraints to the provider.
- The typed config field
tool_choice(AnthropicClientConfiguration,autogen_ext/models/anthropic/config/__init__.py:58-60) is stored but never used.create()setstool_choiceonly from its owntool_choiceparameter, which defaults toauto(_anthropic_client.py:660-664).AssistantAgentdoes not passtool_choicetocreate(), so an agent built withAnthropicChatCompletionClient(tool_choice="none")(or{"type": "tool", ...}, or{"type": "auto", "disable_parallel_tool_use": True}) sends"tool_choice": {"type": "auto"}. convert_tools(_anthropic_client.py:319-358) copies onlyproperties,requiredandtypeintoinput_schema. A top-leveladditionalProperties: falseis lost.convert_toolsnever readsToolSchema["strict"], sostrict=Truetools are sent withoutstrict.
Repro (point base_url at a local server that logs request bodies):
from autogen_agentchat.agents import AssistantAgent
from autogen_core.models import ModelFamily
from autogen_ext.models.anthropic import AnthropicChatCompletionClient
def lookup_order(order_id: str) -> str:
return "delivered"
def issue_refund(order_id: str, amount: int) -> str:
return "refunded"
client = AnthropicChatCompletionClient(
model="claude-sonnet-4-5", api_key="sk-dummy", base_url="http://127.0.0.1:8080",
tool_choice="none",
model_info={"vision": False, "function_calling": True, "json_output": False,
"structured_output": False, "family": ModelFamily.CLAUDE_4_SONNET},
)
agent = AssistantAgent("assistant", model_client=client, tools=[lookup_order, issue_refund])
await agent.run(task="Check order ORD-123456")
Expected: "tool_choice": {"type": "none"} in the request (or the tool / disable_parallel_tool_use value set in config). Tool input_schema keeps additionalProperties: false, and strict: true tools carry "strict": true.
Actual: "tool_choice": {"type": "auto"}. input_schema has only type, properties, required. No strict. In our test the server then answered with tool calls, and the agent ran lookup_order under tool_choice: none, ran issue_refund when lookup_order was forced, and ran two calls when parallel calls were disabled.
Impact: an application that uses these settings to stop or limit tool calls gets auto behavior instead, and is not told.
Suggested fix: use the configured tool_choice when the create() parameter is not given, support disable_parallel_tool_use, and copy additionalProperties and strict in convert_tools.
Which packages was the bug in?
Python Extensions (autogen-ext)
AutoGen library version.
Python 0.7.5
Other library version.
anthropic 0.49.0
Model used
claude-sonnet-4-5
Model provider
Anthropic
Other model provider
No response
Python version
3.12
.NET version
None
Operating system
None
Looking at python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py, there is a fourth schema-fidelity issue in convert_tools (lines 319-358) right next to additionalProperties and strict:
input_schema={
"type": "object",
"properties": tool.schema["parameters"]["properties"],
"required": required,
}
When a tool parameter uses a nested Pydantic model, Enum, or recursive/shared sub-model (or when a tool comes from an MCP server via McpWorkbench), Pydantic v2 places the sub-schemas under tool.schema["parameters"]["$defs"] (or "definitions") and emits {"$ref": "#/$defs/SubModel"} inside properties. Because convert_tools only copies "type", "properties", and "required", any top-level "$defs", "definitions", and "additionalProperties" keys on parameters are stripped, leaving dangling "$ref" pointers inside input_schema["properties"].
Clean fix for all four in _anthropic_client.py
- In
convert_tools(_anthropic_client.py:319-358): Preserve"additionalProperties","$defs", and"definitions"fromparameters(or inline$defsintoproperties), and forwardstrictontoToolParamwhentool.schema.get("strict")is set:params = tool.schema["parameters"] input_schema: dict[str, Any] = { "type": "object", "properties": params["properties"], "required": required, } for extra_key in ("additionalProperties", "$defs", "definitions"): if extra_key in params: input_schema[extra_key] = params[extra_key] - In
create()/create_stream()(_anthropic_client.py:660-664): Fall back toself._config.get("tool_choice")when the per-calltool_choiceargument is left at its default and the caller configuredtool_choiceonAnthropicChatCompletionClient(...), and map"none"to omitting/disabling tool use ({"type": "none"}on current Anthropic Messages API) rather than forcing{"type": "auto"}.
(For MCP-backed tools where $defs/$ref stripping or verbose schemas cause similar validation and token issues across client SDKs, we also inline $defs/$ref directly at the stdio layer in SalyyS1/mcp-slim.)
What happened?
AnthropicChatCompletionClientchanges three tool constraints before the request is sent, without any warning. We found this while testing how SDKs carry tool-call constraints to the provider.
- The typed config field
tool_choice(AnthropicClientConfiguration,autogen_ext/models/anthropic/config/__init__.py:58-60) is stored but never used.create()setstool_choiceonly from its owntool_choiceparameter, which defaults toauto(_anthropic_client.py:660-664).AssistantAgentdoes not passtool_choicetocreate(), so an agent built withAnthropicChatCompletionClient(tool_choice="none")(or{"type": "tool", ...}, or{"type": "auto", "disable_parallel_tool_use": True}) sends"tool_choice": {"type": "auto"}.convert_tools(_anthropic_client.py:319-358) copies onlyproperties,requiredandtypeintoinput_schema. A top-leveladditionalProperties: falseis lost.convert_toolsnever readsToolSchema["strict"], sostrict=Truetools are sent withoutstrict.Repro (point
base_urlat a local server that logs request bodies):from autogen_agentchat.agents import AssistantAgent from autogen_core.models import ModelFamily from autogen_ext.models.anthropic import AnthropicChatCompletionClient def lookup_order(order_id: str) -> str: return "delivered" def issue_refund(order_id: str, amount: int) -> str: return "refunded" client = AnthropicChatCompletionClient( model="claude-sonnet-4-5", api_key="sk-dummy", base_url="http://127.0.0.1:8080", tool_choice="none", model_info={"vision": False, "function_calling": True, "json_output": False, "structured_output": False, "family": ModelFamily.CLAUDE_4_SONNET}, ) agent = AssistantAgent("assistant", model_client=client, tools=[lookup_order, issue_refund]) await agent.run(task="Check order ORD-123456")Expected:
"tool_choice": {"type": "none"}in the request (or thetool/disable_parallel_tool_usevalue set in config). Toolinput_schemakeepsadditionalProperties: false, andstrict: truetools carry"strict": true.Actual:
"tool_choice": {"type": "auto"}.input_schemahas onlytype,properties,required. Nostrict. In our test the server then answered with tool calls, and the agent ranlookup_orderundertool_choice: none, ranissue_refundwhenlookup_orderwas forced, and ran two calls when parallel calls were disabled.Impact: an application that uses these settings to stop or limit tool calls gets
autobehavior instead, and is not told.Suggested fix: use the configured
tool_choicewhen thecreate()parameter is not given, supportdisable_parallel_tool_use, and copyadditionalPropertiesandstrictinconvert_tools.Which packages was the bug in?
Python Extensions (autogen-ext)
AutoGen library version.
Python 0.7.5
Other library version.
anthropic 0.49.0
Model used
claude-sonnet-4-5
Model provider
Anthropic
Other model provider
No response
Python version
3.12
.NET version
None
Operating system
None
No#scammer#fake family or friend at all