agent_with_budget

command
v0.3.6 Latest Latest
Warning

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

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

Documentation

Overview

Example demonstrating per-run budget enforcement with WithBudget.

Two scenarios are shown:

  1. BudgetStopRun: the run stops immediately and returns ErrBudgetExceeded when the configured token or cost limit is reached.
  2. BudgetWaitForApproval: the run pauses when the limit is reached; the approval handler decides whether to continue or stop.

Run:

go run ./agent_with_budget
go run ./agent_with_budget "Your custom prompt here"

Set SHOW_LLM_USAGE=true to print token usage at the end of each run. The budget limits in this example are set very low so they trigger on most prompts. Raise them to realistic values (e.g. MaxTokens: 100_000) for production use.

Jump to

Keyboard shortcuts

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