Skip to content

feat(a2a): add streamEvents to A2aAgent - #3674

Merged
jujn merged 1 commit into
agentscope-ai:mainfrom
guslegend0510:fix/issue-2105-a2a-stream-events
Oct 20, 2026
Merged

jujn merged 1 commit into
agentscope-ai:mainfrom
guslegend0510:fix/issue-2105-a2a-stream-events

Conversation

@guslegend0510

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT (main)

Description

Fixes #2105

A2A client 去掉弃用 API 的第二步(第一步是 #3663):给 A2aAgent 加 streamEvents()。之前流式拿远端 Agent 的输出,只能用已弃用的 stream() 或 Hook。

改动

  • A2aAgent.streamEvents(Msg) / (List<Msg>) / (List<Msg>, RuntimeContext),返回 Flux<AgentEvent>,事件和 ReActAgent 一致:
    • AgentStartEvent
    • 远端流式返回的文本、思考:TextBlockDeltaEvent、ThinkingBlockDeltaEvent
    • AgentResultEvent:和 call() 返回的是同一条消息
    • AgentEndEvent;调用失败时以原错误结束。
  • call() 照 ReActAgent 的写法覆盖 callInternal,从同一条事件流里取 AgentResultEvent,保证两者结果一致。
  • 工具调用和工具结果只放在结果消息里,不拆成事件:远端是一块块推的,没有明确的开始和结束,拆成 Start/End 会重复或不完整。
  • 用户的 Hook(包括 Pre/Chunk/PostReasoning)和弃用的 stream() 行为不变。
  • 文档:中英文 a2a.md 加了 streamEvents 的用法。

测试

  • A2aAgentTest:事件顺序、文本和思考的增量、replyId 一致、AgentResultEvent 与 call() 结果一致;带 RuntimeContext 时 AgentStartEvent 带上会话 id;调用失败时以原错误结束且关闭 client。用空实现的骨架确认先失败。
  • A2aHttpEndToEndTest(真实 HTTP,连 Starter 服务端):远端流式返回思考和文本,streamEvents 逐段收到增量,结果与 call() 一致。
  • 原有测试全部通过:A2A client 模块 124 个;Starter 端到端 15 个里 14 个通过、1 个跳过(等 fix(a2a): 取消任务后结束服务端执行,并释放服务端线程池 #3578 的中断用例);Nacos A2A 模块全部通过。
  • 本地(JDK 17,macOS):mvn -B -T1C clean verify 99 个模块全部通过(11,047 个测试,0 失败,200 跳过);之后只补了一条 RuntimeContext 的测试,client 模块 verify 通过。补丁覆盖率:行 54/56,分支 11/14。

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn -B -T1C clean verify)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

A2aAgent had no streamEvents; streaming a remote agent was only possible
through the deprecated stream() or hooks.

streamEvents streams AgentStartEvent, the text and thinking the remote
agent streams as TextBlockDeltaEvent and ThinkingBlockDeltaEvent,
AgentResultEvent and AgentEndEvent, like ReActAgent. call() returns the
result of the same stream, so both always agree. Tool calls and tool
results are only in the result message, since the remote agent sends
them in chunks without start or end. Hooks and the deprecated stream()
work as before.
@jujn
jujn merged commit 00585ec into agentscope-ai:main Oct 20, 2026
4 of 5 checks passed
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.

[Feature]: A2aAgent没有streamEvents,现在的stream都是@Deprecated(since = "2.0.0", forRemoval = true)

3 participants