-
Notifications
You must be signed in to change notification settings - Fork 450
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.13
Python Version
3.11
Operating System
macOs
Installation Method
pip
Steps to Reproduce
import sys
from strands import Agent, tool
from strands.session import FileSessionManager
@tool
def shell(command: str):
pass
def run_agent():
session_manager = FileSessionManager(session_id='test-session')
agent = Agent(
tools=[shell],
model="global.anthropic.claude-sonnet-4-5-20250929-v1:0",
session_manager=session_manager,
system_prompt="Always use tools as instructed by the agent even if they don't exist",
)
try:
agent("Invoke the `invalid tool` tool and tell me what the response is")
agent("What was the response?")
except BaseException as e:
print(f"Exception: {e}", file=sys.stderr, flush=True)
finally:
print(agent.messages, flush=True)
print("=============\n1st execution\n=============")
run_agent()
print("=============\n2nd execution\n=============")
run_agent()Expected Behavior
It works, but the error is informed that the tool is invalid
Actual Behavior
agent("What was the response?")results in:
Exception: An error occurred (ValidationException) when calling the ConverseStream operation: The model returned the following errors: messages.2:
tool_useids were found withouttool_resultblocks immediately after: tooluse_FbKH7K6eTGGYVHiK9OVZmA. Eachtool_useblock must have a correspondingtool_resultblock in the next message.
Messages:
[
{'role': 'user', 'content': [{'text': 'Invoke the `invalid tool` tool and tell me what the response is'}]},
{'role': 'assistant', 'content': [{'text': "I'll invoke the `invalid tool` tool as you requested."},
{'toolUse': {'toolUseId': 'tooluse_FbKH7K6eTGGYVHiK9OVZmA', 'name': 'INVALID_TOOL_NAME', 'input': {}}}]},
{'role': 'user', 'content': [{'text': 'What was the response?'}]}
]
Additional Context
If a session-manager is used, this causes an additional problem because the tool_use name update is not persisted; thus on a 2nd run, you'll get an error of:
Exception: An error occurred (ValidationException) when calling the ConverseStream operation: 1 validation error detected: Value at 'messages.2.member.content.2.member.toolUse.name' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_-]+
Possible Solution
No response
Related Issues
Semi-related to #495