pub struct Budget {
pub max_llm_calls: Option<u64>,
pub max_elapsed_ms: Option<u64>,
}Expand description
Session-level resource limits.
Extracted from ctx.budget at session start. When a limit is reached,
alc.llm() raises a catchable Lua error ("budget_exceeded: ...")
before sending the request to the host. The check happens at
call-site, not after the LLM response arrives.
Budget is shared across the entire session — if alc.pipe() chains
multiple strategies, they all draw from the same budget.
Fields§
§max_llm_calls: Option<u64>Maximum number of LLM calls allowed in this session.
Checked against SessionStatus::llm_calls (incremented in on_paused).
max_elapsed_ms: Option<u64>Maximum wall-clock time (ms) allowed for this session.
Measured from session start (Instant::now() at construction).
Note: this is wall-clock, not CPU time. Includes time spent
waiting for host LLM responses.
Implementations§
Source§impl Budget
impl Budget
Sourcepub fn from_ctx(ctx: &Value) -> Option<Self>
pub fn from_ctx(ctx: &Value) -> Option<Self>
Extract budget from ctx JSON. Returns None if no budget field present.
Sourcepub fn check(&self, llm_calls: u64, elapsed_ms: u64) -> Result<(), String>
pub fn check(&self, llm_calls: u64, elapsed_ms: u64) -> Result<(), String>
Check if the session is within budget given current counters. Returns Err with a structured message if any limit is exceeded.
Sourcepub fn remaining_json(&self, llm_calls: u64, elapsed_ms: u64) -> Value
pub fn remaining_json(&self, llm_calls: u64, elapsed_ms: u64) -> Value
Remaining budget as JSON given current counters.
Returns { llm_calls: N|null, elapsed_ms: N|null }.