Documentation
¶
Overview ¶
This sample demonstrates tools: Go functions the model may call mid-answer, and what a tool hands back when its answer is more than one value.
deployService simulates a rollout that takes a while, then reports how it went. It is a multipart tool, so it answers with two things: a *Rollout as its output, and a chart of the latency it recorded as an attached content part. Attachments reach the model and the client both, so the model can describe the shape of the rollout and the Dev UI can show the picture. They must be media or data parts; a text part is not a valid attachment.
deployFlow streams the run, so the report arrives as the model writes it.
basic-tools-exp is this same sample written against the in-preview tools API in genkit/exp. Reading the two side by side is the shortest way to see what that API changes and what it adds.
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 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."}}'