Communitygithub.com

上下文工程

檢查上下文使用限制、監控剩餘時間、優化Token消耗、除錯上下文故障。適用於詢問上下文使用率、速率限制、使用警告、上下文優化、代理架構、記憶體系統等場景。

上下文工程 是什麼?

上下文工程(Context Engineering)是一項專業技能,專注於為大型語言模型(LLM)任務策劃最小但高訊號的Token集合。其核心目標是在最大化推理品質的同時,最小化Token消耗。這項技能涵蓋了從基礎概念(上下文結構、注意力機制)到進階技術(壓縮、快取、分割)的完整知識體系,並支援多種平台如Claude Code、Cursor和Codex等AI代理工具。技能的核心原則包括「品質重於數量」、「注意力有限」、「漸進式揭露」和「隔離防止退化」,並提供了四大策略(寫入、選擇、壓縮、隔離)來管理上下文。此外,技能還整合了執行時感知功能,能自動監控上下文視窗使用量(70%警告、90%臨界),並提供多個參考文件和腳本(如context_analyzer.py、compression_evaluator.py)來輔助實作。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/majiayu000/claude-skill-registry-data/tree/HEAD/context-management/context-engineering-hoanghd218-landing-page-ai-kien-2

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

上下文工程 是做什麼的?

上下文工程為LLM任務策劃最小但高訊號的Token集合。目標:最大化推理品質,同時最小化Token使用量。

何時啟用

  • 設計/除錯代理系統
  • 上下文限制影響效能
  • 最佳化成本/延遲
  • 建構多代理協調
  • 實作記憶體系統
  • 評估代理效能
  • 開發LLM驅動的流程

核心原則

  1. 上下文品質 > 數量 - 高訊號Token勝過詳盡內容
  2. 注意力有限 - U型曲線偏愛開頭/結尾位置
  3. 漸進式揭露 - 即時載入資訊
  4. 隔離防止退化 - 將工作分割給子代理
  5. 先衡量再最佳化 - 了解你的基準

重要事項:

  • 為了簡潔,可犧牲文法。
  • 在維持高品質的同時確保Token效率。
  • 將這些規則傳遞給子代理。

快速參考

主題使用時機參考
基礎知識了解上下文結構、注意力機制context-fundamentals.md
退化除錯失敗、中間遺失、毒化context-degradation.md
最佳化壓縮、遮罩、快取、分割context-optimization.md
壓縮長時間會話、摘要策略context-compression.md
記憶體跨會話持久化、知識圖譜memory-systems.md
多代理協調模式、上下文隔離multi-agent-patterns.md
評估測試代理、LLM作為評審、指標evaluation.md
工具設計工具整合、描述工程tool-design.md
流程專案開發、批次處理project-development.md
執行時感知使用限制、上下文視窗監控runtime-awareness.md

關鍵指標

  • Token利用率:70%警告,80%觸發最佳化
  • Token變異性:解釋代理80%的效能差異
  • 多代理成本:約為單一代理基準的15倍
  • 壓縮目標:減少50-70%,品質損失低於5%
  • 快取命中目標:穩定工作負載達70%以上

四大策略

  1. 寫入:將上下文儲存於外部(暫存區、檔案)
  2. 選擇:僅提取相關上下文(檢索、過濾)
  3. 壓縮:在保留資訊的同時減少Token(摘要)
  4. 隔離:跨子代理分割(分割)

反模式

  • 詳盡上下文勝過策劃上下文
  • 關鍵資訊放在中間位置
  • 在限制之前沒有壓縮觸發
  • 單一代理處理可並行化的任務
  • 工具缺乏清晰的描述

指南

  1. 將關鍵資訊放在上下文的開頭/結尾
  2. 在利用率達70-80%時實施壓縮
  3. 使用子代理進行上下文隔離,而非角色扮演
  4. 使用4問框架設計工具(做什麼、何時用、輸入、輸出)
  5. 以每任務Token而非每請求Token為最佳化目標
  6. 使用基於探針的評估進行驗證
  7. 在生產環境中監控KV快取命中率
  8. 從最小配置開始,僅在證明必要時增加複雜度

