Week 5 · Phase 2: How AI works

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

Goal for this week
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.
Why it matters for AI security
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 Pipeline Lab: the poisoned document
Watch a company helpdesk bot search documents and build a prompt, step by step. Then slip in a poisoned file and see the bot get hijacked.
Open lab

RAG: where the poisoned document sneaks in

Question"What is the refund policy?"
Search docsvector DB finds top matches
Poisoned dochidden instructions inside
Build promptsystem + docs + question
Model answersmay follow the hidden text

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)

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)

Anthropic docs: tool use & MCP
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

Exercise deck (PPTX) Worksheet (DOCX)

Weekly quiz

Finished the week?
Mark it done to fill your progress bar on the course home.
← Week 4: How LLMs work Week 6: Prompt injection & jailbreaks →