fix(core): 将用户拒绝工具执行原因写入模型上下文 - #2668
Conversation
17994e9 to
2e36a5b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR adds an optional reason field to ConfirmResult so that when a user denies a tool call in the HITL (Human-In-The-Loop) flow, their explanation is propagated into the model's context as part of the DENIED tool result message. The implementation is backward-compatible (new overloaded constructors, @JsonInclude(NON_NULL) on the getter, @JsonCreator handles missing reason as null). Two well-targeted tests cover the core path (reason appears in denied tool result text) and the codec round-trip (reason survives serialization). The change is small, focused, and solves a real usability gap — without it, the model has no idea why the user rejected a tool call.
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR adds an optional reason field to ConfirmResult so that when a user denies a tool call in the HITL (Human-In-The-Loop) flow, their explanation is propagated into the model's context as part of the DENIED tool result message. The implementation is backward-compatible (new overloaded constructors, @JsonInclude(NON_NULL) on the getter, @JsonCreator handles missing reason as null). Two well-targeted tests cover the core path (reason appears in denied tool result text) and the codec round-trip (reason survives serialization). The change is small, focused, and solves a real usability gap — without it, the model has no idea why the user rejected a tool call.
|
@chickenlj 大佬可以看下这个PR吗?改动不大,主要是加了工具审批的时候,可以让调用方把用户拒绝工具执行的原因传进来。目前项目中用到了这个功能,现在只能在外面再加适配层,才能把用户的原因拼进去。 |
- Normalize blank reasons before adding denial context - Limit user-provided reasons to 500 Unicode code points
1f505ee to
025898e
Compare
背景
现在
ReactAgent和HarnessAgent已经有工具审批逻辑,发出RequireUserConfirmEvent和UserConfirmResultEvent事件,用户可以选择通过或者拒绝,但是没有渠道可以把用户主动提供的拒绝调用的原因。已合并的 #2511 建立了工具审批结果的事件和恢复链路,但ConfirmResult只能表达通过或拒绝,拒绝时写入模型上下文的仍是固定文案,无法携带用户主动提供的原因。这个PR拓展了一下工具调用审批需要的ConfirmResult,加入了可选的reason字段,并且将原因加入到了对应的ToolResultBlock里面。改动
ConfirmResult增加可选reason,保留旧构造函数。DENIED工具结果,使模型下一轮可见。测试
ReActAgentHitlTest、RemoteEventCodecPassthroughTest通过。