Intermediate~22 minHazelJS
Cost Budgets and Alerts
Enforce RunBudget maxTokens/maxCostUsd and assert ceilings in tests—with execute snippets.
- Authors
- editorial-team
- Published
- Last reviewed
Progress is stored locally in this browser.
Direct answer
Pass budget: { maxTokens, maxCostUsd } on execute (not maxSteps inside RunBudget). Persist stop reasons; alert on budget exhaustion. Pattern: /patterns/budget-aware-execution.
Worked example
typescript
const result = await runtime.execute('researcher', goal, {
maxSteps: 12, // step ceiling — separate field
budget: {
maxTokens: 80_000,
maxCostUsd: 1.0,
},
});
// In tests:
assertAgentResult(result, {
maxCostUsd: 0.05,
maxLatencyMs: 10_000,
});
Dashboard: budget_exceeded_count by agent + weekly spend. Finance ceilings without hard runtime budgets are wishes.
Artifact: Budget defaults + alert thresholds per agent