Skip to main content

Module cache

Module cache 

Source
Expand description

Prompt caching control types.

Provider-neutral abstractions for marking message content and tool definitions as eligible for prompt caching. Adapters translate these markers to provider-specific wire formats (e.g. Anthropic’s cache_control blocks) or rely on the provider’s automatic caching (e.g. OpenAI’s prefix cache).

§Stability model

  • CacheControl is a per-ContentPart and per-ToolSpec marker.
  • A marker on the last content block of a stable region (system prompt, tool definitions, conversation tail) instructs the provider to create a cache entry covering everything from the start of the prompt up to and including that block.
  • Markers have no effect on providers that do not support caching; they are silently ignored.

§Example

use behest_core::cache::CacheControl;
use behest_core::message::{ContentPart, Message};

let ctrl = CacheControl::ephemeral();
let part = ContentPart::text("You are a research assistant.").with_cache_control(ctrl);
let message = Message::system_text("You are a research assistant.")
    .mark_cache_breakpoint();

Structs§

CacheControl
Provider-neutral cache control marker.

Enums§

CacheControlKind
Cache strategy kinds.
CacheTtl
Time-to-live for a cache entry.