Skip to content

feat(core): add EventStreamingAgent and session-scoped Agent APIs - #3098

Open
dragondyt wants to merge 1 commit into
agentscope-ai:mainfrom
dragondyt:feat/event-streaming-agent
Open

dragondyt wants to merge 1 commit into
agentscope-ai:mainfrom
dragondyt:feat/event-streaming-agent

Conversation

@dragondyt

@dragondyt dragondyt commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT

Description

Closes #1894
Related #2102 #2105 #2552

Background

Protocol adapters such as AG-UI used to hard-code concrete types (ReActAgent / HarnessAgent) to reach fine-grained streamEvents, session-scoped state, and per-session interrupt. Custom agents could not plug in cleanly without extending those types.

Purpose

Extract optional contracts on the core Agent surface so adapters can detect capabilities without knowing the concrete class. AG-UI / adapter wiring is intentionally deferred to a follow-up.

Changes

  • Add EventStreamingAgent with streamEvents(...) overloads. ReActAgent and HarnessAgent implement it. Agents that do not implement it stay on the deprecated v1 stream() path.
  • Add session-scoped Agent.getAgentState(String, String) / getAgentState(RuntimeContext) defaults (null when unsupported). ReActAgent / HarnessAgent override and forward.
  • Add session-scoped Agent.interrupt(RuntimeContext) / interrupt(String, String) (and Msg variants). Defaults fall back to the no-session overloads and log a WARN when a non-blank user/session id is present so silent wrong-slot interrupts are visible. Multi-session wrappers must override.
  • Point deprecated StreamableAgent documentation at EventStreamingAgent.
  • Update EN/ZH docs/v2 release notes.

Out of scope (follow-up)

  • AG-UI adapter routing via instanceof EventStreamingAgent
  • Deleting AguiUtil / changing ProcessResult.interrupt
  • Normalizing null RuntimeContext to RuntimeContext.empty() in ReActAgent#streamEvents

How to test / Test plan

  • EventStreamingAgentTest
  • AgentGetAgentStateOverloadTest
  • AgentBaseTest#testInterruptRuntimeContextFallsBackToNoArg
  • HarnessAgentEventStreamingContractTest
mvn -T1C -pl agentscope-core -Dtest=EventStreamingAgentTest,AgentGetAgentStateOverloadTest,AgentBaseTest#testInterruptRuntimeContextFallsBackToNoArg test
mvn -T1C -pl agentscope-harness -Dtest=HarnessAgentEventStreamingContractTest test

Checklist

  • Code has been formatted with mvn spotless:apply
  • Affected tests are passing
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (EN/ZH release notes + interface Javadoc)
  • Code is ready for review

@codecov

codecov Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...cope/core/agui/processor/AguiRequestProcessor.java 92.85% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@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

Extracts the v2 streaming contract into a new EventStreamingAgent SPI, implements it on ReActAgent/HarnessAgent, and drops the ReActAgent cast plus the reflective HarnessAgent call from AguiAgentAdapter. Nice de-escalation of a hard-coded type check into a proper capability interface, with tests for the ReAct / Harness / custom-agent paths and the v1 fallback.

Verdict

Approachable with one compatibility question answered (see inline): agents that used to reach the v2 path by class name alone now fall back to 1.x silently.


Automated review by github-manager-bot

@dragondyt

Copy link
Copy Markdown
Contributor Author

@oss-maintainer 麻烦审核一下

@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

Re-review after df4b9b20 + 9a142de1. The direction is right and the mechanics hold up: EventStreamingAgent/SessionStateAgent as opt-in capability interfaces is the correct way to let AG-UI adapt custom agents, ReActAgent and HarnessAgent both implement them, callSerializationKey(RuntimeContext) is null-tolerant so the RuntimeContext.empty() normalisation is safe, and AguiRequestProcessor.resolveRuntimeContext pinning sessionId = threadId once and reusing it for disconnect interrupts removes the user-id-dropping bug in the old interrupt(threadId). Verified on the head blob rather than the patch: RuntimeContext.Builder.from(null) returns an empty builder (so builder(resolved) with a null resolver result is fine), HarnessAgent overrides interrupt(RuntimeContext) at line 617, and the removed AguiUtil has no remaining reference in the repo.

