Repository navigation
Description
Summary
The AG-UI adapter (AguiAgentAdapter) consumes the deprecated v1 Flux<io.agentscope.core.agent.Event> stream via agent.stream(...). Because the v1 Event/EventType vocabulary only contains REASONING / SUMMARY / TOOL_RESULT, the fine-grained v2 events — in particular RequireUserConfirmEvent and RequestStopEvent — structurally can never reach the adapter.
As a result, human-in-the-loop (HITL) tool confirmation is completely dropped over AG-UI:
- When a tool call enters
ToolCallState.ASKING(e.g. any non-read-only tool underPermissionMode.DEFAULT, which is the default),ReActAgentemitsRequireUserConfirmEvent+RequestStopEventand pauses. - Neither event is converted to any AG-UI event, so the client sees
TOOL_CALL_START/ARGS/ENDand then a bareRUN_FINISHED(or aRUN_ERRORon a subsequent run whose paused state was persisted) — the tool call silently never executes. - There is also no inbound path:
AguiRequestProcessor/RunAgentInput/AguiMessageConverternever read confirmation results back, so even a client that wanted to approve/deny has no channel to sendConfirmResult(Msgmetadata keyagentscope_confirm_results).
This is especially visible with MCP tools: the MCP server receives initialize and tools/list but never receives tools/call, because the agent halts at the ASKING gate before ToolExecutor runs.
Environment
- agentscope-java:
2.0.0 - Module:
agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agui - Transport: AG-UI over SSE (
agentscope-agui-spring-boot-starter, MVCSseEmitter)
Root cause (verified against main)
1. The adapter is on the deprecated v1 event stream.
AguiAgentAdapter.run(RunAgentInput) calls:
// AguiAgentAdapter.java
Flux<Event> agentEvents = agent.stream(msgs, options, runtimeContext); // io.agentscope.core.agent.Event (v1)
...
agentEvents.concatMapIterable(event -> convertEvent(event, state));and convertEvent(Event, ...) only branches on EventType.REASONING | SUMMARY | TOOL_RESULT. The entire StreamableAgent surface is already marked for removal:
// StreamableAgent.java
* @deprecated since 2.0.0, for removal in a future minor release. Every stream(...)
* method returns the coarse-grained Event type (a v1 carry-over). Use
* ReActAgent#streamEvents(...) instead — it returns Flux<io.agentscope.core.event.AgentEvent>,
* the fine-grained event hierarchy ...
@Deprecated(since = "2.0.0", forRemoval = true)
public interface StreamableAgent { ... }The v1 Event.java deprecation javadoc even names AG-UI explicitly as a module still on the old wire format:
* @deprecated since 2.0.0. This is the v1 coarse-grained event type ... the wire format
* consumed by the harness, AGUI, A2A, chat-completions-web, and Kotlin extension modules.
* New code should use io.agentscope.core.event.AgentEvent via ReActAgent#streamEvents(...).2. The two event hierarchies are disjoint and there is no bridge.
io.agentscope.core.agent.Event (v1, a flat class wrapping Msg + coarse EventType) and io.agentscope.core.event.AgentEvent (v2 abstract base with 28 typed subtypes and its own AgentEventType) are in different packages, unrelated by inheritance. There is no in-core converter from AgentEvent down to v1 Event. So RequireUserConfirmEvent cannot be observed from the stream the adapter currently subscribes to — a "small patch inside the v1 adapter" is not possible.
3. The AG-UI layer already defines the target types but never constructs them.
AguiEvent.java defines Interrupt, RunFinishedOutcome, RunFinishedSuccessOutcome, and RunFinishedInterruptOutcome(List<Interrupt>) — the Interrupt javadoc reads "requiring user input to resolve before the agent can continue" — but no production code ever instantiates them. finishRun(...) always emits the bare new AguiEvent.RunFinished(threadId, runId) (outcome = null). The interrupt types are exercised only in AguiEventTest (serialization).
Reproduction
- Register any
HarnessAgent/ReActAgentwith default permissions (PermissionMode.DEFAULT) behind the AG-UI Spring Boot starter. - Configure any non-read-only tool (e.g. an MCP
echotool viatools.json). POST /agui/runasking the model to call that tool.
Observed: SSE stream shows RUN_STARTED → TEXT_* → TOOL_CALL_START/ARGS/END → RUN_FINISHED, with no TOOL_CALL_RESULT and no confirmation event. Server-side, the agent stops at PRE_ACTING with RequestStopEvent(reason=permission asking) and ToolExecutor never runs; an MCP server never receives tools/call.
Expected: the confirmation request should surface to the client (as an AG-UI Interrupt / RunFinishedInterruptOutcome, or another agreed representation), and the client should be able to resume the run by sending approval/denial that is translated back into ConfirmResult (Msg metadata agentscope_confirm_results).
Workaround today: set PermissionMode.BYPASS (or add explicit allow rules) on the agent's PermissionContextState, which skips the ASK gate entirely. This unblocks tool execution but discards the HITL capability that AG-UI otherwise seems designed to support.
Reference for the intended v2 pattern
The canonical dispatch + resume flow already exists in tests:
agentscope-core/src/test/java/io/agentscope/core/agent/ReActAgentHitlTest.java— subscribes tostreamEvents(...), dispatches viainstanceofoverRequireUserConfirmEvent/RequestStopEvent(GenerateReason.PERMISSION_ASKING), extracts pendingToolUseBlocks viagetToolCalls(), and resumes withnew ConfirmResult(approved, toolCall).agentscope-harness/src/test/java/io/agentscope/harness/agent/HarnessAgentSubagentStreamEventsTest.java— subscribes tostreamEvents(...)and dispatches byAgentEventType.
Suggested direction
Migrate AguiAgentAdapter from the deprecated agent.stream(...) (Flux<Event>) to ReActAgent#streamEvents(...) (Flux<AgentEvent>), rewrite convertEvent to dispatch over the typed v2 events (TEXT_BLOCK_*, THINKING_BLOCK_*, TOOL_CALL_*, TOOL_RESULT_*), and add HITL handling that maps RequireUserConfirmEvent → AguiEvent.Interrupt (+ RunFinishedInterruptOutcome) outbound, plus an inbound path that reads confirmation results from the incoming RunAgentInput and forwards them as ConfirmResult (Msg.METADATA_CONFIRM_RESULTS).
Note: streamEvents is declared on ReActAgent, not on the Agent interface, so the adapter would need to target ReActAgent (or a narrower event-streaming type) — worth deciding as part of the fix.
I'm happy to work on a PR for this.
Note: HITL confirmation over AG-UI is currently non-functional; the adapter being on the forRemoval v1 stream is the underlying cause. This is a defensive/UX correctness issue rather than a data-loss bug.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
oss-maintainer commentedon Jul 28, 2026
wzq-xzwj commentedon Jul 29, 2026
I'd like to take this one. I've already done the root-cause analysis above and have a working local branch.
Plan (single PR, closes this issue):
Migrate
AguiAgentAdapterto the v2AgentEventstream. When the wrapped agent is aReActAgent, consumestreamEvents(msgs, ctx)(Flux<AgentEvent>) and map the fine-grained events onto the AG-UI protocol:TextBlock{Start,Delta,End}Event→TEXT_MESSAGE_{START,CONTENT,END}ThinkingBlock{Start,Delta,End}Event→REASONING_MESSAGE_*(whenenableReasoning)ToolCall{Start,Delta,End}Event→TOOL_CALL_{START,ARGS,END}ToolResult{Start,TextDelta,End}Event→TOOL_CALL_RESULTReActAgent, keep the existing deprecated v1stream(...)path as a fallback, so customAgentimplementations and current integrations keep working.Bridge HITL outbound.
RequireUserConfirmEvent(+RequestStopEventwithGenerateReason.PERMISSION_ASKING) → emit anAguiEvent.Interruptcarrying the pendingToolUseBlocks, and finish the run withRunFinishedInterruptOutcomeinstead of a bareRUN_FINISHED.Bridge HITL inbound. Read confirmation results from
RunAgentInput.forwardedProps, translate toList<ConfirmResult>, and attach them underMsg.METADATA_CONFIRM_RESULTSon the resumed message soReActAgentcan apply them and continue.Testing:
Will open the PR against
mainshortly. Please assign to me / let me know if the approach looks good.jujn commentedon Jul 29, 2026
先等这个合并吧,不然后面大概率冲突: #2306
wzq-xzwj commentedon Jul 29, 2026
Update: @jujn pointed out that #2306 (already approved and mergeable) covers this issue — it migrates the AG-UI adapter from the v1
stream()to the v2streamEvents()API and bridges HITL through the officialRunAgentInput.resume[]contract.I've closed my PR (#2473) in favor of #2306 to avoid conflicts. Happy to re-verify against my local DeepSeek + SSE MCP setup once #2306 lands, and will reopen/complement only if any gap remains. Thanks @jujn for the heads-up!
wzq-xzwj commentedon Jul 30, 2026
做了一个端到端验证,确认目前 #2437 描述的权限型 HITL 场景仍需要补充处理。
#2306 对 suspend 型 HITL(
TOOL_SUSPENDED路径)的 converter registry + interrupt coordinator 架构很完善。但 #2437 是另一条独立分支——PermissionMode.DEFAULT下非只读工具触发RequireUserConfirmEvent+RequestStopEvent(PERMISSION_ASKING),在适配器里还没有对应的 converter。实测(合并后 main @6572a3e,非只读 MCP echo 工具,
PermissionMode.DEFAULT,真实模型):MCP server 收到
tools/call= 0(权限 ASK 正确拦截了执行)。但RequireUserConfirmEvent只被RawAgentEventConverter兜底转发为不透明的RAW,适配器没有产出Interrupt,客户端无法确认/续跑。根因: 目前唯一的中断源是
AgentLifecycleEventConverter(gated onGenerateReason.TOOL_SUSPENDED)。RequireUserConfirmEvent在整个 agui 模块没有 handler。ReActAgent里PERMISSION_ASKING和TOOL_SUSPENDED是两条互斥分支,当前只覆盖了后者。补充方案(基于 #2306 的 registry 架构):
新增
PermissionConfirmEventConverter(实现AgentEventConverter,eventTypes = Set.of(RequireUserConfirmEvent.class)),将RequireUserConfirmEvent转为context.addInterrupt(new Interrupt(id, reason="tool_confirmation", ...)),每个 pendingToolUseBlock一个 Interrupt,metadata 携带toolName/toolInput。扩展
AguiResumeCoordinator和AguiMessageConverter,对reason="tool_confirmation"的中断走不同的 resume 路径:构造携带Msg.METADATA_CONFIRM_RESULTS(List<ConfirmResult>)的 USER role 消息,而不是现有的ToolResultBlock路径。注意:
ConfirmResult.toolCall的content必须是非空 JSON——applyConfirmResults是全量替换 storedToolUseBlock,如果 content 为 null 会在 resume 时触发"argument content is null"校验失败。如果方向 OK 我可以提一个 PR。
fix(agui): emit AG-UI interrupt for permission-type HITL tool confirm…
fix(agui): emit AG-UI interrupt for permission-type HITL tool confirm…
fix(agui): emit AG-UI interrupt for permission-type HITL tool confirm…
fix(agui): emit AG-UI interrupt for permission-type HITL tool confirm…
fix(agui): emit AG-UI interrupt for permission-type HITL tool confirm…