-
Notifications
You must be signed in to change notification settings - Fork 808
feat(agent): add max_turns and max_token_budget execution limits #2139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rshriharripriya
wants to merge
10
commits into
strands-agents:main
Choose a base branch
from
rshriharripriya:feat/agent-execution-limits
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0d38887
feat: implement execution limits for `max_turns` and `max_token_budget`
rshriharripriya c850c44
feat: improve execution limits handling
rshriharripriya f634989
refactor: simplify exception raising and token accumulation logic in …
rshriharripriya b9cf5bd
refactor: clarify `max_turns` docstring and streamline test setup wit…
rshriharripriya cdfa156
test: add `test_max_turns_allows_exactly_n_cycles` to verify behavior…
rshriharripriya ff0c1bd
Merge remote-tracking branch 'origin/main' into feat/agent-execution-…
rshriharripriya 81fd393
refactor: replace exceptions with stop events for `max_turns` and `ma…
rshriharripriya db7b74d
Merge remote-tracking branch 'origin/main' into feat/agent-execution-…
rshriharripriya 52b7e57
Merge remote-tracking branch 'origin/main' into feat/agent-execution-…
rshriharripriya e629a34
test: add `test_max_turns_skipped_model_cycle_does_not_consume_turn` …
rshriharripriya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor correctnss concern -> the early-exit guard fires before checking
agent._interrupt_state.activatedand_has_tool_use_in_latest_message. Those 2 paths execute the model at stop_reason = "tool_use" without incrementing _invocation_turn_count. This means a sequence like:this could burn an extra cycle past
max_turns=1in interrupt/existing-tool-use scenarios. This is an edge case and may be acceptable, but it's worth a comment acknowledging the behavior or a test covering it.invocation_state["request_state"]at early exit, by line 123–124 of event_loop.py, request_state is initialized before the try block where the limit checks now live, so invocation_state["request_state"] is always present when the EventLoopStopEvent is yielded. Safe.The
_retry_strategyattribute name inconsistency, the existing mock fixture in test_event_loop.py sets mock.retry_strategy (no underscore prefix) while agent.py stores it as self._retry_strategy. This is a pre-existing issue, not introduced by this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment at the branch point making it explicit that neither the interrupt nor existing-tool-use path increments _invocation_turn_count (no model call = no turn consumed), and added test_max_turns_skipped_model_cycle_does_not_consume_turn to pin that behaviour.
Also caught two small things on the final pass: stale stop_reason examples in the stream_async/call docstrings weren't listing the two new stop reasons, and test_max_token_budget_stops_when_counter_already_at_limit wasn't using apply_execution_limit_defaults like the rest of the file. Both fixed.
I learned a lot from this one, Thanks for the review, really appreciated!