Community程式設計與開發github.com

自我改進循環

此技能適用於框架、腳手架、工作流程或優化器本身成為優化目標的情況:遞迴自我改進循環、元框架、能夠挖掘自身失敗並提出受限制修改的自我改進框架、對代理腳手架進行演化或基於群體的搜索、自行修改系統的接受閘門,以及機制能夠被版本化和演進的代理上下文演化。

自我改進循環 是什麼?

「自我改進循環」技能深入探討了設計系統的複雜性,在這些系統中,代理不僅僅是在單一循環內運行,而是能夠改寫其自身的框架、提示、上下文或工作流程。它藉由引入「優化階梯」的概念來幫助開發人員,解釋了系統如何從優化簡單的提示指令開始,逐步深入到能修改自身的優化器程式碼。核心挑戰在於設計一個能夠安全地進行自我修改的循環,避免獎勵黑客攻擊、多樣性崩潰或上下文崩潰等陷阱。此技能支援 Claude Code、Cursor 或 Codex 等平台,並強調關鍵的「循環外不變量」,即評估器和沙箱環境必須保持在代理可修改的範圍之外,以防止自我修改機制悄悄破壞用於引導其改進的訊號。它提供了詳細的實作模式,例如用於結構化上下文演進的基於項目的增量更新,以及用於框架程式碼的有界自我編輯。

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

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

在你喜歡的 AI 中提問

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

說明文件

自我改進循環 是做什麼的?

此技能涵蓋框架本身即為優化對象的系統:代理挖掘自身失敗並編輯自身腳手架、元代理對框架程式碼進行搜尋、一組工作流程候選者根據評估器進行演化,或用於產生上下文的機制本身被版本化和改進。設計問題從「如何控制一個循環」(框架工程)轉變為「如何讓循環改寫自身的一部分,而不會腐蝕引導它的訊號」。

所有已發布系統的共同控制約束:循環會優化它得到的任何訊號,包括訊號本身的弱點。設計循環時要假設優化器會找出指標與意圖之間的每個差距。

啟動時機

在以下情況啟用此技能:

  • 建立一個循環,其中代理根據挖掘出的失敗模式,對其自身框架、提示、上下文劇本或工作流程提出修改建議
  • 設計對框架或腳手架程式碼的元級別搜尋:元代理搜尋、工作流程圖的樹搜尋、帶有 LLM 突變運算符的演化程式搜尋
  • 為任何自我修改的代理系統選擇接受標準
  • 演化管理上下文的機制(技能、劇本或上下文函數),而不是手動編輯上下文工件
  • 診斷退化的自我改進循環:獎勵黑客攻擊、多樣性崩潰、上下文崩潰或無聲停滯
  • 決定應在優化階梯的哪個層級(提示、上下文、工作流程、框架程式碼、優化器程式碼)修復重複出現的失敗

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

  • 治理不修改自身的單一自主循環:鎖定和可編輯的表面、持久日誌、回滾、新穎性閘門、PR 準備和人類批准邊界屬於 harness-engineering(框架工程)。該技能定義控制表面;此技能定義當這些表面本身成為優化目標時會發生什麼。
  • 建構對候選者進行評分的評估器、回歸套件或品質閘門:evaluation(評估)。
  • LLM 作為評判的設計、成對比較以及候選者評分中的偏差緩解:advanced-evaluation(進階評估)。
  • 沒有改進循環的一次性令牌效率、遮罩或快取:context-optimization(上下文優化)。
  • 用於運行循環的遠端沙箱和背景執行基礎設施:hosted-agents(託管代理)。
  • 是否要建構循環、管線形狀和成本估算:project-development(專案開發)。
  • 循環優化的自我編輯上下文行為和效率獎勵:self-managed-context(自我管理上下文)。

核心概念

優化階梯

已發布的自我改進系統針對逐漸深入的對象:

階層優化對象範例系統
1指令提示Promptbreeder, GEPA
2結構化上下文ACE (項目化要點劇本)
3上下文機制MCE (產生上下文的技能)
4工作流程圖ADAS, AFlow
5框架程式碼Self-Harness (有界自我編輯), Meta-Harness, Darwin Godel Machine
6優化器程式碼STOP (改進者改進改進者)

每上升一階,都能獲得更大的設計空間和更強的作用力,但每次評估的成本更高,並且被利用的表面也更大。在能夠表達修復的最低階層修復重複出現的失敗。過時庫的失敗是上下文的修復,而不是工作流程的重寫。只有當當前階層的失敗集群在候選者中持續存在時,才向上移動。

循環並非智慧

