Request building
How the Context is assembled belongs upstream. Adding a provider touches only this layer and its provider.json.
Context { system_prompt, messages, tools } --model.api--> provider translation --> wire request
Translation
| Style | System | Conversation | Tools |
|---|---|---|---|
| anthropic-messages | standalone system | messages | tools, strict inside the tool |
| openai-completions | system or developer message at messages[0] | messages | tools, strict is a boolean |
| openai-responses, codex | instructions | input | tools |
| google (gemini) | systemInstruction; assistant becomes model | contents, content is parts | tools |
| bedrock | standalone system | messages | tools |
Translation also smooths thinking-block signatures, tool arguments as objects or strings, and tool schema dialects (strict, additionalProperties).
Caching
| Mode | Mechanism | Declared by |
|---|---|---|
explicit | Breakpoints in the request (cache_control, cachePoint) | anthropic, amazon_bedrock |
auto | Automatic prefix caching, optional prompt_cache_key | openai_responses |
out_of_band | A separate API stores the cache; hit stats only | recognised mode; none declares it |
none | Nothing | every other provider, by default |
Each provider declares this under the cache key of provider.json; a standalone cache.json still loads with a deprecation warning. settings/cache_spec.py: get_cache_spec, cache_mode, ttl_for_retention, cache_key_param, with_lifetime_setting.
{ "mode": "explicit", "breakpoint_format": "cache_control",
"retention_ttl_map": {"short": null, "long": "1h"},
"long_ttl_endpoints": ["api.anthropic.com"], "max_breakpoints": 4 }
{ "mode": "auto", "cache_key_param": "prompt_cache_key" }
Breakpoints
| Rule | Detail |
|---|---|
| Caller marks | cache_control on a content block passes through verbatim; Tool.cache_control likewise (passthrough plan) |
| Unmarked | apply_cache_policy (settings/cache_policy.py) marks the last tool not sent with defer_loading and the latest user message's last text block, else its last block; caller markers stay |
| Budget | max_breakpoints (4), spent tools first, then messages |
| TTL | ≥ 3600 s is 1h, else the provider default of 5 min; models.prompt_cache_ttl set to 1h makes a plain cache live an hour |
| System | One string, so each provider's _build_system marks the whole block; the policy covers tools and messages |
| Anthropic | stream_simple applies the policy before building; _get_cache_control reads the TTL map and long_ttl_endpoints |
| Bedrock | explicit but with its own cachePoint blocks and last-message logic, outside apply_cache_policy |
The policy follows opencode's cache-policy.ts and protocols/utils/cache.ts. opencode marks a last system segment too, because its system prompt is an array. No Context-level structure is added.
Last updated · 2026-11-25