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
@@ -22,6 +22,7 @@ from nisse_core.log.canonical import (
|
||||
)
|
||||
from nisse_core.loop.driver import Driver, RunOutcome
|
||||
from nisse_core.models.catalog import ModelFacts
|
||||
from nisse_core.models.compact import Compactor
|
||||
from nisse_core.oplog import OpLog
|
||||
from nisse_dev.bench.tasks import Task
|
||||
from nisse_dev.config import Tuning
|
||||
@@ -78,10 +79,13 @@ class MeteringClient:
|
||||
tools: list[dict[str, Any]] | None,
|
||||
model: str,
|
||||
system: str | None = None,
|
||||
**options: Any,
|
||||
) -> list[CanonicalEvent]:
|
||||
self.calls += 1
|
||||
try:
|
||||
produced = self._inner.complete(events, tools, model, system=system)
|
||||
produced = self._inner.complete(
|
||||
events, tools, model, system=system, **options
|
||||
)
|
||||
finally:
|
||||
# Counted even when the call fails: a rate limit that never
|
||||
# cleared still cost the run its wait.
|
||||
@@ -95,10 +99,16 @@ class MeteringClient:
|
||||
answered = getattr(self._inner, "last_model", None)
|
||||
if not self._facts.answered(answered):
|
||||
self.fallbacks.append(str(answered))
|
||||
if not any(isinstance(e, ToolCall) for e in produced):
|
||||
# Compaction's notes are prose by request, not a broken turn.
|
||||
asked_for_prose = options.get("require_tool_call") is False
|
||||
if not asked_for_prose and not any(isinstance(e, ToolCall) for e in produced):
|
||||
self.prose_turns += 1
|
||||
return produced
|
||||
|
||||
def __getattr__(self, name: str) -> Any:
|
||||
# The budget (budget_for, estimate) compaction reads.
|
||||
return getattr(self._inner, name)
|
||||
|
||||
|
||||
@dataclass
|
||||
class RunRecord:
|
||||
@@ -222,6 +232,8 @@ def run_task(
|
||||
model,
|
||||
max_turns=tuning.driver.max_turns,
|
||||
failure_limit=tuning.driver.failure_limit,
|
||||
# As the agent runs it, so a long task measures the same thing.
|
||||
compactor=Compactor(meter, tuning.context.compaction()),
|
||||
)
|
||||
system = SYSTEM.format(
|
||||
repo=f"bench/{task.name}",
|
||||
|
||||
Reference in new issue
Block a user