Skip to content

fix(core): 将用户拒绝工具执行原因写入模型上下文 - #2668

Open
hanydd wants to merge 2 commits into
agentscope-ai:mainfrom
hanydd:feat/tool-approval-refusal-reason
Open

fix(core): 将用户拒绝工具执行原因写入模型上下文#2668
hanydd wants to merge 2 commits into
agentscope-ai:mainfrom
hanydd:feat/tool-approval-refusal-reason

Conversation

@hanydd

@hanydd hanydd commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

背景

现在ReactAgentHarnessAgent已经有工具审批逻辑,发出 RequireUserConfirmEventUserConfirmResultEvent事件,用户可以选择通过或者拒绝,但是没有渠道可以把用户主动提供的拒绝调用的原因。已合并的 #2511 建立了工具审批结果的事件和恢复链路,但 ConfirmResult 只能表达通过或拒绝,拒绝时写入模型上下文的仍是固定文案,无法携带用户主动提供的原因。这个PR拓展了一下工具调用审批需要的 ConfirmResult,加入了可选的reason字段,并且将原因加入到了对应的ToolResultBlock里面。

改动

  • ConfirmResult 增加可选 reason,保留旧构造函数。
  • 拒绝时将原因追加到 DENIED 工具结果,使模型下一轮可见。
  • 补充 ReActAgent 上下文测试和 Harness 远程事件编解码测试。

测试

ReActAgentHitlTestRemoteEventCodecPassthroughTest 通过。

@hanydd hanydd changed the title fix(core): 将工具拒绝原因写入模型上下文 fix(core): 将用户拒绝工具执行原因写入模型上下文 Aug 11, 2026
@hanydd
hanydd force-pushed the feat/tool-approval-refusal-reason branch 2 times, most recently from 17994e9 to 2e36a5b Compare August 11, 2026 14:59
@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@hanydd
hanydd marked this pull request as ready for review August 11, 2026 15:38
@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/agent Agent runtime, pipeline, hooks, plan labels Aug 12, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 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.

Comment thread agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java Outdated

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 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.

Comment thread agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java Outdated
@hanydd

hanydd commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@chickenlj 大佬可以看下这个PR吗?改动不大,主要是加了工具审批的时候,可以让调用方把用户拒绝工具执行的原因传进来。目前项目中用到了这个功能,现在只能在外面再加适配层,才能把用户的原因拼进去。

hanydd added 2 commits August 13, 2026 00:02
- Normalize blank reasons before adding denial context
- Limit user-provided reasons to 500 Unicode code points
@hanydd
hanydd force-pushed the feat/tool-approval-refusal-reason branch from 1f505ee to 025898e Compare August 12, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/agent Agent runtime, pipeline, hooks, plan bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants