Skip to content

Honor parallel_tool_calls=false in Chat Completions and Responses - #1181

Open
Sayan Shaw (sayanshaw24) wants to merge 1 commit into
mainfrom
sayanshaw/parallel-tool-call-contract
Open

Sayan Shaw (sayanshaw24) wants to merge 1 commit into
mainfrom
sayanshaw/parallel-tool-call-contract

Conversation

@sayanshaw24

Copy link
Copy Markdown
Contributor

Honor parallel_tool_calls=false in Chat Completions and Responses

Why

Foundry Local accepts parallel_tool_calls in both API request formats, but the flag did not affect generation: a request specifying false could still return and stream multiple tool calls. This matters for coding clients that execute one call at a time and expect the response to respect that choice.

What changed

  • Forward an explicitly supplied parallel_tool_calls value from Chat Completions and Responses into the request-scoped tool context. An omitted value retains the existing parallel behavior.
  • When the value is false, publish the first completed tool call and end the assistant turn. Drop subsequent calls, text, or reasoning already decoded in the same fragment, and cancel unfinished backend generation.
  • Apply the same one-call limit to guided Engine retries. Continue validating a completed tool-call batch before publishing any of its calls.
  • Keep omitted and explicit true requests able to return adjacent calls as before.

Tests and validation

  • Added option-mapping and turn-guard unit tests, plus tiny Qwen fixture cases for whole and bytewise output, final and streaming responses on both APIs, and guided retry.
  • Syntax-checked seven changed C++ production/test translation units with clang-cl in C++20 mode. Editor diagnostics, changed-line formatting, and git diff --check are clean.
  • Full native tests could not run locally: the project pins GenAI 0.17.1, the available local cache contains 0.15.2, and the NuGet download fails TLS on this host. CI needs to run the focused and required test suites.

Scope

This enforces at most one published call when the flag is false. It does not change the model's chat template or prevent the model from generating additional tokens before a completed call reaches the parser. The marker-delimited guidance work in ORT GenAI is separate.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 22:03
@vercel

vercel Bot commented Oct 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
foundry-local Ready Ready Preview Oct 7, 2026 10:04pm UTC

Request Review

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.

🔵 Needs a closer look

It changes core streaming and guided-retry state machines, and the native test suites have not yet run successfully.

0 open findings

What changed in this PR

Enforces parallel_tool_calls=false across Chat Completions and Responses while preserving existing parallel behavior when omitted or enabled.

Changes:

  • Propagates the option into request-scoped tool-call context.
  • Stops publication and generation after the first accepted tool call.
  • Adds converter, turn-guard, streaming, and guided-retry coverage.
File Description
sdk_v2/​cpp/​src/​contracts/​chat_completions_converter.cc Maps the Chat Completions option.
sdk_v2/​cpp/​src/​inferencing/​generative/​openresponses/​response_converter.cc Maps the Responses option.
sdk_v2/​cpp/​src/​inferencing/​generative/​toolcalling/​tool_call_context.h Stores the request-scoped setting.
sdk_v2/​cpp/​src/​inferencing/​generative/​chat/​chat_transcript.h Ends serial turns after one call.
sdk_v2/​cpp/​src/​inferencing/​generative/​chat/​chat_session.cc Applies the limit across generation paths.
sdk_v2/​cpp/​test/​internal_api/​chat_completions_converter_test.cc Tests Chat Completions mapping.
sdk_v2/​cpp/​test/​internal_api/​response_converter_test.cc Tests Responses mapping.
sdk_v2/​cpp/​test/​internal_api/​chat/​chat_transcript_test.cc Tests serial turn guarding.
sdk_v2/​cpp/​test/​internal_api/​chat/​chat_session_test.cc Tests both APIs, streaming, chunking, and retry.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch was successfully deployed

1 active deployment
Preview — be20d926 Deployed Oct 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants