← Learning

Agentic RAG: Retrieval as a Tool the Model Chooses

A linear, one-concept-per-lesson path through Agentic RAG, retrieval as a tool the model chooses to call rather than a fixed pipeline step, from Gemini's native function calling to a complete multi-tool FastAPI service built entirely from scratch. 26 lessons · 3 tiers.

Prerequisites: Comfortable writing basic Python. Assumes you've done this site's Naive RAG course (or otherwise know what dense retrieval and embeddings are) - this course is framework-free and specifically about retrieval-as-a-tool: when an agent should retrieve, how many times, and what else it should be able to call instead.

Lessons use Google's Gemini free tier (gemini-3.5-flash-lite for chat, no embedding model needed) via Gemini's native function calling (google-genai). No Docker, no database, no extra account - GOOGLE_API_KEY in a .env file is the only setup.

Built directly on google-genai, Gemini's native function-calling SDK, no agent framework in between.

Course source

Every lesson's README and lesson.py for this course live in the ai-agent-engineering repo.

View on GitHub →
Agentic RAG: Retrieval as a Tool the Model Chooses

Beginner

Gemini function calling basics, wrapping retrieval as a tool, and a single-step agent loop that correctly decides when to call it.

  1. 01What Is Agentic RAGGitHub
  2. 02The Fixed-Pipeline AssumptionGitHub
  3. 03Gemini Function Calling BasicsGitHub
  4. 04Retrieval as a ToolGitHub
  5. 05A Single-Step Agent LoopGitHub
  6. 06Deciding Not to RetrieveGitHub
  7. 07Multi-Tool AgentsGitHub
  8. 08End-to-End Agent QAGitHub
  9. 09Checkpoint: A CLI Assistant That DecidesGitHub

Intermediate

Multi-step loops, query decomposition, persisted history, bounded iterations, cited multi-call answers, and the failure modes that come with all of it.

  1. 10Multi-Step LoopsGitHub
  2. 11Query Planning and DecompositionGitHub
  3. 12Passing Tool Results Back CorrectlyGitHub
  4. 13Persisting Conversation HistoryGitHub
  5. 14Bounding IterationsGitHub
  6. 15Prompting for Cited, Multi-Call AnswersGitHub
  7. 16Failure Modes of Agentic RetrievalGitHub
  8. 17Minimal Evaluation, Retrieve or NotGitHub
  9. 18Checkpoint: A Multi-Turn Notes AssistantGitHub

Advanced

A tool registry replacing if/elif dispatch, wrapping the agent as a FastAPI service, and a capstone.

  1. 19Where if/elif Dispatch Breaks DownGitHub
  2. 20Structuring run_agent()GitHub
  3. 21A Tool Registry PatternGitHub
  4. 22Optional Corrective Grading as a ToolGitHub
  5. 23Refactoring into tools() and run_agent()GitHub
  6. 24Wrapping It as a ServiceGitHub
  7. 25Capstone: A Complete Agentic RAG ServiceGitHub
  8. 26Where Agentic RAG Hits a WallGitHub
Start at Lesson 1

Contact

Book a Call