بنقرة واحدة
iterative-retrieval
逐步优化上下文检索以解决子代理上下文问题的模式
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
逐步优化上下文检索以解决子代理上下文问题的模式
التثبيت باستخدام 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 | 逐步优化上下文检索以解决子代理上下文问题的模式 |
| origin | ECC |
解决多智能体工作流中的“上下文问题”,即子智能体在开始工作前不知道需要哪些上下文。
子智能体被生成时上下文有限。它们不知道:
标准方法会失败:
一个逐步优化上下文的 4 阶段循环:
┌─────────────────────────────────────────────┐
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ 调度 │─────│ 评估 │ │
│ └──────────┘ └──────────┘ │
│ ▲ │ │
│ │ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ 循环 │─────│ 优化 │ │
│ └──────────┘ └──────────┘ │
│ │
│ 最多3次循环,然后继续 │
└─────────────────────────────────────────────┘
初始的广泛查询以收集候选文件:
// 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);
评估检索到的内容的相关性:
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 {
// 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)
};
}
使用优化后的条件重复(最多 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);
// 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;
}
任务:"修复身份验证令牌过期错误"
循环 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/)