context-optimization

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Context Optimization Techniques

上下文优化技术

Context optimization extends the effective capacity of limited context windows through strategic compression, masking, caching, and partitioning. Effective optimization increases useful capacity without requiring larger models or longer windows — but only when applied with measurement discipline. The techniques below are ordered by impact and risk.
上下文优化通过策略性的压缩、遮蔽、缓存和分区,扩展有限上下文窗口的有效容量。有效的优化无需更大的模型或更长的窗口即可提升可用容量——但前提是应用优化时遵循测量纪律。下述技术按影响和风险排序。

When to Activate

何时启用

Activate this skill when:
  • Context budgets or token costs constrain task complexity
  • Observation masking can replace verbose tool outputs with retrievable references
  • Prefix or KV-cache hit rate needs improvement
  • Retrieval scoping can reduce irrelevant loaded context
  • Context partitioning can extend effective capacity across agents
  • Budget triggers are needed for masking, compaction, or partitioning
Do not activate this skill for adjacent work owned by other skills:
  • Explaining why attention or context windows behave this way:
    context-fundamentals
    .
  • Diagnosing active lost-in-middle, poisoning, distraction, confusion, or clash:
    context-degradation
    .
  • Designing a structured handoff summary for a long conversation:
    context-compression
    .
  • Storing large outputs, plans, or logs as files:
    filesystem-context
    .
  • Model-initiated rewrites of its own context and their re-prefill cost:
    self-managed-context
    .
在以下情况下启用本 skill:
  • 上下文预算或 token 成本限制了任务复杂度
  • Observation masking 可以用可检索的引用替代冗长的工具输出
  • 需要提高 prefix 或 KV-cache 的命中率
  • 检索范围控制可以减少载入的无关上下文
  • 上下文分区可以在多个 Agent 之间扩展有效容量
  • 需要为 masking、compaction 或 partitioning 设置预算触发器
不要将本 skill 用于其他 skill 负责的相邻工作:
  • 解释 attention 或上下文窗口为何产生这些行为:
    context-fundamentals
    。
  • 诊断 active lost-in-middle、poisoning、distraction、confusion 或 clash:
    context-degradation
    。
  • 为长对话设计结构化交接摘要:
    context-compression
    。
  • 将大型输出、计划或日志存储为文件:
    filesystem-context
    。
  • 由模型主动重写其自身上下文及由此产生的 re-prefill 成本:
    self-managed-context
    。

Core Concepts

核心概念

Apply four primary strategies in this priority order:
  1. KV-cache optimization — Reorder and stabilize prompt structure so the inference engine reuses cached Key/Value tensors. This is the cheapest optimization when the runtime supports prefix caching: low quality risk, immediate cost and latency savings. Apply it first when stable prefixes exist.
  2. Observation masking — Replace verbose tool outputs with compact references once their purpose has been served. Tool outputs can dominate agent trajectories (claim-context-optimization-tool-output-dominance), so masking often yields the largest capacity gains. The original content remains retrievable if needed downstream.
  3. Compaction — Summarize accumulated context when utilization exceeds 70%, then reinitialize with the summary. This distills the window's contents while preserving task-critical state. Compaction is lossy — apply it after masking has already removed the low-value bulk.
  4. Context partitioning — Split work across sub-agents with isolated contexts when a single window cannot hold the full problem. Each sub-agent operates in a clean context focused on its subtask. Reserve this for tasks where estimated context exceeds 60% of the window limit, because coordination overhead is real.
