Source profileQuality 79/100

affaan-m/ECC/skills/iterative-retrieval/SKILL.md

iterative-retrieval

Pattern for progressively refining context retrieval to solve the subagent context problem

Source repository stars
234,327
Declared platforms
0
Static risk flags
1
Last source update
2026-07-27
Source checked
2026-07-28

Decision brief

What it does—and where it fits

Solves the "context problem" in multi-agent workflows where subagents don't know what context they need until they start working.

Best for

    Not for

    • Tasks that require unconfirmed production actions or broad system permissions.
    • Environments where the pinned source and install steps cannot be inspected.

    Compatibility matrix

    Platform support, with evidence labels

    PlatformStatusEvidenceWhat to check
    CodexNot declaredNo explicit evidencePortability before use
    Claude CodeNot declaredNo explicit evidencePortability before use
    CursorNot declaredNo explicit evidencePortability before use
    Gemini CLINot declaredNo explicit evidencePortability before use
    Open the compatibility checker

    Installation

    Inspect first. Install second.

    The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.

    Source-detected install commandSource
    npx skills add https://github.com/affaan-m/ECC --skill "skills/iterative-retrieval"
    Safe inspection promptEditorial

    Inspect the Agent Skill "iterative-retrieval" from https://github.com/affaan-m/ECC/blob/4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38/skills/iterative-retrieval/SKILL.md at commit 4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.

    Workflow

    What the source asks the agent to do

    1. 01

      Phase 1: DISPATCH

      Initial broad query to gather candidate files:

      Initial broad query to gather candidate files:
    2. 02

      Phase 2: EVALUATE

      Assess retrieved content for relevance:

      High (0.8-1.0): Directly implements target functionalityMedium (0.5-0.7): Contains related patterns or typesLow (0.2-0.4): Tangentially related
    3. 03

      Phase 3: REFINE

      Update search criteria based on evaluation:

      Update search criteria based on evaluation:
    4. 04

      Phase 4: LOOP

      Repeat with refined criteria (max 3 cycles):

      Repeat with refined criteria (max 3 cycles):
    5. 05

      Example 2: Feature Implementation

      Review the “Example 2: Feature Implementation” section in the pinned source before continuing.

      Review and apply the “Example 2: Feature Implementation” source section.

    Permission review

    Static risk signals and limitations

    Network access

    medium · line 163

    The documentation includes network, browsing, or remote request actions.

    DISPATCH: Search "rate", "limit", "api" in routes/**

    Evidence record

    Why each signal appears

    EvidenceSourceComputedTestedEditorial
    SignalValueEvidence typeMeaning
    Quality score79/100ComputedDocumentation, specificity, maintenance, and trust rules
    Repository stars234,327SourceRepository attention, not individual Skill quality
    Compatibility0 platformsSourceDeclared in the catalog source record
    Usage guideautomated source guideEditorialGenerated or reviewed according to the visible evidence level

    Pinned source

    Provenance and original SKILL.md

    Repository
    affaan-m/ECC
    Skill path
    skills/iterative-retrieval/SKILL.md
    Commit
    4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38
    License
    MIT
    Collected
    2026-07-28
    Default branch
    main
    View the original SKILL.md

    Iterative Retrieval Pattern

    Solves the "context problem" in multi-agent workflows where subagents don't know what context they need until they start working.

    When to Activate

    • Spawning subagents that need codebase context they cannot predict upfront
    • Building multi-agent workflows where context is progressively refined
    • Encountering "context too large" or "missing context" failures in agent tasks
    • Designing RAG-like retrieval pipelines for code exploration
    • Optimizing token usage in agent orchestration

    The Problem

    Subagents are spawned with limited context. They don't know:

    • Which files contain relevant code
    • What patterns exist in the codebase
    • What terminology the project uses

    Standard approaches fail:

    • Send everything: Exceeds context limits
    • Send nothing: Agent lacks critical information
    • Guess what's needed: Often wrong

    The Solution: Iterative Retrieval

    A 4-phase loop that progressively refines context:

    ┌─────────────────────────────────────────────┐
    │                                             │
    │   ┌──────────┐      ┌──────────┐            │
    │   │ DISPATCH │─────│ EVALUATE │            │
    │   └──────────┘      └──────────┘            │
    │        ▲                  │                 │
    │        │                  ▼                 │
    │   ┌──────────┐      ┌──────────┐            │
    │   │   LOOP   │─────│  REFINE  │            │
    │   └──────────┘      └──────────┘            │
    │                                             │
    │        Max 3 cycles, then proceed           │
    └─────────────────────────────────────────────┘
    

    Phase 1: DISPATCH

    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);
    

    Phase 2: EVALUATE

    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:

    • High (0.8-1.0): Directly implements target functionality
    • Medium (0.5-0.7): Contains related patterns or types
    • Low (0.2-0.4): Tangentially related
    • None (0-0.2): Not relevant, exclude

    Phase 3: REFINE

    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)
      };
    }
    

    Phase 4: LOOP

    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;
    }
    

    Practical Examples

    Example 1: Bug Fix Context

    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
    

    Example 2: Feature Implementation

    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
    

    Integration with Agents

    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
    

    Best Practices

    1. Start broad, narrow progressively - Don't over-specify initial queries
    2. Learn codebase terminology - First cycle often reveals naming conventions
    3. Track what's missing - Explicit gap identification drives refinement
    4. Stop at "good enough" - 3 high-relevance files beats 10 mediocre ones
    5. Exclude confidently - Low-relevance files won't become relevant

    Related

    • The Longform Guide - Subagent orchestration section
    • continuous-learning skill - For patterns that improve over time
    • Agent definitions bundled with ECC (manual install path: agents/)

    Alternatives

    Compare before choosing