Repository navigation
feat(a2a): run middlewares in A2aAgent - #3695
Merged
jujn merged 1 commit intoOct 21, 2026
Merged
Conversation
A2aAgent only took hooks, which are deprecated for removal, so A2A calls could not be extended with MiddlewareBase. The builder now takes middlewares, ordered and filtered by active points like in ReActAgent. onAgent wraps the whole call, so it sees and can change every event of streamEvents() and the result of call(). onReasoning wraps the exchange with the remote agent: its input messages are the messages sent, and its events are the text and thinking the remote agent streams. The other extension points do not apply to a remote agent. Hooks work as before.
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
jujn
approved these changes
Oct 21, 2026
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentScope-Java Version
2.1.0-SNAPSHOT (main)
Description
Fixes #2612
A2A client 去掉弃用 API 的第三步(前两步是 #3663、#3674):
A2aAgent支持MiddlewareBase。之前只能用已弃用的 Hook 扩展 A2A 调用。另:#2612 的认领人提过一个 draft #2953,基于 A2A 0.3 的代码,9/3 之后没有更新,#3590 升级到 1.0 后已无法合入。本 PR 在当前 main 上实现
改动
A2aAgent.Builder加middleware(...)/middlewares(...),排序(order())和按activePoints()筛选都和ReActAgent一致。onAgent:包住整次调用。call()和streamEvents()都经过它,middleware 能看到并改写每个事件,包括call()返回的结果。onReasoning:包住和远端 Agent 的交互。输入消息就是发给远端的消息(改写后远端收到的就是改写后的),事件是远端流式返回的文本、思考增量。tools为空,options为默认值。onActing、onModelCall、onSystemPrompt、onAgentStateReady)不适用于远端 Agent,Javadoc 和文档里写明。stream()行为不变;hook()和ReActAgent一样不额外标弃用。测试
A2aAgentTest:onAgent按order()由外到内执行,外层改写的结果就是call()的返回值;onReasoning拿到发给远端的消息,改写后远端收到改写后的消息,并能看到远端流式返回的增量,streamEvents也照常收到;ON_ACTING生效的 middleware 不会在onAgent执行。mvn -B -T1C clean verify99 个模块全部通过(11,084 个测试,0 失败,200 跳过)。补丁覆盖率:行 47/49,分支 8/12(未覆盖的两行是批量添加的middlewares(List))。Checklist
mvn spotless:applymvn -B -T1C clean verify)