[BUG] Wrong toolUseId when using gemini-2.5-flash
Checks
- [x] I have updated to the lastest minor and patch version of Strands
- [x] I have checked the documentation and this is not expected behavior
- [x] I have searched ./issues and there are no duplicates of my issue
Strands Version
1.17.0
Python Version
3.13.2
Operating System
MacOS 15.6.1 (24G90)
Installation Method
pip
Steps to Reproduce
- have environment set up. I have an example here
- run the following script
import asyncio
import random
from strands import Agent, tool
from strands.models.gemini import GeminiModel
model: GeminiModel = GeminiModel(
client_args={"api_key": os.getenv("GOOGLE_AI_API_KEY")},
model_id="gemini-2.5-flash",
)
@tool
async def call_api() -> str:
"""Call API asynchronously."""
await asyncio.sleep(3) # simulated api call
return f"API result: {random.randint(1, 1000)}"
agent = Agent(tools=[call_api], model=model, callback_handler=None, name="gemini_agent")
# Async function that iterators over streamed agent events
async def process_streaming_response(agent: Agent) -> None:
agent_stream = agent.stream_async("Can you call my API twice?")
print(f"Starting to stream events for {agent.name}")
async for event in agent_stream:
print(event)
print(f"Finished streaming events for {agent.name}")
asyncio.run(process_streaming_response(agent))
Expected Behavior
unique toolUseId named in the format tooluse_{identifier}
Actual Behavior
call_api being shown as the toolUseId instead of something like tooluse_{identifier}, like below:
{"message": {"role": "assistant", "content": [{"toolUse": {"toolUseId": "call_api", "name": "call_api", "input": {}}}]}}
Additional Context
No response
Possible Solution
No response
Related Issues
No response
okay I think this is probably the reason
# Note: toolUseId is the only identifier available in a tool result. However, Gemini requires
# that name be set in the equivalent FunctionResponse type. Consequently, we assign
# function name to toolUseId in our tool use block. And another reason, function_call is
# not guaranteed to have id populated.
https://github.com/strands-agents/sdk-python/blob/main/src/strands/models/gemini.py#L267-L270 this is resulting in in-differentiable tool uses if a tool gets used twice.
I think we can store a map<tooluseid, function_name> internally to expose the tooluseid to the user but function name to gemini in FunctionResponse. I am not familiar with the codebase, but willing to contribute
I tried to follow all the guidelines and created #1201
If you find anything inappropriate with the PR, feel free to make changes or dispose it. Thanks.
Left a comment on the PR.
@cagataycali sorry I have not finished the PR that I opened for merging - I saw that you have also created a PR to fix this issue in the similar way, should I close mine in this case?
Hi Qian! @AirswitchAsa
The PR you see in details is automatically created during my benchmarks. Please do continue with your contribution!