pub struct Context {
pub items: Vec<AdmittedItem>,
pub evicted: Vec<EvictionRecord>,
pub budget: TokenBudget,
}Expand description
Γ — the exact admitted token window. Immutable, fully attributed.
§Example
use boundgraph_core::{AdmittedItem, Context, ContextSource, Digest, EvictionReason,
EvictionRecord, TokenBudget};
let ctx = Context::new(
vec![AdmittedItem {
source: ContextSource::Prompt,
digest: Digest::of(b"task"),
tokens: 120,
reason: "declared by the step".into(),
}],
vec![EvictionRecord {
source: ContextSource::Retrieval,
digest: Digest::of(b"a long document"),
tokens: 9_000,
reason: EvictionReason::BudgetExhausted { needed: 9_000, remaining: 880 },
}],
TokenBudget(1_000),
)?;
assert_eq!(ctx.admitted_tokens(), 120);
// The law is auditable: we can say exactly what was withheld, and why.
assert_eq!(ctx.evicted.len(), 1);Fields§
§items: Vec<AdmittedItem>What the reasoner actually saw.
evicted: Vec<EvictionRecord>What it did not, and why.
budget: TokenBudgetThe ceiling this admission ran against.
Implementations§
Source§impl Context
impl Context
Sourcepub fn new(
items: Vec<AdmittedItem>,
evicted: Vec<EvictionRecord>,
budget: TokenBudget,
) -> Result<Self, ContextOverBudget>
pub fn new( items: Vec<AdmittedItem>, evicted: Vec<EvictionRecord>, budget: TokenBudget, ) -> Result<Self, ContextOverBudget>
Build a context, enforcing the budget invariant.
§Errors
Returns ContextOverBudget if the admitted items exceed budget.
This is deliberately a hard error rather than a silent truncation: an
admitter that overruns has broken Law II, and quietly dropping the tail
would hide that while also losing the eviction record that explains it.
Sourcepub fn empty(budget: TokenBudget) -> Self
pub fn empty(budget: TokenBudget) -> Self
An empty window under a given ceiling.
Sourcepub fn admitted_tokens(&self) -> u32
pub fn admitted_tokens(&self) -> u32
Tokens actually admitted. Never exceeds Context::budget.
Sourcepub fn evicted_tokens(&self) -> u32
pub fn evicted_tokens(&self) -> u32
Tokens that were considered and refused.
A large number here against small headroom means the
budget was the binding constraint; a large number against ample
headroom means something was withheld for another reason, which is
usually the more interesting case when debugging.
Sourcepub fn why_evicted(&self, digest: &Digest) -> Option<&EvictionReason>
pub fn why_evicted(&self, digest: &Digest) -> Option<&EvictionReason>
Whether this item was considered and refused, and if so why.
This is the “why did the agent not know X?” query.