mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-03 01:31:47 +03:00
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:
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user