Certopolis

AWS Certified Generative AI Developer – Professional

Converse API tool use and chat history on Bedrock (AIP-C01)

With the Converse API the model never runs a tool. It returns stopReason tool_use with a toolUse block, your code runs the tool, and you send the output back in a toolResult block with the same toolUseId. Converse keeps no session, so every request must carry the full message history.

The tool loop

You describe each tool in toolConfig with a toolSpec: a name, a description and an inputSchema. When the model wants a tool, the response has stopReason tool_use and the assistant message contains a toolUse block with a toolUseId, the tool name and the input.

Your application calls the tool, whether it is an API, a database or a Lambda function. It appends the assistant message and then a user message containing a toolResult block with the matching toolUseId, and calls Converse again. The model then writes its answer using the result.

AWS calls this client-side tool use, and it is the mode for the Converse and InvokeModel APIs. In server-side mode Amazon Bedrock runs the tool itself through a Lambda function or AgentCore Gateway, but that mode is currently available on the Responses API, not Converse.

Reporting a failed tool call

If the tool fails, still send a toolResult for that toolUseId. Put a text description of the error in the content and set status to error. The status field is supported only by Amazon Nova and Anthropic Claude 3 and 4 models. The AWS example code does this when a station lookup raises an error.

This keeps each toolUse and its outcome next to each other in the history, and the model can tell the user or ask for different input.

toolChoice

toolChoice controls whether the model must request a tool. auto is the default and is supported by every model that supports tool use. any (at least one tool) and tool (one named tool) are supported by some models only. An unsupported setting fails with a ValidationException instead of falling back to auto.

Conversation history

Amazon Bedrock doesn't store the text, images or documents you send as content. To keep context, include all earlier messages in each later Converse request, with the role field set to user or assistant.

Example: a chatbot runs in a Lambda function and answers 'Can I move it to Friday?' without knowing which booking the user meant. Storing each session's messages in a DynamoDB item keyed by session ID and resending them on every turn fixes it.

Where the exam catches people

  • Believing Bedrock calls your Lambda tool when the response says tool_use: in client-side tool use your application must run the tool and return a toolResult.
  • Believing setting toolChoice makes the tool run: it only forces the model to request the tool. Running it is still your code's job.
  • Believing a failed tool call should be left out of the history: send a toolResult with the toolUseId, an error description and status error.
  • Believing Converse remembers earlier turns: Bedrock stores no content, so the application must resend the messages each time.
  • Believing a prompt cache checkpoint keeps a conversation: caching reduces cost for repeated prefixes, but the messages must still be sent in each request.

Written from Amazon Web Services's documentation

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. A company is building an order-status assistant with the Amazon Bedrock Converse API. A GenAI developer adds a toolConfig with one toolSpec named get_order_status, whose inputSchema requires an order_id. An AWS Lambda function implements the order lookup, and the tool description names the function. In testing, questions about orders return no answer text. Each Converse response has a stopReason of tool_use and a toolUse block that contains the correct order_id. Amazon CloudWatch Logs shows that the Lambda function is never invoked. What is the cause of this issue?

    Right. In the game that’s Renown for your Implementation and Integration building.

    Not that one: D is right. In the game your Implementation and Integration building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    For client-side tool use it names who runs the tool: "Your application code, after the model returns a tool-call request." So a stopReason of tool_use is the model's request, and nothing runs the Lambda function until the application does. The client-side page (https://docs.aws.amazon.com/bedrock/latest/userguide/tool-use-client-side.html) describes the loop: "in your code, you call the tool on the model's behalf", then "You then continue the conversation with the model by supplying a message with the result from the tool."

    Written from docs.aws.amazon.com/bedrock/latest/userguide/tool-use.html

  2. A company's order assistant calls the Amazon Bedrock Converse API with Amazon Nova Pro and a tool named get_order_status. When the model requests the tool, the application calls an internal order service. Sometimes the order service times out. When a tool call fails, the model must learn that this specific tool request failed so that it can tell the customer or ask for a different order number. The conversation must continue in the same message history, and the history must keep each tool request that the model made together with its outcome. Which solution will meet these requirements?

    Right. In the game that’s Renown for your Implementation and Integration building.

    Not that one: A is right. In the game your Implementation and Integration building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    The ToolResultBlock reference (https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ToolResultBlock.html) defines toolUseId as "The ID of the tool request that this is the result for." and gives status the valid values success and error, a field "only supported by Amazon Nova and Anthropic Claude 3 and 4 models." Returning the timeout text with status set to error tells Nova Pro that this request failed, and the history keeps the toolUse and its toolResult side by side.

    Written from docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ToolResultBlock.html

  3. A travel company is building a customer support chatbot. An AWS Lambda function receives each user message and calls the Amazon Bedrock Converse API with that message in the messages field. A chat session can last up to 20 turns. In testing, the model answers single questions well but does not know what the user said earlier in the same session. When a user asks "Can I move it to Friday?" after asking about a booking, the model asks which booking the user means. The chatbot must keep the context of each session. The company wants to add as little infrastructure as possible. Which solution will meet these requirements with the LEAST operational overhead?

    Right. In the game that’s Renown for your Implementation and Integration building.

    Not that one: B is right. In the game your Implementation and Integration building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    The Converse page (https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html) says "Amazon Bedrock doesn't store any text, images, or documents that you provide as content. The data is only used to generate the response." It also gives the fix: "You can maintain conversation context by including all the messages in the conversation in subsequent Converse requests and using the role field to specify whether the message is from the user or the model." A DynamoDB item per session holds those messages between Lambda invocations, which adds one table and no servers.

    Written from docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html