Community程式設計與開發github.com

context-engineering-collection

一套完整的代理技能集,涵蓋情境工程、Harness 工程、多代理架構與生產級代理系統。適用於需要有效情境管理與可靠運作循環的代理系統建構、最佳化、評估與除錯。

context-engineering-collection 是什麼?

此技能集合提供系統性指引,協助開發者透過高效的情境工程,打造可投入生產環境的 AI 代理系統。涵蓋從基礎的情境理解與退化模式辨識,到多代理協調、長時程提示、記憶系統設計、檔案系統式情境、代管代理基礎設施與工具設計原則等進階架構模式。在運作層面,詳述情境壓縮與最佳化技術、自我管理情境、KV 記憶共享(潛勢簡報)、評估框架與 Harness 工程,確保代理系統在複雜任務中維持可靠運作。此外,也納入專案開發方法論與認知架構(如 BDI 心智狀態模型),讓團隊能從任務模型適配開始,逐步疊代出穩定且高效的代理系統。這套技能與平台無關,可應用於 Claude Code、Cursor 或任何支援自訂指令的代理框架。

相容平台✓Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/tree/main

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

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

說明文件

情境工程的代理技能集

本集合提供系統性指引,透過有效的情境工程建構生產級 AI 代理系統。

啟用時機

在以下情況啟用這些技能:

  • 從頭建構新的代理系統
  • 最佳化現有代理效能
  • 除錯與情境相關的失敗
  • 設計多代理架構
  • 建立或評估代理工具
  • 實作記憶與持久層
  • 設計自主研究或評估 Harness

技能地圖

基礎情境工程

理解情境基礎 情境不僅是指令文字,而是在推論時間語言模型可用的完整狀態,包括系統指令、工具定義、檢索文件、訊息歷史與工具輸出。有效的情境工程意味著了解哪些資訊真正對任務重要,並篩選這些資訊以達到最大的訊噪比。

辨識情境退化 語言模型在情境增長時會表現出可預測的退化模式:資訊位於中間時被忽略的「中間遺失」現象、優先注意開頭與結尾的 U 形注意力曲線、錯誤累積導致的情境中毒,以及不相關資訊淹沒相關內容的情境干擾。

架構模式

多代理協調 生產級多代理系統趨向三種主導模式:具集中控制的監督者/協調者架構、用於靈活交接的點對點群架構,以及用於複雜任務分解的層級結構。關鍵洞見在於子代理的主要目的是隔離情境,而非模擬組織角色。

長時程提示 長時間運行的自主代理與平行協調的成功與否取決於啟動提示。擬形式任務簡報指定成功謂詞、非計數結果、持久規則(附審計閘門回傳條件)、努力下限、平行組合的多樣性政策與污染防護,將形式驗證的紀律以語言方式應用於沒有機器可檢查成功條件的問題上。在協調執行中,每個工作者回傳一個包含命名檢查的輸出合約,只有經證實的違規才會阻擋回傳。

記憶系統設計 記憶架構範圍從簡單的暫存區到複雜的時間知識圖譜。向量 RAG 提供語義檢索,但會失去關係資訊。知識圖譜保留結構,但需要更多工程投資。「檔案系統即記憶」模式可在不塞滿情境視窗的情況下實現即時情境載入。

基於檔案系統的情境 檔案系統提供一個統一的介面來儲存、檢索與更新幾乎無限的情境。關鍵模式包括用於卸載工具輸出的暫存區、用於長時程任務的計劃持久化、透過共用檔案進行的子代理通訊,以及動態技能載入。代理使用 ls、glob、grep 和 read_file 進行目標性情境發現,在結構性查詢上通常優於語義搜尋。

代管代理基礎設施 背景編碼代理在遠端沙盒環境中執行,而非本地機器。關鍵模式包括定期更新的預建環境映像、用於即時工作階段啟動的暖沙盒池、用於工作階段持久化的檔案系統快照,以及支援協作代理工作階段的多玩家模式。關鍵最佳化包括允許在 git 同步完成前讀取檔案(僅阻擋寫入)、在使用者開始輸入時進行預測性沙盒加熱,以及用於平行任務執行的自產生代理。

工具設計原則 工具是確定性系統與非確定性代理之間的合約。有效的工具設計遵循整合原則(偏好單一全面工具而非多個狹窄工具)、在錯誤中回傳情境資訊、支援回應格式選項以節省 token,以及使用清晰的名稱空間。

運作卓越

情境壓縮 當代理工作階段耗盡記憶體時,壓縮就成為必要。正確的最佳化目標是每任務 token 數,而非每請求 token 數。具有明確章節(檔案、決策、下一步)的結構化摘要比激進壓縮能保留更多有用的資訊。在所有壓縮方法中,成品追蹤完整性仍然是最弱的維度。

情境最佳化 技術包括壓縮(在接近限制時摘要情境)、觀察遮蔽(將冗長的工具輸出替換為參考)、前綴快取(跨請求重複使用 KV 區塊),以及策略性情境分割(將工作分配給具有隔離情境的子代理)。

自我管理情境 模型(而非 Harness)決定哪些內容保留在其即時情境中:可編輯區域以檔案形式暴露,模型使用程式碼工具重寫並在每一輪重新解析。Harness 保持不變量(固定的系統與任務前綴、角色折疊、編輯閘門、收據、確定性預算讀出、溢位回滾)。在前綴快取下,編輯成本與編輯後的文字長度成正比,因此編輯會進行批次處理並放置在靠近結尾的位置;策略可透過指示引導、作為技能演化,或使用成功閘門的效率獎勵進行訓練。

潛勢簡報(KV 記憶共享) 協調者-工作者系統在監督者累積長軌跡但工作者只看見狹窄文字片段時,可能會 compound tokens。潛勢簡報使用任務引導的注意力(類似 Attention Matching 的壓縮)在工作者的 KV 快取中壓縮協調者軌跡,因此當堆疊暴露工作者 KV 狀態且模型相容時,工作者無需完整文字回放即可接收相關的潛在狀態。

評估框架 生產級代理評估需要確定性檢查與多維度評分表,涵蓋事實準確性、完整性、工具效率與流程品質。僅在結構、證據與評分表數學有效後,才使用模型評審;將評審設計、成對比較與偏差緩解交給「進階評估」。

Harness 工程 可靠的自主代理需要在模型周圍有明確的運作迴圈:鎖定的指標、可編輯的表面、持久的日誌、新穎性檢查、回滾規則與人類核准邊界。Harness 防止代理削弱評估者、在壓縮過程中遺失狀態,或將模糊目標轉變為不可審查的變更。

自我改進迴圈 當 Harness 本身成為最佳化目標時,需要不同的紀律:遞迴自我改進、元 Harness 搜尋、失敗驅動的有限自我編輯、演化式 Scaffold 搜尋,以及情境機制演化。控制約束包括經驗性雙分割接受閘門、帶有原始追蹤的檔案系統經驗存檔、每個可編輯表面之外的執行時期強制約束,以及防止崩潰的多樣性保留。

開發方法論

專案開發 有效的 LLM 專案開發始於任務模型適配分析:透過手動原型驗證任務適合 LLM 處理後,再建立自動化。生產管線遵循階段化、幂等的架構(取得、準備、處理、解析、渲染),並搭配用於除錯與快取的檔案系統狀態管理。具有明確格式規範的結構化輸出設計可實現可靠的解析。從最小架構開始,僅在證實必要時才增加複雜度。

認知架構

BDI 心智狀態 信念-慾望-意圖建模提供了一種正式方式,將結構化外部情境轉譯為代理心智狀態。適用於理性代理、可解釋性,以及需要在信念、目標與選擇行動之間具有可審計連結的系統。

核心概念

