WithBudget on a single agent: BudgetStopRun ends the run with ErrBudgetExceeded, and BudgetWaitForApproval pauses for the caller to continue or stop.
Source: examples/agent_with_budget/
Limits in the example are intentionally low so they trigger on a short prompt. Raise them for real workloads.
What it demonstrates
- Token cap via
MaxTokens - Optional
MaxCostUSDwith caller-suppliedPromptUSDPer1M/CompletionUSDPer1M BudgetStopRun— run stops andGetreturnsErrBudgetExceededBudgetWaitForApproval—WithApprovalHandlerdecides whether to continue
Run
Fromexamples/:
Expected output
Scenario 1 printsrun stopped: per-run budget exceeded (BudgetStopRun) when the token cap is hit.
Scenario 2 prints a [budget] limit reached line, then prompts continue this run? (y/n). Type y to continue or n to stop with ErrBudgetExceeded. task examples:* sets EXAMPLES_AUTO_APPROVE=true and continues without a prompt.
Learn more
Budget
Limits, actions, validation, nested sub-agents
Approvals
Run handler vs Stream CUSTOM events