Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,8 @@ subAgentsTemperature:
textEditor: 0.4
translator: 0.3
summarization:
enabled: true
keepMessages: 5
trigger:
type: tokens
value: 100000
contextFraction: 0.8
telemetry:
enabled: false
exporter:
Expand Down
13 changes: 6 additions & 7 deletions coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ℹ compaction.js | 98.84 | 78.43 | 100.00 | 89-90
ℹ contextBackend.js | 100.00 | 100.00 | 100.00 |
ℹ coreBackend.js | 100.00 | 100.00 | 100.00 |
ℹ deepAgents.js | 93.72 | 69.39 | 66.67 | 156-157 181 197-199 309-316 345-346 459-461 488-500 511 579-580 590-592
ℹ deepAgents.js | 93.91 | 70.83 | 77.78 | 155-156 180 196-198 308-315 344-345 458-460 474-480 531-535 543-545
ℹ evictionCeiling.js | 100.00 | 100.00 | 100.00 |
ℹ skillsMiddleware.js | 100.00 | 87.50 | 100.00 |
ℹ config | | | |
Expand Down Expand Up @@ -62,7 +62,6 @@
ℹ index.js | 100.00 | 100.00 | 100.00 |
ℹ modelInfo.js | 97.25 | 93.98 | 100.00 | 128-129 131-132 179-180
ℹ openai.js | 92.72 | 75.71 | 78.57 | 65 90-92 138-139 145-146 233 236-238 257-259 267-271 279-280 292-295
ℹ summarizationMiddleware.js | 97.01 | 94.00 | 83.33 | 107 126-128 149
ℹ tokenBudget.js | 97.14 | 85.71 | 82.35 | 50-51 83-84
ℹ tokenBudgetMiddleware.js | 98.10 | 78.67 | 87.50 | 94-95 97-98
ℹ sandbox | | | |
Expand Down Expand Up @@ -187,7 +186,7 @@
ℹ xlsxParser.js | 82.21 | 83.33 | 88.89 | 47-48 93-112 130-137 150-156
ℹ zipExtractor.js | 82.32 | 77.78 | 66.67 | 62-63 104-107 124-142 149-152
ℹ git | | | |
ℹ index.js | 87.41 | 64.37 | 83.69 | 324-326 379-380 393-396 481-483 515-516 626-643 689-691 722-723 755-757 821-824 840-843 866-872 906 908-912 914-917 929-933 976-980 984 989-991 1006-1015 1024 1038-1044 1046-1049 1057-1063 1086-1091 1093-1099 1101-1110 1112-1115 1122-1126 1136-1143 1191-1192 1194-1199 1291-1292 1314-1315 1323-1324 1331-1332 1334-1340 1362 1366-1368 1373-1376 1428-1435 1439-1447 1450-1453 1455-1458
ℹ index.js | 87.41 | 64.13 | 83.69 | 324-326 379-380 393-396 481-483 515-516 626-643 689-691 722-723 755-757 821-824 840-843 866-872 906 908-912 914-917 929-933 976-980 984 989-991 1006-1015 1024 1038-1044 1046-1049 1057-1063 1086-1091 1093-1099 1101-1110 1112-1115 1122-1126 1136-1143 1191-1192 1194-1199 1291-1292 1314-1315 1323-1324 1331-1332 1334-1340 1362 1366-1368 1373-1376 1428-1435 1439-1447 1450-1453 1455-1458
ℹ graphql | | | |
ℹ index.js | 97.85 | 98.13 | 93.75 | 57-68
ℹ image | | | |
Expand Down Expand Up @@ -243,15 +242,15 @@
ℹ yaml | | | |
ℹ index.js | 100.00 | 94.38 | 100.00 |
ℹ tui | | | |
ℹ app.js | 45.57 | 56.52 | 21.05 | 160 171 181-187 197-206 214-219 227-230 251-283 290-299 308-335 351-369 379-387 394-402 409-454 460-464 468-591 602-606 609-619 622-635 641-644 656-661 663-667 669-673 675-682 684-690 692-700 715-725 732-774 801-802
ℹ app.js | 45.63 | 55.32 | 21.05 | 160 171 181-187 197-206 214-219 227-230 251-283 290-299 308-335 351-369 379-387 394-402 409-454 460-464 468-591 602-606 609-619 622-635 641-644 656-661 663-667 669-673 675-682 684-690 692-700 715-725 732-774 802-803
ℹ banner.js | 90.36 | 100.00 | 83.33 | 27-34
ℹ commandHelp.js | 100.00 | 100.00 | 100.00 |
ℹ commandParser.js | 97.56 | 89.87 | 100.00 | 90-95
ℹ commandPicker.js | 73.87 | 88.46 | 81.82 | 134-138 143-184 207-217
ℹ conversationPanel.js | 95.45 | 95.83 | 100.00 | 26-31
ℹ filePicker.js | 69.72 | 89.66 | 73.33 | 143-168 194-195 200-244 267-279
ℹ headerClick.js | 99.02 | 96.55 | 100.00 | 99
ℹ inputArea.js | 81.30 | 75.51 | 46.43 | 159-160 174 188-191 199-211 219-235 239-240 246-247 250-255 322-330 334-338 342-346
ℹ inputArea.js | 81.41 | 75.51 | 46.43 | 160-161 175 189-192 200-212 220-236 240-241 247-248 251-256 324-332 336-340 344-348
ℹ inputPanel.js | 100.00 | 100.00 | 100.00 |
ℹ linkHit.js | 100.00 | 91.67 | 100.00 |
ℹ markdownText.js | 97.50 | 86.87 | 96.15 | 76 206-212 236-238
Expand All @@ -271,7 +270,7 @@
ℹ sessionsPanel.js | 83.19 | 41.03 | 90.91 | 44-47 80-81 97-98 102-104 111-115 140-142 151-152 167-173 176-182 193-196
ℹ settingsPanel.js | 72.02 | 80.00 | 73.33 | 55-69 95-121 158-168 174-178 184-186
ℹ skillsPanel.js | 86.67 | 55.56 | 66.67 | 45-47 53-59
ℹ statusBar.js | 99.05 | 98.11 | 100.00 | 29-30
ℹ statusBar.js | 99.11 | 98.15 | 100.00 | 34-35
ℹ subagentsPanel.js | 96.40 | 74.42 | 86.36 | 62-64 101-105
ℹ subagentStore.js | 100.00 | 100.00 | 100.00 |
ℹ useMouseScroll.js | 100.00 | 100.00 | 100.00 |
Expand All @@ -286,6 +285,6 @@
ℹ loadAgents.js | 74.29 | 78.57 | 50.00 | 25-26 41 56-70
ℹ project.js | 100.00 | 100.00 | 100.00 |
ℹ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ℹ all files | 93.39 | 86.75 | 88.37 |
ℹ all files | 93.38 | 86.70 | 88.51 |
ℹ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ℹ end of coverage report
25 changes: 8 additions & 17 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,8 @@ Graceful shutdown flushes all buffered log entries to disk before process exit.
| `search` | `tavily.apiKey` | _(empty)_ | Tavily search API key |
| `skillAgentMap` | `[].pattern` | _(none)_ | Regex pattern to match skill names |
| | `[].agent` | _(none)_ | Agent name to assign when pattern matches |
| `summarization` | `enabled` | `false` | Enable proactive context compaction |
| | `trigger.type` | `tokens` | Trigger type (`tokens`, `messages`, `fraction`) |
| | `trigger.value` | `100000` | Trigger threshold value |
| | `keepMessages` | `5` | Most recent messages kept verbatim after compaction (older history becomes one summary) |
| | `keep` _(deprecated)_ | _(none)_ | Legacy form; a `messages` value is used when `keepMessages` is unset |
| `summarization` | `keepMessages` | `5` | Most recent messages kept verbatim after compaction (older history becomes one summary) |
| | `contextFraction` | `0.8` | Fraction of the context window at which the TUI auto-compacts |
| `vector` | `model` | `local` | Embedding model (`local` or `openai`) |
| | `projects.<name>.rootDir` | `.` | Project root directory to scan |
| | `projects.<name>.dbPath` | _(none)_ | Path to sqlite-vec database file |
Expand Down Expand Up @@ -151,28 +148,22 @@ Each element renders only when its boolean is `true` **and** its data is present

