agentleFS
Goodnight77Goodnight77/rag-skills/skills/rag-agents/agentic-rag-routing/SKILL.md

agentic-rag-routing

Skill8 starsChanged 7 months agoMITView on GitHub

Route each query to the right retrieval strategy, data source, or tool with an LLM-driven router.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    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:

    Use an LLM or a lightweight classifier to map each query to a route, returning a structured decision rather than free text.

    line 34
  2. Distinctive:

    All queries are answered well by one retrieval path

    line 51

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “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

Overview

Agentic routing puts a decision step in front of retrieval: the agent classifies the query and chooses whether to retrieve, which source or index to hit, and which tool to call. This turns a one-size-fits-all pipeline into one that adapts per query.

Problem Statement

Different queries need different handling. A definitional question, a multi-hop question, and a live-data question all fail under a single fixed retrieval path. Without routing, the pipeline over-retrieves for simple queries and under-serves complex ones.

Key Concepts

  • Retrieval decision: Whether the query needs retrieval at all.
  • Source routing: Selecting the right index, collection, or tool for the query.
  • Query classification: Mapping a query to a handling strategy.
  • Fallback: A safe default path when the router is unsure.

Implementation Guide

Step 1: Define the Route Space

Enumerate the concrete routes available, such as no-retrieval, vector search, keyword search, web search, or a structured-data tool.

Why: A router can only choose from routes you have defined; an open-ended router is unpredictable and hard to evaluate.

Step 2: Classify the Query

Use an LLM or a lightweight classifier to map each query to a route, returning a structured decision rather than free text.

Why: Structured routing decisions are testable and can be logged, replayed, and evaluated.

Step 3: Add Fallback and Guardrails

Define a default route for low-confidence decisions and cap how many tools or hops a single query may trigger.

Why: Guardrails prevent runaway tool loops and keep latency and cost bounded.

For patterns, see the LangGraph agentic RAG guide and the LlamaIndex router query engine.

When to Use This Skill

  • Queries span multiple sources, formats, or freshness needs
  • Some queries need no retrieval and others need several hops
  • You want per-query control before adding full multi-agent orchestration

When NOT to Use This Skill

  • All queries are answered well by one retrieval path
  • The extra classification call breaks the latency budget
  • There is only one data source and no tool choice to make

Related Skills

  • Adaptive Retrieval - Strategy selection by query type
  • Self-RAG - Retrieval decisions at generation time
  • CRAG - Corrective RAG - Fallback search on weak retrieval
  • Multi-Agent RAG Orchestration - When routing is not enough

Metrics & Success Criteria

  • Route Accuracy: Queries reach the correct handling path
  • No-Retrieve Savings: Simple queries skip unnecessary retrieval
  • Bounded Cost: Tool and hop counts stay within limits
  • Fallback Rate: Low-confidence routing stays rare and safe

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.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

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.