A lot of production AI incidents look like intelligence failures.
The default diagnosis is: the model hallucinated.
Sometimes that is true. But often, the model is doing exactly what we asked with the context it was given. The real bug is that the context was compacted badly before the model saw it.
This article is about that failure mode, and how to fix it with a lightweight probe harness.
What you will get from this:
Readable summaries can still be operationally wrong.
That sentence is the center of this problem.
Most teams review compaction output like editors:
Production systems need a different check:
When state drops, downstream behavior looks irrational even when the model is behaving consistently with the compacted input.
This is not a customer-support-specific issue. It is a long-horizon workflow issue.
In every domain, there are fields that are low-frequency in text but high-impact in action:
These fields are exactly what prose-style compaction tends to blur first.
Let us walk a single incident-assistant example through the whole pattern.
An SRE asks an assistant to coordinate a production issue.
Initial facts:
After several tool calls and runbook lookups, compaction runs. A few minutes later, the assistant proposes a global restart and misses the rollback threshold.
The model did not suddenly become dumb. The compacted state lost critical constraints.
Before touching prompts, measure token composition.
In the reference implementation used for this article:
conversation: 445 tokens
tool results: 5400 tokens (92% of the window)
Token composition pattern from the reference implementation. Image by author.
This finding matters because it changes where you spend effort.
If tool payloads are 92% of the context, compressing dialogue alone is a minor optimization.
If a tool result has already informed a decision, keep a re-fetch pointer and remove the heavy payload from active context.
def clear_tool_results(self, keep_pointers: bool = True) -> int:
"""Replace consumed payloads with re-fetch pointers and return tokens reclaimed."""
reclaimed = 0
for t in self.tools:
if t.used:
before = t.context_tokens()
t.used = False
t.cleared_note = (
f"[{t.tool} result for {t.entity_id} cleared; re-call to refetch]"
if keep_pointers else ""
)
reclaimed += before - t.context_tokens()
return reclaimed
This single change usually improves both cost and quality stability, because it removes stale high-volume noise.
Narrative summaries are good for readability and bad for regression detection.
Use a typed state target instead:
from typing import TypedDict
class TaskState(TypedDict):
entities: list[str] # IDs, service names, task anchors
constraints: list[str] # hard boundaries and guardrails
commitments: list[str] # promised actions with conditions/amounts
decisions: list[str] # completed decisions with rationale
open_items: list[str] # unresolved tasks with explicit owners
risk_flags: list[str] # safety/compliance/escalation markers
State-first compaction shape from the reference implementation. Image by author.
Why this works:
A probe is an executable question over compacted state.
from dataclasses import dataclass
from typing import Callable
@dataclass
class Probe:
question: str
answer: Callable[[TaskState], object]
expected: object
def score(state: TaskState, probes: list[Probe]) -> tuple[int, list[str]]:
passed, failures = 0, []
for p in probes:
if p.answer(state) == p.expected:
passed += 1
else:
failures.append(p.question)
return passed, failures
For the incident example, probes include:
If these fail, you caught the regression before a production decision.
This is where teams often get confused.
No, you do not need to run live model prompts in unit tests.
Use two lanes:
This keeps developer feedback fast and still catches model/prompt drift.
In the reference benchmark:
naive prose compactor: 3/6 pass (50%)
field-preserving compactor: 6/6 pass (100%)
Probe scoreboard from the reference implementation. Image by author.
The key point is not the headline percentage.
The key point is diagnostic clarity.
Instead of "the assistant is flaky," you can now say: "commitment preservation regressed on this release." That changes debugging speed and architecture decisions.
Once compaction is measurable, teams stop guessing and start engineering.
Here are practical moves this unlocks:
This is the part most teams miss: compaction instrumentation is not only a bug fix. It becomes a capability multiplier.
If you want to try this without replatforming:
Day 1:
Day 2-3:
Day 4:
Day 5:
After week 1:
Three anti-patterns keep showing up:
Avoid those, and this approach is straightforward to maintain.
If you remember one thing, make it this: when an assistant appears forgetful, inspect compaction quality before you replace the model.