Repository navigation
Description
Context
After extensively testing the current implementation of the sliding context window, I conclude it's very much AI-oriented, which causes a lot (hours) of lost time because how fragmented the compacted conversation becomes. It is — in my opinion — one of the biggest issues with Claude, and also one of the reasons to have switched to open-weights/-source options.
Issues
Typical issues include:
Tool calls getting blocked
No room in the window for this result, so mcp__#####__unified_document_manager returned nothing usable. Re-reading will not help. Continue from what you have, and deliver the work in parts if it will not fit at once.
AI getting lost
Opaque compaction and AI "forgetting" to check for prior knowledge: this is attribuable to the fact that the AI is missing an overview of the full thread.
The model frequently calls the "search_conversation" tool now with the latest message to try to understand where it's at, re-filling its context with what often turns out to be loads of old garbage (rather than specifically-needed context).
Proposition
Introduce human-first context window management meeting the following requirements (to be discussed in contributions to this thread):
- The compaction must always submit the entire conversation tree.
- Each message must at least include:
- Some sort of unique id by which it can be called
- Some sequence number, accounting for branches if needed
- The compaction always sends to the model the contents of all previous messages, each in one of the following forms:
- An empty string
- A shortened version (ideally guided by a length parameter)
- A summary
- The full/original contents
- An embedding of the contents, whereby the embedding can happen:
- At the completion of each turn automatically
- When 1st requested (form set to embedding)
- The swap must be controllable (via tools) by the AI (with the option to override by the user) per message.
- The per-message compression settings must persist across turns, i.e. there is a single current state of which message has which compaction setting (empty, shortened, etc. as above) currently chosen.
- The AI or the user can modify the setting for each message before the next run
- The modificaiton of settings should not be blocked by the AI currently running — it shall apply to the next turn (including intermediate turns).
- The UI should allow the user to override the form of each message:
- The user's setting should persist
- The AI's fallback setting should also persist
- The user's setting should apply until it is cleared
UI implementation
Chat view
- For example, a drop-down should appear next to each message, the default option being lighty highlighted, the AI-selected option strongly highlighted, and the user's override should appear in the drop-down window (what's selected).
- A button to clear the user override should appear next to the drop-down.
General settings
- A toggle for the embedding logic (immediate or lazy) should be added to the general settings.
Activity
konradbr commentedon Sep 5, 2026
Additional note on experienced behaviour
Sooner or later the whole conversation starts looping because an (unknown to the user) context gets sent to the AI, which tries to re-pull (de-facto wrong, because missing correct context) older "chunks", which then bloats its context, which compacts again, etc.
konradbr commentedon Sep 5, 2026
Additional note on experienced behaviour I
Sending "no room in the window" responses contradicts the whole point of a context window.
Solution
Using the mechanism described above, the thread should get sent in full with this latest response in summary or truncated form so that the model gets notified and the result is accessible. The model (or even, the user) can then change the form of the thread's messages so that the model can safely process the full (or even, truncated) output for said message.
konradbr commentedon Sep 5, 2026
Additional note on experienced behaviour II
What I have been noticing regarding the
search_conversationbehaviour:Solution
As above:
Current behaviour
Chunks from earlier turns are returned by using the
search_conversationtool.The returned chunks now become part of the (de facto new) context.
Proposed behaviour
The context is modified by changing which messages are sent in full.
Griggelor commentedon Oct 27, 2026
I can confirm this is still an issue in Unsloth Studio v0.1.911-beta. I've been observing it for several weeks.
Setup
rolling, overflow:truncate_oldest0.35Latest observation: ~9-hour agent run
Current workaround
My system prompt explicitly instructs the agent to handle missing tool results and context-limit messages: check whether operations actually completed, inspect saved files, recover results, retry if necessary, and keep working.
This helps, but shouldn't be necessary.
Expected behavior
Context management should be almost invisible to the agent, making long-running sessions feel like they have unlimited context:
Ideally, an agent should be able to work for hours or days through repeated context rotations without getting stuck or losing access to tool results.
The full backend and llama-server logs from the 9-hour run are available if helpful.
jploski commentedon Nov 4, 2026
Instead of a particular implementation of compaction, it would be great to make it possible to plug in custom (out-of-process, API-fied) compaction logic.
Also, add API to remove or inject messages from/to an existing chat session programatically, or just edit the whole chat session. The edits more or less need to pass through the chat client because if performed server-side through a proxy, the client keeps sending the pruned messages (and they have to be pruned away again on each turn, while the client is getting sluggish from the ever-growing fake context window).
Built-in hard-coded compaction schemes, however they are implemented, will be suboptimal depending on application.
It appears that today no chat client supports custom compaction/session editing (e.g. see the rejected OpenCode feature: openchamber/openchamber#2599). But custom, application-specific session management goes a long way of making an agent appear both smart and fast, rather than the usual "summarize at the end and forget half the important things while keeping plenty of unnecessary details" scenario. The key insight is to realize that Unsloth has no way of guiding the agent which messages/tools are really important, but a custom logic infused with application knowledge might.
Force-injecting tools like search_conversation (apparently with no way to disable this behavior?) and auto-indexing stuff through Unsloth's baked in RAG is maybe nice as a simple reference implementation for a better out-of-the-box experience. But having such features hard-coded into an otherwise quite flexible client framework is unfortunate.
ReinerBforartists commentedon Nov 23, 2026
+1 for this approach. Two additions from using Studio with Qwen3.8 on a local GGUF:
A per-message form that is a lossless rewrite (same content, fewer tokens: no filler, quoted facts/paths/numbers/code kept verbatim) would be more useful than a summary for long coding sessions. It could be computed once per turn after the reply and stored, so the prompt prefix stays stable and the llama.cpp prompt cache keeps hitting.
Reasoning is a separate part of the problem. Qwen3.8's template preserves prior blocks by default (preserve_thinking), so they fill the window, but render_turn() in conversation_archive.py only indexes content and tool calls, so after a checkpoint reset the earlier reasoning is neither in the prompt nor searchable. A per-message form for reasoning (drop / shorten) would help.
EDIT
Prior art for the compression step itself (no claim about their numbers, only that the pattern exists and is reversible): LLMLingua-2 (small distilled model, usable as a Python library, so it could run in-process in the backend) and Headroom (OpenAI-compatible proxy; compressed content stays retrievable from a cache, which matches the per-message "form" idea here).