Documentation
¶
Overview ¶
This sample is basic-tools, written against the in-preview tools API in genkit/exp. It is slated to replace the one basic-tools uses in the next major version, so the two are worth reading side by side: same rollout, same flow, same chart, and the differences are all API.
The tool function takes a plain context.Context rather than *ai.ToolContext, and the runtime helpers in ai/exp/tool do the rest:
- 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.SendPartial streams structured progress while the rollout runs, so a slow tool does not look like a hang.
- tool.SendChunk streams a chunk the tool builds itself, for an update that is a line of prose rather than a value.
The two streaming helpers are best-effort: with a caller that is not streaming they are no-ops, so the tool still works when nobody is listening, and the returned *Rollout is always the authoritative answer. Neither is 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."}}'