Skip to content

Introduce AgentProtocolEventBus for pluggable SSE event handling - #2634

Merged
chickenlj merged 1 commit into
agentscope-ai:mainfrom
songdayi:feature/agent-protocol-event-bus-extension
Aug 9, 2026
Merged

Introduce AgentProtocolEventBus for pluggable SSE event handling#2634
chickenlj merged 1 commit into
agentscope-ai:mainfrom
songdayi:feature/agent-protocol-event-bus-extension

Conversation

@songdayi

@songdayi songdayi commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.3-SNAPSHOT(pom.xml 中的 )

Description

背景: 当前 Agent Protocol 的 SSE 事件流由 AgentProtocolTaskEventBus 直接提供,回放缓冲保存在进程内存中,且 TaskStore、自动配置与具体实现类强耦合。对于需要跨实例(多副本)流式输出的场景(例如基于 Redis Streams 的共享事件总线),只能复制代码改造,无法通过配置替换实现。

改动内容:

新增 AgentProtocolEventBus 接口,抽象事件总线能力(publish / subscribe / complete),由实现方负责单调递增 seq 的分配与回放
AgentProtocolTaskEventBus 实现该接口,保持原有进程内回放缓冲行为不变(默认实现)
AgentProtocolAutoConfiguration 改为声明 AgentProtocolEventBus bean,并加上 @ConditionalOnMissingBean,允许应用提供自定义实现(如 Redis Streams 适配器)自动覆盖默认实现
AgentProtocolTaskStore 依赖接口 AgentProtocolEventBus 而非具体类
新增测试:
AgentProtocolAutoConfigurationTest:默认创建内存实现;用户提供自定义 bean 时保留自定义实现
AgentProtocolTaskEventBusTest 新增用例:验证并发 publish 时 seq 单调唯一

如何测试:

格式检查

mvn spotless:check

相关测试(注意:本机需 JDK 17+ 运行 Maven,默认 JDK 8 与 spotless 3.4.0 不兼容)

mvn test -pl agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agent-protocol
-Dtest='AgentProtocolTaskEventBusTest,AgentProtocolAutoConfigurationTest'

验证结果:spotless:check 通过;7 个测试(AgentProtocolTaskEventBusTest 5 + AgentProtocolAutoConfigurationTest 2)全部通过,BUILD SUCCESS。

破坏性变更: 无。仅新增接口与抽象,默认行为不变。

Checklist

Code has been formatted with mvn spotless:apply(已验证 spotless:check 通过)
All tests are passing (mvn test)(已跑改动模块相关测试,7 个全部通过;全量 mvn test 未执行)
Javadoc comments are complete and follow project conventions(新增接口含完整 Javadoc)
Related documentation has been updated (e.g. links, examples, etc.)(本次未更新文档;如需可补充自定义 EventBus 的使用说明)
Code is ready for review

Copilot AI lite review requested due to automatic review settings August 9, 2026 12:42
@CLAassistant

CLAassistant commented Aug 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new AgentProtocolEventBus abstraction so Agent Protocol SSE streaming can be backed by pluggable/shared implementations (e.g., cross-instance event buses), while keeping the existing in-memory replay behavior as the default.

Changes:

  • Added AgentProtocolEventBus interface (publish/subscribe/complete) for pluggable SSE event handling.
  • Updated default in-memory bus (AgentProtocolTaskEventBus) to implement the interface and updated wiring (AgentProtocolAutoConfiguration, AgentProtocolTaskStore) to depend on the interface.
  • Added tests to validate auto-configuration override behavior and to validate sequencing behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agent-protocol/src/main/java/io/agentscope/extensions/agentprotocol/AgentProtocolEventBus.java New event bus interface defining the contract for publish/subscribe/complete.
agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agent-protocol/src/main/java/io/agentscope/extensions/agentprotocol/AgentProtocolTaskEventBus.java Default in-memory implementation updated to implement the new interface.
agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agent-protocol/src/main/java/io/agentscope/extensions/agentprotocol/AgentProtocolAutoConfiguration.java Registers AgentProtocolEventBus conditionally to allow user-provided implementations to override.
agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agent-protocol/src/main/java/io/agentscope/extensions/agentprotocol/AgentProtocolTaskStore.java Switches from concrete bus dependency to the interface.
agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agent-protocol/src/test/java/io/agentscope/extensions/agentprotocol/AgentProtocolTaskEventBusTest.java Adds contract/concurrency-related sequencing tests.
agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agent-protocol/src/test/java/io/agentscope/extensions/agentprotocol/AgentProtocolAutoConfigurationTest.java New test verifying default bus creation and custom-bean override behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@@ -53,7 +53,8 @@
public class AgentProtocolAutoConfiguration {

@Bean
Comment on lines +62 to +81
@Test
void publish_assignsUniqueSequencesForConcurrentPublishers() {
int eventCount = 200;

List<RemoteAgentEvent> published =
LongStream.range(0, eventCount)
.parallel()
.mapToObj(
ignored ->
bus.publish(
"task-concurrent", event(RemoteEventType.STATUS)))
.toList();

assertEquals(
eventCount, published.stream().map(RemoteAgentEvent::getSeq).distinct().count());
assertEquals(
LongStream.rangeClosed(1, eventCount).boxed().toList(),
published.stream().map(RemoteAgentEvent::getSeq).sorted().toList());
assertTrue(published.stream().allMatch(e -> "task-concurrent".equals(e.getTaskId())));
}
Comment on lines 91 to 95
public AgentProtocolTaskStore(
AgentFactory agentFactory,
ProtocolTaskRepository taskRepository,
AgentProtocolTaskEventBus eventBus,
AgentProtocolEventBus eventBus,
AgentProtocolProperties properties) {
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@chickenlj
chickenlj merged commit f4bb687 into agentscope-ai:main Aug 9, 2026
6 checks passed
wzl521 pushed a commit to wzl521/agentscope-java that referenced this pull request Aug 12, 2026
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.

4 participants