Open
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
Commit 6a1ccea
Python Version
3.13.1
Operating System
Amazon linux 2
Installation Method
git clone
Steps to Reproduce
Run this script
from strands import Agent, tool
from strands.models import BedrockModel
import random
@tool
def weather_forecast(city: str, days: int = 3) -> str:
"""Get weather forecast for a city.
Args:
city: The name of the city
days: Number of days for the forecast
"""
weather = random.choice(["sunny", "rainy", "cloudy"])
return f"Weather forecast for {city} for the next {days} days is {weather}."
def create_bedrock_model():
bedrock_model = BedrockModel(
boto_session=boto3.Session(region_name="us-west-2"),
model_id="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
cache_prompt="default",
cache_tools="default",
temperature=0.0,
)
return bedrock_model
def convert_tool_metrics_to_dict(tool_metrics) -> dict:
from dataclasses import asdict
output = {}
for key, value in tool_metrics.items():
output[key] = asdict(value)
return output
agent = Agent(
model=create_bedrock_model(),
system_prompt="You are a helpful AI assistant",
tools=[weather_forecast],
)
response = agent(
"Whats the weather in Berlin tomorrow? Use a tool. Afterwards check the weather in Paris for tomorrow. Then check the weather in Rome."
)
print(convert_tool_metrics_to_dict(response.metrics.tool_metrics))
Check the printed tool metrics. They look like
{
'weather_forecast': {
'tool': {
'toolUseId': 'tooluse_nQBPOmkJTsOY3hXIbjTr1A',
'name': 'weather_forecast',
'input': {
'city': 'Rome'
}
},
'call_count': 3,
'success_count': 3,
'error_count': 0,
'total_time': 0.0002276897430419922
}
}
Expected Behavior
The tool metrics should either not mention the tool inputs ('city': 'Rome'
) or they should list all inputs from the three tool invocations, i.e., [('city': 'Berlin'), ('city': 'Paris'), ('city': 'Rome')]
.
Actual Behavior
The tool metrics show three invocations of the tool. However, only one input (the latest one) is included. Here, this is 'city': 'Rome'
. However, the tool was also invoked for two other cities.
{
'weather_forecast': {
'tool': {
'toolUseId': 'tooluse_nQBPOmkJTsOY3hXIbjTr1A',
'name': 'weather_forecast',
'input': {
'city': 'Rome'
}
},
'call_count': 3,
'success_count': 3,
'error_count': 0,
'total_time': 0.0002276897430419922
}
}
Additional Context
No response
Possible Solution
No response
Related Issues
No response