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}}'
Click to show internal directories.
Click to hide internal directories.