遞迴結構會在兩個方向上放大基礎模型的品質。相同的遞迴改進器設計,若使用強大模型則能複合成長,若使用較弱模型則會使疊代間的平均表現下降(claim-self-improvement-capability-threshold)。這有兩個含義:

  1. 在啟用遞迴之前執行能力驗證:在保留的任務集上進行固定次數的疊代,如果軌跡下降,則將循環視為淨負值。
  2. 偵測退化的停滯模式。一個壞掉的改進器,若無聲地原樣返回其輸入,在總體指標上看起來就像穩定性。追蹤編輯差異,而不僅僅是分數。

循環外不變量

評估器、其儀器化、權限控制和預算執行必須存在於循環可以修改的表面之外。每個有記錄的獎勵黑客攻擊都違反了這個不變量:代理移除了幻覺檢測器所依賴的日誌標記,並且當檢查程式碼對代理可見時,黑客攻擊變得更加頻繁(claim-self-improvement-visible-evaluator-hacking)。能夠看到評分函數的代理會覆寫計時函數並對評估器進行猴子修補以返回完美分數(claim-self-improvement-scorer-visibility)。

操作規則:

  • 在提示文字中陳述的約束會被演化掉。在執行環境中執行預算、權限和沙箱邊界,永遠不要在可變的提示或框架程式碼中。
  • 對提議者隱藏評分實作。公開分數和軌跡,而不是評估器原始碼。
  • 在作業系統或容器層級進行沙箱隔離。框架層級的權限閘門可以透過循環發現的側通道繞過。
  • 將任何檢測到的利用視為失敗的候選者,而不是高分,否則黑客行為會膨脹引導循環的指標。

基於經驗證據,而非推理

僅憑測量證據接受自我修改,使用兩個資料分割:一個保留的內部(held-in)分割,用於檢查目標弱點是否已解決;以及一個提議者從未見過的保留外部(held-out)分割,用於檢查沒有其他項目回歸。最嚴格的已發布閘門僅在兩個分割都沒有回歸且至少有一個嚴格改善時才接受,並在隨機評分下進行重複評估;這在所有測試的基礎模型上都產生了保留的外部收益(claim-self-improvement-two-split-acceptance)。拒絕即使在總和改善時用一個分割交易另一個分割的候選者。記錄被拒絕的候選者及其證據,以便提議者停止重新發現它們。

檔案系統經驗存檔

將每個候選者儲存為一個包含其原始碼、分數和原始執行軌跡的目錄。讓提議者使用搜尋工具(類似於 grep 的檔案查詢)導航存檔,而不是將歷史記錄塞入其上下文視窗。在直接消融實驗中,擁有完整原始軌跡存取的提議者在表現上顯著優於僅有分數的提議者以及被餵養 LLM 對相同軌跡的摘要的提議者;摘要無法恢復任何丟失的訊號,有時甚至會造成損害(claim-self-improvement-raw-trace-ablation)。不要預先摘要存檔。管理存取路徑,而不是內容。

多樣性保存

除非刻意設計多樣性,否則演化式和 RL 風格的循環會向當前最佳變體收斂。在已發布系統的消融實驗中倖存下來的機制:

  • 保留每個保留核心能力的候選者的存檔;絕不只在最新版本上登峰造極。基石在它們被發現許多次疊代後仍然會產生回報。
  • 根據後代數量打折適應度壓力來選擇父代,因此被大量挖掘的候選者優先級會降低,而每個存檔成員保持非零的選擇機率。
  • 在支付評估成本之前,透過嵌入相似性拒絕幾乎重複的提案。
  • 在選擇分佈中保留一條返回種子或空白候選者的持久路徑,作為逃離局部最優的出口。

詳細主題

失敗驅動的自我編輯循環的結構

代理改進自身框架的最強已發布模式包含三個階段:

  1. 弱點挖掘。根據三部分特徵對失敗軌跡進行聚類:驗證器層級的原因(被拒絕的內容)、代理行為的因果狀態(是否實際負責)以及軌跡暴露的抽象機制(可重複的行為模式)。絕不要僅根據錯誤字串進行聚類;超時是無關機制共享的症狀。套用可定址性過濾器:排除反映任務難度或能力限制而非框架缺陷的集群。
  2. 有界提案。向提議者提供恰好四個輸入:已聲明的可編輯表面、挖掘到的失敗模式、必須保留的通行行為記錄以及先前嘗試過的編輯摘要。要求提案是最小化的(觸及一個表面)、跨並行候選者之間是彼此不同的,並附帶一份審計記錄,說明目標模式、預期效果和回歸風險。
  3. 驗證與合併。套用雙分割接受閘門。合併相容的已接受編輯;記錄被拒絕的編輯,但不改變活動的框架。每次轉換都會記錄更改的表面、分割結果和決策,以便血統可以審計。

框架程式碼的元層級搜尋

