fix(core): add ToolUseBlock.getSuggestedRules() implementation - #2916
Open
ShuiMu-peng wants to merge 6 commits into
Open
fix(core): add ToolUseBlock.getSuggestedRules() implementation#2916ShuiMu-peng wants to merge 6 commits into
ShuiMu-peng wants to merge 6 commits into
Conversation
Add complete implementation of ToolUseBlock.getSuggestedRules() as documented: - Add suggestedRules field to ToolUseBlock with JSON serialization support - Implement withSuggestedRules() and withStateAndSuggestedRules() methods - Update ReActAgent to invoke getSuggestedRules() and attach rules to ToolUseBlock - Add comprehensive unit tests for suggestedRules functionality - Update PermissionHITLExample to use getSuggestedRules() Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
dailingtao
reviewed
Sep 1, 2026
| List<PermissionRule> suggested = decision.getSuggestedRules(); | ||
| ToolUseBlock toolUseBlock = use; | ||
| if (suggested != null && !suggested.isEmpty()) { | ||
| toolUseBlock = use.withSuggestedRules(suggested); |
Contributor
There was a problem hiding this comment.
[P2] 轻量权限路径也需要传递 suggested rules
这里的复制只发生在 useEngine == true 的分支。默认构建的 ReActAgent 使用 trivial PermissionContextState,会进入下面的轻量权限路径;如果自定义 ToolBase.checkPermissions() 返回 PermissionDecision.ask(...).withSuggestedRules(...),case ASK 仍用原始 use 构造 PermissionVerdict,这些规则会被静默丢失。
我用针对性测试复现后,完整 PermissionEngine 路径可以拿到 1 条规则,但默认轻量路径得到的是 0 条。这样本次 HITL 确认虽然仍能进行,暂停返回的 Msg 和 RequireUserConfirmEvent 中 getSuggestedRules() 却为空,调用方无法接受工具生成的规则,后续同类调用仍会重复询问。
建议让轻量路径的 ASK 分支也把 decision.getSuggestedRules() 附加到 ToolUseBlock,并补一个默认 agent 下的端到端回归测试。
…ules-final' into fix/add-tooluseblock-suggested-rules-final
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.
实现了 ToolUseBlock.getSuggestedRules() 的完整功能,该功能已在文档中描述但尚未实现。
变更内容
关闭: #1592
核心实现
测试
示例
测试
已通过的测试
mvn test -Dtest=ToolUseBlockTest
mvn spotless:check
所有新功能都包含了单元测试,代码格式符合项目规范。
相关 Issue
此 PR 实现了已在 javadoc 中承诺但缺失的功能,修复了代码与文档不一致的问题。
检查清单