KS
Killer-Skills

iterative-retrieval — what is iterative-retrieval what is iterative-retrieval, how to use iterative-retrieval pattern, solve subagent context problem, iterative-retrieval vs traditional RAG, iterative-retrieval for MCP, iterative-retrieval setup guide, Claude code context optimization, multi-agent workflow context handling, iterative-retrieval install, AI agent token usage optimization

Verified
v1.0.0
GitHub

About this Skill

Essential for Multi-Agent Architectures tackling complex codebase exploration and RAG workflows. Iterative-retrieval is an AI agent pattern for progressively refining context retrieval to solve the subagent context problem. It is activated when spawning subagents that need unpredicted codebase context or when encountering context-related failures in agent tasks.

Features

Solves the subagent context problem in multi-agent workflows
Progressively refines context retrieval for agents like Claude
Addresses 'context too large' and 'missing context' failures
Optimizes token usage in AI agent tasks
Designed for RAG-like retrieval pipelines for code exploration
Activated when spawning subagents needing unpredictable codebase context

# Core Topics

affaan-m affaan-m
[62.0k]
[7678]
Updated: 3/6/2026

Quality Score

Top 5%
68
Excellent
Based on code quality & docs
Installation
SYS Universal Install (Auto-Detect)
Cursor IDE Windsurf IDE VS Code IDE
> npx killer-skills add affaan-m/everything-claude-code/iterative-retrieval

Agent Capability Analysis

The iterative-retrieval MCP Server by affaan-m is an open-source Categories.official integration for Claude and other AI agents, enabling seamless task automation and capability expansion. Optimized for what is iterative-retrieval, how to use iterative-retrieval pattern, solve subagent context problem.

Ideal Agent Persona

Essential for Multi-Agent Architectures tackling complex codebase exploration and RAG workflows.

Core Value

Enables progressive refinement of context retrieval for subagents that cannot predict their required context upfront. Directly addresses 'context too large' and 'missing context' failures in multi-agent workflows by implementing a dynamic retrieval pipeline.

Capabilities Granted for iterative-retrieval MCP Server

Spawning subagents for codebase analysis
Building multi-agent workflows with progressive context refinement
Optimizing token usage in RAG-like retrieval pipelines
Solving the subagent context problem in complex tasks

! Prerequisites & Limits

  • Requires integration into multi-agent architectures
  • Designed specifically for code exploration contexts
  • Needs a retrieval mechanism for initial context gathering
Project
SKILL.md
6.4 KB
.cursorrules
1.2 KB
package.json
240 B
Ready
UTF-8
SKILL.md
Readonly

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:

javascript
1// Start with high-level intent 2const initialQuery = { 3 patterns: ['src/**/*.ts', 'lib/**/*.ts'], 4 keywords: ['authentication', 'user', 'session'], 5 excludes: ['*.test.ts', '*.spec.ts'] 6}; 7 8// Dispatch to retrieval agent 9const candidates = await retrieveFiles(initialQuery);

Phase 2: EVALUATE

Assess retrieved content for relevance:

javascript
1function evaluateRelevance(files, task) { 2 return files.map(file => ({ 3 path: file.path, 4 relevance: scoreRelevance(file.content, task), 5 reason: explainRelevance(file.content, task), 6 missingContext: identifyGaps(file.content, task) 7 })); 8}

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:

javascript
1function refineQuery(evaluation, previousQuery) { 2 return { 3 // Add new patterns discovered in high-relevance files 4 patterns: [...previousQuery.patterns, ...extractPatterns(evaluation)], 5 6 // Add terminology found in codebase 7 keywords: [...previousQuery.keywords, ...extractKeywords(evaluation)], 8 9 // Exclude confirmed irrelevant paths 10 excludes: [...previousQuery.excludes, ...evaluation 11 .filter(e => e.relevance < 0.2) 12 .map(e => e.path) 13 ], 14 15 // Target specific gaps 16 focusAreas: evaluation 17 .flatMap(e => e.missingContext) 18 .filter(unique) 19 }; 20}

Phase 4: LOOP

Repeat with refined criteria (max 3 cycles):

javascript
1async function iterativeRetrieve(task, maxCycles = 3) { 2 let query = createInitialQuery(task); 3 let bestContext = []; 4 5 for (let cycle = 0; cycle < maxCycles; cycle++) { 6 const candidates = await retrieveFiles(query); 7 const evaluation = evaluateRelevance(candidates, task); 8 9 // Check if we have sufficient context 10 const highRelevance = evaluation.filter(e => e.relevance >= 0.7); 11 if (highRelevance.length >= 3 && !hasCriticalGaps(evaluation)) { 12 return highRelevance; 13 } 14 15 // Refine and continue 16 query = refineQuery(evaluation, query); 17 bestContext = mergeContext(bestContext, highRelevance); 18 } 19 20 return bestContext; 21}

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:

markdown
1When retrieving context for this task: 21. Start with broad keyword search 32. Evaluate each file's relevance (0-1 scale) 43. Identify what context is still missing 54. Refine search criteria and repeat (max 3 cycles) 65. 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 in ~/.claude/agents/

Related Skills

Looking for an alternative to iterative-retrieval or building a Categories.official AI Agent? Explore these related open-source MCP Servers.

View All

flags

Logo of facebook
facebook

flags is a feature flag management system that enables developers to check flag states, compare channels, and debug feature behavior differences across release channels.

243.6k
0
Design

extract-errors

Logo of facebook
facebook

extract-errors is a skill that assists in extracting and managing error codes in React applications using yarn extract-errors command.

243.6k
0
Design

fix

Logo of facebook
facebook

fix is a technical skill that resolves lint errors, formatting issues, and ensures code quality in declarative, frontend, and UI projects

243.6k
0
Design

flow

Logo of facebook
facebook

Flow is a type checking system for JavaScript, used to validate React code and ensure consistency across applications

243.6k
0
Design