generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 499
Closed
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.5
Python Version
3.12
Operating System
Ubuntu 24
Installation Method
pip
Steps to Reproduce
Hi, I built a minimal example to test asynchronous tool invocation as explained HERE. However, the model waits for the first tool to finish before it starts the second one, instead of running them in parallel. Am I perhaps using the asyncio library incorrectly with Strands?
Here the snippet I used:
import asyncio
from strands import Agent, tool
from strands.models import BedrockModel
@tool
async def call_api_color() -> str:
"""
API to get the animal's color.
"""
print("Entered in api_color!")
await asyncio.sleep(10) # simulated api call
print("Finished api_color!")
return "It's Grey"
@tool
async def call_api_physical_features() -> str:
"""
API to get a hint about the animal's main physical feature.
"""
print("Entered in api_physical_features!")
await asyncio.sleep(10) # simulated api call
print("Finished api_physical_features!")
return "Has a trunk"
async def async_example():
agent = Agent(
tools=[call_api_color, call_api_physical_features],
model=BedrockModel(
model_id="claude-3-7-sonnet-20250219-v1:0",
region_name=REGION_NAME,
max_tokens=2**13,
additional_request_fields={
"thinking": {"type": "enabled", "budget_tokens": int(2**13 / 2)},
},
),
)
# New, improved prompt to encourage parallel execution
prompt = "Use your tools in parallel to find out the color and a key feature of the secret animal."
await agent.invoke_async(prompt)
if __name__ == "__main__":
asyncio.run(async_example())Expected Behavior
Entered in api_color!
Entered in api_physical_features!
(wait 10s)
Finished api_color!
Finished api_physical_features!
The secret animal is an elephant!
Actual Behavior
Entered in api_color!
(wait 10s)
Finished api_color!
Entered in api_physical_features!
(wait 10s)
Finished api_physical_features!
The secret animal is an elephant!
alesanfra and reptillicus
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working