免費諮詢
技術Anthropic 官方 cookbook,context engineering 主題被多篇 2026 教學引用Token節費與提示工程

Claude Cookbook:上下文工程三招——記憶、壓縮(compaction)、清除工具結果

Context engineering: memory, compaction, and tool clearing

來源:Anthropic(Claude Cookbook)・發布 2026-03-20・本站摘要分析(非全文轉載)

📌 一句話啟示:理解「上下文會腐壞」與三種對策,是從會聊天進階到會建 agent 的分水嶺。

摘要分析

Anthropic 2026-03-20 的 cookbook 比較三種官方上下文管理機制:Compaction(compact_20260112)在輸入達 150K 時把對話摘要、之後只帶摘要;Tool-result clearing(clear_tool_uses_20250919)把舊工具結果換成占位符,零推論成本;Memory tool(memory_20250818)讓模型在 /memories 讀寫檔案跨 session 保留。實測清除工具結果讓峰值上下文從 335K 降到 173K。建議依瓶頸選:工具輸出肥用 clearing、長對話用 compaction、跨 session 用 memory。

  • Compaction:betas=["compact-2026-01-12"],context_management edits type=compact_20260112,trigger input_tokens 150_000
  • Clearing:type=clear_tool_uses_20250919,設 trigger/keep/clear_at_least,exclude_tools 保護 memory
  • Memory:tools 加 {"type":"memory_20250818","name":"memory"},自己實作 view/create/str_replace/insert/delete/rename
  • 回傳的 compaction block 要序列化回歷史,API 會丟掉它之前的內容
  • 選擇原則:工具輸出肥→clearing;對話長→compaction;要跨 session→memory

Published 2026-03-20, this Claude Cookbook compares three first-party context-management primitives. Compaction (compact_20260112 with beta header compact-2026-01-12) summarizes the whole transcript when input reaches a trigger (default 150K, minimum 50K) and continues from the summary; it is lossy, so custom instructions should name details that must survive. Tool-result clearing (clear_tool_uses_20250919) replaces old tool_result content with placeholders while keeping tool_use records, at zero inference cost; parameters include trigger, keep and clear_at_least. The memory tool (memory_20250818) lets the model read and write files under /memories that persist across sessions, with your app implementing the handler and guarding path traversal. Measured results: clearing cut peak context from about 335K to 173K tokens, and a memory-enabled second session needed 4 file reads instead of 8. Choose by bottleneck: clearing for bulky tool output, compaction for long dialogue, memory for cross-session knowledge.

  • Compaction: beta compact-2026-01-12, edit type compact_20260112, trigger 150K
  • Clearing: clear_tool_uses_20250919 with trigger/keep/clear_at_least
  • Memory: tool type memory_20250818 with six commands you implement
  • Serialize the compaction block back into history
  • Pick by bottleneck: clearing, compaction, or memory

關鍵字:context engineeringcompactionmemory tooltool clearingClaude API

來源原文:https://platform.claude.com/cookbook/tool-use-context-engineering-context-engineering-tools
本頁為報導內容的摘要與分析,版權屬原媒體所有;請以原文為準。

看完趨勢,下一步

對應的變現路徑與聯成課程

路徑 A 職場加薪路徑 B 轉職高薪

產學就業班路徑 B

AI 人工智慧工程師

整合 Python、爬蟲與 AI 數據分析,從深度學習基礎到實務部署,切入年薪中位數逾百萬的熱門職缺。

就業待遇 $62,000~$80,000

到官網了解課程

到聯成官網免費諮詢

同主題報導

技術文章・Anthropic(platform.claude.com 官方文件)・Anthropic 官方核心文件;2026-10-07 Sonnet 5.5 快取讀取降價為 0.05x・2026-10-07・Token節費與提示工程

Claude 官方文件:Prompt caching 快取讀取只要 0.1 倍(新模型 0.05 倍)

Claude Developer Platform docs: Prompt caching

Prompt caching 是 Claude API 最直接的省錢機制:快取 tools→system→messages 前綴,命中時跳過重算。官方文件列出倍率:5 分鐘寫入 1.25 倍、1 小時寫入 2 倍、讀取多…

看摘要分析 →
技術文章・OpenAI Cookbook・openai/openai-cookbook ⭐76.6k;Cookbook Evals 主題首篇(2026-09-14)・2026-09-14・Token節費與提示工程

OpenAI Cookbook:客服 agent 成本與品質最佳化,四輪把每張工單成本砍 95%

Optimizing Customer Support Agents for Cost and Quality

OpenAI Cookbook(repo ⭐7.7 萬)2026-09-14 驗證的這篇教一套可重複的最佳化迴圈:量基準、每次只改一件事、品質過關才接受省下的成本。範例是電商客服 agent,四輪結果:壞基準每張工單 1…

看摘要分析 →

1 分鐘測出你的變現路徑

免費職涯/變現診斷 → 專屬學習地圖 → 成果里程碑計畫書。全台 26 校,週一至五 09:00–18:00。

免費變現路徑診斷LINE 官方帳號撥打 0800-580-581