Community程式設計與開發github.com

Harness 工程

此技能用於設計自主代理的控管系統:研究迴圈、評估框架、鎖定與可編輯表面、持久日誌、新穎性閘門、修剪、回滾、PR 準備以及人工核准邊界。

Harness 工程 是什麼?

Harness 工程 (Harness Engineering) 是一項關鍵技能,用於設計圍繞 AI 代理的控制系統,確保其在長時間自主運行時的安全性和效率。它定義了代理可以編輯的內容、如何接收反饋、狀態寫入位置、故障恢復方式,以及誰能批准不可逆操作。此技能支援多種平台,如 Claude Code、Cursor 和 Codex,並提供一套完整的實用指南,包括核心概念(如鎖定/可編輯/僅附加/人類控制表面)、緊密反饋迴圈、持久狀態管理、搜索紀律和治理規則。通過遵循 Harness 工程的原則,開發者可以構建能夠運行數天而不偏離目標的自主研究迴圈、PR 生成代理或評估框架,並有效防止代理作弊、複雜性累積和狀態遺失等常見問題。

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

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

在你喜歡的 AI 中提問

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

說明文件

Harness 工程 是做什麼的?

Harness 工程設計圍繞代理的控制系統:它可編輯的內容、接收反饋的方式、寫入狀態的位置、故障復原方式,以及誰可以核准不可逆操作。Harness 是區分一個有用的代理會話和一個可以運行數天而不會破壞其目標的自主循環的關鍵。

何時啟用

在以下情況啟用此技能:

  • 建構自主研究或實驗循環
  • 設計具有鎖定指標和可編輯程式碼或內容的代理環境
  • 建立產生 PR 或背景執行的代理
  • 評估代理是否可以安全地運行而無需頻繁的人為提示
  • 為代理工作流程添加新穎性、消融、修剪、回滾或持久記錄
  • 防止代理作弊基準、削弱評分標準或在壓縮過程中遺失狀態

對於由其他技能負責的相關工作,請勿啟用此技能:

  • 一般的品質閘門、回歸套件或沒有自主控制面的結果指標:evaluation。
  • 工具模式、回應格式和 harness 工具的復原錯誤:tool-design。
  • 專案層級的任務-模型契合度、流程形狀和成本規劃:project-development。
  • 遠端沙箱、熱池和託管會話基礎設施:hosted-agents。

核心概念

Harness 邊界

將代理與其運作的環境分開。代理提出行動;harness 定義允許的表面、回饋、持久性和晉升規則。

使用四個表面類別:

表面範例規則
鎖定評估指標、評分標準、驗證腳本、合併策略代理可以讀取並提出變更,但不能使用修改後的規則對自己進行評分
可編輯技能草稿、實驗檔案、提示詞、正在測試的配置代理可以在循環期間進行變異
僅附加結果記錄、研究執行緒、被拒絕的想法代理可以附加,但不能重寫
人類控制合併、生產部署、憑證、破壞性操作需要明確的人類核准

緊密反饋迴圈

當回饋快速、明確且難以作弊時,自主性才能發揮作用。Karpathy 的 autoresearch 是最簡模式:一個可編輯檔案、一個鎖定的評估檔案、固定的時鐘預算、一個標量指標、git 回滾和一個持久的結果記錄。其教訓並非每個 harness 都需要一個指標;而是模糊的回饋會導致模糊的自主性。

對於開放式的研究到技能工作,將標量指標替換為鎖定的評分標準、確定性結構檢查、來源可追溯性和人類審查門檻。

持久狀態

長時間運行的代理必須將狀態外部化。將計劃、來源佇列、結果、失敗和交接儲存在檔案中,以便未來的代理無需依賴聊天歷史即可恢復。Prime Intellect 的自動 nanoGPT 工作展示了持久記事板和 THREAD.md 風格記錄在恢復、監控和稽核方面的價值。

使用僅附加記錄來記錄:

  • 嘗試了什麼
  • 什麼改進了或失敗了
  • 為什麼保留了、丟棄了或將候選項目送去審查
  • 檢查了哪些上游來源
  • 下一個代理應該做什麼

