- 1
//! Spend-admission seam (docs/design/15-reliability.md). The agent loop asks the - 2
//! gate before every paid dispatch and reports settled usage after; the - 3
//! implementation lives above (vak-core) where the ledger, caps, and - 4
//! pricing config exist. Budget denial is a typed Ask through the normal - 5
//! approver channel — unattended surfaces auto-deny, silence means no. - 6
- 7
use vak_llm::Usage; - 8
- 9
pub struct SpendCheck<'a> { - 10
pub model: &'a str, - 11
/// Serving provider of the current frozen-ladder leg. Empty when the - 12
/// caller cannot know it (legacy fixtures). - 13
pub provider: &'a str, - 14
pub session_id: &'a str, - 15
/// Planning estimate of the next call's input size. - 16
pub est_input_tokens: u64, - 17
/// Reserved completion size (context policy max output). - 18
pub planned_output_tokens: u64, - 19
} - 20
- 21
#[async_trait::async_trait] - 22
pub trait SpendGate: Send + Sync { - 23
/// Err(reason) denies the dispatch. Denial routes through the approver - 24
/// once as a budget Ask before the run fails closed. - 25
async fn authorize(&self, check: &SpendCheck<'_>) -> Result<(), String>; - 26
- 27
/// A settled dispatch: record it against run/day windows. `provider` - 28
/// attributes the spend to the serving leg for per-provider FinOps - 29
/// rollups. - 30
fn record_settled(&self, provider: &str, model: &str, session_id: &str, usage: &Usage); - 31
- 32
fn record_settled_with_latency( - 33
&self, - 34
provider: &str, - 35
model: &str, - 36
session_id: &str, - 37
usage: &Usage, - 38
_latency_ms: u64, - 39
) { - 40
self.record_settled(provider, model, session_id, usage); - 41
} - 42
- 43
/// The approver accepted the budget Ask: lift the cap for the REST of - 44
/// this run (raise-cap-once semantics, docs/design/15-reliability.md). Default no-op - 45
/// for gates without run state. - 46
fn on_budget_approved(&self) {} - 47
} - 48
Indexing the workspace…
Vakyartha documentation is discovering safe artifacts, anchors, and source references.