Compaction: the model's notes replace the middle of a long run (#158)
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 1m57s
CI / e2e (pull_request) Successful in 4m57s

Before each driver call, over compact_at (0.6) of the prompt budget, the
same model is asked for notes over the very request it was about to get,
plus one message, so the server's cache covers all but the notes. The notes,
with code's list of the calls they replace, become a compaction event that
renders in place of its range, keeping word for word what started the work
and the last few turns. Rare, large steps keep the prompt's start unchanged
between them. A later compaction folds in the earlier; one from an earlier
run's view is hidden.

Failed notes are logged and fitting takes over. Fitting now applies
compactions before it measures, records what it cuts (Trim) and logs each
cut as context.trimmed. Wired into both agents' drivers and the benchmark;
nisse-dev's helper loop is a follow-up.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J5Utyfzw7gF7UhjRDEtjTk
This commit is contained in:
dongarandClaude Opus 5.5 committed 2026-10-17 22:51:36 +00:00
1 parent fa8d93cf41
commit cb638fe687
20 files changed
+952 -44

No files matched your search

+12
View File
@@ -354,6 +354,18 @@ def test_context_tuning_is_read_and_checked() -> None:
build(tuning={"context": {"safety_margin": 1}})
def test_compaction_tuning_is_read_and_checked() -> None:
compaction = build().tuning.context.compaction()
assert (compaction.compact_at, compaction.compact_to) == (0.6, 0.25)
assert compaction.keep_turns == 3
off = build(tuning={"context": {"compact_at": 0}}).tuning.context
assert off.compaction().compact_at == 0
with pytest.raises(ConfigError, match="compact_to must be less than compact_at"):
build(tuning={"context": {"compact_at": 0.3, "compact_to": 0.5}})
with pytest.raises(ConfigError, match="compact_to must be less than compact_at"):
build(tuning={"context": {"compact_at": 1.5}})
def test_the_build_host_is_required_and_defaults_to_root_on_22() -> None:
host = only(build()).build_host
assert (host.address, host.user) == ("build.test", "root")