搜索紀律

代理傾向於利用最近的表面、堆疊複雜性以及不足夠的修剪。添加明確的搜索規則:

  1. 按計劃重新整理上游來源。
  2. 在花費大量預算之前,要求進行新穎性檢查。
  3. 保留被拒絕的嘗試以避免重新發現。
  4. 當堆疊有多個新增項目時,執行留一法修剪。
  5. 當品質相同時,獎勵簡化。
  6. 在晉升之前使用獨立的驗證。

機制註冊表

對於研究到技能的系統,需分別追蹤已接受的機制和散文。一個機制記錄應包含穩定的 mechanism_id、owning_skill、status、啟動場景、行為變更、證據和失敗模式。新穎性閘門應先與此註冊表進行比較,然後再使用更廣泛的語料庫重疊,因為關鍵詞重疊會捕捉到陳舊的措辭,而機制比較則能捕捉到真正的重複。

治理

自主代理可以準備 PR,但治理必須明確。它們可以起草變更、執行檢查和撰寫 PR 摘要。除非使用者已明確授予該特定操作的權限,否則它們不應合併、部署或推送,而無需人類核准。

詳細主題

Autoresearch 風格的循環

在針對穩定的評估器優化工件時使用此模式:

讀取鎖定的上下文 -> 選擇假設 -> 編輯允許的表面 -> 提交/檢查點
-> 執行評估器 -> 記錄結果 -> 如果更好則保留 -> 如果更差則丟棄或回滾
-> 重複

必要屬性:

  • 評估器位於可編輯表面之外。
  • 回饋節奏足夠固定以比較嘗試。
  • 失敗的嘗試留下稽核軌跡。
  • 回滾成本低廉。
  • 代理有處理崩潰和超時的策略。

研究到技能循環

在來源變為技能變更時使用此模式:

發現 -> 檢索 -> 閘門 -> 評分 -> 提取機制
-> 映射到現有或新的技能 -> 起草提案 -> 驗證結構
-> 準備 PR -> 人類審查

鎖定的評估器是來源評分標準、技能變更評分標準、結構檢查和審查者核准的組合。可編輯的工件是提議的技能增量。

指標作弊抵抗力

假設一個最佳化代理會學習 harness。防範以下情況:

  • 編輯評估程式碼或評分標準,然後使用新版本進行自我核准
  • 添加能取悅評判者但損害技能啟動的冗長內容
  • 引用未檢索的來源
  • 在關鍵維度失敗的同時最佳化總分
  • 在記錄中避免失敗的結果

緩解措施:每次運行鎖定評分標準,報告每個維度的分數,要求提供來源檢索證據,保留被拒絕的嘗試,並將治理變更路由到人類審查。

監控代理

對於長時間運行,請使用監控代理,但除非明確指派任務,否則將其限制為唯讀報告。監控輸出應報告:

  • 最佳當前候選項目
  • 進行中的工作或草稿
  • 上次上游重新整理
  • 失敗或停滯的循環
  • 記錄與聲稱狀態之間的不一致
  • 下一步行動和阻礙因素

實用指南

Harness 設計檢查清單

  1. 用一句話定義目標。
  2. 識別鎖定、可編輯、僅附加和人類控制的表面。
  3. 選擇回饋機制:標量指標、評分標準、確定性測試、人類審查或組合。
  4. 定義保留、丟棄、崩潰、超時和審查狀態。
  5. 在循環開始前建立一個持久的執行緒記錄。
  6. 為長時間運行的循環添加來源重新整理、機制註冊表新穎性和修剪規則。
  7. 定義代理無需詢問即可執行的事項以及需要核准的事項。
  8. 使用一個已知良好和一個已知不良的工件來驗證 harness。

檔案佈局

research-run/
  THREAD.md
  sources/
    queue.md
    evaluations/
  proposals/
  logs/
    results.tsv
    rejected.md
  drafts/

對僅附加的機器可讀記錄使用 TSV 或 JSONL。對交接和供審查者閱讀的摘要使用 Markdown。

範例

範例 1:鎖定指標

