#[non_exhaustive]pub struct CacheConfig {
pub enabled: bool,
pub strategy: CacheStrategy,
pub session_key: Option<String>,
}Expand description
Controls yoagent-managed prompt caching hints.
By default, caching is enabled with automatic breakpoint placement. What
that produces on the wire depends on the protocol — see CacheStrategy
for the per-provider table. enabled: false suppresses every hint yoagent
would otherwise send; it cannot switch off a provider’s automatic
server-side caching, which is not under client control.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.enabled: boolMaster switch — set to false to disable all caching hints. Default: true.
strategy: CacheStrategyHow cache breakpoints are placed.
session_key: Option<String>Stable identifier for this conversation, for providers that route cache
lookups by key rather than by explicit breakpoints (OpenAI’s
prompt_cache_key).
Leave None and one is derived from the system prompt (see
StreamConfig::cache_session_key).
That derivation is correct for the common case and costs nothing, but
sessions sharing a system prompt share a key. Set this explicitly when
sessions must be routed apart, or to spread a hot key.
Read only by the key-routed protocols — OpenAI Chat Completions (when the compat flag allows it), the OpenAI Responses API and Azure OpenAI. Ignored by Anthropic, which takes explicit breakpoints, and by Google, Vertex and Bedrock, which yoagent sends no cache hints to.
Note for crate::SubAgentTool: it holds one CacheConfig and clones
it into every invocation, so a key set there is shared by every run the
tool performs rather than identifying one conversation.
Implementations§
Source§impl CacheConfig
impl CacheConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Caching enabled with automatic breakpoint placement.
Identical to Default::default; provided because this struct is
#[non_exhaustive] and new() is where callers look first.
Sourcepub fn with_session_key(self, key: impl Into<String>) -> Self
pub fn with_session_key(self, key: impl Into<String>) -> Self
Set the session key used by key-routed providers.
A blank key is treated as unset — sending prompt_cache_key: "" would
route every caller who did that onto one cache, which is worse than
sending nothing. with_session_key(format!("tenant-{id}")) with an
empty id is the ordinary way to arrive here.
Sourcepub fn with_strategy(self, strategy: CacheStrategy) -> Self
pub fn with_strategy(self, strategy: CacheStrategy) -> Self
Set the breakpoint-placement strategy.
Needed because this struct is #[non_exhaustive]: downstream crates
cannot use a struct literal, so Manual { .. } would otherwise be
unreachable from outside.
Sourcepub fn hints_enabled(&self) -> bool
pub fn hints_enabled(&self) -> bool
Whether yoagent should emit any caching hint at all.
Three configurations mean “no”: enabled: false, Disabled, and
Manual with every flag off. The third is easy to miss — Anthropic
honours it correctly by placing no breakpoints, so a key-routed
provider that still sent a key would be reading the same value as
“yes”. One predicate, so every protocol agrees on what off means.