agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Question] What is the best practice for obtaining permission suggestedRules in the ReActAgent HITL flow?

Open Alanyaeer opened this issue 2 months ago • 4 comments

When the permission system decides ASK, PermissionEngine.checkPermission auto-generates suggested rules and attaches them to the decision (PermissionDecision.getSuggestedRules()). The docs tell users to accept those rules via toolCall.getSuggestedRules() on the ToolUseBlock carried by RequireUserConfirmEvent — but ToolUseBlock has no such method, and the event carries no suggestions at all. Is there an intended way to obtain them when driving HITL through ReActAgent.streamEvents()?

Current Version is 2.0.3

Alanyaeer avatar Sep 22 '26 01:09 Alanyaeer

Issue Evaluation

Category: bug (documentation/API mismatch) | Status: Confirmed — ToolUseBlock.getSuggestedRules() does not exist; the docs describe an API that was never implemented (verified against main @ c0d03ccea; latest published tag is v2.0.2, working tree revision 2.0.4-SNAPSHOT)

What is true in the code

  • Suggested rules are produced in exactly one place and are attached to the decision, not the message: PermissionEngine.checkPermission(...) returns askDecision.withSuggestedRules(tool.generateSuggestions(input)) — agentscope-core/.../permission/PermissionEngine.java:152, :172, :201; getter is PermissionDecision.getSuggestedRules() — PermissionDecision.java:93.
  • The tool-call block has no such accessor. ToolUseBlock is a final class extends ContentBlock with fields id, name, input, content, metadata, state only — agentscope-core/.../message/ToolUseBlock.java:39-44, getters at :126-174. grep -rn "getSuggestedRules" across all *.java in the repo hits only PermissionDecision.java:93 plus tests (PermissionEngineTest, PermissionDecisionTest) — zero production callers.
  • The event carries nothing else. RequireUserConfirmEvent has only replyId and toolCalls — agentscope-core/.../event/RequireUserConfirmEvent.java:28-29, :52, :56 — and it is constructed as new RequireUserConfirmEvent(replyId, pending) at ReActAgent.java:3050.
  • The point where the data is dropped: ReActAgent.evaluateOne collapses the decision to a bare enum — private record PermissionVerdict(ToolUseBlock use, PermissionBehavior behavior) {} (ReActAgent.java:3372), built from decision.getBehavior() (:3344-3351). Everything after that is a List<ToolUseBlock>, so suggestedRules cannot be recovered from the stream.

The docs are wrong in four places, all of which are compile errors as written:

  • docs/v2/en/docs/building-blocks/agent.md:367 (ToolUseBlock "exposing ... getSuggestedRules()"), :377, :397
  • docs/v2/zh/docs/building-blocks/agent.md:367, :377, :397
  • docs/v2/en/docs/building-blocks/permission-system.md:212 and docs/v2/zh/.../permission-system.md:212 (toolCall.getSuggestedRules())

The runnable examples already know this: PermissionHITLExample.java:180-182 builds new ConfirmResult(approved, t) — the 2-arg overload (ConfirmResult.java:60) — and never passes rules, so the shipped path silently opts out of suggestion acceptance.

Resume contract that the suggestions must reach (this part does exist): ConfirmResult(boolean confirmed, ToolUseBlock toolCall, List<PermissionRule> rules) (ConfirmResult.java:55), and applyConfirmResults calls permissionEngine.addRule(rule) for each rule when confirmed is true (ReActAgent.java:2069-2085). So the plumbing on the way in is complete; only the way out is missing.

What you can do today

  1. Recompute from the tool instance — the same source the engine used, so results are identical:
    ToolBase tool = (ToolBase) agent.getToolkit().getTool(tc.getName()); // name from ToolUseBlock
    List<PermissionRule> rules = tool.generateSuggestions(tc.getInput());
    confirmResults.add(new ConfirmResult(true, tc, rules));
    
    generateSuggestions is public and overridable (ToolBase.java:253; the default returns one tool-name-level ALLOW rule with source = "suggested"). This is the fix direction PR #3238 took for permission-system.md, but that PR touches only that file — agent.md:367/377/397 (en + zh) still shows tc.getSuggestedRules().
  2. Re-run the engine while paused: agent.getPermissionEngine() is public (ReActAgent.java:4719), so getPermissionEngine().checkPermission(tool, tc.getInput()).block().getSuggestedRules() returns the exact list the ASK was built from. Deterministic for the default implementation, but it re-evaluates policy, so treat it as a stopgap, not a documented pattern.
  3. Build the rules explicitly yourself (new PermissionRule(name, pattern, PermissionBehavior.ALLOW, "approved-by-user")). Note that today every auto-suggestion is indistinguishable from a user-authored one — source is hardcoded to "suggested" in ToolBase.java:254 — so there is no audit trail distinguishing an accepted suggestion from a hand-written rule.

Assessment / recommendation

There are two competing open fixes for this and the issue should be resolved by choosing one contract, not by merging both:

  • PR #2916 (fix(core): add ToolUseBlock.getSuggestedRules() implementation, +305/-28, currently CONFLICTING) makes the docs true by putting the rules on the block.
  • PR #3238 (fix(doc): replace getSuggestedRules with generationSuggestions in ToolBase, mergeable) makes the code true by fixing one doc page.

A design caveat worth a maintainer's eye before either lands: ToolUseBlock is a serialized ContentBlock (metadata is documented as provider-specific), so a mutable rules field on it is both wire-format and semantic churn, and it is already being abused as a carrier for confirmation state (withState(ToolCallState.ALLOWED) at ReActAgent.java:2077). The smaller, better-scoped change is to carry the decision alongside the tool call on RequireUserConfirmEvent — e.g. List<PermissionDecision> or Map<String, List<PermissionRule>> keyed by toolCallId — which matches the documented "the event carries them" intent and leaves ContentBlock untouched. That is an agentscope-core API decision, so no bot-generated PR this tick; a maintainer can reply /approve (doc-only fix) or /revise <direction> to have one generated.


Automated evaluation by github-manager-bot

oss-maintainer avatar Sep 22 '26 02:09 oss-maintainer

