fn __budget_envelope(opts) {
return opts?.budget
}
/**
* agent_budget_pre_call_blocked.
*
* @effects: [host]
* @allocation: heap
* @errors: []
* @api_stability: experimental
* @example: agent_budget_pre_call_blocked(session, opts)
*/
pub fn agent_budget_pre_call_blocked(session, opts) {
let envelope = __budget_envelope(opts)
if envelope == nil {
return false
}
return __host_agent_budget_pre_call_blocked(session.session_id, envelope)
}
/**
* agent_budget_post_call_blocked.
*
* @effects: []
* @allocation: heap
* @errors: []
* @api_stability: experimental
* @example: agent_budget_post_call_blocked(totals, opts)
*/
pub fn agent_budget_post_call_blocked(totals, opts) {
let envelope = __budget_envelope(opts)
if envelope == nil && opts?.token_budget == nil {
return false
}
if opts?.token_budget != nil && totals?.tokens_used != nil {
if totals.tokens_used >= opts.token_budget {
return true
}
}
if envelope?.total_budget_usd != nil && totals?.cost_usd != nil {
if totals.cost_usd >= envelope.total_budget_usd {
return true
}
}
return false
}