Tool use with the Bedrock Converse API

How a model uses your tools through Converse. You describe each tool, the model asks for one with stopReason tool_use, your code runs it and sends back a toolResult, and the model answers. The loop every agent runs, by hand in exercise 2.

GazeekAMAZON BEDROCK DEEP DIVE·LESSON 7
LESSON 7

Tool use with the Bedrock Converse API

How a model uses your tools through Converse. You describe each tool, the model asks for one with stopReason tool_use, your code runs it and sends back a toolResult, and the model answers. The loop every agent runs, by hand in exercise 2.

0:00 / 1:45

Diagrams in this video · 1Free in archhy

Copy and edit in archhy: Tool use, step by step (new tab)

The diagrams, full size

Copy any of them into archhy, free, and change it for your own system.

After this lesson you can

  • Describe a tool in toolConfig
  • Follow the tool_use and toolResult loop
  • Explain why the model never runs tools itself
  • Run the loop yourself (exercise 2)
Transcript

Tool use with the Bedrock Converse API

Space Llama here. Models know a lot, but they can't look things up, or count reliably, or call your systems. Today, tools. And this is the idea every agent is built on.

Tool use, step by step

Here's the whole loop. Your app asks a question, and in tool config, describes each tool. Its name, what it does, and the shape of its input. The model decides it needs one. It stops with stop reason tool use, and says which tool, with what input. Your code runs the tool. With Converse, the model never runs anything itself. It only asks. You send the result back, as a tool result, in the next message, with the same tool use ID the model gave you, after the model's own message. And the model answers, with stop reason end turn. Run that loop for the model, as many times as it takes, and you have an agent. That's part five. Bedrock can also run some tools for you, on the server, but that's a later story.

Describing a tool

Describing a tool is just data. A name. A description, and write it well, because it's how the model decides when to use the tool. And a JSON schema for the input.

Exercise 2: run the loop yourself

Exercise two runs this loop by hand, with a word counting tool. Then try making the tool lie. The model believes it. Whoever writes the tools owns the answers.

Remember

Let's recap. You describe tools in tool config. The model asks for one, and your code runs it. Tool use, tool result, answer. That loop is the heart of every agent.

Practice and what's next

Next, structured outputs and prompt caching. See you there.

Gazeek Flash · free

Exam questions on your phone

Free questions on Amazon Bedrock: quick-fire batches and timed exams, on the web or Android.