Repository navigation
Raise the Strands runner's recursion limit to allow 1,000 tool turns - #209
Merged
Merged
Conversation
Strands' event loop calls itself after every round of tool calls and adds 3 frames per turn, so Python's default limit of 1,000 frames ends a task after about 320 turns. A Claude Haiku 4.5 task in #206 crashed this way. The runner now raises the limit to 3,500 frames before it starts the agent: MAX_TOOL_TURNS (1,000) x FRAMES_PER_TOOL_TURN (3) plus 500 frames of headroom. It never lowers a higher limit. A task that runs past the budget still stops with RecursionError. Closes #208
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.
Summary
Strands' event loop calls itself after every round of tool calls (
_handle_tool_execution->recurse_event_loop->event_loop_cycle) and adds 3 Python frames per turn. With Python's default recursion limit of 1,000 frames, a Strands task crashes after about 320 tool turns. A Claude Haiku 4.5 task in #206 failed withRecursionError: maximum recursion depth exceeded.This PR raises the limit in
benchmarks/scripts/strands_agent_runner.pytoRECURSION_LIMIT= 3,500 frames before the agent starts. That isMAX_TOOL_TURNS(1,000) xFRAMES_PER_TOOL_TURN(3) plus 500 frames of headroom. The runner never lowers a higher limit, and a task that runs past 1,000 turns still stops withRecursionError. Only--agent strandsruns this file.Evidence
A fake model that answers every call with one no-op tool call, on Strands 1.57.1, with no network or real model:
RecursionErrorafter 319 turnsRecursionErrorafter 1,153 turnsStack depth grew from 29 frames at the first model call to 329 at the 101st, 3 frames per turn. Our longest finished Strands task took 222 turns. The first attempt at
consistent-csrf-across-toggle-endpointsin theminicpm5-2brun (#204) looped for 316 turns, just under the old ceiling of about 320.Changes
strands_agent_runner.py:MAX_TOOL_TURNS,FRAMES_PER_TOOL_TURN,RECURSION_HEADROOMandRECURSION_LIMITconstants, and_raise_recursion_limit(), called frommain().docs/strands-setup.md: a sixth row in the table of places the runner departs from Strands as it ships.docs/harness-strands-swe3.md: the note on Haiku's failed task points to this fix.Testing
uv run python -m unittest discover -s testspasses inbenchmarks/. Ruff, mypy and Bandit are clean, and thesecurity-checkgate passed.hello-worldrun throughrun-e2e-benchmark.sh --agent strandson vLLM scored 6/6 artifacts in 74 turns.Closes #208