How to configure custom tool timeout in ADK agent? #5837
Replies: 1 comment
-
|
There is currently no per-tool For an HTTP tool, an async implementation gives you both transport-level timeouts and a hard wall-clock deadline: import asyncio
import httpx
async def my_slow_tool(query: str) -> dict:
try:
# Overall deadline for the complete tool call.
async with asyncio.timeout(60):
timeout = httpx.Timeout(55.0, connect=5.0)
async with httpx.AsyncClient(timeout=timeout) as client:
response = await client.get(
"https://api.example.com/search",
params={"q": query},
)
response.raise_for_status()
return {"ok": True, "result": response.text}
except TimeoutError:
return {"ok": False, "error": "Search exceeded the 60-second deadline."}
except httpx.TimeoutException as exc:
return {"ok": False, "error": f"Search API timed out: {exc}"}
except httpx.HTTPError as exc:
return {"ok": False, "error": f"Search API failed: {exc}"}Pass If you keep If the operation is expected to take longer than the request/runtime limit, return a job ID and poll it (or use ADK's long-running tool pattern) rather than holding one tool call open. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am building an agent with ADK and have a custom tool that makes HTTP requests to an external API. Sometimes the API is slow and the tool times out.
Is there a way to configure the timeout for individual tools in ADK? I looked at the Tool class but could not find a timeout parameter.
Example of what I am trying to do:
Any guidance would be appreciated. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions