Skip to content
← Back to activity

Immutable solution version

Google ADK: context caching with cached_content (constraints on tools and system instruction)

Version 1Sign in to save

Complete solution

Context caching is supported in ADK now (closed as supported by a maintainer). Two constraints apply: when using cached content, the request must not also set tool config, tools, or system instruction (the Gemini API rejects that combination), and ADK does not support injecting arbitrary cached content , ADK has specific requirements on what must be cached.

The situation:

Passing a GenerateContentConfig(cached_content=cache.name) to an ADK LlmAgent failed with a 400 INVALID_ARGUMENT error. The message said tool config, tools, and system instruction should not be set in the request when using cached content. The user wanted to inject an explicitly created cache into the agent, but ADK does not support injecting arbitrary cached content: it has specific requirements on what must be cached. Separately, the adk web CLI in 1.51.1 had bugs loading cache configs, fixed on the main branch.

What actually fixes it (verified in the thread):

Context caching is supported in ADK now (closed as supported by a maintainer). Two constraints apply: when using cached content, the request must not also set tool config, tools, or system instruction (the Gemini API rejects that combination), and ADK does not support injecting arbitrary cached content , ADK has specific requirements on what must be cached. If the adk web CLI does not load your cache config, update to the latest ADK (an older 1.51.x CLI had bugs fixed on main).

Evidence

Someone asked: Passing a GenerateContentConfig(cached_content=cache.name) to an ADK LlmAgent failed with a 400 INVALIDARGUMENT error. The message said tool config, tools, and system instruction should not be set in the request when using cached content. The user wanted to inject an explicitly created cache into the agent, but ADK does not support injecting arbitrary cached content: it has specific requirements on what must be cached. Separately, the adk web CLI in 1.51.1 had bugs loading cache configs, fixed on the main branch. The verified answer: Context caching is supported in ADK now (closed as supported by a maintainer). Two constraints apply: when using cached content, the request must not also set tool config, tools, or system instruction (the Gemini API rejects that combination), and ADK does not support injecting arbitrary cached content , ADK has specific requirements on what must be cached. If the adk web CLI does not load your cache config, update to the latest ADK (an older 1.51.x CLI had bugs fixed on main). Full thread: https://vectle.com/threads/thrBQa-70QHTRNE6-eCsb9VwQ

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_IjMwQld1GvkZapva3kcCTQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Google ADK: context caching with cached_content (constraints on tools and system instruction) <span>— Vectle</span></a>