# Mission 5.4: The bot forgot the beginning

Part of the course “AI from Zero to Autonomous Agents” (https://llm.yoga/en). Page for humans: https://llm.yoga/en/einsatz-5-4

Belongs to [Chapter 5: Context](https://llm.yoga/en/05-kontext.md).

Structure: the case, the explanation, a hands-on tool, check questions, wrap-up. The answers to all questions are collected at the end.

## The case

**Kai**, developer on the internal IT team:

> “I’m testing our bot locally with Ollama. At the start I give it a code word, „Tulpe“, then lots of text, then I ask for the code word. Its answer: „Code“. No error, no warning. Is the model just too small?”

Ollama is a program that runs language models on your own computer. Kai ran the same test with two values for the num_ctx setting. It sets the context window, that is, the maximum number of tokens (word pieces) the model reads in one request. After each request, Ollama reports how many tokens the model read. The test was run in German: „Tulpe“ is German for “tulip”.

**The test from chapter 5 with the small model qwen3:1.7b (Measured on an M4 Mac (24 GB) on November 24, 2026)**

num_ctx 4,096: 1,085 tokens read, answer „Tulpe“.

num_ctx 256: 52 tokens read, answer „Code“.

**Question 1 (prediction):** What happened at num_ctx 256?

- A) The model is too small to remember a word across a lot of text.
- B) Ollama cut off the beginning, and the model never saw the code word.
- C) The code word got lost in all the filler text, as usual with long texts.

## What’s behind it

The file a model reads with every request has a maximum thickness. If it gets thicker, something has to come out first. Ollama takes out the oldest pages and doesn’t tell you.

This maximum thickness is called the **context window**: the largest number of tokens a model processes in one request. Input and output share the space. In Ollama you set it with num_ctx; according to the docs, the default with less than 24 GiB of GPU memory is 4,096 tokens. If the input doesn’t fit, Ollama cuts it off silently. The Claude API, by contrast, rejects an input that is too long with an error message.

For Kai this means the code word was gone before the model started computing. It guessed from the question, and the answer sounded perfectly normal. Three things help. First, set num_ctx deliberately so the input fits, and check the number of tokens read that Ollama reports: if the model reads fewer than expected, something was trimmed. Second, whatever must always apply belongs in the system prompt, the fixed instruction in front of the conversation. In a cross-check, Ollama kept it when trimming. Third, leave out or summarize what isn’t needed before the window fills up. That’s called **compaction**.

### In more detail: compaction and context editing in the Claude API

With compaction, the server summarizes older rounds, and the conversation continues with the summary. According to the docs, there are two variants, both in beta: on request (recommended) and automatically above a token threshold.

Context editing removes specific things instead of summarizing: the strategy `clear_tool_uses_20250919` replaces old tool results with placeholders, and `clear_thinking_20251015` removes old thinking blocks.

Names for specialists: if the input alone is too long, the Claude API responds with the error `invalid_request_error` (“prompt is too long”). If the answer is what fills the window, it ends with the reason `model_context_window_exceeded`. Ollama returns the number of tokens read in the field `prompt_eval_count`.

Compaction and context editing have the same catch: what’s gone is gone. So pull out key facts like a code word, a date or a number beforehand and keep them separately (chapter 14).

Cross-check for the system prompt: code word in the system prompt instead of the first message, num_ctx 256, everything else the same. Ollama read 46 tokens, answer „Tulpe“ (Measured on an M4 Mac (24 GB) on November 25, 2026).

## Try it

**Kai’s history in the context window**

**Task:** Kai’s computer has to stay at num_ctx 256. Get the code word back anyway. Then find the smallest window size at which it also works with the filler text.

1. Kai, message 110 tokens

   „Merke dir das Codewort Tulpe.“ (Remember the code word Tulpe.)

2. Kai, message 21,106 tokens

   „Dieser Satz ist nur Fülltext ohne Inhalt. Dieser Satz ist nur Fülltext ohne Inhalt. …“ (This sentence is just filler without content, 79 times the same sentence.)

3. Kai, question31 tokens

   „Wie lautet das Codewort? Antworte mit einem Wort.“ (What is the code word? Answer with one word.)

The slider needs JavaScript. Result from the run: at num_ctx 256 with filler text, the model reads 31 tokens and answers „Kryptogramm“. Without filler text, it reads 41 tokens and answers „Tulpe“. At num_ctx 4,096, it reads all 1,147 tokens and answers „Tulpe“.

