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

basic-tools

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: 21 Imported by: 0

Documentation

Overview

This sample demonstrates a tool whose answer is more than one value: a slow deployment that streams progress while it runs and attaches a chart to what it returns. The runtime helpers in ai/tool do the work without changing the tool's signature (*ai.ToolContext embeds the context they take):

  • tool.AttachParts attaches the chart, so the tool returns a plain *Rollout instead of an *ai.MultipartToolResponse. The signature stops having to announce that the tool sometimes has more to say.
  • tool.SendChunk streams progress while the rollout runs, so a slow tool does not look like a hang.
  • tool.Fail returns an error to the model instead of failing the flow. Ask for a service that does not exist ("Ship checkout to production.") and the model reads the names of the real ones and calls the tool again.

Streaming is best-effort: with a caller that is not streaming, SendChunk is a no-op, so the tool still works when nobody is listening, and the returned *Rollout is always the authoritative answer. Streamed chunks are not written to history, since progress is for showing, not for the model to read.

Run it:

go run .

Or with the Dev UI, which renders the attached chart and keeps a trace of the whole rollout at http://localhost:4000/traces:

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

Or over HTTP. Streaming needs ?stream=true, otherwise the progress goes nowhere and only the final report comes back:

curl -N -X POST 'http://localhost:8080/deployFlow?stream=true' \
  -H "Content-Type: application/json" \
  -d '{"data": {"request": "Ship checkout-api to production."}}'

Jump to

Keyboard shortcuts

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