Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Pattern for progressively refining context retrieval to solve the subagent context problem
.claude/skills/loulanyue-iterative-retrieval/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-04 | ✗→✓ | ▲ Improved | 110% | 0% |
| case-17 | ✗→✓ | ▲ Improved | 41% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 58% | 0% |
| case-13 | ✗→✓ | ▲ Improved | 24% | 0% |
| case-19 | ✗→✓ | ▲ Improved | 88% | 0% |
解決多 agent 工作流程中的「上下文問題」,其中子 agents 在開始工作之前不知道需要什麼上下文。
子 agents 以有限上下文產生。它們不知道:
標準方法失敗:
一個漸進精煉上下文的 4 階段循環:
┌─────────────────────────────────────────────┐
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ DISPATCH │─────▶│ EVALUATE │ │
│ └──────────┘ └──────────┘ │
│ ▲ │ │
│ │ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ LOOP │◀─────│ REFINE │ │
│ └──────────┘ └──────────┘ │
│ │
│ 最多 3 個循環,然後繼續 │
└─────────────────────────────────────────────┘初始廣泛查詢以收集候選檔案:
javascript// 從高層意圖開始 const initialQuery = { patterns: ['src/**/*.ts', 'lib/**/*.ts'], keywords: ['authentication', 'user', 'session'], excludes: ['*.test.ts', '*.spec.ts'] }; // 派遣到檢索 agent const candidates = await retrieveFiles(initialQuery);
評估檢索內容的相關性:
javascriptfunction evaluateRelevance(files, task) { return files.map(file => ({ path: file.path, relevance: scoreRelevance(file.content, task), reason: explainRelevance(file.content, task), missingContext: identifyGaps(file.content, task) })); }
評分標準:
基於評估更新搜尋標準:
javascriptfunction refineQuery(evaluation, previousQuery) { return { // 新增在高相關性檔案中發現的新模式 patterns: [...previousQuery.patterns, ...extractPatterns(evaluation)], // 新增在程式碼庫中找到的術語 keywords: [...previousQuery.keywords, ...extractKeywords(evaluation)], // 排除確認不相關的路徑 excludes: [...previousQuery.excludes, ...evaluation .filter(e => e.relevance < 0.2) .map(e => e.path) ], // 針對特定缺口 focusAreas: evaluation .flatMap(e => e.missingContext) .filter(unique) }; }
以精煉標準重複(最多 3 個循環):
javascriptasync function iterativeRetrieve(task, maxCycles = 3) { let query = createInitialQuery(task); let bestContext = []; for (let cycle = 0; cycle < maxCycles; cycle++) { const candidates = await retrieveFiles(query); const evaluation = evaluateRelevance(candidates, task); // 檢查是否有足夠上下文 const highRelevance = evaluation.filter(e => e.relevance >= 0.7); if (highRelevance.length >= 3 && !hasCriticalGaps(evaluation)) { return highRelevance; } // 精煉並繼續 query = refineQuery(evaluation, query); bestContext = mergeContext(bestContext, highRelevance); } return bestContext; }
任務:「修復認證 token 過期 bug」
循環 1:
DISPATCH:在 src/** 搜尋 "token"、"auth"、"expiry"
EVALUATE:找到 auth.ts (0.9)、tokens.ts (0.8)、user.ts (0.3)
REFINE:新增 "refresh"、"jwt" 關鍵字;排除 user.ts
循環 2:
DISPATCH:搜尋精煉術語
EVALUATE:找到 session-manager.ts (0.95)、jwt-utils.ts (0.85)
REFINE:足夠上下文(2 個高相關性檔案)
結果:auth.ts、tokens.ts、session-manager.ts、jwt-utils.ts任務:「為 API 端點增加速率限制」
循環 1:
DISPATCH:在 routes/** 搜尋 "rate"、"limit"、"api"
EVALUATE:無匹配 - 程式碼庫使用 "throttle" 術語
REFINE:新增 "throttle"、"middleware" 關鍵字
循環 2:
DISPATCH:搜尋精煉術語
EVALUATE:找到 throttle.ts (0.9)、middleware/index.ts (0.7)
REFINE:需要路由器模式
循環 3:
DISPATCH:搜尋 "router"、"express" 模式
EVALUATE:找到 router-setup.ts (0.8)
REFINE:足夠上下文
結果:throttle.ts、middleware/index.ts、router-setup.ts在 agent 提示中使用:
markdown為此任務檢索上下文時: 1. 從廣泛關鍵字搜尋開始 2. 評估每個檔案的相關性(0-1 尺度) 3. 識別仍缺少的上下文 4. 精煉搜尋標準並重複(最多 3 個循環) 5. 回傳相關性 >= 0.7 的檔案
continuous-learning 技能 - 用於隨時間改進的模式~/.claude/agents/ 中的 Agent 定義| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-04 | fail→pass | 21,763 | 2,100 | -90% | 1 | 1 | 0% | 983 | 2,064 | +110% | 0 | 0 | — |
case-01 | pass→pass | 11,218 | 14,647 | +31% | 1 | 1 | 0% | 1,771 | 4,010 | +126% | 0 | 0 | — |
case-02 | pass→pass | 3,664 | 4,397 | +20% | 1 | 1 | 0% | 553 | 2,415 | +337% | 0 | 0 | — |
case-03 | pass→pass | 13,282 | 9,909 | -25% | 1 | 1 | 0% | 1,983 | 3,219 | +62% | 0 | 0 | — |
case-05 | pass→pass | 9,343 | 2,581 | -72% | 1 | 1 | 0% | 1,580 | 2,142 | +36% | 0 | 0 | — |
case-06 | pass→pass | 9,710 | 2,940 | -70% | 1 | 1 | 0% | 1,475 | 2,225 | +51% | 0 | 0 | — |
case-07 | fail→fail | 7,707 | 4,775 | -38% | 1 | 1 | 0% | 1,077 | 2,416 | +124% | 0 | 0 | — |
case-08 | pass→pass | 14,523 | 10,769 | -26% | 1 | 1 | 0% | 2,259 | 3,545 | +57% | 0 | 0 | — |
case-17 | fail→pass | 13,174 | 7,069 | -46% | 1 | 1 | 0% | 2,060 | 2,903 | +41% | 0 | 0 | — |
case-09 | pass→pass | 7,711 | 3,986 | -48% | 1 | 1 | 0% | 1,244 | 2,458 | +98% | 0 | 0 | — |
case-10 | fail→pass | 7,974 | 2,144 | -73% | 1 | 1 | 0% | 1,311 | 2,068 | +58% | 0 | 0 | — |
case-11 | pass→pass | 7,668 | 2,827 | -63% | 1 | 1 | 0% | 1,344 | 2,203 | +64% | 0 | 0 | — |
case-12 | fail→fail | 10,623 | 5,017 | -53% | 1 | 1 | 0% | 1,520 | 2,564 | +69% | 0 | 0 | — |
case-18 | pass→pass | 9,406 | 6,465 | -31% | 1 | 1 | 0% | 1,635 | 2,849 | +74% | 0 | 0 | — |
case-13 | fail→pass | 11,976 | 3,509 | -71% | 1 | 1 | 0% | 1,845 | 2,282 | +24% | 0 | 0 | — |
case-14 | pass→pass | 6,500 | 7,332 | +13% | 1 | 1 | 0% | 1,035 | 2,802 | +171% | 0 | 0 | — |
case-15 | pass→pass | 16,025 | 10,541 | -34% | 1 | 1 | 0% | 2,411 | 3,465 | +44% | 0 | 0 | — |
case-16 | pass→pass | 7,925 | 6,848 | -14% | 1 | 1 | 0% | 1,318 | 2,855 | +117% | 0 | 0 | — |
case-19 | fail→pass | 13,182 | 13,382 | +2% | 1 | 1 | 0% | 2,019 | 3,798 | +88% | 0 | 0 | — |
case-20 | pass→pass | 14,593 | 4,883 | -67% | 1 | 1 | 0% | 2,475 | 2,557 | +3% | 0 | 0 | — |
case-21 | pass→pass | 8,885 | 5,101 | -43% | 1 | 1 | 0% | 1,411 | 2,521 | +79% | 0 | 0 | — |
case-22 | pass→pass | 15,637 | 15,496 | -1% | 1 | 1 | 0% | 2,448 | 4,241 | +73% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 21 counted toward the lift figure. The other 1 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +23 percentage points is the difference between those two pass rates over the 21 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.