feat(core): add middleware execution ordering - #2532
Open
zouyx wants to merge 2 commits into
Open
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an explicit middleware ordering mechanism to AgentScope-Java so middleware execution can be prioritized deterministically (while keeping registration order stable for ties), with accompanying tests and documentation updates.
Changes:
- Introduces
MiddlewareBase.order()(default1) as the standard middleware priority hook. - Sorts registered middlewares once during
ReActAgent.Builder.build()using a stable descending sort byorder(). - Adds/updates core + harness tests and updates English/Chinese middleware documentation to describe the ordering behavior.
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 |
|---|---|
| docs/v2/zh/docs/building-blocks/middleware.md | Documents the new order()-based execution ordering (Chinese). |
| docs/v2/en/docs/building-blocks/middleware.md | Documents the new order()-based execution ordering (English). |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/HarnessMiddlewareOrderTest.java | Adds harness-level coverage to validate ordering interactions with harness middlewares. |
| agentscope-core/src/test/java/io/agentscope/core/agent/ReActAgentNewLoopBuilderTest.java | Adds core-level coverage for descending + stable tie behavior. |
| agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java | Applies a stable descending sort of middlewares by MiddlewareBase.order() during build. |
| agentscope-core/src/main/java/io/agentscope/core/middleware/MiddlewareBase.java | Adds the new order() API with Javadoc describing its semantics. |
| ### Execution order | ||
|
|
||
| Onion hooks (`onAgent`, `onReasoning`, `onActing`, `onModelCall`) — **the first middleware in the list is outermost**: | ||
| Onion hooks (`onAgent`, `onReasoning`, `onActing`, `onModelCall`) are ordered by `MiddlewareBase.order()` — **higher values are outermost**. The default order is `1`; middlewares with the same order retain their builder registration order: |
| ### 执行顺序 | ||
|
|
||
| Onion 类 hook(`onAgent`、`onReasoning`、`onActing`、`onModelCall`)—— **列表中第一个 middleware 处于最外层**: | ||
| Onion 类 hook(`onAgent`、`onReasoning`、`onActing`、`onModelCall`)按 `MiddlewareBase.order()` 排序——**数值越大越处于最外层**。默认值是 `1`;相同 order 的 middleware 保持其 Builder 注册顺序: |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
5 tasks
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.0.1-SNAPSHOT
Description
Closes #2449
Adds
MiddlewareBase.order()with a default priority of1.ReActAgent.Builder.build()now performs one stable descending sort after all user and automatic middleware registrations. Higher numeric values are outermost; equal priorities retain registration order.Also adds core/Harness coverage and updates Chinese and English middleware documentation.
Validation:
mvn -pl agentscope-core,agentscope-harness -am \ -Dtest=ReActAgentNewLoopBuilderTest,HarnessMiddlewareOrderTest \ -Dsurefire.failIfNoSpecifiedTests=false testChecklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)