Skip to content

feat(agui): add first-class userId to AguiRuntimeContextRequest - #3936

Merged
jujn merged 1 commit into
agentscope-ai:mainfrom
xzxiaoshan:feat/agui-user-id
Nov 2, 2026
Merged

jujn merged 1 commit into
agentscope-ai:mainfrom
xzxiaoshan:feat/agui-user-id

Conversation

@xzxiaoshan

@xzxiaoshan xzxiaoshan commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

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.

Solution

Add a first-class userId to AguiRuntimeContextRequest (alongside headerAgentId / pathAgentId) and merge it in AguiRequestProcessor:

Priority: resolver (deployer adjudication) > request (caller assertion) > none.

  • A resolver-provided id always wins — a caller-asserted value flowing through the request must not override a server-verified identity.
  • The request value is adopted only when the resolver provided none. It is never set unconditionally: RuntimeContext.Builder#userId would overwrite the resolver value copied by Builder#from.
  • When both are present and differ, a WARN is logged to expose identity drift.

Hosts driving AguiRequestProcessor directly (custom transports) pass the authenticated user id via builder().userId(...); starter users should keep registering an AguiRuntimeContextResolver bean.

Compatibility

Purely additive (new optional field, getter, builder method, merge step). Binary compatible; hosts that pass no userId behave exactly as before.

Testing

  • AguiRequestProcessorTest: 4 new tests — request id adopted when no resolver is configured, resolver id wins on conflict, request id adopted when the resolver context has none (resolver extras preserved), blank treated as not provided.

Docs

docs/v2/{en,zh}/integration/protocol/agui.md: documented both identity entry points, the merge priority, and the starter-vs-direct-processor guidance.

AG-UI protocol payloads carry no user identity, so the only userId entry
was the optional AguiRuntimeContextResolver. Add a first-class userId
field to AguiRuntimeContextRequest and merge it in AguiRequestProcessor
with priority resolver (deployer adjudication) > request (caller
assertion) > none, logging a WARN on conflict. Purely additive and
binary compatible.

Fixes agentscope-ai#3931
@mintlify

mintlify Bot commented Nov 2, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit a3fef50.

Approve preview

@jujn
jujn merged commit 5e2e7d0 into agentscope-ai:main Nov 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants