-
Notifications
You must be signed in to change notification settings - Fork 470
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.14.0
Python Version
3.12
Operating System
Linux
Installation Method
pip
Steps to Reproduce
- Using SummarizingConversationManager
- Using structured_output_model
- hitting a context window overflow
Using Cluade Haiku 4.5 model for the agent with above conditions. Using Pydantic class for structured output. After few intreactions with the agent, the context window overflow reaches and then the validation exception is thrown by bedrock model.
Agent execution failed: An error occurred (ValidationException) when calling the ConverseStream operation: User messages cannot contain tool uses. Please remove the tool uses and try again
The user messages are simple instructions for web automation.
My hypothesis is:
The SummarizingConversationManager._generate_summary() method converts the assistant's response (which contains toolUse for structured output) into a user message. This violates AWS Bedrock's Converse API rules:
- User messages can only contain text or toolResult
- Assistant messages contain toolUse
When you configure an agent with [structured_output_model=CustomisedResult], every agent response includes a toolUse block for that structured output. The summarization process doesn't account for this, creating malformed messages.
Expected Behavior
The validation exception should not be thrown and the agent should summarise the conversation correctly.
Actual Behavior
An error occurred (ValidationException) when calling the ConverseStream operation: User messages cannot contain tool uses. Please remove the tool uses and try again."",""exception"":""Traceback (most recent call last):
File \""/usr/local/lib/python3.12/site-packages/strands/models/bedrock.py\"", line 669, in _stream
response = self.client.converse_stream(**request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File \""/usr/local/lib/python3.12/site-packages/botocore/client.py\"", line 602, in _api_call
return self._make_api_call(operation_name, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File \""/usr/local/lib/python3.12/site-packages/amazon/opentelemetry/distro/patches/_botocore_patches.py\"", line 510, in patched_api_call
result = original_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File \""/usr/local/lib/python3.12/site-packages/botocore/context.py\"", line 123, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File \""/usr/local/lib/python3.12/site-packages/botocore/client.py\"", line 1078, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the ConverseStream operation: The model returned the following errors: Input is too long for requested model.
Additional Context
No response
Possible Solution
Remove structured_output_model tool from the agent while summarizing the conversation.
Related Issues
No response