fix(agent): finalize react loop on max iterations#1877
Open
BreezyB1n wants to merge 1 commit into
Open
Conversation
ea222b2 to
27690f3
Compare
27690f3 to
abd6eeb
Compare
abd6eeb to
62f0920
Compare
Author
|
@DavdGao Could you please take a look at this pull request (PR) when you have a moment? Thanks a lot. |
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.
PR Title
fix(agent): finalize react loop on max iterations
AgentScope Version
2.0.1
Description
Refs #1805
This PR changes how a ReAct agent behaves when it reaches
max_iters.Previously, the agent stopped the loop and returned a fixed message saying the reasoning-acting loop had reached its maximum iterations. That could end the reply abruptly even when the agent had already completed useful tool work.
Now, when the loop reaches
max_iters, the agent:ExceedMaxItersEvent, so the condition remains observable;HintBlockto the agent context with instructions to stop using tools and summarize progress;ToolChoice(mode="none");The AGUI protocol mapping now treats
ExceedMaxItersEventas aCUSTOMevent namedexceed_max_itersinstead of aRUN_ERROR, since the run can still finish normally after the final text-only reasoning step.Tests cover the final model turn, event stream behavior, persisted hint context, and AGUI protocol conversion.
Compatibility note
ExceedMaxItersEventis still emitted. In the AGUI protocol mapping, consumers should now handle it as aCUSTOMevent namedexceed_max_itersinstead ofRUN_ERROR.Documentation
No documentation PR is included. This change does not add a public API. It changes the runtime behavior after
ReActConfig.max_itersis reached and is covered by tests.Validation
Manual validation
Ran a local smoke test with DashScope
qwen-plusandReActConfig(max_iters=1)using a tool that encourages the first model turn to call a tool.Observed behavior:
continue_workonce.EXCEED_MAX_ITERSafter the first tool result.EXCEED_MAX_ITERS.REPLY_END.source="max_iters".Summary output:
Screenshot:
Checklist