The governing principle: context quality matters more than quantity. Every optimization preserves signal while reducing noise. Measure before optimizing, then measure the optimization's effect.
按以下优先顺序应用四种主要策略:
  1. KV-cache 优化——重新排序并稳定 prompt 结构,使推理引擎能够复用已缓存的 Key/Value tensors。当运行时支持 prefix caching 时,这是成本最低的优化:质量风险低,并能立即节省成本和延迟。存在稳定 prefix 时,应首先应用此策略。
  2. Observation masking——在冗长工具输出的用途已经实现后,将其替换为紧凑的引用。工具输出可能主导 Agent 轨迹(claim-context-optimization-tool-output-dominance),因此 masking 通常能带来最大的容量收益。如果下游需要,原始内容仍可被检索。
  3. Compaction——当上下文利用率超过 70% 时,对累积的上下文进行摘要,然后使用摘要重新初始化。这会在保留任务关键状态的同时提炼窗口中的内容。Compaction 属于有损操作——应在 masking 已经移除低价值的大块内容之后再应用。
  4. Context partitioning——当单个窗口无法容纳完整问题时,将工作拆分给具有隔离上下文的 sub-agents。每个 sub-agent 都在干净且聚焦于其子任务的上下文中工作。仅在预估上下文超过窗口限制 60% 时采用此策略,因为协调开销切实存在。
指导原则:上下文质量比数量更重要。每项优化都应在减少噪声的同时保留有效信号。先测量,再优化,然后测量优化的效果。

Detailed Topics

详细主题

Compaction Strategies

Compaction 策略

Trigger compaction when context utilization exceeds 70%: summarize the current context, then reinitialize with the summary. This distills the window's contents in a high-fidelity manner, enabling continuation with minimal performance degradation. Prioritize compressing tool outputs first (they consume 80%+ of tokens), then old conversation turns, then retrieved documents. Never compress the system prompt — it anchors model behavior and its removal causes unpredictable degradation.
Preserve different elements by message type:
  • Tool outputs: Extract key findings, metrics, error codes, and conclusions. Strip verbose raw output, stack traces (unless debugging is ongoing), and boilerplate headers.
  • Conversational turns: Retain decisions, commitments, user preferences, and context shifts. Remove filler, pleasantries, and exploratory back-and-forth that led to a conclusion already captured.
  • Retrieved documents: Keep claims, facts, and data points relevant to the active task. Remove supporting evidence and elaboration that served a one-time reasoning purpose.
Target 50-70% token reduction with less than 5% quality degradation. If compaction exceeds 70% reduction, audit the summary for critical information loss — over-aggressive compaction is the most common failure mode.
当上下文利用率超过 70% 时触发 compaction:总结当前上下文,然后使用摘要重新初始化。这会以高保真方式提炼窗口中的内容,使任务能够在性能下降极小的情况下继续。优先压缩工具输出(它们占用了 80%+ 的 token),其次是较旧的对话轮次,最后是检索到的文档。切勿压缩 system prompt——它用于锚定模型行为,移除它会导致不可预测的性能退化。
根据消息类型保留不同内容:
  • 工具输出:提取关键发现、指标、错误代码和结论。去除冗长的原始输出、stack traces(除非正在进行调试)以及样板页眉。
  • 对话轮次:保留决策、承诺、用户偏好和上下文变化。删除填充内容、寒暄,以及已经得出结论的探索性来回沟通。
  • 检索文档:保留与当前任务相关的主张、事实和数据点。删除仅用于一次性推理的支撑证据和延伸说明。
目标是在质量退化低于 5% 的情况下,将 token 减少 50-70%。如果 compaction 的压缩幅度超过 70%,应审查摘要是否丢失了关键信息——过度激进的 compaction 是最常见的失败模式。

Observation Masking

Observation masking

Mask observations selectively based on recency and ongoing relevance — not uniformly. Apply these rules:
  • Never mask: Observations critical to the current task, observations from the most recent turn, observations used in active reasoning chains, and error outputs when debugging is in progress.
  • Mask after 3+ turns: Verbose outputs whose key points have already been extracted into the conversation flow. Replace with a compact reference:
    [Obs:{ref_id} elided. Key: {summary}. Full content retrievable.]
  • Always mask immediately: Repeated/duplicate outputs, boilerplate headers and footers, outputs already summarized earlier in the conversation.
