Help us shape the future of Go! Take the 2026 Go Developer Survey

budget

command
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

This sample demonstrates the experimental Budget middleware, which caps the tokens a generate run spends across its whole tool loop.

The model follows a chain of boxes to a treasure. Each box names the next, so every box costs a turn, and a small budget runs out before the end:

  • huntFlow stops the run once it spends maxTokens.
  • huntWithApprovalFlow pauses the run instead, and approves another maxTokens up to "approvals" times.

Run it:

go run .

Or with the Dev UI, to watch each turn and its usage at http://localhost:4000/traces:

curl -sL cli.genkit.dev | bash    # install the Genkit CLI, once
genkit start -- go run .

Or over HTTP:

curl -X POST 'http://localhost:8080/huntWithApprovalFlow' \
  -H "Content-Type: application/json" \
  -d '{"data": {"maxTokens": 3000, "approvals": 3}}'

Jump to

Keyboard shortcuts

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