從外部搜尋整個框架程式,而不是從內部編輯正在運行的框架時:

  • 保持外層循環最小化:沒有手動調整的突變運算符或父代選擇啟發式。將診斷和編輯決策委託給一個強大的程式碼提議代理,這樣系統會隨著程式碼代理的改進而改進。
  • 從最強大的可用框架初始化,而不是從頭開始。成功的編輯通常是微小且附加的(環境啟動、工件建立指令),而提示和完成流程的重寫在經驗上是高風險的。
  • 在實際重要的目標(準確性、上下文成本、延遲)上維護帕累托前沿,而不是崩潰為一個純量。
  • 根據候選者記錄的修改結果來組織搜尋記憶體。將整個存檔傾倒到提議者提示中,隨著歷史增長會急劇退化;具有信用分配的每個節點經驗記錄優於存檔上下文條件化。
  • 當執行模型改變時,重新執行搜尋。發現的框架是執行者相關的,並且不會在基礎模型之間自由轉移。

作為自我改進的上下文演化

能夠更新自身的上下文劇本是入門級的自我改進循環,有兩個命名的失敗模式。簡潔性偏差:優化器趨向於簡潔的通用指令,丟棄了承載價值的領域特定啟發式。上下文崩潰:讓一個模型整體地重寫累積的上下文,會在單一步驟中災難性地縮小它,低於無適應基準(claim-self-improvement-context-collapse)。可行的模式:

  • 將上下文表示為具有穩定識別碼和有用/有害計數器的項目化條目。
  • 產生增量差異,由確定性的非模型邏輯合併。管理者從不重寫整個工件。
  • 透過嵌入相似性進行去重,定期或惰性進行。
  • 將整個機制建立在回饋品質的基礎上。沒有可靠的執行訊號或標籤,自我管理的上下文會低於靜態基準。

再上一層,對產生上下文的機制(技能:靜態元件加上動態運算符)與產生的上下文分別進行版本控制,僅針對驗證分割演化該機制,並從先前的最佳工件及其推出結果開始熱啟動每次疊代。每次疊代都明確檢查訓練-驗證差距,以捕捉機制過擬合。

什麼屬於人類

人類沿著堆疊向上移動,而不是跳出循環。保留給人類的決策點:對評估器或接受閘門的更改、可編輯表面的擴展、將發現的框架推廣到生產環境,以及對研究方向放棄的決策。主要接受成功結果訓練的模型在何時放棄一條工作線方面校準不佳,而保留的負面結果是縮小後續搜尋空間的最便宜方式。將失敗的候選者視為一級工件。

實用指南

循環就緒檢查清單

在每個項目都滿足之前,不要啟用自我修改:

  1. 存在一個快速、確定性、可自動化的評估器。具有緩慢、模糊或僅依賴評判評估的領域是此類循環失敗的地方。
  2. 存在一個提議者從未見過的保留外部(held-out)分割,如果循環運行時間足夠長以過擬合它,則需要刷新。
  3. 預算、權限和沙箱隔離由執行環境執行,位於每個可編輯表面之外。
  4. 可編輯表面被明確宣告(標記區域或配置點);其他所有內容都被鎖定,並且在每個候選者之後程式化地重新驗證不可變性。
  5. 存在一個具有完整差異血統的存檔;審計讀取差異和原始軌跡,而不是適應度訊號。
  6. 評估支出是分階段的:在全面評估之前進行廉價的介面或冒煙測試,在評分存在噪音時進行重複運行。
  7. 能力驗證運行已顯示基礎模型在該任務系列上清除了遞迴閾值。
  8. 為評估器更改、表面擴展和推廣準備了人類決策點。

選擇循環層級

重複出現的失敗修復於循環模式
缺少領域啟發式,重複已知錯誤結構化上下文帶有增量更新的項目化劇本
上下文劇本本身在任務間停滯上下文機制在驗證資料上演化技能
順序錯誤,缺少驗證步驟工作流程對工作流程圖進行帶有每個節點經驗的搜尋
失敗集群在工作流程候選者中持續存在框架程式碼失敗驅動的有界自我編輯或元層級搜尋
改進策略本身很弱優化器程式碼僅在具有強大模型和鎖定的元評估時

範例

範例 1:雙分割接受閘門

def accept(candidate, baseline, held_in, held_out, repeats=3):
    d_in = mean_score(candidate, held_in, repeats) - mean_score(baseline, held_in, repeats)
    d_out = mean_score(candidate, held_out, repeats) - mean_score(baseline, held_out, repeats)
    if d_in < 0 or d_out < 0:
        return False              # no regression on either split
    return max(d_in, d_out) > 0  # strict improv

…

[truncated for translation]

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.

instruction-surface-security

Hardens agent runtimes against persistent prompt injection or unauthorized changes to instructions and permissions. Use to audit what agents auto-load, design reviewed activation for project rules, skills, memory, or tool configuration, and test whether trust boundaries hold after reload, restart, or delegation.

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

相關技能