Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
docs(agent): document the compaction trigger and its per-provider override
thinhlpgb1ca1b04e99f
diff --git a/docs/src/pages/docs/agent/context.mdx b/docs/src/pages/docs/agent/context.mdxindex 32181857d..5f260ba43 100644--- a/docs/src/pages/docs/agent/context.mdx+++ b/docs/src/pages/docs/agent/context.mdx@@ -96,20 +96,39 @@ than counted as free. `/new` starts a new session, and a new count.## Automatic compaction-As the conversation approaches the window, older turns are summarized to make room. The reserve is-the headroom kept free so compaction has space to work in:+As the conversation approaches the window, older turns are summarized to make room. The trigger is a+share of the window, not a fixed number of tokens:```toml[agent]-context_window = 128000 # defaults to 128K-compaction_reserve_tokens = 16384 # defaults to 16K+context_window = 128000 # defaults to 128K+compaction_ratio = 0.8 # share of the window the prompt may fill; defaults to 0.8+# compaction_reserve_tokens = 16384 # absolute headroom instead, in tokens```-Compaction triggers as usage nears `context_window - compaction_reserve_tokens`. When it runs, the-session history is replaced with the compacted version and the console says so:+Compaction fires when the request about to be sent reaches `context_window * compaction_ratio` - 80%+of a 128K window is ~102K. The ratio is the default because it scales with the window: a fixed 16K+reserve is 12% of a 128K window but only 1.6% of a 1M one, where the prompt would grow into a+provider rejection before anything triggered. Setting `compaction_reserve_tokens` pins absolute+headroom instead, and wins over the ratio.++A provider entry can override the ratio for its own routes - windows differ by an order of magnitude+across providers, so one number cannot suit them all:++```toml+[provider]+name = "small-window"+compaction_ratio = 0.6+```++The check runs on the request itself, before it is dispatched, so the break lands at a point the+session chose rather than after a provider rejects an oversized prompt and the run retries. When it+runs, the session history is replaced with the compacted version, the transcript is told, and the+console says so:```auto-compacted 84 -> 31 messages (ctx 96K/128K)+compacted 84 messages into a summary before sending (104K tokens against a 102K token budget)```## Compacting on purpose@@ -128,9 +147,10 @@ preserves the thread of the conversation, including the parts that sent it off c## Context overflow-If a request overflows anyway, the loop compacts and retries rather than erroring out. Each retry-keeps a smaller tail of recent messages. If a pass fails to shrink the conversation at all, it gives-up rather than looping.+If a request overflows anyway, the loop compacts and retries rather than erroring out. That path is+still needed: a route served by a local engine carries no window the loop can read, and an estimate+is an estimate. Each retry keeps a smaller tail of recent messages. If a pass fails to shrink the+conversation at all, it gives up rather than looping.## Capping outputdiff --git a/docs/src/pages/docs/agent/project-config.mdx b/docs/src/pages/docs/agent/project-config.mdxindex f1cb89d8d..a92b5666b 100644--- a/docs/src/pages/docs/agent/project-config.mdx+++ b/docs/src/pages/docs/agent/project-config.mdx@@ -59,7 +59,8 @@ Point at a different file with `instructions_file` if you already keep conventio[agent]# model = "Jan-V4"# context_window = 128000-# compaction_reserve_tokens = 16384+# compaction_ratio = 0.8 # share of the window a prompt may fill before compacting+# compaction_reserve_tokens = 16384 # absolute headroom instead, in tokens; wins over compaction_ratio# max_tokens = 4096# max_parallel_subagents = 10 # max concurrently-running subagents per run; extra dispatches queue FIFO# show_reasoning = false # unfold thinking blocks in the transcript (Ctrl-O still toggles)@@ -72,6 +73,7 @@ instructions_file = "AGENT.md"# api_key = "sk-..."# base_url = "https://api.openai.com/v1"# models = ["gpt-4o"]+# compaction_ratio = 0.6 # override the [agent] ratio for this provider's routes# The run's only cap: new token spend across all turns (replayed context is not# recharged each turn). There is no turn limit. Defaults to 128000 when unset;@@ -100,7 +102,8 @@ inject = "always"| --- | --- | --- || `model` | inherited | Model id. Overridden by `--model` || `context_window` | `128000` | Context limit in tokens |-| `compaction_reserve_tokens` | `16384` | Headroom kept free before [compaction](/docs/agent/context) |+| `compaction_ratio` | `0.8` | Share of `context_window` a prompt may fill before [compaction](/docs/agent/context). Values outside `0.1`-`0.99` are clamped |+| `compaction_reserve_tokens` | unset | Absolute headroom instead of the ratio, in tokens. Wins over `compaction_ratio` when set || `max_tokens` | unset | Cap on tokens generated per response. Omitted from the request when unset || `max_parallel_subagents` | `10` | Subagents that may run at once (min 1); extra dispatches queue FIFO || `show_reasoning` | `false` | Unfold model reasoning (`<thinking>`) blocks in the transcript instead of folding them to a summary row. <kbd>Ctrl</kbd>+<kbd>O</kbd> still toggles a folded block |@@ -113,6 +116,10 @@ inject = "always"A project-local provider override, winning over `~/.jan/config.toml` and anything inherited from JanDesktop. Most projects don't need it. See [Providers](/docs/agent/providers#per-project-override).+| Key | Default | Description |+| --- | --- | --- |+| `compaction_ratio` | inherited | Share of `context_window` a prompt may fill before [compaction](/docs/agent/context) for requests this provider serves. Overrides the `[agent]` value, so a route with a small window can be tuned without loosening it for every other route |+### `[budget]`| Key | Default | Description |diff --git a/docs/src/pages/docs/agent/providers.mdx b/docs/src/pages/docs/agent/providers.mdxindex 757fbb7ff..bf56351b7 100644--- a/docs/src/pages/docs/agent/providers.mdx+++ b/docs/src/pages/docs/agent/providers.mdx@@ -134,6 +134,9 @@ name = "openai"api_key = "sk-..."base_url = "https://api.openai.com/v1"models = ["gpt-4o"]+# Optional: when this route's runs compact, as a share of the window. See+# [Context and compaction](/docs/agent/context).+# compaction_ratio = 0.6```<Callout type="warning">diff --git a/docs/src/pages/docs/agent/slash-commands.mdx b/docs/src/pages/docs/agent/slash-commands.mdxindex 12134aab9..7e1a54941 100644--- a/docs/src/pages/docs/agent/slash-commands.mdx+++ b/docs/src/pages/docs/agent/slash-commands.mdx@@ -69,7 +69,7 @@ See [Run modes](/docs/agent/run-modes), [Goals and todos](/docs/agent/goals-and-| `/login` | Sign in to Tokamak and save the API key || `/config` | View provider config (`~/.jan/config.toml`) || `/terminal-setup` | Configure this terminal so <kbd>Shift</kbd>+<kbd>Enter</kbd> inserts a newline and, on macOS, <kbd>Option</kbd>+<kbd>Delete</kbd> deletes a word. Writes the terminal's own config where it can (VS Code, kitty, Ghostty, tmux) and prints the manual step where it cannot. Idempotent |-| `/settings [max_parallel_subagents N]` | Edit settings in an interactive menu - the project's `agent.toml` (`[agent]` knobs `context_window`, `compaction_reserve_tokens`, `max_tokens`, `max_parallel_subagents`, `instructions_file`, `[budget]` limits, the `[tools]` / `[skills]` toggles) and user-wide `~/.jan/config.toml` keys such as `wave` and `ask_timeout_secs` in the one list (Enter edits a row, `x` resets to default, Esc cancels, clearing the field unsets - except `wave`, where an empty field is the "no sweep" value and `x` restores the default π). The leading `providers` row opens a manager for OpenAI-compatible providers in `~/.jan/config.toml`: `a` adds, Enter edits, `d` twice deletes. `max_parallel_subagents N` works as a one-shot shortcut. Writes apply on the next run, except cosmetic ones like `wave` that apply immediately |+| `/settings [max_parallel_subagents N]` | Edit settings in an interactive menu - the project's `agent.toml` (`[agent]` knobs `context_window`, `compaction_ratio`, `compaction_reserve_tokens`, `max_tokens`, `max_parallel_subagents`, `instructions_file`, `[budget]` limits, the `[tools]` / `[skills]` toggles) and user-wide `~/.jan/config.toml` keys such as `wave` and `ask_timeout_secs` in the one list (Enter edits a row, `x` resets to default, Esc cancels, clearing the field unsets - except `wave`, where an empty field is the "no sweep" value and `x` restores the default π). The leading `providers` row opens a manager for OpenAI-compatible providers in `~/.jan/config.toml`: `a` adds, Enter edits, `d` twice deletes. `max_parallel_subagents N` works as a one-shot shortcut. Writes apply on the next run, except cosmetic ones like `wave` that apply immediately |See [Providers](/docs/agent/providers), [MCP](/docs/agent/mcp), [Plugins](/docs/agent/plugins), and[Keybindings](/docs/agent/keybindings#shiftenter-and-the-option-key).