feat(core): support returnDirect tool result short-circuit - #2891
Open
xzxiaoshan wants to merge 1 commit into
Open
feat(core): support returnDirect tool result short-circuit#2891xzxiaoshan wants to merge 1 commit into
xzxiaoshan wants to merge 1 commit into
Conversation
xzxiaoshan
force-pushed
the
feat/return-direct-tool-support
branch
from
August 29, 2026 12:12
3808802 to
64b2eb6
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
Author
xzxiaoshan
force-pushed
the
feat/return-direct-tool-support
branch
5 times, most recently
from
August 29, 2026 13:03
7817495 to
b9a1ad3
Compare
xzxiaoshan
force-pushed
the
feat/return-direct-tool-support
branch
from
August 29, 2026 13:08
b9a1ad3 to
d5a76b7
Compare
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.
feat(core): 支持
returnDirect工具语义摘要
returnDirect是工具调用的循环控制开关:工具执行成功后,结果不再交回模型推理,直接作为本轮最终输出返回调用方,对应 Spring AI 的@Tool(returnDirect = true)。false:结果喂回模型继续推理。true:跳过下一轮模型调用,结果直接返回。returnDirect=true且执行成功时才整体返回,否则喂回模型。多工具语义
一个 batch 产出多个结果时按整批决定去向:
TOOL_SUSPENDED挂起,returnDirect不生效。returnDirect=true且 state 为SUCCESS→ 返回TOOL_RETURN_DIRECT。实现
returnDirect 触发的本质,是把工具结果「搬进消息序列」充当本轮最终答案。结构上做两件事:
assistant消息,作为本轮最终输出写入 context 并返回,并打上TOOL_RETURN_DIRECT标记。messages是完整性的表达,必须维持tool call → tool result → assistant的闭环。原tool_result保留、内容换成占位句:Tool call completed. The result has been presented to the user as the final output of this turn.。占位句作为 tool result 承接 tool call 的「语言表达」,合成的 assistant「模拟 LLM」收口。这样既避免结果重复,也满足供应商「每个tool_use后必须紧跟tool_result」的要求。判定上同时校验工具声明与结果状态:仅当该轮所有结果均
returnDirect=true且SUCCESS才直接返回;suspended 挂起与 HITL 叫停优先于 returnDirect。兼容性
returnDirect=false),无破坏性变更。ToolBase位置构造器签名,内置工具无需改动。switch的少数消费方;GenerateReasonTest计数断言 11 → 12。