Documentation
¶
Overview ¶
Command budgeted-agent demonstrates LoopKit's budget enforcement.
Overview ¶
This example creates a loop with a $0.50 USD budget and a scripted fake provider whose responses carry realistic token usage. The custom pricing table makes each model call cost $0.20, so the loop is forced to exit with a BudgetExceeded outcome before completing its intended work.
Key concepts demonstrated ¶
- loopkit.WithBudget: set USD (and optionally token/iteration/wallclock) caps.
- Custom model.Table: supply your own per-model pricing so spend accumulates predictably in tests and examples.
- outcome.Match: exhaustive dispatch over all six terminal outcome types, used here to print a human-readable summary.
- Scripted fake provider: inject deterministic usage without a live API.
Expected output ¶
BudgetExceeded: dimension=usd spent=$0.40 (2 model calls × $0.20 each)
The loop requests 3 model calls but the $0.50 budget is exhausted after the second call charges $0.40 total — the third call's pre-authorization fails.
Click to show internal directories.
Click to hide internal directories.