Issue Evaluation — follow-up (state change: PR #3238 closed)

Category: bug (docs describe a non-existent API) | Module: agentscope-core permission system + docs/v2 | Status: Still confirmed, and now with no open PR covering it (re-verified against main @ ed77530a4)

  • PR #3238 was closed without merging (state=CLOSED, updated 2026-09-22T02:19:06Z), and PR #2916 (fix(core): add ToolUseBlock.getSuggestedRules() implementation) is still CONFLICTING. The gap therefore remains on main:
    • ToolUseBlock still has no getSuggestedRules() — fields are id, name, input, content, metadata, state (agentscope-core/src/main/java/io/agentscope/core/message/ToolUseBlock.java:39-44, getters :126-174); the only implementation of that getter in the tree is on the decision object (PermissionDecision.getSuggestedRules(), .../permission/PermissionDecision.java:93, set in PermissionEngine.java:152, :172, :201).
    • docs/v2/en/docs/building-blocks/agent.md:367, :377, :397 and the zh twins, plus docs/v2/{en,zh}/docs/building-blocks/permission-system.md:212, still show toolCall.getSuggestedRules() — all of which are compile errors as written.
  • Concrete compatibility data point for choosing between the two competing contracts: RequireUserConfirmEvent is a Jackson-serialized event (@JsonCreator + @JsonProperty("id")/("createdAt")/("replyId")/("toolCalls") — agentscope-core/src/main/java/io/agentscope/core/event/RequireUserConfirmEvent.java:26-36). Adding a suggestedRules (or Map<String, List<PermissionRule>> keyed by tool-call id) field there is wire-visible but additive and nullable, so old consumers keep deserializing; putting the rules on ToolUseBlock instead changes a persisted polymorphic ContentBlock, which is the larger blast radius (ToolUseBlock is already used as a state carrier via withState(ToolCallState.ALLOWED) at ReActAgent.java:2077).

What the bot can do now, on request:

  1. Doc-only fix (lowest risk, unblocks users today): correct the four stale spots in agent.md and permission-system.md (en + zh) to the API that exists — ToolBase.generateSuggestions(input) (agentscope-core/src/main/java/io/agentscope/core/tool/ToolBase.java:253) on the tool instance, or PermissionDecision.getSuggestedRules() on the decision — and note ConfirmResult(confirmed, toolCall, rules) (ConfirmResult.java:55) as the resume contract. Purely additive doc edits, no API change.
  2. Event-carrier fix (makes the documented intent true): carry the per-tool-call suggestions on RequireUserConfirmEvent as a nullable additive field, populate it where ReActAgent.evaluateOne currently collapses the decision to a bare enum (ReActAgent.java:3344-3351, :3372), and update the two doc pages to match.

Only the doc-only fix is uncontroversial enough to be generated without further decisions, and it is the same scope #3238 had — if its author or a maintainer wants it reopened in this shape, reply /approve (doc-only) or /revise event-carrier and the bot will prepare the PR against main.


Automated evaluation by github-manager-bot

oss-maintainer avatar Sep 22 '26 13:09 oss-maintainer

Status: 72 h feedback window expired — no automated PR will be generated, the proposal window here is closed

The evaluation CTA above (5777151730, posted 2026-09-22T13:12:41Z) reached its 72-hour feedback limit at 2026-09-25T13:12:41Z with no own-line /approve, /revise, or /reject command in the thread, so per our workflow we skip PR generation and no competing PR will be filed from this proposal window. No action is needed from anyone.

This is a timing stand-down, not a verdict on the report. Measured on the thread at 2026-09-25T13:19Z: 0 replies of any kind after the CTA, 0 directive tokens, and 0 reactions on it — so there was nothing to act on, and no community member has claimed the work.

What is still true on main (re-verified this check at ea78c3172):

  • The documented call toolCall.getSuggestedRules() still does not exist on ToolUseBlock. As of ea78c3172 the only declaration in the tree is PermissionDecision.getSuggestedRules() (agentscope-core/src/main/java/io/agentscope/core/permission/PermissionDecision.java:93), while docs/v2/{en,zh}/docs/building-blocks/agent.md (:387, :397, :417) and docs/v2/{en,zh}/docs/permission-system.md (:213) still call it on a ToolUseBlock. The doc pages therefore remain uncompilable as written (the line numbers differ from the ones quoted in the CTA above because main moved since 2026-09-22).
  • The two paths the CTA offered — a doc-only correction to ToolBase.generateSuggestions(input) / PermissionDecision.getSuggestedRules(), or an additive nullable suggestedRules carrier on RequireUserConfirmEvent — were both left open for the community to choose between. Nobody chose.

One item worth flagging for a maintainer, because it is the reason this gap is not simply ours to close: PR #2916 (fix(core): add ToolUseBlock.getSuggestedRules() implementation) is still OPEN and unmerged at head 0d569211f487, and it currently reads CONFLICTING against main (last updated 2026-09-22T01:02:04Z). It targets the API-shape half of this question — the contract the docs describe — so whichever way the maintainers decide that contract, #2916 or its successor will carry the code change, and the doc correction should follow that decision rather than pre-empt it. The closed PR #3238 (doc-only scope) is not a carrier.

If an independent, bot-generated PR for either scope is still wanted despite #2916, open a fresh issue or leave a one-line approve doc-only / approve event-carrier request on this thread and the evaluation will be regenerated from the current main.

Automated by github-manager-bot

oss-maintainer avatar Sep 25 '26 13:09 oss-maintainer

Update — this looks fixed on main and closable.

The confirmed defect here was "the docs describe an API that was never implemented". That text is gone:

  • PR #3293 — docs: fix verified doc-vs-code mismatches (MCP examples, HITL, defaults, tool names) (en+zh), merged 2026-09-26 (squash 00eb6868). It rewrites exactly the HITL passages, in both languages:

    • docs/v2/{en,zh}/docs/building-blocks/agent.md — the RequireUserConfirmEvent section no longer lists getSuggestedRules() among the ToolUseBlock accessors (now getId() / getName() / getInput() only), the tc.getSuggestedRules() sample is gone, and the "Build confirm results" step now states that suggested rules surface on the permission engine's PermissionDecision, not on the tool call.
    • docs/v2/{en,zh}/docs/building-blocks/permission-system.md — the ConfirmResult sample now reads "ASK decisions carry suggested rules on the PermissionDecision (visible to permission hooks), not on the ToolUseBlock."
  • Verified against current main: getSuggestedRules now appears only in PermissionDecision and its tests — no documentation file references it any more.

The direction taken is the docs-side one rather than adding the accessor: PR #2916 (fix(core): add ToolUseBlock.getSuggestedRules() implementation) was closed 2026-09-29 by @jujn with "fixed in: #3293". So the intended way to obtain the rules when driving HITL through ReActAgent.streamEvents() is the permission-hook / PermissionDecision path that the docs now describe.

The last evaluation comment on this thread (2026-09-25T13:24Z) predates the #3293 merge (2026-09-26T03:15Z), which is why it still reports the old state.

wahllllll avatar Oct 03 '26 16:10 wahllllll