budgeted-agent

command
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL