Autonomous AI agents can accumulate significant costs. Each API call, database query, and cloud operation has a price. Without budget controls, an agent running overnight can spend thousands of dollars. Budget controls set hard limits on what the agent can spend.
Cap the cost of any single action:
- tool: "payment.send"
action: allow
when:
args.amount:
lte: 100
reason: "Payments up to $100 are automatic"
- tool: "payment.send"
action: escalate
when:
args.amount:
lte: 1000
reason: "Payments $100-$1000 require approval"
- tool: "payment.send"
action: block
reason: "Payments over $1000 are blocked"
Cap the total cost within a session:
const guard = createGuard({
policy,
budget: {
maxPerSession: 500.00,
tracking: {
'payment.send': (args) => args.amount,
'cloud.compute': (args) => args.estimatedCost,
'api.call': () => 0.01, // Flat cost per call
}
}
});
Cap the total cost across all sessions in a 24-hour period:
budget: {
maxPerDay: 2000.00,
maxPerSession: 500.00,
}
Different tools have different cost profiles:
budget: {
perTool: {
'payment.send': { maxPerDay: 1000.00 },
'cloud.compute': { maxPerDay: 200.00 },
'api.call': { maxPerDay: 50.00 },
}
}
When a budget limit is hit, the guard blocks the action:
const decision = guard('payment.send', { amount: 200, to: 'vendor' });
// decision.action === 'block'
// decision.reason === 'Session budget exceeded ($480/$500)'
For a softer approach, escalate instead of blocking:
budget: {
maxPerSession: 500.00,
onExceeded: 'escalate', // Instead of 'block'
}
For agents that use LLM APIs, track token consumption:
budget: {
maxTokensPerSession: 100_000,
maxTokensPerDay: 1_000_000,
tokenCost: {
input: 0.000003, // Per token
output: 0.000015, // Per token
}
}
Set alert thresholds below the hard limit:
budget: {
maxPerSession: 500.00,
alertAt: 0.8, // Alert at 80% ($400)
onAlert: (usage) => {
notify('budget-alert', {
used: usage.amount,
limit: usage.limit,
session: usage.sessionId,
});
}
}
This gives operators time to review the agent's spending before it hits the hard limit.
An agent with access to payment tools and no budget controls is a liability. A single prompt injection or hallucinated action can trigger a large unauthorized payment. Budget controls are the financial equivalent of rate limiting: they bound the maximum damage from any failure mode.
Explore more guides on AI agent safety, prompt injection, and building secure systems.
View All Guides