symfonic.core.prompt.caching¶
caching ¶
Anthropic prompt caching support: CacheBlock and CacheablePrompt.
CacheBlock
dataclass
¶
CacheBlock(
type: str = "text",
text: str = "",
cache_control: dict[str, str] | None = None,
cache_ttl: CacheTtl | None = None,
)
A content block with optional cache_control annotation.
Matches the Anthropic API content block format. Set cache_control to {"type": "ephemeral"} to mark the block for server-side caching.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
Content block type. Always |
text |
str
|
Rendered body. |
cache_control |
dict[str, str] | None
|
When non-None, the block is advertised as cached.
The marker emitted on the wire depends on |
cache_ttl |
CacheTtl | None
|
v7.24.0 NEW — optional TTL hint when this block is
cached. |
CacheablePrompt
dataclass
¶
A prompt assembled with Anthropic cache_control annotations.
Used when the caller wants cache-annotated output from PromptBuilder.build_cached(). Content is structured as a tuple of CacheBlock instances rather than a single string, matching the format Anthropic expects for system prompt blocks.
to_anthropic_content ¶
Convert to the Anthropic API system-prompt content list format.
Each block becomes a dict with at minimum type and text.
When a block participates in caching, cache_control is
included; the marker is shaped per CacheBlock.cache_ttl via
:func:_serialise_cache_marker.