Repository navigation
Python: Honor allow_multiple_tool_calls in AnthropicClient when tool_choice is unset - #8980
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
This PR ensures allow_multiple_tool_calls is honored for Anthropic requests even when tool_choice is unset, by explicitly sending tool_choice={"type":"auto", "disable_parallel_tool_use": ...} when tools are present. It also adds regression tests to confirm the setting persists across function-invocation loop iterations where tool_choice="required" may be reset internally.
Changes:
- Update
_prepare_tools_for_anthropicto propagatedisable_parallel_tool_usevia default"auto"mode whentool_choiceisNoneand tools are present. - Add unit coverage for
_prepare_optionsto ensureallow_multiple_tool_calls=Falsedisables parallel tool use without an explicittool_choice. - Add a function-loop regression test asserting
disable_parallel_tool_useis sent on every loop request.
| File | Description |
|---|---|
| python/packages/anthropic/agent_framework_anthropic/_chat_client.py | Propagates allow_multiple_tool_calls into Anthropic tool_choice even when user didn’t set tool_choice, but tools are present. |
| python/packages/anthropic/tests/test_anthropic_client.py | Adds regression tests for tool_choice/parallel-tool behavior in both option preparation and multi-iteration function loops. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
Notes on the automated review: the new tests now assert the |
|
Zakaria Khchiche (@Zakariakhchiche) there are still unresolved comments, could you have a look? |
|
Thanks Eduard van Valkenburg (@eavanvalkenburg)! Both open threads were automated review suggestions that were already applied: the tests assert the |

Motivation & Context
allow_multiple_tool_calls=Falseis only translated to Anthropic'stool_choice.disable_parallel_tool_usewhentool_choiceis set. With tools but notool_choice, the setting is silently dropped. The function-invocation loop also resetstool_choice="required"toNoneafter the first iteration, so every later model call in the loop re-enables parallel tool use.Description & Review Guide
_prepare_tools_for_anthropic, whentool_choiceis unset,allow_multiple_tool_callsis set and tools are present, send{"type": "auto", "disable_parallel_tool_use": not allow_multiple_tool_calls}.autois Anthropic's default mode when tools are provided. The function-invocation loop is not touched._prepare_options, and a function-loop test (tool_choice="required"+allow_multiple_tool_calls=False, three mockedBetaMessageresponses) that checksdisable_parallel_tool_useon every request.allow_multiple_tool_callsare unchanged.toolsonly (notmcp_servers), to avoid sending atool_choiceon requests without client tools.Related Issue
Fixes #8979
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.