Skip to content

fix: chain reactive hooks using flatMap to preserve event modifications in A2aAgent#1126

Closed
jujn wants to merge 3 commits intoagentscope-ai:mainfrom
jujn:fix_1120
Closed

fix: chain reactive hooks using flatMap to preserve event modifications in A2aAgent#1126
jujn wants to merge 3 commits intoagentscope-ai:mainfrom
jujn:fix_1120

Conversation

@jujn
Copy link
Copy Markdown
Contributor

@jujn jujn commented Apr 4, 2026

Description

Close #1120
This PR fixes the issue where plugins like TTSHook failed in A2aAgent by chaining the hook executions with flatMap instead of isolated blocks.

Checklist

Please check the following items before code is ready to be reviewed.

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

@jujn jujn requested review from a team and Copilot April 4, 2026 06:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 fixes A2aAgent streaming hook behavior so that hook-returned (potentially modified) HookEvents are passed to subsequent hooks, aligning A2A streaming with the intended “hook chain” semantics and resolving cases like TTSHook-style plugin pipelines.

Changes:

  • Update TaskUpdateEventHandler to chain hook execution using Mono.flatMap(...) so event modifications propagate through the hook sequence.
  • Add a regression test ensuring a modified ReasoningChunkEvent produced by an earlier hook is observed by later hooks during streaming.

Reviewed changes

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

File Description
agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client/src/main/java/io/agentscope/core/a2a/agent/event/TaskUpdateEventHandler.java Chains hook execution via flatMap to preserve event modifications across hooks for streaming chunk updates.
agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client/src/test/java/io/agentscope/core/a2a/agent/A2aAgentTest.java Adds a streaming regression test verifying hook-chain event modification propagation (and side-effect execution).

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Taogang00
Copy link
Copy Markdown

你好,感谢pr, 我拉取了你的分支本地构建,在使用springboot流式接口时,还是没有生效,现在是这样的(目前1.0.11也是):
1、如果llm 回答的内容太少,没有音频内容输出
2、如果llm 回答的内容长些,有音频内容输出,但是只有一部分,就是只输出了内容的前一小部分(这里我怀疑是Agent流关闭时机的问题-tts 还没有输出完,A2AAgent 已经关闭了)
image
image
AgentClientTtsChatController.java
chat.html

@jujn jujn closed this Apr 7, 2026
@jujn jujn deleted the fix_1120 branch April 7, 2026 06:26
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.

[Bug]: A2aAgent 中使用ttshook 无效

3 participants