Canvases 27 diagrams — one per chapter. The architecture of a topic in a single picture:
what talks to what, where a model sits, and where you come in. Each one links to the chapter
that teaches it.
Chat with AI1
Which chatbot for the job?
A decision fork from "what do you need?" to ChatGPT, Claude, Gemini and Perplexity, each labelled with the task it fits.
Which chatbot for the job?
four frontier assistants — pick by the task, not the brand
What do you
need?
ChatGPT
all-rounder — Q&A, drafts, code
Claude
careful writing & analysis
Gemini
Google-grounded · multimodal
Perplexity
research with cited sources
anything
write & analyse
images / search
research
Same question, four strengths — no setup, just open and prompt.
Frontier chatbots → Better prompting4
The context window
Four moves — Write, Select/RAG, Compress, Isolate — all feed into the finite central context window that the model sees each turn.
The context window
what the model sees — managed with four moves
context window
what the model sees this turn
finite — tokens cost, and rot
Write
put what matters in
Select · RAG
pull in only the relevant
Compress
more signal, fewer tokens
Isolate
separate concerns & agents
Most agent failures come from poor context — not a weak model.
Context Engineering →
Anatomy of a loop
you design the system that prompts the agent — not each turn
1 · Trigger
schedule · event · you
2 · Act
agent does one step
3 · Check
tests · reviewer
pass
✓ goal verified
fail → fix & retry
stop after N tries · budget
three rungs — hand off more of the driving
1 · Closed loop
verify every change
2 · Unattended
Ralph + anchor files
3 · Orchestrate
batch · subagents
the whole technique, in one line:
while :; do cat PROMPT.md | claude-code ; done
Trigger · Act · Check · repeat — until a verified goal, with a way to stop.
Loop Engineering →
Anatomy of a strong prompt
A vague prompt vs. a structured prompt with Role, Context, Task, Examples, Format and Constraints — the six parts a model can act on.
Anatomy of a strong prompt
say what you want — then shape the response
✕ vague
"write about dogs"
→ generic, guessy
✓ a prompt it can act on
Role
You are a vet writing for first-time owners.
Context
Audience: UK, no prior experience.
Task
Explain crate training as 5 concrete steps.
Examples
Match this tone: "short, upbeat sessions…"
Format
Numbered list, ≤150 words, plain English.
Constraints
No jargon. Say so if you're unsure.
+ advanced — let it think step by step · ground in your sources
Same ask — a vague line vs. the parts a model can actually act on.
Prompt Engineering →
The test-first prompt loop
Write input → expected examples first, then loop Red → Green → Refactor, and re-run the whole set on every prompt or model change to catch regressions.
The test-first prompt loop
decide what "right" looks like before you write the prompt — then let it drive every edit
1 · Write the examples first
a handful of input → expected pairs — edge cases & known failures = your checkable spec
start red
RED
run the prompt on your set —
a case comes back wrong
GREEN
make the smallest prompt
change that passes it
REFACTOR
tighten & shorten —
every example stays green
loop — repeat for the next failing case
Keep the file. Re-run the whole set on every change.
a prompt edit · a model swap · a silent model update — catch the regression before your users do
TDPE is the loop. How you grade each output — code · LLM-judge · human — lives in Evals & testing.
Test-Driven Prompt Engineering → Build apps1
From a sentence to a working app
A four-step pipeline — describe, AI builds, preview & refine, publish — with a branch showing how Base44, Lovable and v0 differ in what they hand you.
From a sentence to a working app
vibe coding — describe it, get a real app, no code
Describe
plain English prompt
AI builds it
generates the whole app
Preview & refine
see it, ask for changes
Publish
share a live URL
what you get differs by tool ↓
Base44
full-stack, backend baked in
Lovable
you own the code
v0
UI only
Same describe → build loop; the tool decides what you walk away with.
AI app builders → Automation Tools2
Anatomy of an automation workflow
Trigger to AI or transform node to an IF branch that forks into an action on match or an else path, with a dashed error-and-retry loop under the AI node.
Anatomy of a workflow
trigger → nodes that process & route → action — the n8n / Make / Zapier canvas
Trigger
webhook · schedule
· app event
AI / transform
summarize · classify
· extract fields
IF branch
route on a
condition
Action ✓
Slack · email
· update DB
Else
log · skip · stop
match
no match
on error → retry, then alert
Each box is a node you wire on the canvas — no code between the boxes.
Automation tools →
Anatomy of the extensibility layer
Agent core at centre, five plug-ins around it: Skill (top), Slash command (mid-left), Subagent (mid-right), Hook (bottom-left), MCP tool (bottom-right).
Anatomy of the extensibility layer
an agent is a small core — these five plug-ins give it new powers
The agent
model + small core —
bolt powers onto it
Skill
SKILL.md loaded on task match
reusable · portable across tools
Slash command
saved prompt, invoke by name
shortcut, e.g. /review
Subagent
helper in its own context
offload noisy / parallel work
Hook
script that fires on an event
automatic — no prompt needed
MCP tool
connects an external system
GitHub · database · calendar
Same five pieces in every agent — learn them once, carry them everywhere.
Skills, tools & extensions → Agent frameworks1
An agent on a canvas — grounding an LLM, and a multi-agent crew
Pattern one grounds an LLM with context from any retrieval method then reasons with tools and memory. Pattern two has a manager delegate to researcher, writer and reviewer agents that merge into a result.
An agent on a canvas
Flowise · Langflow · CrewAI — wire context, an LLM, tools, and other agents
① GROUNDING AN LLM — give it the right context, then let it reason
User asks
a question
Get context
pull in what's relevant
LLM reasons
tools
memory
Answer
grounded
context can come from — pick any, or combine:
docs pasted in — no search, simplest
vector store — semantic top-k (classic RAG)
keyword / full-text search
live tool — web search · API · database
② MULTI-AGENT CREW — a manager delegates to specialist agents
Manager
plans & delegates
Researcher
gathers sources
Writer
drafts the answer
Reviewer
checks & fixes
Merged result
the crew's output
Build agents → Personal AI Assistants2
How Claude Cowork works
Four-step loop: Describe → Review plan → Claude works → Finished work. Inside step 3: parallel sub-agents, isolated sandbox, your tools (Drive/Gmail/Chrome/plugins).
How Claude Cowork works
describe an outcome → get back finished work (no terminal)
1 · Describe
outcome you want
+ guardrails & folder
2 · Review plan
Claude proposes steps
you approve first
3 · Claude works
files & apps
watch & redirect
4 · Finished work
report, sheet, folder
gaps flagged for you
Inside "Claude works"
Parallel sub-agents
splits a big job,
runs pieces at once
Isolated sandbox
only folders you allow —
nothing else touched
code runs in a separate VM
Your tools
Drive · Gmail · Chrome
+ job-function plugins
Finance · Sales · Research…
You own the what — outcome and guardrails. Claude works out the how . (/schedule repeats weekly.)
Claude Cowork →
Anatomy of a personal assistant
You to a chat app to an always-on assistant that uses web, memory and tools, then returns results to you. Hermes and OpenClaw are the ready-made options.
Anatomy of a personal assistant
install once → chat from anywhere → it works 24/7
You
ask in words
Chat app
Telegram,
WhatsApp · web
Assistant
always on,
remembers you,
runs while you sleep
Done work
sent to your
chat
browse the web
memory
run tools
Uses these to do the job — you use it, you don't build it.
Ready-made: Hermes (self-hosted) · OpenClaw (chat-driven)
Personal AI Assistants - Intro → Chat with your Data - RAG1
The RAG pipeline
A left-to-right flow: your documents are chunked and embedded into a vector store; a question retrieves the top-k chunks, which hybrid search and reranking narrow to the best few; the model answers from those sources with citations; and the retriever and answer are evaluated for precision, recall and faithfulness.
The RAG pipeline
answer from your own files — with citations you can check
Your docs
PDFs · policies
KB · runbooks
1 · Chunk & embed
split with overlap
add chunk context
Vector store
pgvector · Chroma · Qdrant
2 · Retrieve & rank
retrieve top-k chunks
vector + BM25 hybrid
rerank → top 5–10
place best at start/end
beats lost-in-middle
3 · Grounded answer
answer from sources only
cite each chunk
say if not found
→ cited answer
Evaluate — prove it works
retriever: context precision · context recall
answer: faithfulness (supported claims / total)
Under ~200k tokens? Put the docs in the prompt. Bigger / changing corpus → retrieve.
Chat with your own documents → Local AI & Private Cloud3
One URL, open models at cloud speed
Your code to a base URL plus API key, forking to Groq, OpenRouter and Cerebras, with fast tokens returned. All OpenAI-compatible, so swapping is one line.
One URL, open models at cloud speed
point your code at a provider — switch in one line
Your code
OpenAI-compat call
One URL + key
base_url + api_key
swap = 1 line
Groq
fastest · LPU chips
OpenRouter
200+ models · one key
Cerebras
wafer-scale · 1M free/day
fast tokens back
All speak the OpenAI API — pick for speed, model choice, or a free tier, and switch any time.
EU-sovereign inference →
Where a local model runs — and what never leaves
Your machine holds a downloaded GGUF model, a local runtime, and the app that calls it on localhost; the cloud API stays outside the privacy boundary and receives no data.
Where it runs — what never leaves
a local model: prompts and data stay on your machine
YOUR MACHINE
— nothing crosses the dashed line
Download a model
one .gguf file, once
Qwen3.6-35B-A3B
22 GB
gpt-oss-120b
63 GB
DeepSeek-R1 671B
404 GB
Q4 GGUF — fits your RAM
Local runtime
Ollama :11434
LM Studio :1234
Your app
calls localhost
OpenAI-style API
✕
no data sent
Cloud API
OpenAI · Anthropic
not in the loop
No internet needed, no per-token cost — the trade is your own RAM, disk and GPU.
Local & Private Models →
How a change reaches users
test on a private copy first — promote only what you have checked
1 · Edit
on staging branch
— not on prod
2 · Staging
private · :3012
safe to break
3 · Verify
does it look right?
check the real page
4 · Production
live · public · users
keep it boring
push
merge
not right? fix on staging — never touch prod
what actually promotes it (this site):
git push origin staging → verify http://…:3012 → merge staging → main → live
two copies of the same app — one to break, one to trust
Staging — the rehearsal
private · disposable · no users watching
Production — the show
public · live · only proven changes
Edit · Stage · Verify · Promote — the same change, proven before it goes live.
Self-host on a private cloud → Write code2
How a coding agent works — read, edit, run, fix, repeat
A loop: read context, propose edit, run it, read output; fail loops back to propose edit, pass goes to done. A chatbot stops after propose edit.
How a coding agent works
reads code, runs it, fixes its own mistakes — not just a chatbot
Read context
repo · open files
· grep
Propose edit
write & patch
the code
Run it
tests · build
· run command
Read output
pass or fail?
errors · diffs · logs
fail → fix & retry
pass
✓ Done
change verified
A chatbot stops after "Propose edit".
An agent runs it and checks itself.
AI coding assistants →
From idea to build plan
write the blueprint before any code is written
One-liner
idea, one sentence
+ "ask me 5 Qs"
The spec · PRD.md
user stories · data model
screens · acceptance criteria
constraints & guardrails
= source of truth
Build plan
ordered steps, you approve
Build
AI writes code, step by step
change? update spec first
scope v1 · what it will NOT do
the "must-never" rules
Catch a wrong assumption in a 10-line plan — not in a finished, broken app.
Product requirements & spec engineering → Building complex codebases1
Anatomy of the AI layer
Your git repo contains your code plus the AI layer (CLAUDE.md, commands, skills). Every task runs a Plan → Implement → Validate loop; pass = shipped, fail = fix and retry, which feeds improvements back into the AI layer.
Anatomy of the AI layer
a second codebase, checked in next to your code, that teaches the agent your project
your git repo
Your code
src/ · tests · the app itself
— what you ship
+
The AI layer
CLAUDE.md — lean project rules
.claude/commands/ — shortcuts
skills · subagents · MCP — on demand
checked in together — agent context is reviewed and improved like code
drive every task with one loop
1 · Plan
fresh-context blueprint
2 · Implement
follow the plan
3 · Validate
checks must pass
pass
✓ shipped
fail → fix & retry
every miss → new rule in the AI layer ↑
It's context, not a smarter model — give the agent the layer and it stops guessing.
Building complex codebases → AI memory systems1
Marvin — what writes, what reads, what deletes, and what compounds
Capture, hybrid index, recall into the prompt, and the promotion loop that turns an expiring conversation into a reviewed lesson.
Marvin — a memory that outlives the session
what writes · what reads · what deletes — and the one edge that makes it compound
CAPTURE — every session
Prompt hook
your message + its project
Answer hook
the reply, in chunks
fire-and-forget — a memory
write never delays a prompt
Embedding endpoint
text → 768 numbers, local
stored chunks and each
question, tagged apart
The index
hybrid: keyword + meaning
blended half and half
reviewed lessons
grown by promotion
chatter + open tickets
hundreds of lines a day
RECALL — every prompt
Top 5 passages
reserved slots per tier
each passage capped
tier + date shown, always
Into your prompt
before the model reads it
recall@5 gate — the build
fails below its floor, so a
dead retriever stays visible
LIFECYCLE — what expires, and what is kept before it does
Expire — past a
weekend, not before
verified, backed up, deleted
Distill candidates
a local model proposes
lessons worth keeping
Human review
approve → durable lesson
one click, and revertible
Capture and recall are the easy half. Promotion is the edge that compounds:
without it you have a short-lived cache; with it, a memory.
expiring chatter
Heidelberg Marvin memory → AI + Hardware1
AI across the robotics stack
Four layers an engineer drives: write the code, get the model onto the device, the optional LLM/VLM reasoning layer, and the FPGA limit (HLS with AI, not raw HDL).
AI across the robotics stack
you keep the domain expertise — the assistant speeds up the parts it can
You
mechatronics &
embedded engineer
1
Write the code
Claude Code · Cursor · Copilot on C/C++ & ROS 2
review + HIL test
2
Get the model on the device
quantize → TFLite-Micro / TensorRT → MCU · Jetson
measure first
3
Reasoning layer (optional)
LLM/VLM planning + ROS 2 glue · sim-to-real
real, not the brain
4
Know the limit — FPGA
AI drafts C/C++ HLS you verify — not raw Verilog
no un-checked HDL
The assistant augments your engineering — it never replaces the control theory, the standards, or the bench.
AI for robotics & edge devices → GOOD TO KNOW4
The eval loop
A four-step cycle — Look, Measure, Validate, Improve — repeating on every change, above a grading ladder from cheap code checks to costly human grading.
The eval loop
stop vibe-checking — grade your AI on real failures, with a number you trust
1 · Look
error analysis
traces · labels
2 · Measure
build graders
code/LLM/human
3 · Validate
trust the judge
vs human labels
4 · Improve
fix prompt
then re-measure
repeat — on every prompt or model change
The grading ladder — reach for the cheapest check that works
Code-based
exact match · schema
fastest · reliable
LLM-as-judge
binary pass / fail
for judgment calls
Human
the gold standard
slow · costly
cheap → costly · binary by default, numeric only where it earns its keep
Real failures decide what to measure — not a prefab metric dashboard.
Evals & testing →
Layered defense for an AI app
An outer ring of guardrails, monitoring and red-teaming wraps your application. Inside, a trust boundary separates your instructions from untrusted input — the user message, retrieved documents and tool output. Below the boundary, model output is encoded before it reaches another system, and tools run with least privilege plus human approval on risky actions.
Defend the AI app you build
assume injection eventually lands — separate, encode, restrict, and watch
guardrails · monitoring · red-team
Untrusted input
user message
retrieved docs
tool output
label as DATA, not commands
trust boundary — screen here
System prompt + model
instructions stay inside
data in labelled blocks
no secrets · no auth rules
(enforce in code)
Output → encode
HTML-escape · param SQL
strict CSP · schema-validate
Least-privilege tools
narrow tools · scoped creds
human ok on risky actions
log every tool call
No single layer holds. Bound the blast radius and detect what gets through.
Keep your AI app secure →
What leaves your keyboard
Your raw stuff passes a strip-first gate that blocks API keys and masks PII before reaching a cloud chatbot; the most sensitive data stays local.
What leaves your keyboard
before you paste into a cloud chatbot — strip it, control it, or keep it local
your stuff
🔑 API keys · passwords
✕
👤 names · emails · IDs
mask
💬 question + safe data
✓
what you type is what you send
strip first
remove keys
mask the PII
only safe text passes
cloud chatbot
trains on your chats by default?
Claude
no — opt-in
ChatGPT
yes — opt out
Gemini
yes — opt out
opting out stops training — not retention
chats kept a while for safety review
too sensitive? keep it local
run a local model — nothing leaves your machine
→ see "Run AI privately"
won't risk it — never send
Strip secrets · mask PII · prefer opt-in services · keep sensitive data local.
Privacy & safe AI use →
From reading the bill to cutting it
A three-step journey — Understand the bill (tokens in and out), Trim per call (cap output, less context, right-size the model), Scale the savings (caching ~90% off, batch 50% off, routing) — with a measure-and-attribute loop feeding back to the start.
What AI really costs
see the token bill — then cut it without losing quality
1 · Read the bill
tokens IN vs OUT
$/1M input & output
output costs 2–8× input
estimate before you run
2 · Trim per call
cap output length
JSON / structured output
send less context
right-size the model
3 · Scale savings
prompt caching · ~90% off
Batch API · 50% off
model routing / cascade
cheap first, escalate rarely
then
then
Measure & attribute
log tokens per request
tag by feature · model · user
attribution shows which lever to pull next — then repeat
The levers stack
cache the fixed prefix (~90% off) + batch non-urgent work (50% off)
+ right-sized model (~5× cheaper) — savings compound
~4 characters ≈ 1 token · cost = tokens × $/1M · trim the OUTPUT side first
What AI really costs → Across the course3
Choosing a model — a filters-first method
Step 1 filters on data privacy and EU residency, step 2 on cost versus quality, step 3 on the task.
Choosing a model
a filters-first method — start with your hardest constraint
1 · Must data stay
private / in the EU?
yes · sensitive data
no · ordinary work
KEEP IT PRIVATE / IN THE EU
GDPR-safe by design
Self-host — free & fully offline
laptop → Phi-4-mini · gpt-oss-20b
64 GB Mac → Qwen3.6 · Gemma 4
big box → gpt-oss-120b · Llama 4
EU-hosted cloud (managed)
Mistral (FR) · Aleph Alpha (DE)
2 · BEST RESULT, COST-AWARE
US cloud — use a DPA / EU region
Cheap · high-volume
Haiku 4.5 · Gemini Flash-Lite
GPT nano · DeepSeek V4
Balanced production
Claude Sonnet 5 · GPT-5.4
Top quality · hardest tasks
Opus 4.8 · GPT-5.5 · Gemini Pro
3 · Then match the model to the task
coding · long documents · reasoning · vision · cheap bulk
Choosing a model
Which AI tool? — a decision tree by goal
From a root question, goal branches lead to eight tool families, each a chapter, with example tools.
Which AI tool?
start from your goal — follow it to a family
what's the job?
start here
ask, write, research
build software
three ways →
automate tasks
24/7 personal agent
run models myself
Consumer chatbots
ChatGPT, Claude, Gemini, Perplexity
AI app builders
Base44 · Lovable · v0
AI coding assistants
Claude Code · Cursor · Copilot
Agent frameworks
Flowise · Langflow · CrewAI
Automation tools
n8n · Make · Zapier · Dify
Personal AI assistants
Hermes · OpenClaw
Local & private models
Ollama · LM Studio · Jan
Inference providers
Groq · OpenRouter · Cerebras
describe
my repo
custom
offline
fast API
Tools decision tree
Where your work actually lives
Six steps in three zones. The first two are conversation. The middle two — changed files and a saved snapshot — exist only on your own computer. Sending the snapshot away is the step that creates a second copy; after it, the site rebuilds itself.
Where your work actually lives
one sentence in, a live site out — and the one step that makes it safe
ASKING
You ask
in plain words
Memory attached
what the team learned
ONE COPY — YOUR COMPUTER
Files change
on your own disk
Snapshot saved
git commit
A SECOND COPY EXISTS
Snapshot sent away
git push
Site rebuilds
live for everyone
Only the green arrow changes anything about safety — it is the moment the work leaves your computer.
A saved snapshot is not a backup: it sits on the same disk as the files it describes.
Where your work lives