Skip to content

feat(agui): support custom RuntimeContext in AguiAgentAdapter#2101

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

feat(agui): support custom RuntimeContext in AguiAgentAdapter#2101
ningmeng0503 wants to merge 1 commit into
agentscope-ai:mainfrom
ningmeng0503:feature/agui-agent-adapter-runtime-context

Conversation

@ningmeng0503

@ningmeng0503 ningmeng0503 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Allow callers to provide a custom RuntimeContext when running an agent through AguiAgentAdapter and AguiRequestProcessor, and let subclasses override the default context construction.

Problem

AguiAgentAdapter.run(RunAgentInput) always built the RuntimeContext internally, so callers could not:

  • Pass an existing runtime context that already carries request-scoped metadata.
  • Customize the default context via subclassing, because buildRuntimeContext was private.

More importantly, because the adapter owned the context instance, any custom data written by downstream middleware or tools during the run was invisible to the upstream caller. The caller had no way
to read that data back or use it to customize post-run processing.

AguiRequestProcessor had the same limitation: it only exposed process(RunAgentInput, String, String), so AG-UI request handlers could not inject a pre-built context either.

Changes

  • Added AguiAgentAdapter.run(RunAgentInput input, RuntimeContext runtimeContext).
    • Uses the supplied context when non-null; otherwise falls back to buildRuntimeContext(input).
    • The caller keeps the same context reference, so values written by middleware/tools are observable after the run.
  • Changed AguiAgentAdapter.buildRuntimeContext from private to protected for subclass overrides.
  • Added AguiRequestProcessor.process(RunAgentInput, String, String, RuntimeContext).
    • Forwards the context to the adapter; passing null preserves the original behavior.
  • Kept the original run(RunAgentInput) and process(RunAgentInput, String, String) methods unchanged for backward compatibility.

@ningmeng0503 ningmeng0503 requested a review from a team July 10, 2026 05:13
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- Add run(RunAgentInput, RuntimeContext) overload to AguiAgentAdapter;
  passing null falls back to the default context built from the input.
- Change AguiAgentAdapter.buildRuntimeContext from private to protected
  so subclasses can customize the default runtime context.
- Add process(RunAgentInput, String, String, RuntimeContext) overload to
  AguiRequestProcessor so callers can pass a custom context through the
  request processor; passing null falls back to the adapter default.
- Keep the original run/process methods unchanged for backward compatibility.
@ningmeng0503 ningmeng0503 force-pushed the feature/agui-agent-adapter-runtime-context branch from 660b312 to eaa54e8 Compare July 10, 2026 06:22

@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

Clean feature addition — allows callers to inject a custom RuntimeContext into AguiAgentAdapter and AguiRequestProcessor, with proper null-fallback and backward compatibility.

Findings

  • [Info] AguiAgentAdapter.java:104 — The null-check + fallback pattern is correct and consistent.
  • [Info] AguiRequestProcessor.java:99 — Good that the original 3-arg method is preserved as a delegate.
  • [Info] Tests cover all three paths (custom context, null fallback, subclass override) — well done.

Verdict

Straightforward, well-tested, fully backward compatible. LGTM.


Automated review by github-manager

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.

2 participants