Masking should achieve 60-80% reduction in masked observations with less than 2% quality impact. The key is maintaining retrievability — store the full content externally and keep the reference ID in context so the agent can request the original if needed.
应根据内容的时近性和当前相关性进行选择性遮蔽,而不是一刀切地遮蔽。应用以下规则:
  • 绝不遮蔽:对当前任务关键的观察内容、最近一轮的观察内容、活跃推理链中使用的观察内容,以及正在进行调试时的错误输出。
  • 在 3+ 轮之后遮蔽:遮蔽其关键点已经被提取到对话流程中的冗长输出。替换为紧凑的引用:
    [Obs:{ref_id} elided. Key: {summary}. Full content retrievable.]
  • 始终立即遮蔽:重复或重复出现的输出、样板页眉和页脚,以及对话中先前已经摘要过的输出。
Masking 应在被遮蔽的观察内容减少 60-80% 的情况下,将质量影响控制在 2% 以下。关键在于保持可检索性——将完整内容存储在外部,并在上下文中保留引用 ID,以便 Agent 在需要时请求原始内容。

KV-Cache Optimization

KV-cache 优化

Maximize prefix cache hits by structuring prompts so that stable content occupies the prefix and dynamic content appears at the end. KV-cache stores Key and Value tensors computed during inference; when consecutive requests share an identical prefix, the cached tensors are reused, saving both cost and latency.
Apply this ordering in every prompt:
  1. System prompt (most stable — never changes within a session)
  2. Tool definitions (stable across requests)
  3. Frequently reused templates and few-shot examples
  4. Conversation history (grows but shares prefix with prior turns)
  5. Current query and dynamic content (least stable — always last)
Design prompts for cache stability: remove timestamps, session counters, and request IDs from the system prompt. Move dynamic metadata into a separate user message or tool result where it does not break the prefix. Even a single whitespace change in the prefix invalidates the entire cached block downstream of that change. The same rule prices any compaction or masking edit applied to earlier history: its cost is the text that follows it, so batch such edits and prefer them near the end of the context.
Target 70%+ cache hit rate for stable workloads. At scale, this translates to 50%+ cost reduction and 40%+ latency reduction on cached tokens.
通过组织 prompt,使稳定内容位于 prefix、动态内容位于末尾,来最大化 prefix cache 的命中率。KV-cache 存储推理过程中计算出的 Key 和 Value tensors;当连续请求共享完全相同的 prefix 时,缓存的 tensors 会被复用,从而同时节省成本和延迟。
每个 prompt 都应采用以下顺序:
  1. System prompt(最稳定——在一个 session 内从不变化)
  2. Tool definitions(在请求之间保持稳定)
  3. 经常复用的模板和 few-shot examples
  4. Conversation history(会增长,但与之前轮次共享 prefix)
  5. Current query 和动态内容(最不稳定——始终放在最后)
为保证缓存稳定性而设计 prompt:从 system prompt 中移除时间戳、session counter 和 request ID。将动态元数据移至单独的用户消息或 tool result 中,避免破坏 prefix。即使 prefix 中只有一个空格发生变化,也会使该变化之后的所有缓存块失效。同样的规则也决定了对早期历史执行 compaction 或 masking 编辑时的代价:代价由其后的文本决定,因此应批量执行此类编辑,并优先在上下文末尾附近进行编辑。
对于稳定工作负载,目标缓存命中率为 70%+。在规模化场景下,这通常意味着缓存 token 的成本降低 50%+、延迟降低 40%+。

Context Partitioning

Context partitioning

