Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:2akouwu Reverify Prompt Compaction Ladder

From Leeroopedia
Knowledge Sources
Domains Optimization, LLMs, Context_Engineering
Last Updated 2026-10-24 12:00 GMT

Overview

Deterministic compaction order that trims the most redundant prompt material first (imports, strings, old observed values) to fit a character budget, while scoring always uses the full fact sheet.

Description

The prompt compaction ladder is a fixed, ordered sequence of trimming steps applied to the fact sheet shown to the model when the prompt exceeds a character budget (~60k chars, ~15k tokens). The ladder removes the most redundant material first: long import lists are trimmed before strings, strings before old observed values. Critically, only the view is trimmed — the verifier always scores against the full fact sheet. This means hiding a fact can never make restating it profitable: a claim that merely restates a trimmed fact still scores zero, because the scorer sees the original.

Usage

Use this heuristic when the prompt for the reconstruction agent exceeds the character budget. It is applied automatically every round in `compact_facts`. Apply when working with large binaries that have many imports, exports, or sections, or when the context window is small.

The Insight (Rule of Thumb)

  • Action: Trim the shown fact sheet in a fixed order: imports (16x60 → 6x24 → 2x12), strings (8 → 0), observed values (24 → 10), exports (12), sections (16).
  • Value: `PROMPT_BUDGET_DEFAULT = 60_000` characters (~4 chars/token → ~15k tokens). Each step removes increasingly valuable data.
  • Trade-off: The model sees less context, but can re-observe trimmed values through tools (`observe: true`). Scoring is never weakened — it uses the full sheet.
  • Compatibility: Works with any prompt budget; the ladder stops as soon as the prompt fits.

Reasoning

A model that sees the full fact sheet can game the scorer by restating known facts. The compaction ladder solves two problems at once: it keeps the prompt within the context window, and it removes the temptation to parrot visible facts. The order is chosen by information redundancy: import lists are long and rarely all needed; strings are lower-value; observed values are recent and can be re-read. The invariant "scoring uses the full sheet" is the key insight — it makes compaction safe.

Code Evidence

Compaction ladder definition from `agent.py:334-344`:

COMPACTION_LADDER: List[Tuple[str, Callable[[Dict[str, Any]], None]]] = [
    ("imports:16x60", lambda f: _trim_imports(f, 16, 60)),
    ("strings:8", lambda f: _trim_list(f, "top_strings", 8)),
    ("observed:24", lambda f: _trim_observed(f, 24)),
    ("imports:6x24", lambda f: _trim_imports(f, 6, 24)),
    ("exports:12", lambda f: _trim_list(f, "exports", 12)),
    ("observed:10", lambda f: _trim_observed(f, 10)),
    ("imports:2x12", lambda f: _trim_imports(f, 2, 12)),
    ("strings:0", lambda f: _trim_list(f, "top_strings", 0)),
    ("sections:16", lambda f: _trim_list(f, "sections", 16)),
]

Scoring against full facts from `agent.py:465-466`:

# Score against the FULL fact sheet, whatever the model was shown.
report = self.verifier.verify_all(claim_objs, facts=facts, min_information=self.min_information)

Prompt budget from `agent.py:72`:

PROMPT_BUDGET_DEFAULT = 60_000

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment