pub struct Budget {
pub max_llm_calls: Option<u64>,
pub max_elapsed_ms: Option<u64>,
pub max_tokens: 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.
max_tokens: Option<u64>Maximum total tokens (prompt + response) allowed in this session.
Checked against accumulated prompt_tokens + response_tokens.
Token counts may be estimated (±30%) or host-provided depending
on TokenSource. Budget check uses whatever is available.
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,
total_tokens: u64,
) -> Result<(), String>
pub fn check( &self, llm_calls: u64, elapsed_ms: u64, total_tokens: u64, ) -> Result<(), String>
Check if the session is within budget given current counters. Returns Err with a structured message if any limit is exceeded.