generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 590
Open
Labels
bugSomething isn't workingSomething isn't working
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.20.0
Python Version
3.13.5
Operating System
macos 15.7.2
Installation Method
pip
Steps to Reproduce
- Create an agent with any main tool and also add strands stop tool
- Ask agent something that triggers the main tool,
- As the tool is in progress, trigger stop (can be done via direct tool call): https://github.com/strands-agents/tools/blob/main/src/strands_tools/stop.py#L20
from strands import Agent, ToolContext, tool
from strands_tools import stop
@tool(context=True)
def the_tool(tool_context: ToolContext):
tool_context.agent.tool.stop()
tool_context.invocation_state.get("request_state", {})["stop_event_loop"] = True
return f"Result stored in {id}"
agent = Agent(tools=[the_tool, stop])
result = agent("Say hi, then run the_tool")
agent("Continue on!")Expected Behavior
Agent should stop gracefully when stop tool is triggered and then resume back and function normally when asked followup/message is sent.
Actual Behavior
Stop tool, as expected stops the agent but then causes agent to reach a permanent failure scenario (stuck in error) as conversation gets corrupted with following exception:
raise error_class(parsed_response, operation_name)
botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the ConverseStream operation: The number of toolResult blocks at messages.26.content exceeds the number of toolUse blocks of previous turn.
└ Bedrock region: us-west-2
└ Model id: us.anthropic.claude-sonnet-4-20250514-v1:0
Full Error
ERROR | strands.event_loop.event_loop | cycle failed
Traceback (most recent call last):
File "{ProjectPath}/.venv/lib/python3.13/site-packages/strands/event_loop/event_loop.py", line 192, in event_loop_cycle
async for tool_event in tool_events:
yield tool_event
File "{ProjectPath}/.venv/lib/python3.13/site-packages/strands/event_loop/event_loop.py", line 536, in _handle_tool_execution
async for event in events:
yield event
File "{ProjectPath}/.venv/lib/python3.13/site-packages/strands/event_loop/event_loop.py", line 280, in recurse_event_loop
async for event in events:
yield event
File "{ProjectPath}/.venv/lib/python3.13/site-packages/strands/event_loop/event_loop.py", line 155, in event_loop_cycle
async for model_event in model_events:
if not isinstance(model_event, ModelStopReason):
yield model_event
File "{ProjectPath}/.venv/lib/python3.13/site-packages/strands/event_loop/event_loop.py", line 400, in _handle_model_execution
raise e
File "{ProjectPath}/.venv/lib/python3.13/site-packages/strands/event_loop/event_loop.py", line 341, in _handle_model_execution
async for event in stream_messages(
...<7 lines>...
yield event
File "{ProjectPath}/.venv/lib/python3.13/site-packages/strands/event_loop/streaming.py", line 457, in stream_messages
async for event in process_stream(chunks, start_time):
yield event
File "{ProjectPath}/.venv/lib/python3.13/site-packages/strands/event_loop/streaming.py", line 391, in process_stream
async for chunk in chunks:
...<22 lines>...
handle_redact_content(chunk["redactContent"], state)
File "{ProjectPath}/.venv/lib/python3.13/site-packages/strands/models/bedrock.py", line 647, in stream
await task
File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/threads.py", line 25, in to_thread
return await loop.run_in_executor(None, func_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/concurrent/futures/thread.py", line 59, in run
result = self.fn(*self.args, **self.kwargs)
File "{ProjectPath}/.venv/lib/python3.13/site-packages/opentelemetry/instrumentation/threading/__init__.py", line 171, in wrapped_func
return original_func(*func_args, **func_kwargs)
File "{ProjectPath}/.venv/lib/python3.13/site-packages/strands/models/bedrock.py", line 768, in _stream
raise e
File "{ProjectPath}/.venv/lib/python3.13/site-packages/strands/models/bedrock.py", line 683, in _stream
response = self.client.converse_stream(**request)
File "{ProjectPath}/.venv/lib/python3.13/site-packages/botocore/client.py", line 602, in _api_call
return self._make_api_call(operation_name, kwargs)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "{ProjectPath}/.venv/lib/python3.13/site-packages/botocore/context.py", line 123, in wrapper
return func(*args, **kwargs)
File "{ProjectPath}/.venv/lib/python3.13/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 number of toolResult blocks at messages.26.content exceeds the number of toolUse blocks of previous turn.
└ Bedrock region: us-west-2
└ Model id: us.anthropic.claude-sonnet-4-20250514-v1:0
Additional Context
Agent initialization:
agent = Agent(
model=self.bedrock_model,
agent_id=f"{self.agent_type}-strands-agent",
tools=all_tools,
system_prompt=self.get_system_prompt(),
name=self.get_agent_name(),
description=self.get_agent_description(),
callback_handler=None,
)Possible Solution
No response
Related Issues
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working