Part 1 of 7 · 1 min read
Overview
In this module you will
- Build the list of messages for any model call, and explain each role.
- Keep conversation state yourself, and explain why the API does not.
- Trim a long history without losing the system prompt or the newest question.
- Explain what a system prompt can and cannot guarantee, and add enforcement in code.
Every agent step is "build a list of messages, send it, read the reply". Bugs in this part (a lost system prompt, history sent twice, a trimmed message that was needed) look like the model being stupid, but they are your code.
And because the system prompt is only text the model reads, any rule that must never be broken has to be enforced by code. Level 10 builds on this.
About the example model
The code uses FakeLLM, a small offline stand-in that copies the shape of a chat API (messages in; a reply and token usage out) and is stateless like the real thing. It is not a language model: its answers are scripted, so that every behaviour in these notes can be tested without a key or a bill. Real SDK snippets shown in the notes were not run here.