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
@@ -10,6 +10,7 @@ from nisse_core.knowledge.vault import Vault
|
||||
from nisse_core.loop.driver import Driver
|
||||
from nisse_core.loop.expert import ExpertDesk
|
||||
from nisse_core.models.catalog import ModelCatalog
|
||||
from nisse_core.models.compact import Compactor
|
||||
from nisse_core.models.context import BudgetedClient
|
||||
from nisse_core.models.interruptible import Interruptible
|
||||
from nisse_core.models.llm import LiteLLMClient
|
||||
@@ -65,7 +66,7 @@ def check_access(
|
||||
return account, repos
|
||||
|
||||
|
||||
def llm_client(config: ReviewConfig) -> BudgetedClient:
|
||||
def llm_client(config: ReviewConfig, oplog: OpLog | None = None) -> BudgetedClient:
|
||||
"""The one route to the models, every request fitted to its window
|
||||
(L6), against what LiteLLM says the configured models are (L9)."""
|
||||
catalog = ModelCatalog.discover(config.llm_base_url, config.llm_token)
|
||||
@@ -92,6 +93,7 @@ def llm_client(config: ReviewConfig) -> BudgetedClient:
|
||||
keep_recent_turns=tuning.keep_recent_turns,
|
||||
safety_margin=tuning.safety_margin,
|
||||
enforces_tool_choice=lambda m: catalog.facts(m).supports_tool_choice is True,
|
||||
oplog=oplog, # a cut that fitting has to make is logged
|
||||
)
|
||||
|
||||
|
||||
@@ -106,7 +108,7 @@ def build(
|
||||
gitea = gitea or GiteaClient(config.gitea_url, config.gitea_token)
|
||||
account, repos = check_access(gitea, config.repositories, oplog)
|
||||
# Every model call, the reviewer's and ask_expert's, can be broken off.
|
||||
model = Interruptible(client if client is not None else llm_client(config)) # type: ignore[arg-type]
|
||||
model = Interruptible(client if client is not None else llm_client(config, oplog)) # type: ignore[arg-type]
|
||||
config.state_db.parent.mkdir(parents=True, exist_ok=True)
|
||||
store = StateStore(config.state_db, oplog=oplog)
|
||||
vault = (
|
||||
@@ -129,7 +131,12 @@ def build(
|
||||
reviewer = Reviewer(
|
||||
store,
|
||||
gitea,
|
||||
Driver(model, config.roles.resolve("driver"), cancel=cancel), # type: ignore[arg-type]
|
||||
Driver(
|
||||
model, # type: ignore[arg-type]
|
||||
config.roles.resolve("driver"),
|
||||
cancel=cancel,
|
||||
compactor=Compactor(model, tuning.context.compaction(), oplog=oplog),
|
||||
),
|
||||
account=account,
|
||||
gitea_url=config.gitea_url,
|
||||
oplog=oplog,
|
||||
|
||||
Reference in new issue
Block a user