bots-garden/mini-mepublic Fork
⑂ v2.2.2
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/mini-me.git
git clone ssh://git@rickub.com/bots-garden/mini-me.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
manage-the-context-window.md · 41 lines · 3.8 KBmarkdown
Blame HistoryOpen raw

How to keep a long session inside the context window

This guide shows how to stop a long session from overflowing the model's context. It assumes you already run mm and know which server serves your model.

Steps

  1. Tell the agent the size of the window. Either set contextWindow in the YAML to the value you started the server with, or leave it at 0 on llama.cpp, where the agent reads n_ctx from /props. The banner shows the result as ctx: <size> (config) or ctx: <size> (/props).

  2. Turn the automatic compression on:

    context:
      enabled: true
      threshold: 75
      keepLastTurns: 3
    

    Before each question, when the history reaches 75 % of the window, the old turns are replaced by one model-written summary and the last three question turns are kept as they are.

  3. Watch the report. With showStats: true (the default) each compression prints one dimmed line:

    🗜️ compressed 14 messages → 1 summary + 7 kept (18.2k → 4.1k tokens, 6.3s)
    

Variants

  • The window stays unknown (Docker Model Runner tells nothing, and contextWindow is 0). Only the maxMessages trigger can fire; the agent says so in a start-up warning. Set maxMessages to a message count (one command costs two messages) or set contextWindow.
  • Compress by hand. Type /compact at the prompt, or send it from the editor in ACP mode. It ignores the threshold but still keeps the last keepLastTurns turns, and says 🗜️ nothing to compact when there is nothing older.
  • The server was started after the agent. The window is re-probed before the first question while it is still unknown and compression is on; you do not need to restart.
  • Your own summary prompt. Set context.prompt to replace the built-in seven-section prompt.
  • A compression that fails (server down, watchdog) leaves the history unchanged and prints [compact: failed, history kept: …].
  • A 🗜️ in-turn: line ends with "the history before this turn is above the threshold by itself". The earlier turns alone fill the window past the threshold, so the turn is not summarised again. Lower context.keepLastTurns (to 1 for the smallest windows), or run /compact (or /new) before the next question; asking for smaller steps also keeps the history low.
  • A turn ends with "the request (about N tokens, even compressed) is larger than the context window (W), so it was not sent". The work done is kept: ask to continue. If the server serves more than contextWindow, raise contextWindow to its real size; otherwise lower maxOutput so a single tool output takes less of the window, or lower threshold.
  • Tool results start with "[mm: you already ran this exact call earlier in this task…" or the turn ends at maxTurns with reads only. The files the task needs do not fit the window together. Split the request so each step needs less at once — for example "list the routes of server.go and their JSON bodies in API.md", then "write web/app.js from API.md" — or raise contextWindow if the server serves more. Raising maxTurns only makes the reading last longer. A 🔁 not run: … line means context.rereadLimit refused a third identical read; set it to 0 to keep the notes without refusing.
  • Each call after a compression is slow (the server reads the whole prompt again: no cached_tokens in a trace). The compression comes back too often: lower context.inTurnTarget (for example 40 with threshold: 60), so a compression lasts several calls. Raise context.summaryMaxTokens if a 🗜️ a summary was cut line appears.

See also

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# How to keep a long session inside the context window

This guide shows how to stop a long session from overflowing the model's context. It assumes you already run `mm` and know which server serves your model.

## Steps

1. Tell the agent the size of the window. Either set `contextWindow` in the YAML to the value you started the server with, or leave it at `0` on llama.cpp, where the agent reads `n_ctx` from `/props`. The banner shows the result as `ctx: <size> (config)` or `ctx: <size> (/props)`.

2. Turn the automatic compression on:

   ```yaml
   context:
     enabled: true
     threshold: 75
     keepLastTurns: 3
   ```

   Before each question, when the history reaches 75 % of the window, the old turns are replaced by one model-written summary and the last three question turns are kept as they are.

3. Watch the report. With `showStats: true` (the default) each compression prints one dimmed line:

   ```
   🗜️ compressed 14 messages → 1 summary + 7 kept (18.2k → 4.1k tokens, 6.3s)
   ```

## Variants

- **The window stays unknown** (Docker Model Runner tells nothing, and `contextWindow` is `0`). Only the `maxMessages` trigger can fire; the agent says so in a start-up warning. Set `maxMessages` to a message count (one command costs two messages) or set `contextWindow`.
- **Compress by hand.** Type `/compact` at the prompt, or send it from the editor in ACP mode. It ignores the threshold but still keeps the last `keepLastTurns` turns, and says `🗜️ nothing to compact` when there is nothing older.
- **The server was started after the agent.** The window is re-probed before the first question while it is still unknown and compression is on; you do not need to restart.
- **Your own summary prompt.** Set `context.prompt` to replace the built-in seven-section prompt.
- **A compression that fails** (server down, watchdog) leaves the history unchanged and prints `[compact: failed, history kept: …]`.
- **A `🗜️ in-turn:` line ends with "the history before this turn is above the threshold by itself".** The earlier turns alone fill the window past the threshold, so the turn is not summarised again. Lower `context.keepLastTurns` (to `1` for the smallest windows), or run `/compact` (or `/new`) before the next question; asking for smaller steps also keeps the history low.
- **A turn ends with "the request (about N tokens, even compressed) is larger than the context window (W), so it was not sent".** The work done is kept: ask to continue. If the server serves more than `contextWindow`, raise `contextWindow` to its real size; otherwise lower `maxOutput` so a single tool output takes less of the window, or lower `threshold`.
- **Tool results start with "[mm: you already ran this exact call earlier in this task…"** or the turn ends at `maxTurns` with reads only. The files the task needs do not fit the window together. Split the request so each step needs less at once — for example "list the routes of server.go and their JSON bodies in API.md", then "write web/app.js from API.md" — or raise `contextWindow` if the server serves more. Raising `maxTurns` only makes the reading last longer. A `🔁 not run: …` line means `context.rereadLimit` refused a third identical read; set it to `0` to keep the notes without refusing.
- **Each call after a compression is slow** (the server reads the whole prompt again: no `cached_tokens` in a trace). The compression comes back too often: lower `context.inTurnTarget` (for example 40 with `threshold: 60`), so a compression lasts several calls. Raise `context.summaryMaxTokens` if a `🗜️ a summary was cut` line appears.

## See also

- Every `context.*` key and its default: [configuration reference](../reference/configuration.md)
- Why the summary keeps recent turns raw and merges earlier summaries: [context compression](../explanation/context-compression.md)