本集合圍繞四個核心主題組織。首先,情境基礎建立什麼是情境、注意力機制如何運作,以及為什麼情境品質比數量更重要。其次,架構模式涵蓋實現有效代理系統的結構與協調機制。第三,運作卓越處理最佳化、評估與 Harness 可靠性。第四,開發方法論與認知架構涵蓋專案執行與正式心智狀態建模。

實務指引

每個技能可以獨立或組合使用。從基礎開始建立情境管理心智模型。根據系統需求分支到架構模式。在最佳化生產系統時參考運作技能。

這些技能與平台無關,可與 Claude Code、Cursor 或任何支援自訂指令或類似技能結構的代理框架搭配使用。

整合

本集合與自身整合——技能彼此參照並建立在共享概念之上。基礎技能為所有其他技能提供背景。架構技能(多代理、記憶、工具)可組合用於複雜系統。運作技能(最佳化、評估)可應用於任何使用基礎與架構技能建構的系統。

參考資料

本集合中的內部技能:

外部情境工程資源:

  • 關於注意力機制與情境視窗限制的研究
  • 來自頂尖 AI 實驗室的生產級代理系統設計經驗
  • LangGraph、AutoGen 與 CrewAI 的框架文件

技能元資料

建立日期:2025-12-20 最後更新:2026-10-01 作者:情境工程代理技能貢獻者 版本:2.6.0

Individual skills in this repo

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

advanced-evaluation

This skill should be used for advanced LLM evaluation: LLM-as-judge systems, direct scoring, pairwise comparison, rubric calibration, evaluator bias mitigation, confidence scoring, and automated quality assessment.

bdi-mental-states

This skill should be used when modeling agent mental states with BDI concepts: beliefs, desires, intentions, RDF-to-belief transformations, rational agency traces, cognitive agents, BDI ontologies, and neuro-symbolic AI integration.

book-sft-pipeline

This skill should be used for book-to-SFT pipelines: ePub extraction, literary segmentation, author-voice dataset construction, style-transfer training, LoRA workflows, and model evaluation for voice replication.

comprehensive-research-agent

Ensure thorough validation, error recovery, and transparent reasoning in research tasks with multiple tool calls

context-compression

This skill should be used when long-running agent sessions need context compression, structured summarization, compaction, token-per-task optimization, or durable handoff summaries that preserve decisions, files, risks, and next actions.

context-degradation

This skill should be used for diagnosing and mitigating context degradation: lost-in-middle failures, context poisoning, context clash, context confusion, attention-pattern issues, and agent performance degradation caused by accumulated or conflicting context.

context-fundamentals

This skill should be used to explain or reason about the foundational concepts of context engineering: what context is, the anatomy of a context window, how attention mechanics work, the U-shaped attention curve, why context quality matters more than quantity, and the mental models needed to interpret every other context-engineering decision. Use this for conceptual explanation, onboarding, and background reading. Route operational work to the specialized skills: debugging attention failures goes to context-degradation, token-efficiency work goes to context-optimization, conversation summarization goes to context-compression, and project-shape decisions go to project-development.

context-optimization

This skill should be used for improving context efficiency: context budgeting, observation masking, prefix or KV-cache strategy, partitioning, token-cost reduction, retrieval scoping, and extending effective context capacity without lowering answer quality.

evaluation

This skill should be used when building agent evaluation systems: deterministic checks, regression suites, multi-dimensional rubrics, quality gates, production monitoring, baseline comparison, and outcome measurement for agent pipelines.

filesystem-context

This skill should be used when agent work needs file-backed context: durable scratchpads, tool-output offloading, just-in-time discovery, cross-agent handoff files, filesystem memory, or cleanup policies for context stored outside the prompt.

harness-engineering

This skill should be used when designing autonomous agent harnesses: research loops, evaluation scaffolds, locked and editable surfaces, durable logs, novelty gates, pruning, rollback, PR preparation, and human approval boundaries.

