Skip to main content
PreparationZone Logo
PrepZone

RAG with Tools and Agents

When a single retrieval is not enough: ReAct, tool types, and an agent that can search and calculate.

Pass checkpoint below

Why this matters

  • "What is our casual leave, and what is 8 days prorated over a 3-month probation?" needs the handbook and a calculator. One retrieval answers only the first half.
  • Interviewers look for the loop (reason, act, observe) and for the constraints you put on it.
  • Tool access is a security boundary. A retriever that can see every department is a data leak with extra reasoning.
  • Agents are how RAG grows into multi-step products, and how a simple bot becomes an incident.

When a single retrieval is not enough

Classic RAG assumes the evidence is text you can fetch in one shot. Agents earn their place when the system must:

  • fetch from more than one source (handbook, then the employee's record),
  • call an API or run a calculation,
  • decide it does not yet have enough and search again,
  • or follow a procedure with branches ("if probation, use the other table").

If every question is "what does section 4 say?", do not deploy an agent. You will pay for a loop that always calls the same retriever.

What an agent is

An agent is an LLM wrapped in a control loop. The model sees the user goal and a list of tools. It emits a choice: which tool, with which arguments. Your code runs the tool and appends the observation. The model continues until it emits a final answer or you stop it.

The loop, in plain steps

  • Understand the goal. The user question, plus any policy you injected ("never invent leave numbers").
  • Choose a tool. Retriever, SQL, calculator, calendar API. The choice is text the model generates, which your code parses.
  • Act. Run that tool with validated arguments. Do not pass the raw model string into a shell.
  • Observe. Put the tool result back into the conversation as data, clearly marked as a tool result.
  • Repeat or answer. Stop when the model answers, when the step budget is spent, or when a tool fails twice.

This pattern is often called ReAct: interleave reasoning and acting. The reasoning trace is useful in logs and dangerous in the UI if it contains tool arguments the user should not see. Store the trace. Show the user the final answer and the citations.

User goal
Model proposes a tool
Your code runs itValidated args
Observation
Answer or another step
Your process runs the tools. The model only proposes the next action.

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 4 sections

  • Tools you will actually register
  • A small PolicyDesk agent
  • Patterns people name
  • Practices that keep agents boring

Test yourself

Answer these before moving on — recall is what makes it stick.