Iteratively retrieves and refines context for sub-agents in multi-agent workflows, solving the problem of agents not knowing what context they need before starting.
How this skill is triggered — by the user, by Claude, or both
Slash command
/everything-claude-code:iterative-retrievalThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
解决多 agent 工作流中的“上下文问题”,即子 agent 在开始工作之前不知道它们需要什么上下文。
解决多 agent 工作流中的“上下文问题”,即子 agent 在开始工作之前不知道它们需要什么上下文。
子 agent 生成时上下文有限。它们不知道:
标准方法会失败:
一个逐步细化上下文的 4 阶段循环:
┌─────────────────────────────────────────────┐
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ DISPATCH │─────▶│ EVALUATE │ │
│ └──────────┘ └──────────┘ │
│ ▲ │ │
│ │ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ LOOP │◀─────│ REFINE │ │
│ └──────────┘ └──────────┘ │
│ │
│ Max 3 cycles, then proceed │
│ │
└─────────────────────────────────────────────┘
初始广泛查询以收集候选文件:
// 从高层意图开始
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;
}
Task: "修复认证令牌过期 bug"
Cycle 1:
DISPATCH: 在 src/** 中搜索 "token", "auth", "expiry"
EVALUATE: 找到 auth.ts (0.9), tokens.ts (0.8), user.ts (0.3)
REFINE: 添加 "refresh", "jwt" 关键字; 排除 user.ts
Cycle 2:
DISPATCH: 搜索优化后的术语
EVALUATE: 找到 session-manager.ts (0.95), jwt-utils.ts (0.85)
REFINE: 足够的上下文 (2 high-relevance files)
Result: auth.ts, tokens.ts, session-manager.ts, jwt-utils.ts
Task: "添加 API 端点的速率限制"
Cycle 1:
DISPATCH: 在 routes/** 中搜索 "rate", "limit", "api"
EVALUATE: 无匹配 - 代码库使用 "throttle" 术语
REFINE: 添加 "throttle", "middleware" 关键字
Cycle 2:
DISPATCH: 搜索优化后的术语
EVALUATE: 找到 throttle.ts (0.9), middleware/index.ts (0.7)
REFINE: 需要 router 模式
Cycle 3:
DISPATCH: 搜索 "router", "express" 模式
EVALUATE: 找到 router-setup.ts (0.8)
REFINE: 足够的上下文
Result: throttle.ts, middleware/index.ts, router-setup.ts
在 agent prompts 中使用:
当为此任务检索上下文时:
1. 从广泛的关键字搜索开始
2. 评估每个文件的相关性 (0-1 等级)
3. 识别仍然缺失的上下文
4. 优化搜索条件并重复(最多 3 个周期)
5. 返回相关性 >= 0.7 的文件
continuous-learning skill - 用于随时间改进的模式~/.claude/agents/ 中的 Agent 定义npx claudepluginhub aaione/everything-claude-code-zhImplements iterative retrieval pattern to progressively optimize code context for subagents in multi-agent workflows via dispatch-evaluate-refine loops up to 3 cycles.
Progressively refines context retrieval for subagents that don't know what context they need upfront. Uses a 4-phase dispatch-evaluate-refine-loop pattern to solve multi-agent context problems.
Guides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.