adk_context_cache_gemini (erlang_adk v0.7.0)

View Source

Gemini GenerateContent explicit cached-content adapter.

The adapter stores provider request prefixes, never model responses. It is deliberately usable only with the stable gemini-3.1-flash-lite model. The opaque binary returned from create/2 is a local private descriptor; callers must use cached_content_name/2 immediately before a Gemini request. Neither that descriptor nor Google's cachedContents/* name is suitable for events, logs, diagnostics, or persisted configuration.

Transport configuration is read from the erlang_adk application environment key gemini_context_cache. The value is a strict map with optional base_url, api_key, and request_timeout_ms keys. api_key falls back to GEMINI_API_KEY. Validation errors never echo credentials.

Google's current model page declares caching support for 3.1 Flash-Lite, but the current caching guide does not publish an explicit-cache minimum for this model. We therefore use a conservative 4096 estimated-token local floor and still treat the service response as authoritative.

Summary

Functions

cached_content_name(Resource, ExpectedModel)

-spec cached_content_name(binary(), binary()) -> {ok, binary()} | {error, term()}.

Resolve a registry-private descriptor for one immediate model call.

capabilities()

-spec capabilities() -> map().

create(Prefix, Request)

-spec create(map(), map()) -> {ok, binary(), map()} | {error, term()}.

delete(Resource, Request)

-spec delete(binary(), map()) -> ok | {error, term()}.

get(Resource, Request)

-spec get(binary(), map()) -> {ok, map()} | {error, term()}.

minimum_prefix_tokens(_)

-spec minimum_prefix_tokens(binary()) -> {ok, pos_integer()} | {error, unsupported_context_cache_model}.

supports_model(_)

-spec supports_model(binary()) -> boolean().

update(Resource, TtlMs, Request)

-spec update(binary(), pos_integer(), map()) -> {ok, map()} | {error, term()}.

validate_options(Options)

-spec validate_options(map()) -> ok | {error, term()}.

Validate transport options without returning the compiled secret.