Back to Skills

evolve-skill-from-traces

pjt222
Updated 2 days ago
9 views
17
2
17
View on GitHub
Metageneral

About

This skill automatically evolves SKILL.md documentation by analyzing agent execution traces. It uses a three-stage pipeline to collect trajectories, propose improvements through multi-agent analysis, and consolidate edits. Use it when you have observed successful agent runs that outperform existing documentation or need to create skills from scratch.

Quick Install

Claude Code

Recommended
Primary
npx skills add pjt222/agent-almanac -a claude-code
Plugin CommandAlternative
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternative
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/evolve-skill-from-traces

Copy and paste this command in Claude Code to install this skill

Documentation

自跡演技

以三階流轉員執跡為驗 SKILL.md:軌集、並行多員補議、無衝合。此技接已觀員行與已記術,化成功之運為可復之技。

用時

  • 執跡示現技未捕之復模
  • 員行勝於已記術
  • 以錄專家示自零造技
  • 多員於同技議衝改

  • 必要traces —— 員執日或會話錄(薦至少十成功運)
  • 必要target_skill —— 欲演 SKILL.md 之路,或 "new" 自零提技
  • 可選analyst_count —— 並行析員數(默 4)
  • 可選held_out_ratio —— 留以驗不用於草之跡比(默 0.2)

第一步:集執跡

集示目行之員會話日、工具呼序、或對話錄。篩標成功之運。正為標跡式:(state, action, outcome) 三元之序附時戳。

  1. 識跡源:會話日、工呼史、或對話出
  2. 按成功準篩跡(出碼 0、任畢旗、用確)
  3. 正各跡為結三元列:
trace_entry:
  state: <context before the action>
  action: <tool call, command, or decision made>
  outcome: <result, output, or state change>
  timestamp: <ISO 8601>
  1. 分跡:留 held_out_ratio(默 20%)供第七步驗,餘供 2-6 步
