liveBook · Manning

Agentic RAG

As explained in AI Agents in Action, Second Edition

Agentic RAG is a retrieval-augmented generation approach in which an agent dynamically decides how and when to retrieve information, often iterating or using tools before generating a response.

A search system can retrieve documents once and pass them to a model. Agentic retrieval-augmented generation (RAG) adds decisions around that search: an agent can choose a retrieval tool, judge which results matter, and use the retrieved context to answer. The extra control is useful when a question needs different kinds of search or when the first results are insufficient. If one retrieval-and-answer call already works, skip the agent orchestration. section 6.3.3 section 11.3

Build the smallest useful workflow first, then add capabilities for specific failures:

  • Prepare a searchable knowledge base. For example, split a document into chunks, embed them, and store the vectors for later retrieval. section 6.3.2
  • Give the agent a retrieval tool and clear answer rules: use retrieved passages as the authority, cite sources, and say when they do not answer the question. section 6.3.2 section 11.3
  • Add search methods to match the data. Vector search helps with conceptual matches; keyword search helps with exact terms. An agent can choose between them or use both, rather than relying on a single search mechanism. section 6.3.1 section 6.3.3
  • Add routing, evaluation, or corrective retrieval only when needed. In a larger workflow, separate agents may retrieve, answer, and check whether an answer is grounded. section 11.3 section 11.2

From script search to grounded answers

A script-question agent starts with a movie script split into chunks and indexed in Chroma DB. Its first search tool retrieves similar passages. A hybrid version exposes separate vector and keyword tools, letting the agent select relevant passages and cite exact script references. If the script does not contain an answer, the agent should say so—even when it could produce a plausible answer from its existing knowledge. section 6.3.2 section 6.3.3

Listing 6.7 02_RAG_agent_hybrid.py
agent = Agent(
    name="Script Agent",
    instructions="""
## ROLE
You answer questions about the movie *Back to the Future*.
You have access to two search tools:    #1
1. `search_script_with_vector_similarity` - Use for
   semantic/conceptual searches
2. `search_script_with_keyword` - Use for exact
   word/phrase searches
Use both tools when appropriate to get comprehensive
results.    #1

## GROUNDING RULES
IMPORTANT: You must always provide exact references
from the script.    #2
- Quote relevant passages directly from the search
  Results    #2
- Use the [Reference X] markers to cite specific
  passages
- Do not make up information that isn't in the script
- If the script doesn't contain the requested
  information, say so clearly
- Always ground your answers in the actual script text
  provided by the search tools

## ANSWER FORMAT
Format your answers like this:    #3
Based on the script:
[Quote from Reference 1]: "exact text from script"
[Quote from Reference 2]: "exact text from script"

Your interpretation: [your analysis based on the
quotes]
""",
    tools=[search_script_with_vector_similarity, search_script_with_keyword],  #4
)

The hybrid agent listing makes tool choice and answer boundaries inspectable: its instructions distinguish conceptual from exact-phrase searches and require quotations, references, and an explicit response when evidence is absent. section 6.3.3

Treat a retrieved hit as a candidate, not proof. Test questions against expected answers, track answer accuracy and retrieval failures, and inspect cases where the system should have said “I don’t know.” For stricter handling, a grounding guardrail can block an unsupported answer and return a fixed response or trigger another attempt. These checks address different failures: search may miss evidence, while generation may overstate what the evidence supports. section 7.2.1 section 7.3.3 section 11.3

How AI Agents in Action, Second Edition covers it

How deep it goes
Builds from vector retrieval to hybrid tools and guardrails, while leaving hybrid tool implementations aside.
Examples
Uses an indexed movie script, benchmark questions, grounding guardrails, and a customer-support retrieval workflow.
What it assumes
Introduces chunking, embeddings, and grounding through a worked agent example rather than requiring prior RAG-agent experience.
What you can do after
Build it from scratch with retrieval tools, then evaluate answers and block outputs unsupported by retrieved context.
How it connects
Connects vector search, keyword search, hybrid retrieval, grounding, guardrails, and answer evaluation.

Also explained in

Compare how 4 books explain agentic RAG →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.