Partition work across sub-agents when a single context cannot hold the full problem without triggering aggressive compaction. Each sub-agent operates in a clean, focused context for its subtask, then returns a structured result to a coordinator agent.
Plan partitioning when estimated task context exceeds 60% of the window limit. Decompose the task into independent subtasks, assign each to a sub-agent, and aggregate results. Validate that all partitions completed before merging, merge compatible results, and apply summarization if the aggregated output still exceeds budget.
This approach achieves separation of concerns — detailed search context stays isolated within sub-agents while the coordinator focuses on synthesis. However, coordination has real token cost: the coordinator prompt, result aggregation, and error handling all consume tokens. Only partition when the savings exceed this overhead.
当单个上下文无法在不触发激进 compaction 的情况下容纳完整问题时,将工作拆分给 sub-agents。每个 sub-agent 都在干净且聚焦于其子任务的上下文中工作,然后向协调 Agent 返回结构化结果。
当预估任务上下文超过窗口限制 60% 时,规划分区。将任务分解为相互独立的子任务,为每个子任务分配一个 sub-agent,然后汇总结果。合并前应验证所有分区均已完成,合并兼容的结果;如果汇总后的输出仍超出预算,则应用摘要。
这种方法实现了关注点分离——详细的搜索上下文保留在各个 sub-agent 内,而协调 Agent 专注于综合。不过,协调会产生实际的 token 成本:协调 Agent 的 prompt、结果汇总和错误处理都会消耗 token。只有当节省量超过这些开销时,才应进行分区。

Budget Management

预算管理

Allocate explicit token budgets across context categories before the session begins: system prompt, tool definitions, retrieved documents, message history, tool outputs, and a reserved buffer (5-10% of total). Monitor usage against budget continuously and trigger optimization when any category exceeds its allocation or total utilization crosses 70%.
Use trigger-based optimization rather than periodic optimization. Monitor these signals:
  • Token utilization above 80% — trigger compaction
  • Attention degradation indicators (repetition, missed instructions) — trigger masking + compaction
  • Quality score drops below baseline — audit context composition before optimizing
在 session 开始前,为以下上下文类别分配明确的 token 预算:system prompt、tool definitions、检索文档、消息历史、工具输出,以及预留缓冲区(总量的 5-10%)。持续监控预算使用情况,当任一类别的使用量超过其配额,或总利用率超过 70% 时,触发优化。
使用基于触发器的优化,而不是基于周期的优化。监控以下信号:
  • Token 利用率超过 80%——触发 compaction
  • Attention 退化指标(重复、遗漏指令)——触发 masking + compaction
  • 质量分数低于基线——在优化之前审查上下文构成

Practical Guidance

实践指南

Optimization Decision Framework

优化决策框架

Select the optimization technique based on what dominates the context:
Context CompositionFirst ActionSecond Action
Tool outputs dominate (>50%)Observation maskingCompaction of remaining turns
Retrieved documents dominateSummarizationPartitioning if docs are independent
Message history dominatesCompaction with selective preservationPartitioning for new subtasks
Multiple components contributeKV-cache optimization first, then layer masking + compaction
Near-limit with active debuggingMask resolved tool outputs only — preserve error details
根据占主导地位的上下文选择优化技术:
上下文构成首选操作次选操作
工具输出占主导(>50%)Observation masking对剩余轮次执行 Compaction
检索文档占主导摘要文档相互独立时进行 Partitioning
消息历史占主导选择性保留后执行 Compaction对新子任务进行 Partitioning
多个组件共同占用先执行 KV-cache 优化,再叠加 Masking + Compaction
接近上限且正在调试仅遮蔽已解决的工具输出——保留错误详情

Performance Targets

性能目标

Track these metrics to validate optimization effectiveness:
  • Compaction: 50-70% token reduction, <5% quality degradation, <10% latency overhead from the compaction step itself
  • Masking: 60-80% reduction in masked observations, <2% quality impact, near-zero latency overhead
  • Cache optimization: 70%+ hit rate for stable workloads, 50%+ cost reduction, 40%+ latency reduction
  • Partitioning: Net token savings after accounting for coordinator overhead; break-even typically requires 3+ subtasks
