Communitygithub.com

語境工程

檢查上下文使用限制、監控剩餘時間、優化 Token 消耗、除錯上下文失敗。在詢問上下文百分比、速率限制、使用警告、上下文優化、代理架構、記憶系統時使用。

語境工程 是什麼?

語境工程(Context Engineering)是一項專注於為 LLM 任務策劃最小、高訊號 Token 集合的技能。其目標是在最大化推理品質的同時,最小化 Token 使用量。此技能支援 Claude Code、Cursor、Codex 等 AI 代理平台,透過提供核心原則、快速參考表格、關鍵指標、四桶策略以及常見反模式,幫助開發者設計、除錯和最佳化代理系統。它還包含執行時期感知功能,能自動注入使用量感知,並提供閾值警告(70% 警告、90% 嚴重)。此外,該技能附帶實用腳本,如 `context_analyzer.py` 和 `compression_evaluator.py`,用於分析上下文健康和評估壓縮品質。總體而言,它是一個全面的工程指南,旨在提升 LLM 應用的效率、可靠性和成本效益。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/majiayu000/claude-skill-registry/tree/HEAD/skills/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-cache 命中率
  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

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".

majiayu000/claude-skill-registry

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry

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

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

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

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

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

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

majiayu000/claude-skill-registry

BlockRun works with Claude Code and Google Antigravity.

majiayu000/claude-skill-registry

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

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

majiayu000/claude-skill-registry

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

CRITICAL: Use for MolyKit AI chat toolkit. Triggers on: BotClient, OpenAI, SSE streaming, AI chat, molykit, PlatformSend, spawn(), ThreadToken, cross-platform async, Chat widget, Messages, PromptInput, Avatar, LLM

majiayu000/claude-skill-registry

AI and machine learning workflow covering LLM application development, RAG implementation, agent architecture, ML pipelines, and AI-powered features.

majiayu000/claude-skill-registry

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

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

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

相關技能