Compaction: the model's notes replace the middle of a long run (#158)
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:
1 parent
fa8d93cf41
commit
cb638fe687
20 files changed
+952
-44
No files matched your search
@@ -34,6 +34,7 @@ from nisse_core.config import (
|
||||
resolve,
|
||||
)
|
||||
from nisse_core.conversation.matrix import MatrixConfig
|
||||
from nisse_core.models.compact import CompactionTuning, check_tuning
|
||||
from nisse_core.models.llm import (
|
||||
DEFAULT_MAX_OUTPUT_TOKENS,
|
||||
DEFAULT_REQUEST_TIMEOUT_S,
|
||||
@@ -134,6 +135,19 @@ class ToolsTuning:
|
||||
class ContextTuning:
|
||||
keep_recent_turns: int = 6
|
||||
safety_margin: float = 0.1
|
||||
# Compaction (L6): over compact_at of the prompt budget, the model's
|
||||
# notes replace the middle of the run, keeping at most compact_keep_turns
|
||||
# recent turns, in compact_to of it. compact_at 0: never.
|
||||
compact_at: float = field(default=0.6, metadata={"zero": True})
|
||||
compact_to: float = 0.25
|
||||
compact_keep_turns: int = 3
|
||||
|
||||
def compaction(self) -> CompactionTuning:
|
||||
return CompactionTuning(
|
||||
compact_at=self.compact_at,
|
||||
compact_to=self.compact_to,
|
||||
keep_turns=self.compact_keep_turns,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -182,6 +196,7 @@ def _parse_tuning(raw: Any, errors: list[str]) -> Tuning:
|
||||
)
|
||||
if tuning.context.safety_margin >= 1:
|
||||
errors.append("tuning.context.safety_margin: must be less than 1")
|
||||
check_tuning(tuning.context.compaction(), "tuning.context", errors)
|
||||
return tuning
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user