بنقرة واحدة
iterative-retrieval
Pattern for progressively refining context retrieval to solve the subagent context problem
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Pattern for progressively refining context retrieval to solve the subagent context problem
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Use after a complex task, failure, or when reviewing what was learned. Teaches how to write growth logs that extract reusable patterns — not diary entries.
Design a goal-oriented agent loop, and review it for the ways loops go wrong — spinning and burning tokens, Goodhart-gaming the verifier, or running a wrong answer to completion. Two actions: (1) WRITE a loop — gate whether to build it, define a machine-decidable goal, pick the loop type, pick a skeleton; (2) REVIEW a loop — run it past five failure modes plus decidability, boundaries, fallback, judge independence, and keep-judgment-with-the-human red lines. Use when designing an autonomous agent loop, or when you already have one and worry it will spin, cheat, or run a wrong answer to the end. Complements the mechanism-layer loop skills (autonomous-loops, continuous-agent-loop) by covering the judgment layer they don't. 中文触发:写 loop、设计 loop、做一个 loop、检查 loop 对不对、loop 体检、loop 会不会跑飞、可判定目标、五个崩法、plan build judge。English triggers: design an agent loop, write a loop, check a loop, loop review, prevent a runaway loop, goal-oriented loop, decidable goal, plan/build/judge.
Stop hook that blocks Claude from finishing until quality checks pass. Detects rationalization patterns (surface text heuristics), stale learning logs (filesystem mtime), and low disk space. Complements self-audit by mechanically enforcing learning capture habits.
React Native and Expo app patterns — Expo Router navigation, state separation (server/client/route/form), TanStack Query data fetching with Zod, performant lists, NativeWind/StyleSheet styling, native APIs, and secure storage. Use when building or editing React Native / Expo screens, components, navigation, or data layers.
Instinct-based learning system that observes sessions via hooks, creates atomic instincts with confidence scoring, and evolves them into skills/commands/agents. v2.1 adds project-scoped instincts to prevent cross-project contamination.
Use this skill when writing new features, fixing bugs, or refactoring code. Enforces test-driven development with 80%+ coverage including unit, integration, and E2E tests.
| name | iterative-retrieval |
| description | Pattern for progressively refining context retrieval to solve the subagent context problem |
解決多 agent 工作流程中的「上下文問題」,其中子 agents 在開始工作之前不知道需要什麼上下文。
子 agents 以有限上下文產生。它們不知道:
標準方法失敗:
一個漸進精煉上下文的 4 階段循環:
┌─────────────────────────────────────────────┐
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ DISPATCH │─────│ EVALUATE │ │
│ └──────────┘ └──────────┘ │
│ ▲ │ │
│ │ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ LOOP │─────│ REFINE │ │
│ └──────────┘ └──────────┘ │
│ │
│ 最多 3 個循環,然後繼續 │
└─────────────────────────────────────────────┘
初始廣泛查詢以收集候選檔案:
// 從高層意圖開始
const initialQuery = {
patterns: ['src/**/*.ts', 'lib/**/*.ts'],
keywords: ['authentication', 'user', 'session'],
excludes: ['*.test.ts', '*.spec.ts']
};
// 派遣到檢索 agent
const candidates = await retrieveFiles(initialQuery);
評估檢索內容的相關性:
function 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)
}));
}
評分標準:
基於評估更新搜尋標準:
function 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 個循環):
async 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 提示中使用:
為此任務檢索上下文時:
1. 從廣泛關鍵字搜尋開始
2. 評估每個檔案的相關性(0-1 尺度)
3. 識別仍缺少的上下文
4. 精煉搜尋標準並重複(最多 3 個循環)
5. 回傳相關性 >= 0.7 的檔案
continuous-learning 技能 - 用於隨時間改進的模式~/.claude/agents/ 中的 Agent 定義