Skip to main content

compose_for_prompt

Function compose_for_prompt 

Source
pub fn compose_for_prompt<'a, I>(
    frames: I,
    global_budget: u32,
) -> ComposedPrompt
where I: IntoIterator<Item = (&'a str, &'a ContextFrame)>,
Expand description

Compose an accepted frame set into a prompt-ready block: the R3 preamble, the value-ordered fenced frames, a citation map, and a CompositionAudit that explains every included and excluded frame (issue #15). This is the reference answer to “the host has honest frames — now what?”, layered on compose_context’s [render_frame] so the fencing and escaping are identical to the determinism floor.

The pipeline, in order:

  1. Dedup (dedup_cross_provider) — collapse the same evidence from two providers, keeping the higher-scored copy; the losers are excluded with ExclusionReason::Duplicate.
  2. Budget-pack — walk the survivors highest-value first and include each whose canonical token cost still fits global_budget; the rest are excluded with ExclusionReason::OverBudget. This is what makes tokens_used <= global_budget a guarantee rather than a hope.
  3. Place (fold_to_edges) — deal the included frames so the highest-value ones sit at the top/bottom edges (Lost in the Middle).
  4. Render — the preamble, then each frame through [render_frame], so a content-embedded </frame> still cannot break out of its fence.

The audit is a total partition of the input: every offered frame appears once, included-with-verification-state or excluded-with-reason.

Ranking across providers by raw score is a host policy choice, not a protocol guarantee (SPEC.md §6.6, F10) — see order_by_value. Use compose_for_prompt_with to pick a different one.

This entry point checks no attestations, so every entry’s attestation is AttestationState::NotChecked. Use compose_for_prompt_attested — or FanOut::compose_for_prompt, which passes the fan-out’s own ledger — to record what the host found.