RAG and Agents
Ground a language model in your own documents with retrieval, and understand what changes when AI can take actions.
Objective
By the end of this lesson, you can explain how retrieval-augmented generation works, build a toy retriever, and name the main risks of AI agents.
Retrieval-augmented generation
An LLM only knows its training data. Retrieval-augmented generation (RAG) gives it the right documents at question time:
- Retrieve: search your own trusted documents for the passages most related to the question.
- Augment: paste those passages into the prompt.
- Generate: ask the model to answer only from those passages, and to cite them.
RAG lowers made-up answers and lets you update knowledge by updating documents, not retraining. Real systems search with embeddings: lists of numbers that place similar meanings close together. The toy below uses shared words instead.
The bus question has no good answer in these documents. A safe RAG system says "I don't have that information" instead of answering from the wrong document. Teaching a system to say "I don't know" is part of the job.
Agents
An AI agent is an LLM that can use tools and take steps on its own: search the web, run code, send email, fill out forms. You give it a goal. It plans, acts, checks results, and repeats.
Agents raise the stakes, because mistakes become actions:
- Wrong action: sending the wrong message to the wrong person.
- Prompt injection: hidden instructions in a web page or document that trick the agent into doing something else.
- Runaway loops: repeating actions, wasting time and resources.
Safe agent design: give it the fewest tools it needs, require a person to approve anything that sends, spends, deletes, or contacts people, and log every action.
A national example
Quiz: RAG and agents check
Discussion
Ask. Answer. Build together.
Loading…