Skip to content

feat(agui): Upgrade AG_UI module event mechanism - #2306

Merged
chickenlj merged 13 commits into
mainfrom
agui/update-event
Jul 29, 2026
Merged

chickenlj merged 13 commits into
mainfrom
agui/update-event

Conversation

@jujn

@jujn jujn commented Jul 19, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Close #2202

1.0 stream() → 2.0 streamEvents()

This PR upgrades the AG-UI v2 integration to better align with the official AG-UI protocol and make the adapter easier to extend.

Key Changes

  • Introduces a converter registry for AgentEvent -> AguiEvent mapping, allowing users to register custom AgentEventConverters that can override built-in mappings.
  • Adds AguiEventEnricher support for cross-cutting event decoration such as timestamp, rawEvent, tracing metadata, or custom event rewriting.
  • Adds optional AG-UI base event properties support across all AguiEvent types via timestamp and rawEvent.
  • Simplifies v2 lifecycle handling by converting AgentStartEvent / AgentEndEvent into RUN_STARTED / RUN_FINISHED through the normal converter path.
  • Adds optional token usage emission as CUSTOM token_usage events with delta and cumulative usage.
  • Adds official RunAgentInput.resume[] support for HITL interrupts and bridges tool-call resumes back into AgentScope tool-result recovery.
  • Enforces AG-UI interrupt contract rules for open interrupts: pending interrupts block new input, and resume requests must cover all open interrupts. Extends Spring Boot starter support for custom converters, custom enrichers, token usage config, request-scoped RuntimeContext resolution, and custom adapter factories.
  • Adds a full AG-UI example project demonstrating streaming events, custom converters/enrichers, token usage, frontend tools, and HITL approval flow. Path: https://github.com/agentscope-ai/agentscope-java/tree/main/agentscope-examples/agui
  • Updates AG-UI documentation in v1/v2 Chinese and English docs to reflect the current module behavior.

Copilot AI review requested due to automatic review settings July 19, 2026 15:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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

This PR contains 3314 lines of changes. Review in progress.


Automated review by github-manager-bot

@AgentScopeJavaBot AgentScopeJavaBot added enhancement New feature or request area/ext/integration External protocols & middleware integrations area/examples agentscope-examples labels Jul 20, 2026
@jujn
jujn force-pushed the agui/update-event branch from 849a381 to 70d7019 Compare July 24, 2026 09:04
@xzxiaoshan

Copy link
Copy Markdown
Collaborator

这个PR 中,只是抽象定义 AguiRuntimeContextResolver 接口,没有提供任何默认实现,是目前不需要默认的实现是吗?
@oss-maintainer 分析一下。

@jujn

jujn commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

这个PR 中,只是抽象定义 AguiRuntimeContextResolver 接口,没有提供任何默认实现,是目前不需要默认的实现是吗? @oss-maintainer 分析一下。

后面可以慢慢完善,欢迎参与。

@chickenlj
chickenlj merged commit 6572a3e into main Jul 29, 2026
10 checks passed
@xzxiaoshan

Copy link
Copy Markdown
Collaborator

这个PR 中,只是抽象定义 AguiRuntimeContextResolver 接口,没有提供任何默认实现,是目前不需要默认的实现是吗? @oss-maintainer 分析一下。

后面可以慢慢完善,欢迎参与。

当前这个 PR 已合入主分支。

#2463 是延续这个进行调整的,烦请及时确认合并。

