All modules
Part 1 — Foundations of Agents
- 1.01 The Architecture of Prediction
- 1.02 Foundational failures of LLMs
- 1.03 Open weights run on your own machine
- 1.04 The system prompt shapes the agent's persona
- 1.05 The block anatomy of system prompts
- 1.06 The agent loop's four surfaces
- 1.07 Diagnosing prompt failures by variable
- 1.08 An independent critic scores each draft
- 1.09 Four topologies for delegating work
- 1.10 Voice as countable register laws
Part 2 — Agent Design and Evaluation
- 2.02 Routing requests to specialists and providers
- 2.03 Storing and recalling agent memory
- 2.04 Governing a long-term memory store
- 2.05 Runtime tool discovery over MCP
- 2.06 The trust boundary around MCP tools
- 2.07 The specification-first image pipeline
- 2.08 Grading an image without priming the reviewer
- 2.09 Separating claim gathering from judgment
- 2.10 Gating claims into a sourced answer
- 2.11 The agentic coding loop verified by execution
- 2.12 The repository instruments that carry an agent's context
- 2.13 Grading agents with eval suites
- 2.14 The production ledger and the deploy gate
Part 3 — Mastering the Principles of LLMs
- 3.01 Three sources of the thought state
- 3.02 How the next token is chosen
- 3.03 Every score is a dot product
- 3.04 The weights hold more than facts
- 3.05 How attention builds the context term
- 3.06 How the memory term competes with context
- 3.07 Six ways to ask one question
- 3.08 The fixed depth of a single pass
- 3.09 How reasoning models write their working down
- 3.10 Six layers that hold a fact
- 3.11 Choosing a layer for a fact
1.04
The system prompt shapes the agent's persona
Run a local model as a four-sentence agent, swap its personality and its job, and read in the transcript what a persona instruction can and cannot hold.
- Time
- ~45 min
- Builds on
- large language model (LLM) 1.01 token 1.01 context window 1.01
Objectives
- Write an agent in four sentences, run it locally with no key, and change it by swapping personalities and use cases
the system prompt shapes the agent’s persona
the system prompt is pinned at the front of the context window
The weights file is identical for every user who downloads it. It holds no profile of you and no persistent memory across sessions, so the night-shift nurse’s quizmaster cannot live in the file. During inference, the only input the model reads is the text in the context window. The runtime processes your prompt once, and as it generates each new token, the model computes attention over the stored key and value vectors of every preceding position in the sequence, the stored work module 1.01 described. For the same file of weights to behave as a quizmaster on every turn, instructions must reside in the context window where the model can read them. Placing your instructions at the start of the window means every token the model generates attends to them, conditioning each next-token probability distribution on the persona and constraints you specified. That pinned prefix is the system prompt.
An agent’s persona is selected by the text in the context window from what the weights can already produce. The underlying weights supply the model’s learned language, register and conventions, including how a brisk, dry quizmaster talks and an instruction-tuned model’s habit of following a system prompt at all. The system prompt selects which of those behaviors the model expresses, and every message in the conversation conditions the choice as well, because next-token predictions depend on the entire active sequence. When you edit the system prompt, you alter the agent’s behavior immediately while leaving the underlying weights file untouched, and since that file is the same for every user, the text is what makes this agent yours.
Persona is selected by text in the window: the weights provide the repertoire of behavior the model can produce, and the tokens in the sequence, your system prompt and the conversation after it, select which behavior appears. Change the system prompt and you change how the agent behaves, using the exact same file of weights underneath.
Here is a system prompt:
I am a night-shift nurse studying for a cardiology exam in the quiet
hours between rounds. You are my quizmaster: brisk, dry, and secretly
rooting for me. Ask me one exam-style question at a time, and never
explain the answer until I have attempted it. Keep every reply under
four lines.
Every token the model generates attends to these sentences, so their tokens enter the calculation of every reply that follows. By configuring the system prompt, you shape the base model into an agent capable of executing a specific task.
- Sentence 1 defines the audience. It establishes who you are and your technical background. Because the model has no user profile and no persistent memory, stating your background in the prompt provides the first context that calibrates vocabulary, technical depth, and tone; your own messages condition them further as the conversation goes on, so a nurse who writes in clinical vocabulary pulls the replies toward it too.
- Sentences 2 through 4 define the agent. They assign the agent’s operational role, communication style, and specific task boundaries.
run the agent on your machine
-
Install Ollama
Install Ollama, the local runtime.
Done when running ollama --version in a shell prints a version number.
-
Start qwen3:8b
Start the model from your shell:
On the first invocation the runtime downloads the weights once, about 5 GB, and loads them into memory.
Done when the >>> prompt appears after a one-time download of about 5 GB.
ollama run qwen3:8b -
Set the system prompt
When the
>>>prompt appears, set your four sentences as the system prompt:Done when the model answers your first message as a brisk quizmaster with one exam-style question under four lines.
>>> /set system "I am a night-shift nurse studying for a cardiology exam in the quiet hours between rounds. You are my quizmaster: brisk, dry, and secretly rooting for me. Ask me one exam-style question at a time, and never explain the answer until I have attempted it. Keep every reply under four lines."
On the laptop this lesson was written on, qwen3:8b answered “Quiz me on beta blockers.” with one exam-style question on how beta blockers affect cardiac contractility, and it held the answer back until the nurse had tried. We then swapped only the second sentence, making the quizmaster a weary old sea captain who wraps every question in ship talk. The captain asked about “the heart’s engine” and, on the very next line, answered its own question.
customizing the agent reveals the limits of a persona
Now let’s use some commands to customize the agent. Remember that the important lessons here are not in the terminal commands but in the way we are changing the agent: one sentence at a time, keeping the other three, asking the same first question, and comparing.
>>> /clear wipes the conversation
>>> /set system "your instructions here" replaces the system prompt
Follow the instructions below to personalize your agent:
-
Swap the persona
Keep the nurse, keep the rules, and test other personas in the same job: the drill instructor, the gentle encourager, the deadpan examiner, the sea captain from the run above. A quiet character can take several turns to show, so give each audition more than one question; the captain arrived in the first line, and crowded a rule out on the way in.
Done when you auditioned several personas for multiple questions, noting which kept every rule and which broke one to stay in character.
-
Swap the use case
A meal planner for someone who cooks on Sunday for the whole week; an editor for someone who writes too long; an interview partner for the week before the interview. Each is still one sentence of who you are, one of character, one of procedure, one of format.
Done when you wrote a four-sentence agent for another job like an editor, covering who you are, character, procedure, and format.
-
Delete the first sentence
Ask the same question with the audience sentence removed and read what the replies lose. Run it several times before you conclude anything: sampling varies from draw to draw, so the difference shows as a drift across runs rather than a switch.
Done when you asked the same question several times without the audience sentence and can name what the replies lost across runs.
The captain arrived on the first line, and sentence three broke on the second: the reply answers its own question, the exact behavior your instruction forbids.
As a conversation grows, this simple approach encounters three clear limits:
- Context dilution. Your four-sentence prompt becomes a smaller share of the active sequence as the conversation accumulates. As hundreds of conversational tokens fill the window, they compete with the original instructions to influence next-token predictions, and the model’s adherence to the persona and its rules can degrade over long exchanges. Attention weights are computed from what the tokens contain, so the prompt’s share of the window does not measure its influence; whether the rules still hold at turn forty is something you find out by running the conversation to that length.
- Persona over rules. A vividly described character often overpowers negative constraints. When roleplay patterns dominate the prompt, the model will break operational rules simply to stay in character; the captain run is one draw of exactly that.
- Sampling variance. Because any temperature above zero draws from a probability distribution rather than a single deterministic output, the exact same prompt can produce a compliant answer on one pass and a rule violation on the next.
The local runtime sets a fourth limit of its own: the context window it loads the model with. As of Ollama’s documentation in October 2026, the default depends on the video memory the runtime detects: under 24 GiB of VRAM it loads a 4k window, between 24 and 48 GiB a 32k window, and at 48 GiB or more a 256k window. The same documentation recommends at least 64,000 tokens for agents and coding tools, and defaults have changed between releases, so the number that applies to you is the one your own runtime reports. Run ollama ps while the model is loaded and check the CONTEXT column; ollama show qwen3:8b prints the model’s own trained maximum under “context length”, which is a different number from the window the runtime loaded.
Once a conversation or a pasted page outgrows the configured window, the model reads only what fits. A conversation that has outgrown this window is a common cause of a local agent forgetting its instructions part-way through a long session, and the window is the first thing to check, well before the model’s own trained context length matters. You can raise it for one ollama run session with /set parameter num_ctx 16384, or for the whole server by starting it with OLLAMA_CONTEXT_LENGTH=16384 ollama serve. An agent framework that reaches Ollama through its OpenAI-compatible endpoint cannot set the window per request, because that endpoint ignores a num_ctx sent with a request, so for such an agent the window is set on the server.
Whether a larger window fits in memory depends on three allocations: the model weights at the quantization you chose (about 5 GB for qwen3:8b), the runtime’s own working memory, and the KV cache, the stored key and value vectors for every token in the window. Because the cache holds one entry per token, it grows in proportion to the context length, and a larger window on the same model needs more memory.
Resolving these failure modes requires two structural moves. The first is architectural: replace a simple persona with an explicit agent definition, written in named blocks that state the agent’s purpose, its style, the procedure it follows on every turn, and examples of each. The second is measurement: a score you can put on what the agent produced, so that changing a block becomes something you can check rather than something you hope about.
what you can do with this today
You now understand the foundational stack of an agent system: a model runtime, an explicit system prompt that directs behavior, and execution running on your own hardware. Turn this understanding into five practical checks for your daily work.
Whose behavior is this? An agent’s persona is the behavior the weights learned in training, selected by plain text in the window: the system prompt and the conversation after it. Before assuming you need a different model to fix an output problem, inspect and refine the system prompt. The four-part prompt structure (audience, role, procedure, format) can be applied to any chat interface or script immediately.
Where does the context go? Always verify your model routing. If your configuration targets an external cloud endpoint, every token in the context window leaves your private infrastructure. If it points to a local runtime like Ollama, inference happens entirely in local memory. Define your data sensitivity boundaries before running an agent.
Does the model clear the capability floor? Before selecting a model, list the concrete features your task requires: tool calling, structured JSON output, or a specific context size. This list is your capability floor. Choose the smallest, most cost-effective model that clears this baseline.
Does the prompt hold on a smaller model? Write and refine prompts against compact local weights first. Local runs carry no per-token fees, and smaller models expose ambiguous phrasing quickly because they have less capacity than larger systems to infer intent from loose instructions. Once your instructions perform reliably on an 8-billion-parameter model, keep the failing inputs and edge cases you gathered as test cases. When you move the workflow to a larger or different model, run those same test cases through it to check that the prompt transfers before you rely on it.
Is the provider boundary decoupled? Abstract provider differences behind a single adapter interface in your codebase. When your application interacts with models through a consistent abstraction layer, benchmarking alternative models remains a one-line configuration change rather than a code rewrite. Getting started with an open model shows the seam this relies on.
Here is the lesson on one card, in the vocabulary you now own:
1. THE FILE
qwen3:8b, about 5 GB on disk, 5 to 6 GB in memory.
Fixed the day training ended; the same numbers for everyone, on your own disk.
2. FOUR SENTENCES
Who you are; who the agent is; the procedure; the format.
Change one, keep three, ask the same question, compare.
3. THE LIMITS
context dilution · persona over rules · sampling variance
Named blocks and a measured rate reduce them.
Next you give an agent a purpose. The course’s first full specimen, the Tutor, is written in named blocks rather than sentences, and its whole definition lives in one file you can read and change. Open the syllabus to continue.
End of module 1.04
You have reached the end of this module. Marking it finished is your own call, saved in this browser, and you can undo it at any time.
Saved in this browser only. Press again to remove.