hosted-agents

This skill should be used when designing hosted or background agent infrastructure: sandboxed execution, remote coding environments, warm pools, session persistence, multiplayer collaboration, self-spawning agents, or Modal-style sandboxes.

latent-briefing

This skill should be used when the user asks to "share memory between agents", "KV cache compaction for multi-agent", "orchestrator worker context", "latent briefing", "reduce worker tokens", "cross-agent memory without summarization", or discusses Attention Matching compaction, recursive language models with workers, or token explosion in hierarchical agents.

long-horizon-prompting

This skill should be used when writing, enhancing, or evaluating the launch prompt for a long-running autonomous agent or a parallel multi-agent orchestration attacking a hard problem: pseudo-formal task briefs that define terms and an exact success predicate linguistically, enumerate non-counting outcomes, set persistence rules with explicit stop and return conditions and effort floors, manage a diverse portfolio of parallel approaches with an approach registry and blocked-route bookkeeping, and gate the return on adversarial audit. Route agent topology and coordination protocols to multi-agent-patterns, runtime control surfaces and loop governance to harness-engineering, evaluator and quality-gate construction to evaluation, judge design to advanced-evaluation, and compaction or memory mechanics to context-compression and memory-systems.

memory-systems

This skill should be used for persistent semantic memory in agent systems: cross-session knowledge retention, entity tracking, temporal validity, graph or vector retrieval, memory consolidation, and memory benchmark selection. Route file-backed scratchpads to filesystem-context, handoff summaries to context-compression, and token-efficiency tactics to context-optimization.

multi-agent-patterns

This skill should be used when designing multi-agent systems that need context isolation, supervisor or swarm coordination, explicit handoffs, parallel execution, or a decision on whether multiple agents are justified.

project-development

This skill should be used for project-level decisions about LLM-powered systems: whether an LLM is the right primitive for the task at hand, the shape of a multi-stage batch or agent pipeline, token and cost estimation, choosing between single-agent and multi-agent at the project level, structured output design for downstream parsing, and structuring agent-assisted iteration. Use this when the unit of work is a whole project or a multi-stage pipeline. Route individual tool design to tool-design and individual skill-loading or context-budget tactics to context-optimization.

self-improvement-loops

This skill should be used when the harness, scaffold, workflow, or optimizer itself is the optimization target: recursive self-improvement (RSI) loops, meta-harnesses, self-improving harnesses that mine their own failures and propose bounded edits, evolutionary or population-based search over agent scaffolds, acceptance gates for self-modifying systems, and agentic context evolution where the mechanism that produces context is versioned and evolved. Route governance of a single autonomous loop (locked surfaces, durable logs, rollback, novelty gates, approval boundaries) to harness-engineering, measurement and quality-gate design to evaluation, judge design to advanced-evaluation, and remote sandbox infrastructure to hosted-agents.

self-managed-context

This skill should be used when a model gets read-write control over its own live context window instead of a harness-scheduled compaction policy: the context exposed as an editable file the model rewrites with code tools, model-driven eviction and in-place updates, the harness invariants that keep self-editing safe (pinned prefix, edit gate, edit receipts, budget readouts, rollback on overflow), the prefix-cache cost of mid-context edits, and steering or training the model's own context-editing strategy. Route note content and fixed-threshold summarization to context-compression, cache-stable layout under harness control to context-optimization, file offloading to filesystem-context, and loop governance to self-improvement-loops.

tool-design

This skill should be used for the tool-interface layer of an agent system specifically: writing tool descriptions agents can route on, designing tool schemas and response formats, naming conventions, actionable error recovery messages, MCP server design, tool-set consolidation, and deciding when to add or remove an individual tool. Use this when the unit of work is a single tool or a set of tools. Route project-shape, pipeline architecture, and task-model-fit decisions to project-development; route deciding whether to introduce sub-agents to multi-agent-patterns.

相關技能