Tutorial series
AI agents against your own company's data
Build an assistant that answers from your company's documents, queries your own database, takes real actions, and respects who is asking. One worked example, from a blank repository to something people trust.
150 chapters ยท 12 sections
Start with chapter 1 โThe example we build
Atlas, an internal assistant for a 200-person distributor. It answers from the company's policies, contracts and product specs, queries the orders and inventory database, and drafts quotes and tickets โ and it refuses anything the person asking is not allowed to see.
1. Foundations
What you are building, whether you should build it, and the smallest version worth shipping.
- 01What an agent actually is4 min read
- 02When you need an agent, and when you do not4 min read
- 03The failure modes you will hit5 min read
- 04What "your own data" actually means5 min read
- 05Meet Atlas5 min read
- 06The architecture at a glance9 min read
- 07Choosing your first slice8 min read
- 08Setting up the project10 min read
- 09A hello-world agent11 min read
- 10What success looks like11 min read
2. The data layer
Everything that has to be true about your data before retrieval is worth attempting.
- 11Inventorying what the company actually has9 min read
- 12Documents, databases, APIs and inboxes10 min read
- 13Who is allowed to see what10 min read
- 14Reading the permission model you already have10 min read
- 15Structured against unstructured11 min read
- 16Personal data, and what never enters the system11 min read
- 17Residency, retention and what your contracts already promise11 min read
- 18Mapping sources to questions10 min read
- 19Freshness, source by source10 min read
- 20The data you should refuse to connect9 min read
- 21Building the source registry11 min read
- 22A dry run, by hand11 min read
3. Ingestion
Getting the data in: fetching, parsing, chunking, and keeping it current without re-reading everything.
- 23The ingestion pipeline, end to end12 min read
- 24Pulling from a document store12 min read
- 25Pulling from a relational database11 min read
- 26Pulling from a third-party API11 min read
- 27Parsing PDFs, and why it is harder than it looks12 min read
- 28Spreadsheets, and the tables inside documents12 min read
- 29Email and chat archives12 min read
- 30Chunking: the decision that quietly determines quality12 min read
- 31Chunk size, overlap, and measuring instead of guessing11 min read
- 32Keeping document structure through the chunker11 min read
- 33Metadata: what to attach to every chunk11 min read
- 34Incremental sync and change detection11 min read
- 35Deletions, and the chunk that outlives its document12 min read
- 36Running the first full ingest12 min read
4. Retrieval
Finding the right passage, measured on its own, before a model ever sees it.
- 37Retrieval as its own system10 min read
- 38Embeddings, for someone shipping11 min read
- 39Choosing an embedding model11 min read
- 40Vector stores: the real differences11 min read
- 41Your first vector search, and why it disappoints11 min read
- 42Keyword search, and why it beats vectors more often than expected11 min read
- 43Hybrid retrieval, and fusing two ranked lists11 min read
- 44Reranking, and when it earns its latency11 min read
- 45Metadata filters and permission-aware retrieval11 min read
- 46Query rewriting and expansion12 min read
- 47Multi-hop questions, and recognising one11 min read
- 48Evaluating retrieval on its own12 min read
- 49Building a retrieval test set from real questions11 min read
- 50Tuning against the test set, and knowing when to stop12 min read
5. The model layer
Turning retrieved context into a grounded, cited answer that survives a model upgrade.
- 51Choosing a model, and the criteria that matter10 min read
- 52Context windows, and why more is not the answer10 min read
- 53The system prompt as an engineering artifact11 min read
- 54Prompt structure that survives a model upgrade11 min read
- 55Few-shot examples, and where they stop helping10 min read
- 56Structured output10 min read
- 57Schemas, validation and the malformed response12 min read
- 58Temperature, sampling, and determinism you can test10 min read
- 59Streaming responses, and what it changes upstream10 min read
- 60Token budgets and context assembly11 min read
- 61What to put in context and what to leave out10 min read
- 62Citations: making the model show its sources10 min read
- 63Refusal and abstention10 min read
- 64Comparing two models on your own task11 min read
6. Tools and actions
Where the assistant stops answering and starts doing, and the cost of a mistake stops being embarrassment.
- 65From answering to doing11 min read
- 66Tool calling, and how the model decides11 min read
- 67Designing a tool surface a model can actually use11 min read
- 68Tool descriptions, and the writing that makes them work10 min read
- 69Arguments, validation and refusing a bad call11 min read
- 70Read tools against write tools12 min read
- 71Side effects, and the action you cannot take back11 min read
- 72Confirmation flows: when a human must approve12 min read
- 73Idempotency for agent actions12 min read
- 74Querying the database as a tool11 min read
- 75Calling an internal API as a tool11 min read
- 76Composing tools, and letting the model chain them12 min read
- 77Tool errors, and what the model should see when one fails11 min read
- 78Testing tools independently of the model12 min read
7. Agent loops and control
The control flow you no longer own: making it stop, making it resumable, and making it legible.
- 79The loop: plan, act, observe, repeat10 min read
- 80Termination, and the agent that never stops11 min read
- 81Step limits, time limits and spend limits10 min read
- 82Planning: explicit plans against implicit ones11 min read
- 83Reflection, and whether it is worth the tokens10 min read
- 84Subagents, and when splitting helps11 min read
- 85Routing between specialised agents11 min read
- 86Handling partial failure mid-task10 min read
- 87Resumability, and picking up an interrupted run11 min read
- 88Parallel tool calls, and when they are unsafe11 min read
- 89Making a run's trace legible to a human10 min read
- 90The control-flow bugs that only appear in production12 min read
8. Memory and state
What it should remember, for how long, who it belongs to, and the attack surface a store that writes itself creates.
- 91What an agent should remember, and for how long9 min read
- 92Conversation state inside one session8 min read
- 93Long-term memory across sessions8 min read
- 94Per-user memory, and keeping it separate8 min read
- 95Summarising a conversation without losing the thread8 min read
- 96Memory invalidation, and the fact that changed8 min read
- 97Storing memory: the options and their trade-offs8 min read
- 98Letting a user see and edit what it remembers7 min read
- 99Memory as an attack surface8 min read
- 100Testing that memory helps rather than drifts8 min read
9. Evaluation
The harness every number in this series leans on: the case set, the judge and its calibration, and telling a real improvement from noise.
- 101Why you cannot ship this without evals7 min read
- 102Building the first eval set from real questions7 min read
- 103Writing a good eval case8 min read
- 104Exact-match, fuzzy and semantic scoring8 min read
- 105LLM-as-judge, and its specific traps8 min read
- 106Calibrating a judge against human ratings7 min read
- 107Evaluating retrieval, generation and actions separately8 min read
- 108Regression testing a prompt change7 min read
- 109Regression testing a model upgrade8 min read
- 110Measuring groundedness and catching confident invention8 min read
- 111Measuring refusal: did it decline when it should have8 min read
- 112Tracking quality over time as the data moves under you7 min read
- 113A/B testing agent changes with real users8 min read
- 114Making the eval suite fast enough that people run it8 min read
10. Guardrails and security
Assume the model will be manipulated, and build so that a manipulated model cannot reach anything that matters.
- 115The threat model for an agent with your data9 min read
- 116Prompt injection, demonstrated against Atlas8 min read
- 117Indirect injection through ingested documents8 min read
- 118Why filtering prompts does not solve injection7 min read
- 119Permissions enforced at query time, not in the prompt8 min read
- 120The confused deputy problem, and the agent acting as itself8 min read
- 121Preventing data leakage between users8 min read
- 122Output filtering, and its limits8 min read
- 123Rate limiting and abuse8 min read
- 124Audit logs: what to record for every run8 min read
- 125Incident response when an agent does something wrong9 min read
- 126The security review before you let anyone else use it8 min read
11. Production
Running it: observability, cost, latency, degradation, deployment, and the runbook for the night it breaks.
- 127What production means for a system that is non-deterministic8 min read
- 128Observability: traces, spans and what to log8 min read
- 129Debugging a bad answer after the fact8 min read
- 130Cost: where the money actually goes7 min read
- 131Model routing, and using a cheaper model where it suffices8 min read
- 132Caching: prompts, embeddings and whole responses8 min read
- 133Latency budgets and where the time goes7 min read
- 134Rate limits, retries and backoff against a provider9 min read
- 135Graceful degradation when the model is down7 min read
- 136Deployment, environments and promoting a prompt change8 min read
- 137Versioning prompts, models and the data together8 min read
- 138Scaling ingestion as the corpus grows8 min read
- 139On-call for an agent: what to alert on8 min read
- 140The runbook for the three most likely failures8 min read
12. Interface and adoption
Whether anyone uses it: the box that shapes the question, the failure screens people actually see, and trust that survives the first wrong answer.
- 141The interface shapes what people ask7 min read
- 142Streaming UX, and what to show while it thinks7 min read
- 143Showing sources so an answer can be checked7 min read
- 144Designing the failure state8 min read
- 145Feedback: capturing it and actually using it8 min read
- 146Onboarding people who have never used one7 min read
- 147Setting expectations so trust survives the first wrong answer7 min read
- 148Measuring adoption against usage7 min read
- 149Knowing when to expand scope, and when not to8 min read
- 150What to build next, and how to decide8 min read