執行時感知

系統透過PostToolUse掛鉤自動注入使用感知:

<usage-awareness>
Claude 使用限制:5h=45%,7d=32%
上下文視窗使用率:67%
</usage-awareness>

閾值:

  • 70%:警告 - 考慮最佳化/壓縮
  • 90%:臨界 - 需立即採取行動

資料來源:

  • 使用限制:Anthropic OAuth API(https://api.anthropic.com/api/oauth/usage)
  • 上下文視窗:狀態列暫存檔(/tmp/ck-context-{session_id}.json)

腳本

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

majiayu000/claude-skill-registry-data

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry-data

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry-data

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry-data

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry-data

Analyzes current state and user query to answer BMad questions or recommend the next workflow or agent. Use when user says what should I do next, what do I do now, or asks a question about BMad

majiayu000/claude-skill-registry-data

Build AI agents with Google ADK Python (Agent Development Kit). Use for multi-agent systems, workflow agents (sequential/parallel/loop), Vertex AI deployment, tool integration, human-in-the-loop.

majiayu000/claude-skill-registry-data

Build AI agents with Google ADK Python (Agent Development Kit). Use for multi-agent systems, workflow agents (sequential/parallel/loop), Vertex AI deployment, tool integration, human-in-the-loop.

majiayu000/claude-skill-registry-data

Portfolio allocation and rebalancing optimizer. Manages asset allocation across stocks/cash/bonds, performs periodic rebalancing, and ensures diversification according to market regime and risk tolerance.

majiayu000/claude-skill-registry-data

Create a hilarious and ultra-realistic video of an anthropomorphic animal acting like a human vlogger in a real-world setting.

majiayu000/claude-skill-registry-data

Speech-to-text transcription and translation via OpenAI Audio API -- models, response formats, timestamps, prompting, streaming, chunking, and diarization

majiayu000/claude-skill-registry-data

This skill should be used when the user asks about libraries, frameworks, API references, or needs code examples. Activates for setup questions, code generation involving libraries, or mentions of specific frameworks like React, Vue, Next.js, Prisma, Supabase, etc.

majiayu000/claude-skill-registry-data

小省导购员数字人带货版即梦视频提示词生成系统,基于四大智能体协同(提示词生成师、质量管控师、知识库运维师、跨环节适配师),按照"主体+运动+场景+(镜头语言+光影+氛围)"公式输出中英文双版提示词,适配5s短视频。确保人物一致性、视觉连贯性、情绪连贯性,支持知识库智能复用和跨工具适配(Suno音乐、AI绘画),为数字人带货视频提供高质量提示词生成服务。

majiayu000/claude-skill-registry-data

Upload and manage files using Google Gemini File API via scripts/. Use for uploading images, audio, video, PDFs, and other files for use with Gemini models. Supports file upload, status checking, and file management. Triggers on "upload file", "file API", "upload image", "upload PDF", "upload video", "file management".

majiayu000/claude-skill-registry-data

Analyze images/audio/video with Gemini API (better vision than Claude). Generate images (Imagen 4), videos (Veo 3). Use for vision analysis, transcription, OCR, design extraction, multimodal AI.

majiayu000/claude-skill-registry-data

Analyze images/audio/video with Gemini API (better vision than Claude). Generate images (Imagen 4), videos (Veo 3). Use for vision analysis, transcription, OCR, design extraction, multimodal AI.

majiayu000/claude-skill-registry-data

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

majiayu000/claude-skill-registry-data

Conduct domain and industry research. Use when the user says "lets create a research report on [domain or industry]

majiayu000/claude-skill-registry-data

Conduct market research on competition and customers. Use when the user says "create a market research report about [business idea]".

majiayu000/claude-skill-registry-data

Conduct technical research on technologies and architecture. Use when the user says "create a technical research report on [topic]".

majiayu000/claude-skill-registry-data

Builds, edit or validate Agent Skill through conversational discovery. Use when the user requests to "Create an Agent", "Optimize an Agent" or "Edit an Agent".

相關技能