### Summarization

The `summarization` section controls proactive context compaction. When `enabled` is `false` (the default), deepagents' library default applies — a 170k token trigger that keeps the last 6 messages, and compaction only happens **reactively** after a request overflows the context window. When `enabled` is `true`, madz registers its own `SummarizationMiddleware` that fires at the configured `trigger`, so compaction is **proactive**.
The `summarization` section controls context compaction. The TUI compacts automatically once the context (the same count the status bar shows) reaches `contextFraction` of the model's context window, checked before each new message and after each turn. `/compact` runs the same routine manually, and the reactive context-window handler remains the safety net if a request still overflows.

```yaml
summarization:
enabled: true
trigger:
type: tokens
value: 100000
keepMessages: 5
contextFraction: 0.8
```

When the trigger fires, madz summarizes the history and **rewrites the checkpointer** to `[summary, ...last keepMessages messages]`. The system prompt is injected on every call rather than stored in state, so it is unaffected. The old history is not kept in state; the summarized messages are saved best-effort to `/conversation_history/` and the summary links to that file.
When compaction runs, madz summarizes the history and **rewrites the checkpointer** to `[summary, ...last keepMessages messages]`. The system prompt is injected on every call rather than stored in state, so it is unaffected.

- **`trigger`** — the threshold at which compaction fires. `tokens` counts the system prompt plus all stored messages; `messages` counts stored messages. `fraction` is not supported by the proactive middleware.
- **`keepMessages`** — how many recent messages stay verbatim (default `5`). The tail never starts on a tool result: if the boundary lands on one, the whole tool call and result are summarized and the tail shrinks (possibly to zero).
- **`contextFraction`** (default `0.8`) — when the model's context length can be resolved at startup, the trigger is overridden with 80% of that context length (the configured `trigger.value` is then only a fallback).
- **`contextFraction`** (default `0.8`) — fraction of the context window at which auto-compaction fires. The status bar's context meter and streaming spinner turn red at the same point. The window is the model's real context length when it can be resolved at startup, otherwise the configured `contextWindow`.

The summary is stored as a user message (some providers reject mid-conversation system messages). If summarization fails, state is left unchanged, a warning is logged, and compaction is retried after a few more messages; the reactive context-window handler remains the safety net. `/compact` uses the same routine.
The summary is stored as a user message (some providers reject mid-conversation system messages). If summarization fails, the legacy trim-only fallback is used.

Token counts come from the model's real tokenizer — the same count the status bar shows — so a status bar at 80% means compaction fires on the next model call. If the tokenizer is unavailable or errors, a characters-per-token estimate is used.

**Note:** the custom middleware reaches the **orchestrator only**. Subagents are not forked, so they keep the library default `SummarizationMiddleware`.
**Note:** the removed keys `enabled`, `trigger` and `keep` are now rejected by the config schema; delete them from `config.yaml`.

### API Tool

Expand Down
11 changes: 4 additions & 7 deletions docs/DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,10 @@ The active provider is selected by the `enabled` flag, not by config position or

### Summarization

| Variable | Default | Description |
| ----------------------------- | ---------- | ----------------------------------------------- |
| `SUMMARIZATION_ENABLED` | `false` | Enable proactive context compaction |
| `SUMMARIZATION_TRIGGER_TYPE` | `tokens` | Trigger type (`tokens`, `messages`, `fraction`) |
| `SUMMARIZATION_TRIGGER_VALUE` | `100000` | Trigger threshold value |
| `SUMMARIZATION_KEEP_TYPE` | `messages` | Keep type (`tokens`, `messages`, `fraction`) |
| `SUMMARIZATION_KEEP_VALUE` | `10` | Messages/tokens to keep after compaction |
| Variable | Default | Description |
| -------------------------------- | ------- | ------------------------------------------------------------- |
| `SUMMARIZATION_CONTEXT_FRACTION` | `0.8` | Fraction of the context window at which the TUI auto-compacts |
| `SUMMARIZATION_KEEP_MESSAGES` | `5` | Recent messages kept verbatim after compaction |

### Vector Search

Expand Down
9 changes: 1 addition & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ export function bootstrap() {
async function doBootstrap() {
config = loadConfig();

const { createDeepAgentsOrchestrator, toConversationExchange } =
await import("./src/agent/deepAgents.js");
const { createDeepAgentsOrchestrator } = await import("./src/agent/deepAgents.js");
const { ensureToolsDir, ensureScreenshotsDir, ensureContextDir, expireEphemeralMemories } =
await import("./src/memory/index.js");
const { ensureDownloadsDir } = await import("./src/downloads/index.js");
Expand Down Expand Up @@ -266,12 +265,6 @@ async function doBootstrap() {
// Manual context compaction (the `/compact` slash command)
compactContext = (options) => agent.compactContext(currentSessionConfig(), sessionState, options);

// Automatic compaction rewrites the checkpointer mid-run; keep the session's
// conversation in step so saved sessions and the TUI agree with the model.
agent.onCompacted?.((result) => {
sessionState.loadConversation(result.messages.map(toConversationExchange));
});

// Real LangChain message array from the checkpointer for the context counter.
// Returns null on failure so the TUI falls back to sessionState.
getContextMessages = async () => {
Expand Down
Loading
Loading