|
|
@@ -4,6 +4,7 @@ import pytest
|
|
|
|
|
|
from agent.core.prompts import build_summary_header
|
|
|
from agent.core.runner import AgentRunner, RunConfig
|
|
|
+from agent.orchestration import CompletionPolicy
|
|
|
from agent.trace.compaction import (
|
|
|
CompressionConfig,
|
|
|
calibrate_prompt_estimate,
|
|
|
@@ -188,6 +189,42 @@ async def test_oversized_minimum_context_fails_before_model_request(tmp_path):
|
|
|
assert "context_budget_exceeded" in [event["event"] for event in events]
|
|
|
|
|
|
|
|
|
+@pytest.mark.asyncio
|
|
|
+@pytest.mark.parametrize("sentinel", ["worker-latest", "validator-latest", "repair-latest"])
|
|
|
+async def test_compression_refreshes_latest_protected_role_context(tmp_path, sentinel):
|
|
|
+ store = FileSystemTraceStore(str(tmp_path))
|
|
|
+ trace = Trace(
|
|
|
+ trace_id=f"trace-{sentinel}",
|
|
|
+ mode="agent",
|
|
|
+ agent_role="worker",
|
|
|
+ context={"root_trace_id": "root"},
|
|
|
+ )
|
|
|
+ await store.create_trace(trace)
|
|
|
+
|
|
|
+ class Coordinator:
|
|
|
+ async def task_context(self, root_trace_id):
|
|
|
+ assert root_trace_id == "root"
|
|
|
+ return '{"state_revision":"ledger:latest"}'
|
|
|
+
|
|
|
+ runner = AgentRunner(trace_store=store, task_coordinator=Coordinator())
|
|
|
+ config = RunConfig(
|
|
|
+ completion_policy=CompletionPolicy.EXPLICIT_VALIDATION,
|
|
|
+ protected_context_refresh={"role_context": {"sentinel": sentinel}},
|
|
|
+ )
|
|
|
+ context = await runner._current_execution_context(trace.trace_id, None, config)
|
|
|
+
|
|
|
+ assert "ledger:latest" in context
|
|
|
+ assert sentinel in context
|
|
|
+ rebuilt = runner._rebuild_history_after_compression(
|
|
|
+ [
|
|
|
+ {"role": "system", "content": "policy"},
|
|
|
+ {"role": "user", "content": "old attempt bootstrap"},
|
|
|
+ ],
|
|
|
+ {"role": "user", "content": f"summary\n\n{context}"},
|
|
|
+ )
|
|
|
+ assert sentinel in rebuilt[-1]["content"]
|
|
|
+
|
|
|
+
|
|
|
@pytest.mark.parametrize(
|
|
|
"kwargs",
|
|
|
[
|