Two things need attention before merge, one of which is blocking CI:

  • [Warning] AguiWebFluxHandlerTest.java:7 — the new file's license header duplicates the "you may not use this file…" sentence with a stray *, and that is exactly the one invalid: 1 file reported by the failing Check License job on this head. Copy the block from the sibling AguiMvcControllerTest.java and the job goes green.
  • [Warning] Agent.java:100 — deleting AguiUtil replaces a structural probe (any agent with a public getDelegate() returning a ReActAgent) with an override obligation. In-repo wrappers are covered, but an external wrapper that only exposes getDelegate() now silently falls into interrupt(), i.e. the wrong-session behaviour this PR fixes, with no signal. A fallback, a log, or a migration note would close that.
  • [Info] AguiRequestProcessor.java:104 — ProcessResult.interrupt(String) → interrupt() and the AguiUtil removal are source-breaking for published 2.0.x consumers and the PR touches no docs/v2/**; a release-notes bullet naming Agent.interrupt(RuntimeContext) as the replacement is enough.
  • [Info] ReActAgent.java:1122 — the null → empty() normalisation is safe against every in-repo ctx == null guard on this path; worth one javadoc sentence making "implementations pass a non-null context" an explicit contract for custom agents.

The Check License failure is the only red check; everything else passes, and CLA is signed.


Automated review by github-manager-bot

@dragondyt

Copy link
Copy Markdown
Contributor Author

@oss-maintainer 麻烦审核一下

@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

Re-review of d0b44c9 — the only commit pushed since my previous review on 9a142de1. It is a docs-only change plus a license-header fix, and it lands the two things that mattered: the malformed header in AguiWebFluxHandlerTest.java (that was the single invalid: 1 file behind the red Check License job — the job is green now, along with build (ubuntu-latest), build (windows-latest), Check Module Sync and codecov/patch) and the explicit "implementations must pass a non-null RuntimeContext" contract on EventStreamingAgent. CLA is signed.

Two items from the previous review are only partly addressed, so I am leaving this as COMMENT rather than APPROVE:

  • Agent.java:98 — the override obligation is now documented ("Multi-session agents and wrappers should override"), but the failure mode is still silent. Before this PR, AguiUtil.asReActAgent unwrapped any agent exposing a public getDelegate() returning a ReActAgent; now such a third-party wrapper falls through default interrupt(RuntimeContext) → interrupt() and interrupts the default slot — exactly the wrong-session behaviour this PR set out to fix, with no signal. A WARN log when ctx != null && ctx.sessionId() != null, or a reflection-free unwrap hook consulted by the default method, closes it.
  • AguiRequestProcessor.java:103 — the javadoc replacement note helps source readers but not consumers who only read release notes. ProcessResult.interrupt(String threadId) and the public AguiUtil class are both gone (source-breaking for published 2.0.x artifacts) and this PR still touches 0 docs/ paths. One changelog bullet in docs/v2/en/** + docs/v2/zh/** naming Agent.interrupt(RuntimeContext) as the replacement is enough.

Nothing in the new code paths themselves looks incorrect, and the null → RuntimeContext.empty() normalisation is now consistent across ReActAgent, EventStreamingAgent and AguiRequestProcessor.interrupt(). Happy to re-review and approve once the wrapper fallback/log and the changelog bullet are in (or tell me why you would rather keep the javadoc-only mitigation for the wrapper case).

Findings

  • [Warning] agentscope-core/.../agent/Agent.java:98 — documented but still silent regression for wrappers exposing only getDelegate()
  • [Info] agentscope-extensions-agui/.../processor/AguiRequestProcessor.java:103 — source-breaking removals need a docs/v2/** changelog entry, not just javadoc
  • [Info] agentscope-core/.../agent/EventStreamingAgent.java:35 — resolved: non-null RuntimeContext contract is now explicit

Automated review by github-manager-bot

* Interrupt the in-flight call identified by {@code ctx}.
*
* <p>The default implementation falls back to {@link #interrupt()}. Multi-session agents and
* wrappers should override this to target the session in {@code ctx} instead of the default

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.

Thanks for picking this up in d0b44c9 — the javadoc now tells wrappers to override, but the behaviour for an external wrapper is still silent: AguiUtil.asReActAgent used to unwrap any agent exposing a public getDelegate() returning a ReActAgent, while default void interrupt(RuntimeContext ctx) { interrupt(); } routes such a wrapper to the default slot. So a third-party wrapper that only exposes getDelegate() keeps interrupting the wrong session, with no signal. A minimal non-doc mitigation would be one of: (a) log at WARN in the default method when ctx != null && ctx.sessionId() != null, or (b) keep a reflection-free unwrap hook (e.g. an optional DelegateAware marker interface) that the default method consults before falling back. Either closes the silent-regression hole without restoring the old reflection probe.

* @param threadId The AG-UI thread id for this request
* <p>Uses the resolved {@link RuntimeContext} so multi-session agents receive both the
* caller user id and the AG-UI {@code threadId} (session id). Replaces the former {@code
* interrupt(String threadId)} overload; call {@link Agent#interrupt(RuntimeContext)}

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.

The javadoc replacement note is the right call for readers of the source, but it does not reach consumers who only read release notes: ProcessResult.interrupt(String threadId) is gone and public class AguiUtil is deleted, both source-breaking for anyone compiling against the published 2.0.x artifacts. Please add one bullet to the v2 changelog/release notes (docs/v2/en/** + docs/v2/zh/**) naming Agent.interrupt(RuntimeContext) as the replacement — this PR currently touches zero docs/ paths.

* <p>Implementations of {@link #streamEvents(List, RuntimeContext)} must pass a non-null
* {@link RuntimeContext} into their execution pipeline (middleware, reactor context, and
* session lookup). Use {@link RuntimeContext#empty()} when the caller has none. The
* convenience overloads already do this, so custom agents should not re-introduce {@code

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.

Good — this makes "implementations pass a non-null RuntimeContext" an explicit contract instead of an emergent property of ReActAgent, and the matching @param note on ReActAgent#streamEvents(List, RuntimeContext) closes the earlier item. No change requested; noting it here so the thread is visibly resolved.

@oss-maintainer

Copy link
Copy Markdown
Collaborator

⚠️ Merge conflict detected

This PR currently conflicts with main and cannot be merged (head feat/event-streaming-agent). Please rebase (or merge main in) and resolve the conflicts:

git fetch upstream
git checkout feat/event-streaming-agent
git rebase upstream/main
# resolve conflicts, then:
git push --force-with-lease

Once conflicts are resolved, ping @oss-maintainer for a re-review if the head also moves. This is a one-time reminder.


Automated notification by github-manager-bot

@oss-maintainer

Copy link
Copy Markdown
Collaborator

⚠️ Merge conflict detected

This PR has conflicts with the main branch and cannot be merged. Please rebase or merge main into your branch and resolve the conflicts:

git fetch origin
git checkout feat/event-streaming-agent
git rebase origin/main
# resolve conflicts, then:
git push --force-with-lease

This is a one-time reminder. Feel free to @mention oss-maintainer for a re-review after conflicts are resolved.


Automated notification by github-manager-bot

Extract optional streaming and session contracts so protocol adapters can adapt custom agents without hard-coding ReActAgent or HarnessAgent.
@dragondyt
dragondyt force-pushed the feat/event-streaming-agent branch from d0b44c9 to 4bd0c65 Compare October 28, 2026 08:48
@mintlify

mintlify Bot commented Oct 28, 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 4bd0c65.

Approve preview

@dragondyt dragondyt changed the title feat(core): add EventStreamingAgent so AG-UI can adapt custom agents feat(core): add EventStreamingAgent and session-scoped Agent APIs Oct 28, 2026
@jujn jujn added the P2 重要不紧急 label Nov 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HarnessAgent和ReActAgent 中streamEvent 为什么不放在Agent接口层

3 participants