-
Notifications
You must be signed in to change notification settings - Fork 719
Description
Checks
- I have updated to the lastest 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.25.0
Python Version
3.14.1
Operating System
macOS 26.3.1
Installation Method
other
Steps to Reproduce
- Create a Strands agent using the Bedrock model provider (ConverseStream API) — e.g., Claude Opus 4.6
- Equip the agent with tools that produce large outputs (e.g., AgentCore browser tool — page navigation, page inspection)
- Run an agent session where accumulated tool results push conversation context past the model's token limit (200k for Claude)
- Observe the error when the next ConverseStream call is made
Expected Behavior
The Bedrock model provider should detect a ValidationException with a "prompt is too long" message and raise ContextWindowOverflowException. This would allow conversation managers (e.g., SlidingWindowConversationManager) to catch the exception, call reduce_context(), trim conversation history, and retry automatically — which is how other model providers already handle context overflow.
Actual Behavior
The botocore.errorfactory.ValidationException propagates up as-is and gets wrapped as a generic EventLoopException. The SlidingWindowConversationManager overflow handling never fires because it's looking for ContextWindowOverflowException, not ValidationException. The agent fails hard instead of gracefully trimming context and retrying.
Error message:botocore.errorfactory.ValidationException: prompt is too long: 248369 tokens > 200000 maximum
Additional Context
- This is a widespread issue — multiple teams and users are hitting the same ValidationException on context overflow with Bedrock across #bedrock-interest, #wasabi-interest, #pippin-interest, #kiro-cli-internal-software-builders, #strands-agents-interest, and #bedrock-agents-interest. Users are forced to manually clear context or start new sessions.
- The Kiro CLI team shipped a fix for their version of this issue in CLI v1.26.2, suggesting the pattern is well-understood.
- Bedrock Agents (managed) also surfaces this as a validationException through InvokeAgent, so this may affect multiple integration paths.
Possible Solution
In the Bedrock model provider implementation, detect when:
- The exception type is a Bedrock ValidationException (via botocore)
- The error message contains "prompt is too long" (or similar pattern like "Input is too long")
→ Raise ContextWindowOverflowException instead of letting the ValidationException propagate.
This aligns Bedrock's behavior with other providers where token overflow is already surfaced as ContextWindowOverflowException, enabling existing conversation manager retry logic to work correctly.
Related Issues
No response