Automatic context compaction in Amplifier
As an agent works, its conversation history keeps growing. Left unmanaged, a human ends up pruning context by hand, or the session crashes on a cryptic token-overflow API error. Either way the person becomes the bottleneck.
Amplifier's answer: make managing the budget the agent's job, not yours.
SimpleContextManager is Amplifier's reference and default context manager (1390 lines in one module). And its compaction was designed to happen before overflow, not after — proactively, so sessions don't crash.
So how does it keep the budget under control on its own?
It watches the token budget — provider context_window, minus a 50% output reserve, minus a 4096-token safety margin. When usage crosses the threshold, it compacts to restore headroom so work continues.
But automatic compaction is only safe if nothing is actually lost.
Compaction is ephemeral: get_messages_for_request() returns a compacted VIEW without modifying stored messages, while get_messages() always returns the full, uncompacted history for transcripts and replay.
Trustworthy automation — which is exactly why silent failure is so dangerous.
Whenever a provider advertised a context window, context-simple ignored the configured max_tokens. On large-context (e.g. 1M-token) models, compaction effectively never triggered — and context grew unbounded again.
The automation stopped, and the human quietly became the bottleneck again.
Commit 020bd8c makes an explicitly-configured max_tokens cap the provider-derived budget. The effective budget becomes min(provider_budget, max_tokens) — so the budget is honest even on huge context windows.
Cap the budget, and compaction starts triggering again.
Compaction fires again on big-context models — the agent, not you, owns the token budget.
Make context management the agent's job: watch an honest budget, compact automatically before overflow, and keep the full history intact behind an ephemeral view. Do that, and the human stops being the bottleneck.
Automation you can trust only works when the budget it enforces is real.
Data as of: HEAD commit 020bd8c, June 28 2026
Feature status: Shipped & default (reference context manager)
Repos: microsoft/amplifier-module-context-simple (HEAD 020bd8c); ramparte/amplifier-core
Research performed:
wc -l amplifier_module_context_simple/__init__.py → 1390 linesgrep -n 'compact_threshold' __init__.py → default 0.92 (line 55/75)grep -n 'target_usage' __init__.py → default 0.50 (line 56/76)grep -n 'safety_margin' __init__.py → 4096 (line 1338); git show e702dcc (1000→4096, PR #7)git show 1ac0631 → ephemeral non-destructive compaction; grep -n interfaces.py lines 170/192git show 020bd8c (HEAD) → honor max_tokens as a budget ceiling; git show 2eb7729 → proactive compactionsed -n '104,125p' __init__.py → 8 progressive levels; uv run pytest tests/ -q → 44 passed / 1 failedGaps: No benchmark numbers (latency, tokens-saved, session-length) exist in code or commits; every metric shown is a config default, constant, or commit fact — not a measured performance result. Test suite currently reports 44 passed / 1 failed (test_tool_result_truncation_phase1); CI status on the canonical remote was not queried.
Primary contributor: Brian Krabach (50 commits); HEAD fix 020bd8c by Sam Schillace.