Repository navigation
feat(agui): add first-class userId to AguiRuntimeContextRequest - #3936
Merged
Merged
Conversation
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
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
jujn
approved these changes
Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
userIdon the AG-UI starter path. #2306 partially fixed it: it introducedAguiRuntimeContextResolverand 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 drivingAguiRequestProcessordirectly on custom transports still had no field to pass an authenticated id through.This PR completes it: the request-level
userIdbelow 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 frontendforwardedProps(#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
userIdandsessionIdare 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,sessionIdhas a native protocol source (threadId), butuserIdhas none — this PR closes that asymmetry.Problem
AG-UI protocol payloads carry no user identity, so the only entry point for
userIdwas the optionalAguiRuntimeContextResolver. 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),userIdis silentlynullfor the whole chain:ReActAgent#slotKeynormalizes null to__anon__, so state is persisted under__anon__/<sessionId>/.interrupt(userId, sessionId)creates a phantom state viacomputeIfAbsentthat 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.
agentIdhas 3 sources and 5 fallback levels;userIdhad zero.Solution
Add a first-class
userIdtoAguiRuntimeContextRequest(alongsideheaderAgentId/pathAgentId) and merge it inAguiRequestProcessor:Priority: resolver (deployer adjudication) > request (caller assertion) > none.
RuntimeContext.Builder#userIdwould overwrite the resolver value copied byBuilder#from.Hosts driving
AguiRequestProcessordirectly (custom transports) pass the authenticated user id viabuilder().userId(...); starter users should keep registering anAguiRuntimeContextResolverbean.Compatibility
Purely additive (new optional field, getter, builder method, merge step). Binary compatible; hosts that pass no
userIdbehave 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.