Repository navigation
Use native Qwen tool continuations - #1296
Open
Sayan Shaw (sayanshaw24) wants to merge 27 commits into
Open
Sayan Shaw (sayanshaw24) wants to merge 27 commits into
Sayan Shaw (sayanshaw24) wants to merge 27 commits into
Conversation
Probe model-published tool boundaries and tool-result projection semantics for every compatible model type. Preserve explicit catalog capability metadata and fail closed when the rendered protocol is ambiguous. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Treat unknown catalog metadata as inferable, preserve single-call support when result rendering fails, and require probe sentinels to occur in one complete non-nested tool region. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore unrelated formatting while retaining the review fixes and their regression coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the tool-capability precedence helper on the catalog API's int64_t type so MSVC does not reject a narrowing optional conversion under warnings-as-errors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Preserve free-form automatic responses, enforce tool-only choices, and normalize strict Qwen tool envelopes without leaking raw markup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Scope Qwen2 compatibility, distinguish executable wrappers from Markdown examples, prevent tool-only text leakage, and preserve stop and retry semantics across backends. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore automatic tool-calling behavior to the frozen base and retain only the Qwen2 required/named compatibility path with focused regression coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use compatibility boundaries during guided retry and admit validated bare JSON only for fenced tool-only recovery. Detect Qwen2 catalog variants by model ID when needed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Project template-qualified Qwen tools and results through the native protocol, reject completed-call repetition, and recover bounded final answers after tool results. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Resolve native tool boundaries from the model-published GenAI tags and compare completed calls using semantic JSON equality. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> # Conflicts: # sdk_v2/cpp/src/inferencing/generative/chat/chat_session.cc # sdk_v2/cpp/src/inferencing/generative/toolcalling/tool_call_context.h
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical issues can cause freed-memory reads and route valid tool calls as ordinary text, bypassing parsing, validation, and repeat checks.
14 open issues
Avoid reading a string view after modifying its backing string · New Preserve token provenance when replaying buffered continuations · New Fall back when native XML cannot represent the tool schema · New Limit completed-call interception to qualified native models · New Do not infer request completion from tool-name coverage · New Preserve parameterless schemas when adding retry exclusions · New Switch native XML retries to canonical JSON consistently · New Keep reasoning recovery within the original output budget · New Honor explicit response guidance during native activation · New Honor required and forced tool choices in native prompts · New Scope completed calls to the latest user request · New Preserve JSON escaping when restoring templated values · New Require decoder-compatible framing when qualifying XML templates · New Use the string-aware scanner to find the closing marker · New
What changed in this PR
This PR extends Foundry Local’s C++ chat pipeline to use template-qualified native Qwen tool protocols for multi-turn continuations, building on the protocol detection work in #1231.
Changes:
- Adds native XML and tagged-JSON prompt projection, parsing, and configurable tool boundaries.
- Tracks completed calls and introduces repeat-call and hidden-reasoning recovery.
- Expands capability and continuation tests, and includes the Qwen2 required/named fenced-output compatibility path.
| File | Description |
|---|---|
sdk_v2/cpp/test/internal_api/toolcalling/tool_call_stream_accumulator_test.cc |
Tests tagged-JSON parsing and custom boundaries. |
sdk_v2/cpp/test/internal_api/genai_model_instance_test.cc |
Tests template-qualified native capabilities. |
sdk_v2/cpp/test/internal_api/chat/chat_template_test.cc |
Tests fenced required/named prompt instructions. |
sdk_v2/cpp/test/internal_api/chat/chat_session_test.cc |
Tests repeat interception, retries, and capability precedence. |
sdk_v2/cpp/src/inferencing/generative/toolcalling/tool_call_context.h |
Adds native protocol and continuation state. |
sdk_v2/cpp/src/inferencing/generative/toolcalling/qwen_xml_tool_call_decoder.h |
Declares tagged-JSON parsing and configurable boundaries. |
sdk_v2/cpp/src/inferencing/generative/toolcalling/qwen_xml_tool_call_decoder.cc |
Implements tagged-JSON parsing and generalized XML boundaries. |
sdk_v2/cpp/src/inferencing/generative/genai_model_instance.h |
Exposes inferred tool-protocol capabilities. |
sdk_v2/cpp/src/inferencing/generative/genai_model_instance.cc |
Qualifies protocols through rendered-template probes. |
sdk_v2/cpp/src/inferencing/generative/chat/prepared_chat_prompt.cc |
Projects native tool definitions and conversation history. |
sdk_v2/cpp/src/inferencing/generative/chat/chat_template.cc |
Adds fenced tool-only instructions. |
sdk_v2/cpp/src/inferencing/generative/chat/chat_session.h |
Declares tool-support resolution helper. |
sdk_v2/cpp/src/inferencing/generative/chat/chat_session.cc |
Integrates native parsing, completion tracking, and recovery. |
Review effort: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…-tool-continuations-update
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Why
Qwen templates define native tool protocols and
<tool_response>history, but Foundry's canonical projection bypasses those contracts on continuation turns. In real multi-turn requests this can make the model repeat an already completed call, exhaust its output in hidden reasoning, or fail to select legitimate pending work.This is stacked on #1231, which provides template-qualified protocol detection. #1264 remains a separate narrow Qwen2 required/named compatibility change.
What
Validation
Deterministic combined stack validation:
Real-model validation:
The exact repeated call observed before this change is intercepted and never published; no repeated call occurred in either real-model matrix.