fix: remove duplicate action_step yield and prevent NameError when max_steps=0#2323
Open
gauravSsinha wants to merge 1 commit into
Open
Conversation
…x_steps=0 Two bugs in _run_stream: 1. Duplicate yield: when max_steps is reached, action_step was yielded in the finally block (line 601) AND again on line 605. Consumers of the stream received duplicate step events. 2. NameError: if max_steps=0, the while loop never executes so action_step is never defined. The post-loop code tried to yield this undefined variable. Fix: remove the redundant 'yield action_step' after the while loop. The finally block already yields every action_step, and _handle_max_steps_reached handles the max-steps case without needing to re-yield the last step. Fixes huggingface#1816 Signed-off-by: Gaurav Kumar Sinha <gaurav@substrai.dev>
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.
Description
Fixes two bugs in
MultiStepAgent._run_stream():Duplicate yield: When
max_stepsis reached,action_stepwas yielded in thefinallyblock AND again after the while loop. Stream consumers received duplicate step events.NameError when max_steps=0: If
max_steps=0, the while loop never executes, soaction_stepis never defined. The post-loopyield action_stepraisesNameError.Fix
Remove the redundant
yield action_stepafter the while loop. Thefinallyblock already yields everyaction_stepon each iteration, and_handle_max_steps_reached()handles the max-steps case without needing to re-yield.One-line change
if not returned_final_answer and self.step_number == max_steps + 1: final_answer = self._handle_max_steps_reached(task) - yield action_stepFixes #1816