Iterate on strategies based on measured results. If an optimization technique does not measurably improve the target metric, remove it — optimization machinery itself consumes tokens and adds latency.
跟踪以下指标,以验证优化的有效性:
  • Compaction:token 减少 50-70%,质量退化 <5%,compaction 步骤本身造成的延迟开销 <10%
  • Masking:被遮蔽的观察内容减少 60-80%,质量影响 <2%,延迟开销接近零
  • Cache 优化:稳定工作负载的命中率 70%+,成本降低 50%+,延迟降低 40%
  • Partitioning:扣除协调开销后仍实现净 token 节省;通常至少需要 3+ 个子任务才能回本
根据测量结果迭代策略。如果某项优化技术未能可测量地改善目标指标,应将其移除——优化机制本身也会消耗 token 并增加延迟。

Examples

示例

Example 1: Compaction Trigger
python
if context_tokens / context_limit > 0.8:
    context = compact_context(context)
Example 2: Observation Masking
python
if len(observation) > max_length:
    ref_id = store_observation(observation)
    return f"[Obs:{ref_id} elided. Key: {extract_key(observation)}]"
Example 3: Cache-Friendly Ordering
python
undefined
示例 1:Compaction 触发条件
python
if context_tokens / context_limit > 0.8:
    context = compact_context(context)
示例 2:Observation masking
python
if len(observation) > max_length:
    ref_id = store_observation(observation)
    return f"[Obs:{ref_id} elided. Key: {extract_key(observation)}]"
示例 3:缓存友好的排序方式
python
undefined

Stable content first

Stable content first

context = [system_prompt, tool_definitions] # Cacheable context += [reused_templates] # Reusable context += [unique_content] # Unique

**Example 4: Budget-triggered optimization policy**
```yaml
budgets:
  tool_outputs: 35%
  message_history: 30%
  retrieved_documents: 20%
  reserved_buffer: 15%
triggers:
  tool_outputs_over_budget: mask resolved observations
  total_context_over_70_percent: compact message history
  repeated_irrelevant_retrievals: tighten retrieval scope
context = [system_prompt, tool_definitions] # Cacheable context += [reused_templates] # Reusable context += [unique_content] # Unique

**示例 4:基于预算触发的优化策略**
```yaml
budgets:
  tool_outputs: 35%
  message_history: 30%
  retrieved_documents: 20%
  reserved_buffer: 15%
triggers:
  tool_outputs_over_budget: mask resolved observations
  total_context_over_70_percent: compact message history
  repeated_irrelevant_retrievals: tighten retrieval scope

Guidelines

指南

  1. Measure before optimizing—know your current state
  2. Apply masking before compaction — remove low-value bulk first, then summarize what remains
  3. Design for cache stability with consistent prompts
  4. Partition before context becomes problematic
  5. Monitor optimization effectiveness over time
  6. Balance token savings against quality preservation
  7. Test optimization at production scale
  8. Implement graceful degradation for edge cases
  1. 优化前先测量——了解当前状态
  2. 先执行 masking,再执行 compaction——先移除低价值的大块内容,然后总结剩余内容
  3. 使用一致的 prompt 设计,以保持缓存稳定性
  4. 在上下文变得棘手之前进行分区
  5. 持续监控优化的有效性
  6. 在 token 节省与质量保留之间取得平衡
  7. 在生产规模下测试优化
  8. 为边缘情况实现优雅降级

Gotchas

