Replies: 1 comment
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: Yes, you should reuse a single Hello! That's a great question. Your instinct is correct—creating a new Here’s a breakdown of the best practice for using ADK in a web service like FastAPI: 1. Reuse
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I’m building a backend service with Google ADK using a custom FastAPI app (not the default CLI app).
Right now, for each incoming request I create a new App and Runner inside the route handler. I’m concerned this per-request initialization may be inefficient and/or increase memory/CPU overhead under high concurrency.
Here’s a simplified version of what I’m doing:
router/writing.py
services/agent_service.py
My questions:
1. Is it recommended to reuse a single Runner instance across multiple requests for the same agent (e.g., a singleton or a per-agent cache), or is creating a Runner per request the intended pattern?
2. If reuse is recommended, what is the correct approach regarding session isolation and concurrency safety?
• For example, should Runner be long-lived but create a new session per request?
• Are App/Runner designed to be thread-safe / async-safe for concurrent calls?
I’m considering refactoring to a service that caches Runner instances by agent name (similar to how ADKWebServer appears to manage runners). Any best-practice guidance would be appreciated.
Thanks!
All reactions