agentleFS
peopleforresterpeopleforrester/claude-dotfiles/skills/optimization/iterative-retrieval/SKILL.md

iterative-retrieval

Skill3 starsChanged 7 months agoMITView on GitHub

Progressive context refinement pattern for subagents. Solves the problem of agents not knowing what context they need until they start working. Uses a 4-phase loop: DISPATCH, EVALUATE, REFINE, LOOP.

We split this skill into the rules it gives an agent

3 rules. 1 is common, 2 are distinctive, and 0 are very specific to this project.

  • 1

    Common

    Most of the 35 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When delegating to subagents, you face a dilemma:

    line 22
  2. Common:

    Update search criteria based on evaluation:

    line 57
  3. Distinctive:

    No critical gaps identified

    line 71

“Common” is measured: kept by at least 6 in 10 of the 35 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Iterative Retrieval Pattern

Solve the subagent context problem: agents don't know what they need until they start looking.

The Problem

When delegating to subagents, you face a dilemma:

  • Send everything: Context overflow, wasted tokens, confused agent
  • Send nothing: Agent lacks context, produces poor results
  • Guess what's needed: Often wrong, misses critical files

The Solution: 4-Phase Iterative Loop

Phase 1: DISPATCH

Send a broad initial query to gather candidate context:

Search for files related to: [topic]
Keywords: [initial keywords]
File patterns: [likely patterns]
Return: File paths with relevance scores

Phase 2: EVALUATE

Score each result for relevance (0.0 to 1.0):

| File | Relevance | Reason |
|------|-----------|--------|
| src/auth/login.ts | 0.9 | Core auth logic |
| src/utils/hash.ts | 0.7 | Used by auth |
| src/config.ts | 0.3 | Has auth config section |
| src/routes.ts | 0.2 | Only references auth path |

Identify gaps:

  • What terminology does this codebase use? (update search terms)
  • What patterns are referenced but not found?
  • What dependencies need exploration?

Phase 3: REFINE

Update search criteria based on evaluation:

Updated keywords: [refined keywords from codebase terminology]
New file patterns: [patterns discovered during evaluation]
Specific files to read: [high-relevance files]
Gaps to fill: [what's still missing]

Phase 4: LOOP

Repeat phases 1-3 with refined criteria.

Stopping Criteria:

  • 3+ files with relevance >= 0.7
  • No critical gaps identified
  • OR max 3 iterations reached (proceed with best available)

Example: Finding Auth Implementation

Iteration 1:

  • DISPATCH: Search for "auth", "login", "session"
  • EVALUATE: Found middleware but not the auth service
  • REFINE: Codebase uses "identity" not "auth"

Iteration 2:

  • DISPATCH: Search for "identity", "credential", "token"
  • EVALUATE: Found IdentityService, TokenManager, SessionStore
  • Result: 5 files with relevance >= 0.8 — stop and proceed

Implementation Pattern

async function iterativeRetrieve(topic: string, maxIterations = 3) {
  let keywords = extractKeywords(topic);
  let context: FileContext[] = [];

  for (let i = 0; i < maxIterations; i++) {
    // DISPATCH
    const candidates = await searchCodebase(keywords);

    // EVALUATE
    const scored = await scoreRelevance(candidates, topic);
    context = mergeContext(context, scored.filter(s => s.relevance >= 0.5));

    // Check stopping criteria
    const highRelevance = context.filter(c => c.relevance >= 0.7);
    if (highRelevance.length >= 3) break;

    // REFINE
    keywords = refineKeywords(keywords, scored);
  }

  return context;
}

When to Use

  • Delegating research to a subagent
  • Exploring unfamiliar codebases
  • Gathering context for code review
  • Building context for architectural analysis

When NOT to Use

  • You already know exactly what files are needed
  • The task is in a single file
  • The codebase is small enough to read entirely

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.