fix(harness): avoid duplicating GracefulShutdownMiddleware in fromAgent#1952
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #1950 by preventing GracefulShutdownMiddleware from being duplicated when cloning a ReActAgent into a HarnessAgent via HarnessAgent.Builder.fromAgent(...). It ensures the cloned delegate ends up with exactly one system-level graceful-shutdown middleware while still propagating user-provided middleware.
Changes:
- Exclude
GracefulShutdownMiddlewarefrom the middleware list copied from the source agent duringfromAgent(...). - Add a regression assertion to verify the cloned delegate contains exactly one
GracefulShutdownMiddleware.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgent.java | Filters out GracefulShutdownMiddleware from copyable middlewares during fromAgent(...) cloning. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/HarnessAgentTest.java | Adds regression coverage asserting the cloned delegate has exactly one GracefulShutdownMiddleware. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
Author
I think it doesn't matter. Because if i don't change this line, there is two |
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.0-SNAPSHOT
Description
This PR fixes #1950.
Background:
When
HarnessAgent.Builder.fromAgent(ReActAgent)is used to wrap an existingReActAgent, the source agent's middleware chain currently gets copied into the harness builder. SinceReActAgentalways adds a system-levelGracefulShutdownMiddlewareduring construction, copying that middleware causes the final harness delegate to contain twoGracefulShutdownMiddlewareinstances.Purpose:
Ensure
GracefulShutdownMiddlewareappears exactly once after cloning aReActAgentinto aHarnessAgent.Changes made:
HarnessAgent.Builder.filterCopyableMiddlewares(...)to excludeGracefulShutdownMiddlewareHarnessAgentTestto verify the cloned delegate contains exactly oneGracefulShutdownMiddlewareHow to test:
mvn -T1 -pl agentscope-harness -am -Dtest=HarnessAgentTest testfromAgent_filtersRuntimeMiddlewareAndStillPropagatesUserMiddlewarepasses and the cloned delegate keeps only oneGracefulShutdownMiddlewareChecklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)