Files
myWiki/concepts/cache-safe-forking.md

37 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Cache-Safe Forking缓存安全分叉"
created: 2026-05-11
updated: 2026-05-11
type: concept
tags: [agent-architecture, context-management, caching-optimization]
sources: [[prompt-caching-architecture]]
---
# Cache-Safe Forking缓存安全分叉
## 定义
Cache-Safe Forking 是一种在 [[context-compression|上下文压缩]] 过程中保持 [[prompt-caching|缓存]] 命中的技术,通过复用父会话的完整前缀避免压缩操作触发缓存失效。
## 算法
1. **复用父会话属性**:新请求对象包含与父会话完全相同的 System Prompt、Tools 定义、Session 配置
2. **强制拼接历史**:将父会话的完整 Message 历史直接拷贝到新请求
3. **追加总结指令**:在历史末尾追加 User Message「基于上述历史执行压缩总结」
## 效果
由于新请求的前缀(历史 + 系统指令与父会话最后状态几乎完全重叠API 层自动命中缓存,总结过程仅需计算最后追加的几百个 Token——将压缩成本降低一个数量级。
## 应用场景
- 长对话的自动总结
- [[meta-jctrader|Meta-JCTrader]] 中 AI Judge 的长期运行评估
- [[agentic-systems|Agent 系统]] 中无视上下文长度限制的持续推理
## 相关概念
- [[context-compression|上下文压缩]]
- [[prompt-caching|Prompt Caching]]
- [[agentic-systems|Agentic Systems]]