iterative-retrieval
OfficialPattern for progressively refining context retrieval to solve the subagent context problem
What this skill does
When applied, it prepends a system prompt before your request is sent — no extra calls and no change to how you are billed beyond the added tokens.
---
name: iterative-retrieval
description: Pattern for progressively refining context retrieval to solve the subagent context problem
---
# 迭代檢索模式
解決多 agent 工作流程中的「上下文問題」,其中子 agents 在開始工作之前不知道需要什麼上下文。
## 問題
子 agents 以有限上下文產生。它們不知道:
- 哪些檔案包含相關程式碼
- 程式碼庫中存在什麼模式
- 專案使用什麼術語
標準方法失敗:
- **傳送所有內容**:超過上下文限制
- **不傳送內容**:Agent 缺乏關鍵資訊
- **猜測需要什麼**:經常錯誤
## 解決方案:迭代檢索
一個漸進精煉上下文的 4 階段循環:
```
┌─────────────────────────────────────────────┐
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ DISPATCH │─────│ EVALUATE │ │
│ └──────────┘ └──────────┘ │
│ ▲ │ │
│ │ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ LOOP │─────│ REFINE │ │
│ └──────────┘ └──────────┘ │
│ │
│ 最多 3 個循環,然後繼續 │
└─────────────────────────────────────────────┘
```
### 階段 1:DISPATCH
初始廣泛查詢以收集候選檔案:
```javascript
// 從高層意圖開始
const initialQuery = {
patterns: ['src/**/*.ts', 'lib/**/*.ts'],
keywords: ['authentication', 'user', 'session'],
excludes: ['*.test.ts', '*.spec.ts']
};
// 派遣到檢索 agent
const candidates = await retrieveFiles(initialQuery);
```
### 階段 2:EVALUATE
評估檢索內容的相關性:
```javascript
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)
}));
}
```
評分標準:
- **高(0.8-1.0)**:直接實作目標功能
- **中(0.5-0.7)**:包含相關模式或類型
- **低(0.2-0.4)**:間接相關
- **無(0-0.2)**:不相關,排除
### 階段 3:REFINE
基於評估更新搜尋標準:
```javascript
function refineQuery(evaluation, previousQuery) {
return {
// 新增在高相關性檔案中發現的新模式
patterns: [...previousQuery.patterns, ...extractPatterns(evaluation)],
// 新增在程式碼庫中找到的術語
keywords: [...previousQuery.keywords, ...extractKeywords(evUse this skill
Add a "skill" field with the skill’s ID to your chat completion request. It is applied server-side before your prompt is sent — no extra calls.
{
"model": "gpt-4o-mini",
"skill": "imp-9cf391ee-ff41-49e5-a4e7-a37691ec977c",
"messages": [{ "role": "user", "content": "…" }]
}Install the skill, enable it in your dashboard and (optionally) limit it to specific models. It then applies automatically to every matching request — with no "skill" field to send each time.
Set it up in your dashboardMore skills
Delegate coding work to Codex, Claude Code, or OpenCode as background workers; not simple edits or read-only code lookup.
Create, edit, audit, tidy, validate, or restructure AgentSkills and SKILL.md files.
Search and analyze your own session logs (older/parent conversations) using jq.
Create, view, edit, delete, search, move, or export Apple Notes via the memo CLI on macOS.
Diagnose OpenClaw Android, iOS, or macOS node pairing, QR/setup code, route, auth, and connection failures.
Set up and use 1Password CLI for sign-in, desktop integration, and reading or injecting secrets.
List, add, edit, complete, or delete Apple Reminders and reminder lists via remindctl.
Create, search, and manage Bear notes via grizzly CLI.