Skip to content

Python: Honor allow_multiple_tool_calls in AnthropicClient when tool_choice is unset - #8980

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 3 commits into
microsoft:mainfrom
Zakariakhchiche:issue-8979-anthropic-parallel-tool-use
Oct 23, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 3 commits into
microsoft:mainfrom
Zakariakhchiche:issue-8979-anthropic-parallel-tool-use

Conversation

@Zakariakhchiche

Copy link
Copy Markdown
Contributor

Motivation & Context

allow_multiple_tool_calls=False is only translated to Anthropic's tool_choice.disable_parallel_tool_use when tool_choice is set. With tools but no tool_choice, the setting is silently dropped. The function-invocation loop also resets tool_choice="required" to None after the first iteration, so every later model call in the loop re-enables parallel tool use.

Description & Review Guide

  • What are the major changes?
    • In _prepare_tools_for_anthropic, when tool_choice is unset, allow_multiple_tool_calls is set and tools are present, send {"type": "auto", "disable_parallel_tool_use": not allow_multiple_tool_calls}. auto is Anthropic's default mode when tools are provided. The function-invocation loop is not touched.
    • Regression tests: a unit test on _prepare_options, and a function-loop test (tool_choice="required" + allow_multiple_tool_calls=False, three mocked BetaMessage responses) that checks disable_parallel_tool_use on every request.
  • What is the impact of these changes? The parallel-tool setting now applies to every request, including later function-loop iterations. Requests without tools or without allow_multiple_tool_calls are unchanged.
  • What do you want reviewers to focus on? Gating on tools only (not mcp_servers), to avoid sending a tool_choice on requests without client tools.

Related Issue

Fixes #8979

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Medium severity

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_anthropic to propagate disable_parallel_tool_use via default "auto" mode when tool_choice is None and tools are present.
  • Add unit coverage for _prepare_options to ensure allow_multiple_tool_calls=False disables parallel tool use without an explicit tool_choice.
  • Add a function-loop regression test asserting disable_parallel_tool_use is 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.

Comment thread python/packages/anthropic/tests/test_anthropic_client.py Outdated
Comment thread python/packages/anthropic/tests/test_anthropic_client.py Outdated
@Zakariakhchiche

Copy link
Copy Markdown
Contributor Author

Notes on the automated review: the new tests now assert the tool_choice fields individually, like the neighbouring _prepare_options tests (pushed). They still fail on main and pass with the fix.

@eavanvalkenburg

Copy link
Copy Markdown
Member

Zakaria Khchiche (@Zakariakhchiche) there are still unresolved comments, could you have a look?

@Zakariakhchiche

Copy link
Copy Markdown
Contributor Author

Thanks Eduard van Valkenburg (@eavanvalkenburg)! Both open threads were automated review suggestions that were already applied: the tests assert the tool_choice fields individually (lines 1434 and 1487-1493). I've replied on each and resolved them. Happy to change anything else.

Merged via the queue into microsoft:main with commit 71cf48c Oct 23, 2026
46 of 47 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — 634bc90b Deployed Oct 2, 2026 by Zakariakhchiche via add_label #24310
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

3 participants