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
-
Tell the agent the size of the window. Either set
contextWindowin the YAML to the value you started the server with, or leave it at0on llama.cpp, where the agent readsn_ctxfrom/props. The banner shows the result asctx: <size> (config)orctx: <size> (/props). -
Turn the automatic compression on:
context: enabled: true threshold: 75 keepLastTurns: 3Before 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.
-
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
contextWindowis0). Only themaxMessagestrigger can fire; the agent says so in a start-up warning. SetmaxMessagesto a message count (one command costs two messages) or setcontextWindow. - Compress by hand. Type
/compactat the prompt, or send it from the editor in ACP mode. It ignores the threshold but still keeps the lastkeepLastTurnsturns, and says🗜️ nothing to compactwhen 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.promptto replace the built-in seven-section prompt. - A compression that fails (server down, watchdog) leaves the history unchanged and prints
[compact: failed, history kept: …].
See also
- Every
context.*key and its default: configuration reference - Why the summary keeps recent turns raw and merges earlier summaries: context compression
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 |
|