Fix max-steps warning timing to appear after final step completes#249
Merged
Fix max-steps warning timing to appear after final step completes#249
Conversation
Fixes #221 - Off-by-one bug where max-steps warning appeared BEFORE the final step's work was executed. ## Problem With max_steps=5, the warning appeared after Step 4 output and before Step 5 began executing. This created confusion as users saw: - Step 4 output - Warning: "Reached maximum steps limit (5 steps)" - Step 5 output ## Root Cause The max-steps check occurred immediately after incrementing steps_taken (line 1173) and before the step's actual work was performed (lines 1182+). ## Solution Move the max-steps check to the END of the while loop, after: 1. The step's work completes 2. Final answer check (lines 1968-1972) This ensures Step 5 executes completely before the warning appears. ## After Fix Users now see: - Step 4 output - Step 5 output - Warning: "Reached maximum steps limit (5 steps)" The warning only appears if no final answer was provided during Step 5. If a final answer is found, the agent exits cleanly without showing the warning. ## Testing - All unit tests pass (27 tests in tests/unit/) - Verified control flow with demonstration script - Default max_steps remains at 5 (conservative)
kovtcharov
approved these changes
Jan 23, 2026
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 #221
Problem
The max-steps warning appeared BEFORE the final step's work was executed, creating confusing output:
Before this fix (with max_steps=5):
Root Cause
The while loop checked
if steps_taken == steps_limitimmediately after incrementing the counter (line 1173), but before the step's actual work was performed. This caused the warning to appear prematurely.Solution
Move the max-steps check to the end of the while loop, after:
This ensures Step 5 executes completely before any warning appears.
After This Fix
Users now see the correct behavior:
If a final answer is provided during Step 5, the agent exits cleanly without showing the warning at all.
Testing
tests/unit/)max_steps=5preserved (conservative base class default)Files Changed
src/gaia/agents/base/agent.py: Moved max-steps check from line 1177 to line 1975