generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 444
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.11.0
Python Version
3.11.13
Operating System
15.7.1
Installation Method
pip
Steps to Reproduce
import asyncio
import httpx
from strands import Agent
from strands.models.openai import OpenAIModel
client = httpx.AsyncClient()
agent = Agent(
model=OpenAIModel(
model_id="gpt-4o-mini-2024-07-18",
client_args={
"api_key": "your-openai-key",
"http_client": client
}
)
)
async def chat(prompt: str):
result = await agent.invoke_async(prompt)
print(result)
async def main():
await chat("this works")
await chat("this doesn't work")
if __name__ == "__main__":
asyncio.run(main())
Expected Behavior
As per the documentation, I should be able to pass any parameters supported by the OpenAI client in the constructor of the OpenAIModel
.
That should include the http_client
parameter, that let me pass a custom HTTPx client to the OpenAI client, as documented in here.
Actual Behavior
When passing a custom HTTPx client, only the first request will pass through, because that client will be automatically closed by Strands right after processing it. Subsequent requests fails.
Additional Context
No response
Possible Solution
No response
Related Issues
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working