refactor(agent): let runner own context compaction (#5568)

* refactor(agent): consolidate accepted history under pressure

* fix(agent): align provider and session compaction

* refactor(agent): simplify runner context compaction

* refactor(agent): remove background token consolidation

* fix(agent): keep injected transcript messages distinct

* refactor(agent): unify native compaction summaries

* fix(agent): preserve native compaction boundary

* fix(agent): unify context compaction paths

* fix(agent): preserve exact compaction request boundaries
This commit is contained in:
chengyongru
2026-09-02 18:05:54 +08:00
committed by GitHub
parent da96c5c6eb
commit d81aa5a4ab
44 changed files with 1914 additions and 1666 deletions
+29 -5
View File
@@ -22,7 +22,10 @@ from nanobot.providers.openai_codex_provider import (
_request_codex,
_should_retry_status,
)
from nanobot.providers.openai_responses import build_responses_state
from nanobot.providers.openai_responses import (
build_responses_state,
responses_state_items,
)
from nanobot.providers.registry import find_by_name
@@ -811,12 +814,33 @@ async def test_codex_compacts_state_at_ninety_percent_before_next_request(
)
assert response.content == "done"
assert len(bodies) == 2
assert bodies[0]["input"][-1] == {"type": "compaction_trigger"}
assert bodies[1]["input"][-1] == {
assert response.provider_compaction_applied is True
assert response.provider_compaction_state is not None
assert response.provider_compaction_scope == "prior_context"
assert responses_state_items(response.provider_compaction_state) == [{
"type": "compaction",
"encrypted_content": "compacted opaque state",
}
}]
assert len(bodies) == 2
assert bodies[0]["input"][-1] == {"type": "compaction_trigger"}
assert not any(
item.get("role") == "user"
and "new question" in str(item.get("content"))
for item in bodies[0]["input"]
)
assert {
"type": "compaction",
"encrypted_content": "compacted opaque state",
} in bodies[1]["input"]
assert bodies[1]["input"].index({
"type": "compaction",
"encrypted_content": "compacted opaque state",
}) < next(
index
for index, item in enumerate(bodies[1]["input"])
if item.get("role") == "user"
and "new question" in str(item.get("content"))
)
assert not any(
item.get("type") == "reasoning"
for item in bodies[1]["input"]