fix: add loop detection to prevent agent from repeating identical actions#392
Open
octo-patch wants to merge 1 commit intoalibaba:mainfrom
Open
fix: add loop detection to prevent agent from repeating identical actions#392octo-patch wants to merge 1 commit intoalibaba:mainfrom
octo-patch wants to merge 1 commit intoalibaba:mainfrom
Conversation
…ions (fixes alibaba#112) When an agent gets stuck repeating the same action (e.g., clicking the same button 4 times in a row), it now receives a system observation warning that its current approach is not working and should try a different strategy. The detection checks the last 4 consecutive steps. If they all share the same action name and identical input, a loop is flagged and an observation is pushed into the agent history.
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.
Fixes #112
Problem
The agent can get stuck in an infinite loop, repeatedly calling the same action with the same input (e.g., clicking the same button or entering the same text 4+ times in a row) without making progress. There was already a
@todo loop detectioncomment in#handleObservationsacknowledging this.Solution
Added loop detection logic in
PageAgentCore.#handleObservations(). After each step, the agent checks the last 4 consecutive history entries. If all 4 share the identical action name and input, a system observation is pushed into the agent's history:This warning is included in the next LLM invocation as part of
<agent_history>, prompting the model to reconsider its approach.Testing
JSON.stringify(action.input)for deep equality on the action payload.click_element_by_index,input_text,scroll_down, etc.).