with one click
iterative-retrieval
サブエージェントのコンテキスト問題を解決するために、コンテキスト取得を段階的に洗練するパターン
Menu
サブエージェントのコンテキスト問題を解決するために、コンテキスト取得を段階的に洗練するパターン
| name | iterative-retrieval |
| description | サブエージェントのコンテキスト問題を解決するために、コンテキスト取得を段階的に洗練するパターン |
マルチエージェントワークフローにおける「コンテキスト問題」を解決します。サブエージェントは作業を開始するまで、どのコンテキストが必要かわかりません。
サブエージェントは限定的なコンテキストで起動されます。以下を知りません:
標準的なアプローチは失敗します:
コンテキストを段階的に洗練する4フェーズのループ:
┌─────────────────────────────────────────────┐
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ DISPATCH │─────│ EVALUATE │ │
│ └──────────┘ └──────────┘ │
│ ▲ │ │
│ │ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ LOOP │─────│ REFINE │ │
│ └──────────┘ └──────────┘ │
│ │
│ 最大3サイクル、その後続行 │
└─────────────────────────────────────────────┘
候補ファイルを収集する初期の広範なクエリ:
// 高レベルの意図から開始
const initialQuery = {
patterns: ['src/**/*.ts', 'lib/**/*.ts'],
keywords: ['authentication', 'user', 'session'],
excludes: ['*.test.ts', '*.spec.ts']
};
// 検索エージェントにディスパッチ
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;
}
タスク: "認証トークン期限切れバグを修正"
サイクル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
エージェントプロンプトで使用:
このタスクのコンテキストを取得する際:
1. 広範なキーワード検索から開始
2. 各ファイルの関連性を評価(0-1スケール)
3. まだ不足しているコンテキストを特定
4. 検索基準を洗練して繰り返す(最大3サイクル)
5. 関連性が0.7以上のファイルを返す
continuous-learningスキル - 時間とともに改善するパターン用~/.claude/agents/内のエージェント定義Create reproducible, cross-platform (macOS/Linux) development environments with Flox, a declarative Nix-based environment manager. Use when setting up project toolchains for any language, installing system-level dependencies (compilers, databases, native libs like openssl/BLAS), pinning exact package versions for a team, running local services (PostgreSQL, Redis, Kafka), onboarding developers with one command, or solving 'works on my machine' problems — including agent/vibe-coding setups that need project-scoped tools without sudo. Also use when the user mentions .flox/, manifest.toml, flox activate, or FloxHub.
Commercial-grade Python installer expert for Windows: Nuitka extreme compilation, dist slimming, DLL footprint analysis, and Inno Setup packaging to ship the smallest, fastest installers. Use only for advanced packaging/optimization (minimal size, fast startup), not basic script-to-exe conversion. 中文触发:Nuitka 极限优化、Python 商业打包、极限编译 Python、dist 瘦身、DLL 分析、最小安装包、最快启动、商业级打包风格
Use when a brand needs to discover or articulate its identity through structured multi-session interviews. Covers purpose, positioning, audience, personality, voice, narrative, and founder-brand tension across 8 modules using laddering, 5 Whys, and projective techniques. Produces a resumable session with disk-persisted state and a master brandbook (90_SYNTHESIS.md).
Use when a brand needs to discover or articulate its identity through structured multi-session interviews. Covers purpose, positioning, audience, personality, voice, narrative, and founder-brand tension across 8 modules using laddering, 5 Whys, and projective techniques. Produces a resumable session with disk-persisted state and a master brandbook (90_SYNTHESIS.md).
Use this skill to automate visual testing and UI interaction verification using browser automation after deploying features.
Visualize whether skills, rules, and agent definitions are actually followed — auto-generates scenarios at 3 prompt strictness levels, runs agents, classifies behavioral sequences, and reports compliance rates with full tool call timelines