Context squeeze
Keeps long conversations inside a small context window: each aged turn is replaced by one structured summary, the newest turns stay verbatim, and the agent can expand any summary back to the original log on demand. The full transcript stays in the session log and in the UI.
Cost
In the author's own tests, the average session cost was about 40% lower. That figure comes from the author's own long sessions, not a controlled benchmark; the gain depends on conversation length and how much tool output the session produces.
How it works
After a turn ends and the agent is idle:
- The oldest surface span outside the retained window is selected (the newest 2 completed turns stay verbatim by default).
- The cut is aligned to tool-call / tool-result pairs so a tool call is never split.
- The plugin's own summarization prompt turns the span into a structured checkpoint (goals, decisions, facts, files, errors, next steps, expandable clues).
- The span is replaced through the Harness surface replacement primitive, with a
compaction/summaryrecord that carries the shadowed token count and the summarizer usage.
The expand_context tool
expand_context({ id?: "squeeze-…", query?: "keyword", maxChars?: 8000 })
- Without
id: list the squeezed spans of this session. - With
id: return the original messages, truncated tomaxChars. - With
query: only messages mentioning the keyword.
Configuration
Configure the context-squeeze row in cordis.patch.yml:
| Field | Default | Meaning |
|---|---|---|
enabled |
true |
Master switch. |
retainTurns |
2 |
Newest completed turns kept verbatim. |
maxRegionChars |
60000 |
Input cap for one squeeze. |
minRegionChars |
1200 |
Skip smaller spans. |
maxSummaryTokens |
1200 |
Summary output cap. |
messageChars |
4000 |
Per-message cap while rendering the span. |
expandChars |
8000 |
Default expansion budget. |
expandMaxChars |
24000 |
Hard expansion cap. |
timeoutMs |
180000 |
Summarizer timeout. |
Install
dsh plugin --profile web add dsh-context-squeeze
Host-only plugin; no browser UI. Requires DSH 0.2.2-rc.5 or later.
Limits
- Fixed overhead (system prompt, tool schemas, runtime context) is not compressed.
- The newest
retainTurnsturns and the current turn stay verbatim. - When a summary would be at least 90% of the original size, the original is kept.
- Subagent sessions are skipped.
- Coexists with the built-in
/compact; both write standardcompaction/*records.
License
MIT. See LICENSE.
还没有评论,来写第一条。