Skip to content

fix(core): emit tool result events on manual HITL denial and support custom denial reason - #2546

Merged
jujn merged 4 commits into
agentscope-ai:mainfrom
liulangjietou:fix/2492-deny-reason-events
Sep 21, 2026
Merged

jujn merged 4 commits into
agentscope-ai:mainfrom
liulangjietou:fix/2492-deny-reason-events

Conversation

@liulangjietou

@liulangjietou liulangjietou commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2492 — both points reported in the issue.

1. Custom denial reason (ConfirmResult.reason)

The manual-deny path wrote a hardcoded "Permission denied by user" tool result. ConfirmResult now carries an optional reason field: when the user denies a tool call with a reason, that text becomes the DENIED tool result written back to the model context (and the event delta text), so the model can understand why the call was rejected and react accordingly.

Backward compatibility:

  • All existing constructors are preserved as delegating overloads ((confirmed, toolCall) and (confirmed, toolCall, rules) still compile and behave identically).
  • JSON payloads without reason deserialize with reason = null, which falls back to the existing default text — behavior is unchanged for all current callers.

2. Manual denial now emits tool result events

Verified asymmetry on main: the rule-based auto-deny path emits ToolResultStartEvent → ToolResultTextDeltaEvent → ToolResultEndEvent (state DENIED), but the manual user deny path in applyConfirmResults only wrote the DENIED ToolResultBlock into context — streamEvents consumers (e.g. AG-UI frontends) never saw any tool result for the denied call.

applyConfirmResults now emits the same event triple per denied tool call via the call's bound event sink (publishEvent), carrying the denial reason as the delta text. A fresh replyId is generated for the resume call's denial events, consistent with how each acting phase generates its own replyId.

Tests

Three new regression tests in ReActAgentHitlTest:

  • deniedConfirmResultWithCustomReasonWritesReasonToContext — custom reason replaces the default text in the persisted tool result.
  • deniedConfirmResultOnResumeEmitsToolResultEventTriple — Start/Delta/End events are emitted in order with state DENIED and the reason as delta (fails on current main).
  • deniedConfirmResultWithoutReasonKeepsDefaultText — no reason supplied → default "Permission denied by user" preserved.

Full agentscope-core suite passes: 2246 tests, 0 failures. mvn spotless:check passes.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@liulangjietou
liulangjietou force-pushed the fix/2492-deny-reason-events branch from 03f8c97 to 21897b6 Compare August 4, 2026 02:42
…custom denial reason

Two fixes for the ASK-permission deny flow (issue agentscope-ai#2492):

1. ConfirmResult gains an optional 'reason' field. When the user denies a
   tool call, the reason (if present) becomes the text of the DENIED tool
   result instead of the hardcoded "Permission denied by user", so the
   model can see why the call was rejected. All existing constructors are
   preserved as delegating overloads; old JSON payloads without 'reason'
   deserialize unchanged.

2. The manual-deny path in applyConfirmResults now emits the same
   ToolResultStartEvent -> ToolResultTextDeltaEvent -> ToolResultEndEvent
   triple that the rule-based auto-deny path already emits. Previously a
   manual denial only wrote the DENIED ToolResultBlock into context, so
   streamEvents consumers (e.g. AG-UI frontends) never observed any tool
   result for the denied call.

Closes agentscope-ai#2492
@liulangjietou
liulangjietou force-pushed the fix/2492-deny-reason-events branch from 21897b6 to 6cfffed Compare August 4, 2026 02:45
@codecov

codecov Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

@oss-maintainer

Copy link
Copy Markdown
Collaborator

⚠️ Merge conflict detected

This PR has conflicts with the main branch and cannot be merged. Please rebase or merge main into your branch and resolve the conflicts:

git fetch origin
git checkout fix/2492-deny-reason-events
git rebase origin/main
# resolve conflicts, then:
git push --force-with-lease

This is a one-time reminder. Feel free to @mention me for a re-review after conflicts are resolved.


Automated notification by github-manager-bot

@oss-maintainer oss-maintainer 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.

Summary

Reviewed the changes in this PR. The modifications look reasonable and follow the project conventions.


Automated review by "github-manager-bot"

…n-events

# Conflicts:
#	agentscope-core/src/test/java/io/agentscope/core/agent/ReActAgentHitlTest.java
@jujn
jujn merged commit c0d03cc into agentscope-ai:main Sep 21, 2026
7 checks passed
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

4 participants