# Example: count available traces and compute partition
total_traces=$(ls traces/*.json | wc -l)
held_out=$(echo "$total_traces * 0.2 / 1" | bc)
drafting=$((total_traces - held_out))
echo "Drafting: $drafting traces, Held-out: $held_out traces"

得: 正後跡集分為草(80%)與留(20%)。各條含 state、action、outcome、timestamp 域。

敗則: 若成功跡不足十,先集更多。小集生過擬之技,新入則敗。若跡缺時戳,賦序號代之。

第二步:聚軌

按結模聚正跡。識不變核(諸成功軌皆有之步)對變枝(諸運中異之步)。不變核為技術之骨。

  1. 按行類對跡——各跡映為行籤序
  2. 求諸跡之最長公共子序以識不變核
  3. 餘行類為變枝,記何跡含之、於何條件
  4. 記枝頻:多少成功跡含各變步
invariant_core:
  - action: "read_input_file"
    frequency: 100%
  - action: "validate_schema"
    frequency: 100%
  - action: "transform_data"
    frequency: 100%

variant_branches:
  - action: "retry_on_timeout"
    frequency: 35%
    condition: "network latency > 2s"
  - action: "fallback_to_cache"
    frequency: 15%
    condition: "API returns 503"

得: 不變核行(諸跡皆有)與變枝(有條件,於子集)之明分。各變枝附頻計與觸條件。

敗則: 若無不變核現(跡過雜),目行或實為多異技。按結類分跡為一致子,各處之。

第三步:草技骨

自不變核生初 SKILL.md:frontmatter、When to Use(自諸跡入條件導)、Inputs(諸運中異之參)、Procedure(各不變行一步)。

  1. 自各跡首態取入條件填 When to Use
  2. 識諸運中異之參(路、閾、選)填 Inputs
  3. 各不變核行造一步,用諸跡最常措辭
  4. 按已觀結加 Expected/On failure 占位
# Scaffold the skeleton if creating a new skill
mkdir -p skills/<skill-name>/
# Skeleton structure
## When to Use
- <derived from common entry conditions>

## Inputs
- **Required**: <parameters present in all traces>
- **Optional**: <parameters present in some traces>

## Procedure
### Step N: <invariant action label>
<most common implementation from traces>

**Expected:** <most common success outcome>
**On failure:** <placeholder -- refined in Steps 4-6>

得: 語法有效之 SKILL.md 骨含 frontmatter、When to Use、Inputs、Procedure 各不變核行一步。Expected 映已觀結;On failure 為占位。

敗則: 若骨加變枝前已逾 500 行,不變核過細。合常共現之鄰行為單步。目標 5-10 步。

第四步:並行多員補議

生 N 析員(薦 4-6),各以異析鏡審全跡集對草骨。各員生結補:節、舊文、新文、理。

各員一鏡:

AnalystLensFocus
1CorrectnessDoes the skeleton capture all success paths? Are any invariant steps missing?
2EfficiencyAre there redundant steps? Can any steps be merged or parallelized?
3RobustnessWhich failure modes are unhandled? What should On failure blocks contain?
4Edge CasesWhich variant branches should become conditional steps or pitfalls?
5 (optional)ClarityIs each step unambiguous? Can an agent follow it mechanically?
6 (optional)GeneralizabilityAre there trace-specific artifacts that should be abstracted?

各析員受:

  • 第三步之草骨
  • 全草跡集(非留)
  • 所賦鏡與焦問

各員返結補之列:

patch:
  analyst: "robustness"
  section: "Procedure > Step 3"
  old_text: "**On failure:** <placeholder>"
  new_text: "**On failure:** If the API returns 503, wait 5 seconds and retry up to 3 times. If retries are exhausted, fall back to the cached response from the previous successful run."
  rationale: "Traces #4, #7, #12 show 503 errors resolved by retry. Trace #15 shows cache fallback when retries fail."
  supporting_traces: [4, 7, 12, 15]

得: 各員返 3-10 結補附節引、舊新文、理、援跡 ID。諸補集為一補集。

敗則: 若員返無補,其鏡或不適此技。可——非各鏡皆浮問。若員返模糊補無跡引,拒並求具體 supporting_traces 再生。

第五步:察並類衝

較四步諸補之重編。各重對類為三。

  1. 按目節索補
  2. 於同節之補,較 old_text 與 new_text
  3. 各重類:
Conflict TypeDefinitionResolution
CompatibleDifferent sections, no overlapMerge directly
ComplementarySame section, additive (both add content, no contradiction)Combine text
ContradictorySame section, mutually exclusive (one adds X, other removes X or adds Y instead)Needs resolution in Step 6
conflict_report:
  total_patches: 24
  compatible: 18
  complementary: 4
  contradictory: 2
  contradictions:
    - section: "Procedure > Step 5"
      patch_a: {analyst: "efficiency", action: "remove step"}
      patch_b: {analyst: "robustness", action: "add retry logic"}
      supporting_traces_a: [2, 8, 11]
      supporting_traces_b: [4, 7, 12, 15]

得: 衝報列諸補對、類、及於矛盾各方之援跡計。

敗則: 若類模糊(補同節加又改),分為二:一加、一改。類小補。

第六步:合補

以三層解策合諸補為單 SKILL.md。

  1. 相容補:直施——異節不衝
  2. 互補補:合二補之 new_text 為連貫塊,保二貢
  3. 矛盾補:以頻權解:
    • 計諸變各有幾跡援
    • 偏跡更多之補
    • 若等(或相差 10% 內),以 argumentation 技評何補更事技之目
    • 記被拒替為 Common Pitfall 或於相 On failure 塊之注
consolidation_log:
  applied_directly: 18
  combined: 4
  resolved_by_prevalence: 1
  resolved_by_argumentation: 1
  rejected_alternatives_documented: 2

合後驗 SKILL.md:

  • 諸節存(When to Use、Inputs、Procedure、Validation、Common Pitfalls、Related Skills)
  • 諸步皆 Expected 與 On failure
  • 無重複或矛盾指
  • 行數於 500 限內

得: 單合 SKILL.md 含諸員補。矛盾以記理解。各矛盾之被拒替現為陷或注。

敗則: 若合生內不一之文(如第三步假文存而第二步被效率補去),復原衝編,該節留原骨文。標不一供手審。

第七步:驗並登

心中以留跡(一步留 20%)運合技。驗 Expected/On failure 合未見跡中已觀結。

  1. 於各留跡,逐步循技
  2. 於各步,較技之 Expected 與跡之實
  3. 記合與不合:
validation_results:
  held_out_traces: 5
  full_match: 4
  partial_match: 1
  no_match: 0
  mismatches:
    - trace_id: 23
      step: 4
      expected: "API returns 200"
      actual: "API returns 429 (rate limited)"
      action: "Add rate-limit handling to On failure block"
  1. 若不合率逾 20%,返第四步,將不合跡入草集
  2. 若技為新,循 create-skill 造目、登條、造 symlink
  3. 若演既有技,循 evolve-skill 升版並同譯
# Final validation: line count
lines=$(wc -l < skills/<skill-name>/SKILL.md)
[ "$lines" -le 500 ] && echo "OK ($lines lines)" || echo "FAIL: $lines lines > 500"

得: 至少 80% 留跡合技首尾。技於 skills/_registry.yml 登附正元數。

敗則: 若驗敗(>20% 不合),技過擬草跡。加不合跡入草集重運自第二步。若二迭仍敗,行或過變為單技——按結類分為多技。

  • 草前至少集十成功跡
  • 跡分為草(80%)與留(20%)
  • 不變核與變枝明記
  • 至少四析員以異鏡審骨
  • 諸補衝已類(相容、互補、矛盾)
  • 矛盾補以記理解
  • 合 SKILL.md 有諸必節附 Expected/On failure
  • 留驗合率至少 80%
  • 行數於 500 限內
  • 技已登(新)或已升版(舊),循標程

  • 跡過少:少於十成功運則模提不可靠。不變核或含偶步,變枝亦無足頻數。先集更多再始
  • 過擬跡藝:工具特行(如某 API 客戶之重試模)或不通。第三步中抽工具行為工具無涉述。技當述為,非述何具
  • 略敗跡:敗跡示技宜於 On failure 所警。第一步亦集敗運並標。四步用於健性員評未處之敗模
  • 單鏡析:唯 1-2 析員失要觀。效率員獨則剝健員將保之安檢。至少用四異鏡以均覆
  • 合矛盾補而不解:施二方致內不一之技(如某步「行 X」而另步「略 X」)。六步必類並明解
  • 不對留驗:無留驗,合技或完合草跡而於新運敗。必留 20% 跡並於之測末技

  • evolve-skill —— 簡之人導演(互補:跡不得時用)
  • create-skill —— 為新提尚未存之技;七步登中用
  • review-skill-format —— 合後驗以確 agentskills.io 合規
  • argumentation —— 六步中解頻等之矛盾補
  • verify-agent-output —— 補議之證鏈;四步中驗員出

GitHub Repository

pjt222/agent-almanac
Path: i18n/wenyan/skills/evolve-skill-from-traces
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Related Skills

content-collections

Meta

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

View skill

polymarket

Meta

This skill enables developers to build applications with the Polymarket prediction markets platform, including API integration for trading and market data. It also provides real-time data streaming via WebSocket to monitor live trades and market activity. Use it for implementing trading strategies or creating tools that process live market updates.

View skill

creating-opencode-plugins

Meta

This skill helps developers create OpenCode plugins that hook into 25+ event types like commands, files, and LSP operations. It provides the plugin structure, event API specifications, and implementation patterns for JavaScript/TypeScript modules. Use it when you need to intercept, monitor, or extend the OpenCode AI assistant's lifecycle with custom event-driven logic.

View skill

sglang

Meta

SGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.

View skill