Files
myWiki/articles/prompt-caching-architecture.md

2.0 KiB

title, created, updated, type, tags, sources
title created updated type tags sources
Prompt Caching 架构工程手册 2026-05-11 2026-05-11 article
prompt-caching
agent-architecture
system-design
ai-engineering
https://mp.weixin.qq.com/s/gyd4cqxadv3YW5Fe09r95g

Prompt Caching 架构工程手册 (Volume I)

概述

本文系统阐述了 Prompt Caching 在大规模 AI Agent 系统中的工程实践,以高频交易系统 meta-jctrader 为案例。Prompt Caching 不仅是降低延迟和成本的财务工具,更是系统稳健性与推理确定性的架构基石。

核心问题

在大规模 Agent 系统中,动态变化的 System Prompt 和工具定义导致缓存频繁失效(cache-invalidation),使模型丧失"热启动"能力,造成不可控的延迟和成本。

方法论贡献

四层架构分层

构建 Global → Project → Session → Dynamicprompt-layering 堆栈,将不可变静态前缀与高频动态数据严格分离。

Stub 模式

引入 stub-patterntool-registry 统一接口,在 System Prompt 中仅保留最小化工具占位符,避免工具定义变更触发 cache-invalidation

Cache-Safe Forking

实现 cache-safe-forking,在 context-compression 时复用父会话的完整前缀,将总结成本降低一个数量级。

状态管理工具化

规避 system-message-abuse,将状态切换从 System Message 迁移到消息化标签或工具调用。

可观测性体系

建立以 cache-hit-ratio (CHR) 为核心的 cache-health-observability 系统,包含失效点识别和成本效率评分。

与现有 Wiki 的关联