Skip to content

fix(A2A): fix A2aAgent lifecycle events to support TTSHook and reasoning completion#1150

Open
jujn wants to merge 2 commits intoagentscope-ai:mainfrom
jujn:fix_1120
Open

fix(A2A): fix A2aAgent lifecycle events to support TTSHook and reasoning completion#1150
jujn wants to merge 2 commits intoagentscope-ai:mainfrom
jujn:fix_1120

Conversation

@jujn
Copy link
Copy Markdown
Contributor

@jujn jujn commented Apr 7, 2026

Description

Close #1120
This PR fixes the issue where plugins like TTSHook failed in A2aAgent by introducing a state machine in ClientEventContext to guarantee the execution order of PreReasoningEvent, ReasoningChunkEvent, and PostReasoningEvent.

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 7, 2026 08:30
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 lifecycle hook behavior so that reasoning lifecycle events (PreReasoning / ReasoningChunk / PostReasoning) are emitted in a consistent order, enabling plugins like TTSHook to work correctly with A2A streaming.

Changes:

  • Introduces unified lifecycle event publishing in ClientEventContext (pre/chunk/post).
  • Updates A2A client event handlers to use the unified publishing APIs and trigger PreReasoning/PostReasoning at the right times.
  • Extends A2aAgentTest to validate lifecycle hook triggering and updates stream expectations to include PostReasoning.

Reviewed changes

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

Show a summary per file
File Description
agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client/src/main/java/io/agentscope/core/a2a/agent/A2aAgent.java Captures input messages into the client event context for PreReasoning emission.
agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client/src/main/java/io/agentscope/core/a2a/agent/event/ClientEventContext.java Adds unified APIs to publish Pre/Chunk/Post reasoning hook events with “fire once” guards.
agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client/src/main/java/io/agentscope/core/a2a/agent/event/TaskEventHandler.java Triggers PreReasoning when a task is created.
agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client/src/main/java/io/agentscope/core/a2a/agent/event/TaskUpdateEventHandler.java Routes task updates through unified chunk/post publishers (instead of ad-hoc hook calls).
agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client/src/main/java/io/agentscope/core/a2a/agent/event/MessageEventHandler.java Triggers post reasoning lifecycle on single-message completion flows.
agentscope-extensions/agentscope-extensions-a2a/agentscope-extensions-a2a-client/src/test/java/io/agentscope/core/a2a/agent/A2aAgentTest.java Updates stream assertions and adds a new test for lifecycle hook triggering.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 84.61538% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...scope/core/a2a/agent/event/ClientEventContext.java 81.81% 1 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@Taogang00
Copy link
Copy Markdown

测试了,可以了,谢谢

@jujn
Copy link
Copy Markdown
Contributor Author

jujn commented Apr 7, 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.

[Bug]: A2aAgent 中使用ttshook 无效

3 participants