一個代理優化了 train.py,但 prepare.py 擁有資料載入和評估的權限。代理可以編輯模型但不能更改指標。失敗的實驗會被記錄並回滾。

範例 2:鎖定評分標準

一個代理評估一篇新的 Anthropic 或 OpenAI 工程文章,但來源策展評分標準在運行期間被鎖定。如果來源通過,代理會起草一個技能提案。它不能降低評分標準門檻來接納該來源。

範例 3:自動 PR 而不自動合併

一個代理在通過來源、技能和結構檢查後準備了一個分支和 PR 主體。PR 陳述了未解決的風險,並等待人類合併核准。

指導方針

  1. 在開始循環之前鎖定評估器。
  2. 保持可編輯表面足夠狹窄以進行可靠的差異比較。
  3. 在上下文壓縮可能清除狀態之前,寫入持久的記錄。
  4. 報告每個維度的分數,而不僅僅是總分。
  5. 在引用之前要求來源檢索。
  6. 為廣泛的搜索添加新穎性閘門,為複雜的堆疊添加修剪閘門。
  7. 當品質相同時,偏好簡化。
  8. 將 PR 準備與合併權限分開。
  9. 使用舊的和新的評估器重新驗證 harness 變更。
  10. 將停止的自主循環視為 harness 的失敗,而不是代理的性格怪癖。

常見陷阱

  1. 可變評估器:如果代理可以編輯指標,它可能會優化基準而不是任務。在運行期間保持評分標準和評估程式碼鎖定。
  2. 僅聊天記憶體:當計劃僅存在於對話歷史中時,長時間運行在壓縮後會失敗。從一開始就寫入執行緒記錄和結果檔案。
  3. 無丟棄記錄:如果沒有被拒絕嘗試的記錄,代理會重複失敗的想法。保留失敗的細節以避免重新發現。
  4. 複雜性累積:代理會堆疊變更,並且很少移除它們。要求進行修剪輪次並獎勵同等品質的簡化。
  5. 過早的新穎性聲明:代理將重新組合標記為新穎。在聲明新穎性之前,請與現有的 repo 技能、來源佇列和被拒絕的記錄進行比較。
  6. 監控誤報:監控代理可以總結過時或不一致的狀態。要求它們引用支持聲明的檔案或記錄。
  7. 人類核准模糊性:「準備 PR」不等於「合併 PR」。在 harness 中明確規定核准邊界。
  8. 易變的來源漂移:快速變動的實驗室聲明很快就會過時。在參考文獻中放入附有日期的證據,並安排重新驗證。

整合

此技能連接到:

  • evaluation - 評分標準和品質閘門提供鎖定的回饋表面
  • advanced-evaluation - 成對比較和偏差緩解改善了提案審查
  • filesystem-context - 持久記錄、記事板和執行緒檔案保留了狀態
  • multi-agent-patterns - 研究員、驗證員、監控員和作者代理需要隔離的上下文
  • tool-design - Harness 工具必須公開清晰的契約和復原錯誤
  • project-development - 基於檔案的流程和任務-模型契合度分析使循環保持簡單
  • hosted-agents - 背景執行需要沙箱、快照和核准邊界

參考資料

內部參考資料:

  • researcher/README.md - 在實現倉庫原生研究到技能作業系統時閱讀
  • researcher/rubrics/harness-change.md - 在評估對代理 harness 的變更時閱讀
  • researcher/runbooks/autonomous-research-loop.md - 在運行來源到技能循環時閱讀

外部資源:

  • Karpathy autoresearch - 具有鎖定評估的約束自主實驗循環
  • Prime Intellect 自主 nanoGPT 極速挑戰 - 持久記事板、交接、監控和自主性失敗模式
  • AlphaEvolve 和 FunSearch - LLM 生成的候選項目與系統性評估器配對
  • HELM 和 LM Evaluation Harness - 透明、可重現的評估基礎設施

技能元資料

建立日期:2026-05-14 最後更新:2026-05-15 作者:Agent Skills for Context Engineering Contributors 版本:1.1.0

Individual skills in this repo

This repo contains 19 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.

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.

相關技能