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."}}'