You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have updated to the latest minor and patch version of Strands
I have checked the documentation and this is not expected behavior
I have searched ./issues and there are no duplicates of my issue
Strands Version
1.36.0
Python Version
3.12+
Operating System
All
Installation Method
pip
Steps to Reproduce
Create an agent with tools
Invoke the agent with input that causes the model to hit the max_tokens limit
Catch the MaxTokensReachedException
Attempt to invoke the same agent instance again with a new prompt
Expected Behavior
When max_tokens is reached, the agent raises an exception (this is fine)
The caller catches the exception and can continue using the same agent instance for subsequent calls without reinitializing
The exception message should not say "unrecoverable state" — hitting a token budget is a recoverable, expected condition
Actual Behavior
The exception declares an "unrecoverable state" at event_loop.py line 177:
MaxTokensReachedException: Agent has reached an unrecoverable state due to max_tokens limit.
Depending on the context, the agent may not be reusable after this exception without a full reset. In hosted environments where the agent loop runs inside a managed runtime, an unrecoverable state means the entire invocation fails with no way to return partial results or gracefully degrade.
In the AgentCore Harness context, there are two levels of maxTokens: a per-LLM-call cap (bedrockModelConfig.maxTokens) and a top-level agent loop budget (maxTokens). Both should result in recoverable states.
The relevant code path is in src/strands/event_loop/event_loop.py lines 167-180 where stop_reason == "max_tokens" triggers the exception.
Recovery logic exists in src/strands/event_loop/_recover_message_on_max_tokens_reached.py but only handles tool use cleanup — it does not help the caller access partial results.
Possible Solution
Make the agent instance reusable after MaxTokensReachedException is raised — no internal state should be corrupted
Rename or update the exception message to remove "unrecoverable state" (e.g., "Agent loop stopped: max_tokens limit reached")
Add partial results to the exception object by accepting an optional Message dict in MaxTokensReachedException.__init__ so callers can extract whatever was generated before the limit was hit
Checks
Strands Version
1.36.0
Python Version
3.12+
Operating System
All
Installation Method
pip
Steps to Reproduce
max_tokenslimitMaxTokensReachedExceptionExpected Behavior
max_tokensis reached, the agent raises an exception (this is fine)Actual Behavior
The exception declares an "unrecoverable state" at
event_loop.pyline 177:Depending on the context, the agent may not be reusable after this exception without a full reset. In hosted environments where the agent loop runs inside a managed runtime, an unrecoverable state means the entire invocation fails with no way to return partial results or gracefully degrade.
Additional Context
max_tokens. That issue is closed, but the recoverability concern remains.maxTokens: a per-LLM-call cap (bedrockModelConfig.maxTokens) and a top-level agent loop budget (maxTokens). Both should result in recoverable states.src/strands/event_loop/event_loop.pylines 167-180 wherestop_reason == "max_tokens"triggers the exception.src/strands/event_loop/_recover_message_on_max_tokens_reached.pybut only handles tool use cleanup — it does not help the caller access partial results.Possible Solution
MaxTokensReachedExceptionis raised — no internal state should be corruptedMessagedict inMaxTokensReachedException.__init__so callers can extract whatever was generated before the limit was hitRelated Issues
#1320