常见陷阱

  1. Whitespace breaks KV-cache: Even a single whitespace or newline change in the prompt prefix invalidates the entire KV-cache block downstream of that point. Pin system prompts as immutable strings — do not interpolate timestamps, version numbers, or session IDs into them. Diff prompt templates byte-for-byte between deployments.
  2. Timestamps in system prompts destroy cache hit rates: Including
    Current date: {today}
    or similar dynamic content in the system prompt forces a full cache miss on every new day (or every request, if using time-of-day). Move dynamic metadata into a user message or a separate tool result appended after the stable prefix.
  3. Compaction under pressure loses critical state: When the model performing compaction is itself under context pressure (>85% utilization), its summarization quality degrades — it omits task goals, drops user constraints, and flattens nuanced state. Trigger compaction at 70-80%, not 90%+. If compaction must happen late, use a separate model call with a clean context containing only the material to summarize.
  4. Masking error outputs breaks debugging loops: Over-aggressive masking hides error messages, stack traces, and failure details that the agent needs in subsequent turns to diagnose and fix issues. During active debugging (error in the last 3 turns), suspend masking for all error-related observations until the issue is resolved.
  5. Partitioning overhead can exceed savings: Each sub-agent requires its own system prompt, tool definitions, and coordination messages. For tasks with fewer than 3 independent subtasks, the coordination overhead often exceeds the context savings. Estimate total tokens (coordinator + all sub-agents) before committing to partitioning.
  6. Cache miss cost spikes after deployment changes: Reordering tools, rewording the system prompt, or changing few-shot examples between deployments invalidates the entire prefix cache, causing a temporary cost spike of 2-5x until the new cache warms up. Roll out prompt changes gradually and monitor cache hit rate during deployment windows.
  7. Compaction creates false confidence in stale summaries: Once context is compacted, the summary looks authoritative but may reflect outdated state. If the task has evolved since compaction (new user requirements, corrected assumptions), the summary silently carries forward stale information. After compaction, re-validate the summary against the current task goal before proceeding.
  1. 空白字符会破坏 KV-cache:即使 prompt prefix 中只有一个空格或换行发生变化,也会使该位置之后的所有 KV-cache 块失效。将 system prompt 固定为不可变字符串——不要向其中插入时间戳、版本号或 session ID。在不同部署之间,应逐字节对比 prompt 模板。
  2. System prompt 中的时间戳会破坏缓存命中率:在 system prompt 中加入
    Current date: {today}
    或类似的动态内容,会导致每天(如果使用具体时间,则为每次请求)都发生完整缓存未命中。将动态元数据移至用户消息或单独的 tool result 中,并追加在稳定 prefix 之后。
  3. 在压力下执行 compaction 会丢失关键状态:如果执行 compaction 的模型自身也处于上下文压力下(利用率 >85%),其摘要质量会下降——遗漏任务目标、丢失用户约束,并抹平细微状态。应在 70-80% 时触发 compaction,而不是等到 90%+。如果必须延迟执行 compaction,应使用独立的 model call,并提供一个仅包含待摘要材料的干净上下文。
  4. 遮蔽错误输出会破坏调试循环:过度激进的 masking 会隐藏 Agent 在后续轮次中诊断和修复问题所需的错误消息、stack traces 和失败详情。在主动调试期间(最近 3 轮内出现错误),应暂停遮蔽所有与错误相关的观察内容,直到问题得到解决。
  5. 分区开销可能超过节省量:每个 sub-agent 都需要自己的 system prompt、tool definitions 和协调消息。对于少于 3 个独立子任务的任务,协调开销通常会超过上下文节省量。在决定分区之前,应估算总 token 数(协调 Agent + 所有 sub-agents)。
  6. 部署变更后缓存未命中的成本会激增:在部署之间重新排序 tools、改写 system prompt 或更改 few-shot examples,会使整个 prefix cache 失效,并在新缓存预热之前造成 2-5 倍的临时成本激增。应逐步发布 prompt 变更,并监控部署窗口内的缓存命中率。
  7. Compaction 会让过时的摘要营造虚假信心:上下文完成 compaction 后,摘要看起来权威可信,但可能反映的是过时状态。如果任务在 compaction 后已经发生变化(新增用户要求、修正了假设),摘要会在不知情的情况下继续传播过时信息。Compaction 后,应根据当前任务目标重新验证摘要。

Integration

