Documentation
¶
Overview ¶
Example demonstrating per-run budget enforcement with WithBudget.
Two scenarios are shown:
- BudgetStopRun: the run stops immediately and returns ErrBudgetExceeded when the configured token or cost limit is reached.
- 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.
Click to show internal directories.
Click to hide internal directories.