Replies: 1 comment
-
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: To enable context caching with Hello! That's an excellent question, and your observation is correct. The This is because context caching is configured at the The correct way to enable this feature is to construct and export the Here is an example of how you can structure your from google.adk.agents import Agent, App, ContextCacheConfig
# 1. Define your agent as usual
my_agent = Agent(
# ... your agent configuration
)
# 2. Define your context cache configuration
my_cache_config = ContextCacheConfig(
min_tokens=4096, # Example: Only cache if context is larger than 4096 tokens
ttl_seconds=600, # Example: Cache expires after 10 minutes
cache_intervals=3 # Example: Refresh cache after 3 invocations
)
# 3. Create an App instance, passing in your agent and the cache config
my_app = App(
name="my_fastapi_app",
root_agent=my_agent,
context_cache_config=my_cache_config,
)
# 4. Export the App object. The deployment tools will discover this.
# For backward compatibility, you can also export root_agent.
app = my_app
root_agent = my_agent By exporting This approach is demonstrated in the [1] https://github.com/google/adk-python/blob/main/contributing/samples/cache_analysis/agent.py |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
With the introduction of context caching feature, what is the correct way to utilize this feature when we are using the
get_fast_api_app
deployment strategy that is referenced here: https://google.github.io/adk-docs/deploy/gke/If I'm not mistaken, the initialization of the FastAPI application leads down to this execution stream in the
AdkWebServer
(https://github.com/google/adk-python/blob/main/src/google/adk/cli/adk_web_server.py#L450-L454)There does not appear to be any opportunity of injecting the
context_cache_config
hereBeta Was this translation helpful? Give feedback.
All reactions