Implementing Tool Use with the Converse API
This lesson explains the tool use flow in the Converse API, also called function calling, which lets a model request that the application run a function with structured arguments.
Learning outcomes
After completing this lesson, you will be able to:
- Define tools with names, descriptions and input schemas.
- Handle the tool use request and response cycle.
- Handle parallel tool calls and streaming.
Defining tools
With the Converse API, tools are passed in the toolConfig parameter. Each tool has a name, a description that tells the model what the tool does and when to use it, and an input schema in JSON Schema that defines its arguments, their types and allowed values, and which arguments are required. The model never runs a tool itself: when it decides a tool is needed, it returns a tool use request with the arguments, the application runs the tool and sends the result back in the next message.
The toolChoice setting controls whether the model may answer without calling a tool (auto), must call one of the tools (any), or must call a specific named tool (tool). Forcing a specific tool is a common way to obtain structured output, because the tool's input schema then defines the shape of the response.
The following diagram compares the two tool definitions.

Tools the model misuses
The request and response cycle
When the model decides to use a tool, the response has stopReason tool_use and the assistant message contains one or more toolUse blocks, each with a toolUseId, the tool name and the input arguments. The application runs the tool, then sends a new request that includes the assistant message and a user message containing a toolResult block with the same toolUseId and the result content. If the tool failed, the result has status error and an explanation, so the model can recover. The loop repeats until stopReason is end_turn.
messages = [{"role": "user", "content": [{"text": "What is the status of order 1182?"}]}]
while True:
r = brt.converse(modelId=model_id, messages=messages, toolConfig=tool_config)
msg = r["output"]["message"]
messages.append(msg)
if r["stopReason"] != "tool_use":
break
results = []
for block in msg["content"]:
if "toolUse" in block:
use = block["toolUse"]
try:
out = TOOLS[use["name"]](**use["input"])
results.append({"toolResult": {"toolUseId": use["toolUseId"], "content": [{"json": out}]}})
except Exception as e:
results.append({"toolResult": {"toolUseId": use["toolUseId"], "status": "error",
"content": [{"text": f"Tool failed: {e}"}]}})
messages.append({"role": "user", "content": results})The following diagram shows one tool call passing between the application, the model and the tool.

The tool use cycle
Parallel tool calls and streaming
Some models request several tools in one turn, for example looking up two orders at once; the application can run them in parallel and return all results in one user message. With ConverseStream, tool use arrives as streamed events, and the application assembles the tool input from content block deltas before running the tool. A production loop also needs an iteration limit, timeouts on tool execution and logging of every call. The following table summarises the key fields.
| Field | Meaning |
|---|---|
| toolConfig.tools[].toolSpec | Name, description and JSON Schema of each tool |
| toolChoice auto / any / tool | Model may, must, or must use a named tool |
| stopReason tool_use | The model is waiting for tool results |
| toolUse block | toolUseId, name and input arguments |
| toolResult block | Result for a toolUseId; status error on failure |
The model never calls the tool
An assistant has a tool get_data described as "Gets data". Users ask about shipment status, and the model answers from general knowledge instead of calling the tool.
The description gives the model no reason to use it. Renaming it get_shipment_status, describing it as "Returns the live status, location and estimated delivery date of a shipment. Use for any question about where an order is", and defining an order_id parameter with its format fixes tool selection.
A tool call fails. How should the failure be returned to the model?
Show answer
As a toolResult with the same toolUseId and status error, so the model can recover or try another approach.
Exam Tips
Remember for the exam
- Tools need a clear name, a description of when to use them and a JSON Schema.
- stopReason tool_use: run the tool and return toolResult with the same toolUseId.
- Return tool errors with status error so the model can recover.
- toolChoice forces a specific tool for structured output.