Codumentor logo Codumentor

Context Management Plugin

The Context Management plugin keeps long conversations usable by summarizing
older turns in the background and, when it helps, replacing distant history
with those summaries before the next model call. Unlike
Context Summarization (which reacts when the
context window overflows), this plugin runs after every turn.

It maintains several summaries of the same conversation at different lengths
(15, 50, 250, and 1000 tokens by default). When the topic shifts, older
summaries cascade down to shorter levels so distant history stays compact
while recent discussion stays detailed.

How compression looks

Context sent to the model:
┌────────────────────────────────────────────────────────┐
│ Distant history  — ~15 tokens (oldest, most compressed)│
│ Older history    — ~50 tokens                          │
│ Past history     — ~250 tokens                         │
│ Recent history   — ~1000 tokens                        │
│ Raw messages from after the latest compaction point    │
└────────────────────────────────────────────────────────┘

A topic shift moves the previous 1000-token summary down to 250 tokens, 250
down to 50, and 50 down to 15, and starts a new 1000-token summary at the
shift. Detail increases as you approach the present.

When estimate_sufficient_tokens is on (the default), each turn also gets an
estimate of how short a summary can be and still be adequate — a typo-fix
might need ~30 tokens; an architecture discussion might need ~800. Smaller
levels are used when they are already enough.

Compacted summaries can include retrieval hints: short phrases naming
details that were compressed away (for example "JWT expiry, refresh flow,
error codes") so the agent knows what it can ask about.

Configuration

plugins:
  - module: codumentor.plugins.context_management
    class: ContextManagementPlugin
    args:
      enabled: true
      target_token_levels: [15, 50, 250, 1000]
      provide_retrieval_tool: true
      min_turns_before_compaction: 3
      compaction_token_threshold: 1000
      ui_verbosity: normal

Parameters

UI verbosity

LevelCards shown
"all"Per-turn state updates, topic shifts, and compaction
"normal"Topic shifts and compaction (default)
"minimal"Topic shifts only
"off"None

Each user can also change Card Visibility in Settings (same four values).

args:
  ui_verbosity: minimal   # only topic-shift cards

Custom token levels

args:
  target_token_levels: [10, 100, 500, 2000]
  compaction_token_threshold: 2000

The retrieve_conversation_history tool's brief / medium / full levels
still map to 50 / 250 / 1000 tokens even if you change target_token_levels.

Retrieval tool

When provide_retrieval_tool is true, the agent can call
retrieve_conversation_history:

ArgumentMeaning
start_turnFirst turn (1-based)
end_turnLast turn, inclusive
detail_level"brief" (~50 tokens), "medium" (~250, default), "full" (~1000), or "raw" (original messages)

Disable the tool if you do not want the agent pulling old turns back:

args:
  provide_retrieval_tool: false

Notes