@jujn
jujn deleted the agui/update-event branch July 30, 2026 09:13
wzq-xzwj added a commit to wzq-xzwj/agentscope-java that referenced this pull request Jul 30, 2026
…ation (agentscope-ai#2437)

The AG-UI adapter only handled suspend-type HITL (ToolSuspendException /
frontend tools, GenerateReason.TOOL_SUSPENDED). Permission-type HITL --
where a non-readonly tool under DEFAULT permission mode makes ReActAgent
emit RequireUserConfirmEvent + RequestStopEvent(PERMISSION_ASKING) -- was
dropped: RequireUserConfirmEvent fell through to the RAW fallback and no
Interrupt reached RUN_FINISHED, so the frontend could never confirm/deny.

Building on the converter-registry architecture introduced by agentscope-ai#2306:

- Add PermissionConfirmEventConverter that maps RequireUserConfirmEvent to
  one AG-UI Interrupt per pending ToolUseBlock (reason "tool_confirmation"),
  carrying toolName/toolInput/toolContent/replyId metadata, and register it
  in AgentEventConverterRegistry. Interrupt id keeps the "replyId:toolCallId"
  format so resume can recover the tool call id.
- AguiResumeCoordinator now tracks "tool_confirmation" interrupts alongside
  "tool_call" ones and exposes them via a new resume-interrupts runtime key.
- AguiAgentAdapter forwards the resume interrupts to the message converter.
- AguiMessageConverter builds a ConfirmResult (approved/denied) from the
  resume payload for confirmation interrupts, reconstructing the ToolUseBlock
  with non-null JSON content to avoid the tool-input validation NPE on resume;
  non-confirmation resumes keep the existing ToolResultBlock path.
- Add unit tests covering resolved/cancelled/explicit-false confirmations and
  the non-confirmation fallback.
wzq-xzwj added a commit to wzq-xzwj/agentscope-java that referenced this pull request Aug 5, 2026
…ation (agentscope-ai#2437)

The AG-UI adapter only handled suspend-type HITL (ToolSuspendException /
frontend tools, GenerateReason.TOOL_SUSPENDED). Permission-type HITL --
where a non-readonly tool under DEFAULT permission mode makes ReActAgent
emit RequireUserConfirmEvent + RequestStopEvent(PERMISSION_ASKING) -- was
dropped: RequireUserConfirmEvent fell through to the RAW fallback and no
Interrupt reached RUN_FINISHED, so the frontend could never confirm/deny.

Building on the converter-registry architecture introduced by agentscope-ai#2306:

- Add PermissionConfirmEventConverter that maps RequireUserConfirmEvent to
  one AG-UI Interrupt per pending ToolUseBlock (reason "tool_confirmation"),
  carrying toolName/toolInput/toolContent/replyId metadata, and register it
  in AgentEventConverterRegistry. Interrupt id keeps the "replyId:toolCallId"
  format so resume can recover the tool call id.
- AguiResumeCoordinator now tracks "tool_confirmation" interrupts alongside
  "tool_call" ones and exposes them via a new resume-interrupts runtime key.
- AguiAgentAdapter forwards the resume interrupts to the message converter.
- AguiMessageConverter builds a ConfirmResult (approved/denied) from the
  resume payload for confirmation interrupts, reconstructing the ToolUseBlock
  with non-null JSON content to avoid the tool-input validation NPE on resume;
  non-confirmation resumes keep the existing ToolResultBlock path.
- Add unit tests covering resolved/cancelled/explicit-false confirmations and
  the non-confirmation fallback.
jujn pushed a commit that referenced this pull request Aug 8, 2026
…ation (#2437) (#2495)

Fixes #2437.

The AG-UI adapter only surfaced **suspend-type** HITL (tools that throw
`ToolSuspendException` / frontend tools, i.e.
`GenerateReason.TOOL_SUSPENDED`). The **permission-type** HITL path was
dropped:

- Under `DEFAULT` permission mode, a non-readonly tool makes
`ReActAgent` emit `RequireUserConfirmEvent` +
`RequestStopEvent(PERMISSION_ASKING)`.
- `RequireUserConfirmEvent` had no converter, so it fell through to the
`RAW` fallback and **no `Interrupt` reached `RUN_FINISHED`**.
- The frontend therefore had nothing to confirm/deny, and resume was
impossible.

This builds directly on the converter-registry architecture introduced
in #2306, extending it to the confirmation path rather than changing its
design.
dargoner pushed a commit to dargoner/agentscope-java that referenced this pull request Aug 10, 2026
…ation (agentscope-ai#2437)

The AG-UI adapter only handled suspend-type HITL (ToolSuspendException /
frontend tools, GenerateReason.TOOL_SUSPENDED). Permission-type HITL --
where a non-readonly tool under DEFAULT permission mode makes ReActAgent
emit RequireUserConfirmEvent + RequestStopEvent(PERMISSION_ASKING) -- was
dropped: RequireUserConfirmEvent fell through to the RAW fallback and no
Interrupt reached RUN_FINISHED, so the frontend could never confirm/deny.

Building on the converter-registry architecture introduced by agentscope-ai#2306:

- Add PermissionConfirmEventConverter that maps RequireUserConfirmEvent to
  one AG-UI Interrupt per pending ToolUseBlock (reason "tool_confirmation"),
  carrying toolName/toolInput/toolContent/replyId metadata, and register it
  in AgentEventConverterRegistry. Interrupt id keeps the "replyId:toolCallId"
  format so resume can recover the tool call id.
- AguiResumeCoordinator now tracks "tool_confirmation" interrupts alongside
  "tool_call" ones and exposes them via a new resume-interrupts runtime key.
- AguiAgentAdapter forwards the resume interrupts to the message converter.
- AguiMessageConverter builds a ConfirmResult (approved/denied) from the
  resume payload for confirmation interrupts, reconstructing the ToolUseBlock
  with non-null JSON content to avoid the tool-input validation NPE on resume;
  non-confirmation resumes keep the existing ToolResultBlock path.
- Add unit tests covering resolved/cancelled/explicit-false confirmations and
  the non-confirmation fallback.
wzl521 pushed a commit to wzl521/agentscope-java that referenced this pull request Aug 12, 2026
wzl521 pushed a commit to wzl521/agentscope-java that referenced this pull request Aug 12, 2026
…ation (agentscope-ai#2437) (agentscope-ai#2495)

Fixes agentscope-ai#2437.

The AG-UI adapter only surfaced **suspend-type** HITL (tools that throw
`ToolSuspendException` / frontend tools, i.e.
`GenerateReason.TOOL_SUSPENDED`). The **permission-type** HITL path was
dropped:

- Under `DEFAULT` permission mode, a non-readonly tool makes
`ReActAgent` emit `RequireUserConfirmEvent` +
`RequestStopEvent(PERMISSION_ASKING)`.
- `RequireUserConfirmEvent` had no converter, so it fell through to the
`RAW` fallback and **no `Interrupt` reached `RUN_FINISHED`**.
- The frontend therefore had nothing to confirm/deny, and resume was
impossible.

This builds directly on the converter-registry architecture introduced
in agentscope-ai#2306, extending it to the confirmation path rather than changing its
design.
jujn pushed a commit that referenced this pull request Aug 24, 2026
…lver / AguiRequestBodyParser 到 extensions-agui 协议层 (#2822)

## 背景

`AguiRuntimeContextRequest`、`AguiRuntimeContextResolver`(PR #2306 引入)与
`AguiRequestBodyParser`(PR #2638 引入)目前被放在 Spring starter 的 `common`
包内。但它们三处均不含任何 Spring 依赖(仅依赖 `RuntimeContext` 与 `RunAgentInput`),本质上与
`AgentEventConverter`、`AguiEventEnricher`、`AguiAgentAdapterFactory`
属于同一类协议层 SPI。

锁在 starter 里形态上似乎违背了 starter 作为“Spring 装配层”的职责边界,让非 Spring 接入方(纯
WebFlux/RSocket 等)无法复用这三类协议层能力。本 PR 将其下沉到 `agentscope-extensions-agui`
协议模块。

## 改动内容

1. **归位**:将
`AguiRuntimeContextRequest`、`AguiRuntimeContextResolver`、`AguiRequestBodyParser`
下沉到 `agentscope-extensions-agui` 的 `io.agentscope.core.agui.runtime`
包,与同类扩展点同模块。

2. **类型安全**:`AguiRuntimeContextRequest` 泛型化为
`AguiRuntimeContextRequest<T>`,用编译期泛型刻画 transport-specific 的
`nativeRequest`,替代原先 `Object + 运行期 Class<T>` 的转型方式。

3. **职责收口**:以
`AguiRequestProcessor#process(AguiRuntimeContextRequest<?>)` 作为统一入口,将
runtimeContextResolver 内置到 processor。MVC/WebFlux handler 不再各自持有
resolver、各自调用 `resolve()`,只负责把原生请求(`HttpServletRequest` /
`ServerRequest`)映射为 `AguiRuntimeContextRequest<T>` 后交给 processor 统一解析。

4. **Parser Bean 化**:`AguiRequestBodyParser` 改为可通过 Spring Bean
覆盖的组件(`@ConditionalOnMissingBean`),并注入 MVC/WebFlux 控制器,允许应用自定义请求体解析。
jujn pushed a commit that referenced this pull request Nov 2, 2026
Fixes #3931
Closes #2014

## History: #2014 was already partially fixed by #2306

#2014 (filed against RC4) asked for the official way to pass a
server-authenticated `userId` on the AG-UI starter path. #2306 partially
fixed it: it introduced `AguiRuntimeContextResolver` and wired it into
both the MVC and WebFlux starter auto-configurations, so starter users
could already register a resolver bean and inject identity from Spring
Security — but that stayed undocumented, and hosts driving
`AguiRequestProcessor` directly on custom transports still had no field
to pass an authenticated id through.

This PR completes it: the request-level `userId` below fills the
direct-processor gap, and the docs now state the recommended pattern for
both entry points (starter → resolver bean; direct processor →
`builder().userId(...)`), the merge priority, and that authenticated
identity belongs on the server side rather than frontend
`forwardedProps` (#901). The one remaining question in #2014 (starter
vs. custom gateway) is advisory — with identity now supported on the
starter path there is no capability gap left, so that issue is closed by
this merge as well.

## Context

`userId` and `sessionId` are first-class citizens of the AgentScope
runtime: the `(userId, sessionId)` pair keys state persistence
(`AgentStateStore`), in-flight call serialization, interrupt targeting,
and the multi-session state cache. On the AG-UI bridge, `sessionId` has
a native protocol source (`threadId`), but `userId` has none — this PR
closes that asymmetry.

## Problem

AG-UI protocol payloads carry no user identity, so the only entry point
for `userId` was the optional `AguiRuntimeContextResolver`. Hosts that
resolve identity in their service layer had no field to pass it through.
Without a resolver configured (an optional component with no wiring
hint), `userId` is silently `null` for the whole chain:

- `ReActAgent#slotKey` normalizes null to `__anon__`, so state is
persisted under `__anon__/<sessionId>/`.
- Native `interrupt(userId, sessionId)` creates a phantom state via
`computeIfAbsent` that nobody listens to — the interrupt is a no-op.
- `stateStore.delete(userId, sessionId)` targets a different directory
than the one written — a silent miss leaving orphan data.

All three failures are silent: no WARN, no exception, no metric.
`agentId` has 3 sources and 5 fallback levels; `userId` had zero.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/examples agentscope-examples area/ext/integration External protocols & middleware integrations enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Upgrade AG_UI module event mechanism

6 participants