OpenProgram Docs

请求构建

Context 怎么组装归上游。新增提供商只动这一层和它的 provider.json。

Context { system_prompt, messages, tools }  --model.api-->  provider translation  -->  wire request

翻译

风格system对话工具
anthropic-messages独立的 systemmessagestools,strict 在工具对象内
openai-completionssystem 或 developer 消息放在 messages[0]messagestools,strict 是布尔值
openai-responses、codexinstructionsinputtools
google(gemini)systemInstruction;assistant 变 modelcontents,内容叫 partstools
bedrock独立 systemmessagestools

翻译还处理思考块签名、工具参数是对象还是字符串,以及工具 schema 方言(strict、additionalProperties)。

缓存

模式机制声明者
explicit请求里放断点(cache_control、cachePoint)anthropic、amazon_bedrock
auto自动前缀缓存,可选 prompt_cache_keyopenai_responses
out_of_band用单独 API 存缓存;只读命中统计代码认识此模式,目前没有提供商声明
none不做其余提供商,默认

各提供商在 provider.json 的 cache 键下声明;独立的 cache.json 仍能加载,但有弃用警告。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" }

断点

规则细节
调用方标记内容块上的 cache_control 原样透传;Tool.cache_control 同样(透传方案)
未标记apply_cache_policy(settings/cache_policy.py)标记最后一个不带 defer_loading 的工具和最新用户消息的最后文本块,否则其最后一块;调用方的标记保留
预算max_breakpoints(4),先给工具,再给消息
TTL≥ 3600 秒 为 1h,否则提供商默认 5 分钟;models.prompt_cache_ttl 设为 1h 时普通缓存活一小时
system单个字符串,由各提供商的 _build_system 标记整块;策略只管工具和消息
Anthropicstream_simple 构建前应用策略;_get_cache_control 读 TTL 映射和 long_ttl_endpoints
Bedrockexplicit,但有自己的 cachePoint 块和最后消息逻辑,不走 apply_cache_policy

策略来自 opencode 的 cache-policy.ts 和 protocols/utils/cache.ts。opencode 的 system 是数组,还能标记最后一段。这里不新增 Context 级结构。

Last updated · 2026-11-25