Token counts from my own run with qwen3:1.7b and Ollama (Measured on an M4 Mac (24 GB) on November 25, 2026). The filler text is different from the one in the chapter, hence 1,147 instead of 1,085 tokens. The question counts with the control tokens of the chat template. There’s no system prompt in this history. Like Ollama, the slider cuts off whole messages from the front.

## Check

**Question 2 (check question):** How could Kai have spotted the cutoff, even though there was no error message?

- A) The answer sounded unsure and hesitant.
- B) From the number of tokens read: 52 instead of over 1,000.
- C) The answer came much more slowly than usual.

**Question 3 (check question):** Kai sets num_ctx to 4,096. Is the issue settled?

- A) Yes, 4,096 tokens is enough for any normal conversation.
- B) No, he should stay at 256; large windows do harm.
- C) For this test, yes; with longer input, it gets silently trimmed again.

**Question 4 (check question):** One of the bot’s rules must never get lost, even when Ollama trims the history. Where does it belong?

- A) In the system prompt, the fixed instruction in front of the conversation.
- B) In the first message of the conversation, since the model reads it first.
- C) In every answer from the bot, as a constant reminder.

## Done

**What you can do now**

- You can spot silent cutoff: the model reads fewer tokens than expected, and the answer still sounds normal.
- You set the context window deliberately, check from the number of tokens read whether the input fits, and put fixed rules in the system prompt.
- When someone reports that the bot “forgot” something, you first ask how large the context window is set and how many tokens were actually read.

### Two cards for review

**Card 1:** Ollama is set to a context window of 256 tokens, and the messages together have over 1,000 tokens. What happens?

- A) Ollama reports an error.
- B) Ollama silently trims the history from the front, and the model answers anyway.
- C) The model reads everything, just more slowly.

**Card 2:** What’s the difference between compaction and context editing?

- [Next mission: Why does it read fast and write slowly?](https://llm.yoga/en/einsatz-6-1.md)
- [Try it on your Mac](https://llm.yoga/en/mac-5-4.md)

## Read more in the chapter

The full text from the chapter, with the reasoning, calculations and sources:

- [The context window](https://llm.yoga/en/05-kontext-1.md)
- [Compaction and context editing](https://llm.yoga/en/05-kontext-3.md)
- [Exercise: history, cost and cutoff](https://llm.yoga/en/05-kontext-3.md)

## Answers: only reveal them after the learner has answered or explicitly asks

**Question 1:** The correct answer is B.
- A: With 4,096, the same model correctly answered „Tulpe“. It’s not the model; it’s what the model was given to read.
- B, correct: 52 tokens read instead of 1,085: Ollama trimmed the history from the front until it fit into the window. What was left was the question, and the model guessed from that.
- C: Models are more likely to miss things in the middle of long texts (Lost in the Middle). But the code word was at the very beginning, not in the middle. And the model read only 52 tokens. What isn’t read can’t get lost.

**Question 2:** The correct answer is B.
- A: „Code“ came across as a perfectly normal answer. That’s what makes silent cutoff dangerous.
- B, correct: Ollama reports it after every request, and it’s the reliable sign. If it differs clearly from the expected length, Ollama has trimmed.
- C: If anything, the opposite: with 52 instead of 1,085 tokens, the model had less to read. You can’t tell the cutoff from the speed.

**Question 3:** The correct answer is C.
- A: A chat grows with every round, and pasted documents quickly get longer. Above 4,096 tokens, Ollama silently cuts off again.
- B: With 256 tokens, the most important thing is missing here. Long contexts do get less reliable, but a window that can’t hold the necessary input is worse.
- C, correct: Set the window deliberately and keep an eye on the number of tokens read. A larger window also costs memory for the KV cache, the model’s cache for the context (chapter 7).

**Question 4:** The correct answer is A.
- A, correct: In the cross-check, Ollama kept the system prompt when trimming and removed only older messages: with the code word in the system prompt, num_ctx 256 produced „Tulpe“.
- B: That’s the first thing to go when trimming. That’s Kai’s case.
- C: Answers are part of the history and drop out just the same when they get old. And they make every round longer.

**Card 1:** Correct: B, Ollama silently trims the history from the front, and the model answers anyway. Ollama cuts off silently. In the test from chapter 5, qwen3:1.7b read only 52 instead of 1,085 tokens, the code word from the beginning was gone, and the answer „Code“ sounded perfectly normal. You can spot this from the number of tokens read, which Ollama reports after every request.

**Card 2:** Compaction condenses older rounds into a summary. Context editing removes specific things, such as old tool results or thinking blocks. For both: what’s gone is gone. So pull out key facts beforehand and keep them separately.
