RAG, agents & tools (+ a little Python)
How AI apps read your documents and take actions, and why that's risky.
Time this week: 7–9 hours
By Sunday you can explain RAG, AI agents and tool use, read a 10-line Python API call, and see how a poisoned document can trick a bot.
Real business AI isn't just chat. It reads company files (RAG) and takes actions (agents with tools: email, search, code). Each new input and each new tool is a new door for attackers.
Start here: this week's labs
RAG: where the poisoned document sneaks in
Key ideas
RAG
Retrieval-Augmented Generation. The app first searches your documents, then pastes the best matches into the prompt so the model can answer from them.
Embeddings & vector database
Text turned into lists of numbers so the app can find 'similar meaning'. The vector DB stores them.
Agent
An LLM in a loop: think, choose a tool, use it, read the result, repeat until the job is done.
Tool use (function calling)
The model asks the app to run a function, like send_email() or search_web(). The app runs it and gives back the result.
MCP
Model Context Protocol. An open standard for plugging tools and data sources into AI apps like Claude.
API key
A secret password for a program to call an AI service. Never paste it in code you share or in a prompt.
A tiny Python example (read it, no need to run it)
# pip install anthropic (or: pip install openai)
import os
from anthropic import Anthropic
client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"]) # key from an env variable, never hard-coded
reply = client.messages.create(
model="claude-sonnet-4-5", # check the docs for current model names
max_tokens=300,
system="You are a helpful security tutor. Keep answers short.", # system prompt
messages=[{"role": "user", "content": "What is prompt injection?"}], # user message
)
print(reply.content[0].text)- Line 5: the API key is read from an environment variable. Hard-coding keys in code is a classic leak.
- system= is the system prompt. messages= is the chat. The model receives both as one context.
- max_tokens limits cost. No limit can mean a huge bill ('unbounded consumption', LLM10).
Day-by-day plan
Tick each day when you finish it. Your ticks are saved in this browser.
Mini game: Put the agent loop in order
Practice outside this course (free)
Search for 'tool use' and 'MCP'.Model Context Protocol
The official site for MCP.Python for beginners (python.org)
Only if you want to run the example.
These links need the internet. Everything else on this page works offline.
Exercises & worksheet
Weekly quiz
Mark it done to fill your progress bar on the course home.