iterative-retrieval by affaan-m/everything-claude-code
npx skills add https://github.com/affaan-m/everything-claude-code --skill iterative-retrieval解决多智能体工作流中的“上下文问题”,即子智能体在开始工作前无法预知需要哪些上下文。
子智能体生成时上下文有限。它们不知道:
标准方法会失败:
一个逐步细化上下文的 4 阶段循环:
┌─────────────────────────────────────────────┐
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ 调度阶段 │─────▶│ 评估阶段 │ │
│ └──────────┘ └──────────┘ │
│ ▲ │ │
│ │ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ 循环阶段 │◀─────│ 优化阶段 │ │
│ └──────────┘ └──────────┘ │
│ │
│ 最多 3 个循环,然后继续执行 │
└─────────────────────────────────────────────┘
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
初始广泛查询以收集候选文件:
// 从高层次意图开始
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:
调度阶段:在 src/** 中搜索 "token"、"auth"、"expiry"
评估阶段:找到 auth.ts (0.9)、tokens.ts (0.8)、user.ts (0.3)
优化阶段:添加 "refresh"、"jwt" 关键词;排除 user.ts
循环 2:
调度阶段:搜索优化后的术语
评估阶段:找到 session-manager.ts (0.95)、jwt-utils.ts (0.85)
优化阶段:上下文足够(2 个高相关性文件)
结果:auth.ts、tokens.ts、session-manager.ts、jwt-utils.ts
任务:"为 API 端点添加速率限制"
循环 1:
调度阶段:在 routes/** 中搜索 "rate"、"limit"、"api"
评估阶段:无匹配项 - 代码库使用 "throttle" 术语
优化阶段:添加 "throttle"、"middleware" 关键词
循环 2:
调度阶段:搜索优化后的术语
评估阶段:找到 throttle.ts (0.9)、middleware/index.ts (0.7)
优化阶段:需要路由器模式
循环 3:
调度阶段:搜索 "router"、"express" 模式
评估阶段:找到 router-setup.ts (0.8)
优化阶段:上下文足够
结果:throttle.ts、middleware/index.ts、router-setup.ts
在智能体提示中使用:
为此任务检索上下文时:
1. 从广泛的关键词搜索开始
2. 评估每个文件的相关性(0-1 分制)
3. 识别仍缺少哪些上下文
4. 优化搜索条件并重复(最多 3 个循环)
5. 返回相关性 >= 0.7 的文件
continuous-learning 技能 - 用于随时间改进的模式agents/)每周安装量
900
代码仓库
GitHub 星标数
72.1K
首次出现时间
2026 年 1 月 26 日
安全审计
安装于
opencode721
codex700
claude-code689
gemini-cli685
cursor629
github-copilot619
Solves the "context problem" in multi-agent workflows where subagents don't know what context they need until they start working.
Subagents are spawned with limited context. They don't know:
Standard approaches fail:
A 4-phase loop that progressively refines context:
┌─────────────────────────────────────────────┐
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ DISPATCH │─────▶│ EVALUATE │ │
│ └──────────┘ └──────────┘ │
│ ▲ │ │
│ │ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ LOOP │◀─────│ REFINE │ │
│ └──────────┘ └──────────┘ │
│ │
│ Max 3 cycles, then proceed │
└─────────────────────────────────────────────┘
Initial broad query to gather candidate files:
// Start with high-level intent
const initialQuery = {
patterns: ['src/**/*.ts', 'lib/**/*.ts'],
keywords: ['authentication', 'user', 'session'],
excludes: ['*.test.ts', '*.spec.ts']
};
// Dispatch to retrieval agent
const candidates = await retrieveFiles(initialQuery);
Assess retrieved content for relevance:
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)
}));
}
Scoring criteria:
Update search criteria based on evaluation:
function refineQuery(evaluation, previousQuery) {
return {
// Add new patterns discovered in high-relevance files
patterns: [...previousQuery.patterns, ...extractPatterns(evaluation)],
// Add terminology found in codebase
keywords: [...previousQuery.keywords, ...extractKeywords(evaluation)],
// Exclude confirmed irrelevant paths
excludes: [...previousQuery.excludes, ...evaluation
.filter(e => e.relevance < 0.2)
.map(e => e.path)
],
// Target specific gaps
focusAreas: evaluation
.flatMap(e => e.missingContext)
.filter(unique)
};
}
Repeat with refined criteria (max 3 cycles):
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);
// Check if we have sufficient context
const highRelevance = evaluation.filter(e => e.relevance >= 0.7);
if (highRelevance.length >= 3 && !hasCriticalGaps(evaluation)) {
return highRelevance;
}
// Refine and continue
query = refineQuery(evaluation, query);
bestContext = mergeContext(bestContext, highRelevance);
}
return bestContext;
}
Task: "Fix the authentication token expiry bug"
Cycle 1:
DISPATCH: Search for "token", "auth", "expiry" in src/**
EVALUATE: Found auth.ts (0.9), tokens.ts (0.8), user.ts (0.3)
REFINE: Add "refresh", "jwt" keywords; exclude user.ts
Cycle 2:
DISPATCH: Search refined terms
EVALUATE: Found session-manager.ts (0.95), jwt-utils.ts (0.85)
REFINE: Sufficient context (2 high-relevance files)
Result: auth.ts, tokens.ts, session-manager.ts, jwt-utils.ts
Task: "Add rate limiting to API endpoints"
Cycle 1:
DISPATCH: Search "rate", "limit", "api" in routes/**
EVALUATE: No matches - codebase uses "throttle" terminology
REFINE: Add "throttle", "middleware" keywords
Cycle 2:
DISPATCH: Search refined terms
EVALUATE: Found throttle.ts (0.9), middleware/index.ts (0.7)
REFINE: Need router patterns
Cycle 3:
DISPATCH: Search "router", "express" patterns
EVALUATE: Found router-setup.ts (0.8)
REFINE: Sufficient context
Result: throttle.ts, middleware/index.ts, router-setup.ts
Use in agent prompts:
When retrieving context for this task:
1. Start with broad keyword search
2. Evaluate each file's relevance (0-1 scale)
3. Identify what context is still missing
4. Refine search criteria and repeat (max 3 cycles)
5. Return files with relevance >= 0.7
continuous-learning skill - For patterns that improve over timeagents/)Weekly Installs
900
Repository
GitHub Stars
72.1K
First Seen
Jan 26, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode721
codex700
claude-code689
gemini-cli685
cursor629
github-copilot619
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装