集成

This skill owns token-efficiency tactics and budget policy. Adjacent skills own diagnosis, storage, and architecture:
  • context-fundamentals
    : mental models for why context quality and attention placement matter.
  • context-degradation
    : diagnosis when output quality has already dropped.
  • context-compression
    : lossy summarization and handoff strategy.
  • filesystem-context
    : file-backed offloading for full outputs and logs.
  • multi-agent-patterns
    : partitioning work across isolated agent contexts.
  • latent-briefing
    : selective KV retention across orchestrator-worker boundaries in compatible runtimes.
  • self-managed-context
    : the model, not the harness, decides when and what to edit in its live context.
  • evaluation
    : measuring whether the optimization improved quality, cost, or latency.
  • memory-systems
    : persistent retrieval layers that feed context just in time.
本 skill 负责 token 效率策略和预算策略。相邻 skill 分别负责诊断、存储和架构:
  • context-fundamentals
    :解释上下文质量和 attention 位置为何重要的心智模型。
  • context-degradation
    :输出质量已经下降时的诊断方法。
  • context-compression
    :有损摘要和交接策略。
  • filesystem-context
    :将完整输出和日志卸载到文件。
  • multi-agent-patterns
    :将工作划分到相互隔离的 Agent 上下文中。
  • latent-briefing
    :在兼容的 runtime 中跨 orchestrator-worker 边界进行选择性 KV 保留。
  • self-managed-context
    :由模型而非 harness 决定何时以及如何编辑其实时上下文。
  • evaluation
    :衡量优化是否改善了质量、成本或延迟。
  • memory-systems
    :为上下文即时提供内容的持久化检索层。

References

参考资料

Internal reference:
  • Optimization Techniques Reference - Read when: implementing a specific optimization technique and needing detailed code patterns, threshold tables, or integration examples beyond what the skill body provides
Related skills in this collection:
  • context-fundamentals - Read when: unfamiliar with context window mechanics, token counting, or attention distribution basics
  • context-degradation - Read when: diagnosing why agent performance has dropped and needing to identify which degradation pattern is occurring before selecting an optimization
  • evaluation - Read when: setting up metrics and benchmarks to measure whether an optimization technique actually improved outcomes
External resources:
  • Research on context window limitations - Read when: evaluating model-specific context behavior (e.g., lost-in-the-middle effects, attention decay curves)
  • KV-cache optimization techniques - Read when: implementing prefix caching at the inference infrastructure level (vLLM, TGI, or cloud provider APIs)
  • Production engineering guides - Read when: deploying context optimization in a production pipeline and needing operability patterns (monitoring, alerting, rollback)

内部参考资料:
  • 优化技术参考——在实现某种具体优化技术,并需要本 skill 正文未提供的详细代码模式、阈值表或集成示例时阅读
本合集中的相关 skill:
  • context-fundamentals——在不了解上下文窗口机制、token 计数或 attention 分布基础时阅读
  • context-degradation——在诊断 Agent 性能下降的原因,并需要在选择优化方式之前确定具体的退化模式时阅读
  • evaluation——在设置指标和基准,以衡量某项优化技术是否真正改善了结果时阅读
外部资源:
  • 上下文窗口限制研究——在评估特定模型的上下文行为时阅读,例如 lost-in-the-middle 效应、attention 衰减曲线
  • KV-cache 优化技术——在推理基础设施层面实现 prefix caching 时阅读,例如 vLLM、TGI 或云服务商 API
  • 生产工程指南——在生产管道中部署上下文优化,并需要可运维模式(监控、告警、回滚)时阅读

Skill Metadata

Skill 元数据

Created: 2025-12-20 Last Updated: 2026-05-15 Author: Agent Skills for Context Engineering Contributors Version: 2.1.0
创建时间:2025-12-20 最后更新时间:2026-05-15 作者:Agent Skills for Context Engineering Contributors 版本:2.1.0