Skip to content

feat(agui): propagate userId from forwardedProps to RuntimeContext#2044

Open
ningmeng0503 wants to merge 1 commit into
agentscope-ai:mainfrom
ningmeng0503:feature/agui-runtime-context-user-id
Open

feat(agui): propagate userId from forwardedProps to RuntimeContext#2044
ningmeng0503 wants to merge 1 commit into
agentscope-ai:mainfrom
ningmeng0503:feature/agui-runtime-context-user-id

Conversation

@ningmeng0503

Copy link
Copy Markdown
Contributor

When an AG-UI client sends a userId inside RunAgentInput.forwardedProps, AguiAgentAdapter now copies it into the built RuntimeContext so that downstream agents, tools, and hooks can access
it via RuntimeContext.getUserId().

Changes

  • Added FORWARDED_PROP_USER_ID_KEY = "userId" constant in AguiAgentAdapter.
  • Updated AguiAgentAdapter.buildRuntimeContext(RunAgentInput) to read userId from input.getForwardedProps() and set it on RuntimeContext.Builder.userId(...).
  • Empty or blank userId values are ignored.
  • Existing behavior of storing the full forwardedProps map under agui.forwardedProps is preserved.
  • Added unit tests in AguiAgentAdapterTest covering:
    • userId set from forwarded props
    • non-String userId converted to String
    • missing userId keeps RuntimeContext.getUserId() null
    • blank userId is ignored

Example

An AG-UI client can now forward the user identity like this:

{
  "threadId": "thread-1",
  "runId": "run-1",
  "forwardedProps": {
    "userId": "user-123"
  }
}

Inside the agent run, RuntimeContext.getUserId() will return "user-123".

Checklist

- [x] Change is localized to AguiAgentAdapter.
- [x] Existing RuntimeContext behavior is preserved.
- [x] Unit tests added and passing.
- [x] Spotless formatting applied.

@ningmeng0503 ningmeng0503 requested a review from a team July 7, 2026 14:02
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ningmeng0503 ningmeng0503 force-pushed the feature/agui-runtime-context-user-id branch from e8d07f8 to 61a18aa Compare July 10, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant