hot-ai tool-calling adapter for Amazon Bedrock, over the Converse API.
chat-with-tools and chat-with-tools-stream satisfy the ::ai::chat
chat contract, so any Bedrock model that supports tool use (Claude,
Nova, Llama, Mistral and others) runs under ::ai::chat/run-loop and
run-loop-stream.
hot-ai's built-in registry has no Bedrock entry, and leaves every
provider's chat-fn null. Wire these on ChatOptions, or register
provider() with ::ai::chat/with-providers. The registration claims
ids written as bedrock/<model id>; the prefix is stripped before the
call.
Credentials and region come from ::aws::core/resolve: the trailing
opts (or ChatOptions.provider-opts) first, then ctx. Calls are
SigV4-signed.
- A call's id is Bedrock's
toolUseId. Reasoning blocks from a model with extended thinking ride on the first call'sToolCall.metaasreasoning, and go back on the next turn, which Claude requires. - Tool results that answer one assistant turn go back in one user turn.
A failed result is sent with
status: "error". - The Converse stream arrives as one AWS event stream body. The adapter
parses it once the response is in, then sends each
ReplyDeltain order, so deltas come all at once rather than as tokens arrive. - A refused call is an Err holding
::aws::core/AwsError. An exception inside the stream, a stream with no stop reason, and a reply with no text and no call are Errs holding aReplyError.
Example
bigger fn (x: Int, y: Int): Int { if(gt(x, y), x, y) }
opts ::ai::chat/ChatOptions({
chat-fn: ::aws::bedrock::chat-tools/chat-with-tools,
chat-stream-fn: ::aws::bedrock::chat-tools/chat-with-tools-stream,
model: "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
tools: [::ai::tool/from-fn(bigger)]
})
answer ::ai::chat/run-loop(opts, "Which is larger, 17 or 25?")
Values
DEFAULT_MAX_TOKENS
DEFAULT_MAX_TOKENS: Int 4096
EMPTY_STATE
EMPTY_STATE: Map {
text: "",
calls: [],
reasoning: [],
open: null,
reasoning-text: "",
signature: null,
redacted: null,
stop-reason: null,
usage: null
}
MODEL_PREFIX
MODEL_PREFIX: Str "bedrock/"
PROVIDER_NAME
PROVIDER_NAME: Str "AWS Bedrock"
Functions
build-request
fn (messages: Vec<::ai::chat/Message>, system: Str?, tools: Vec<::ai::tool/Tool>?, options: ChatRequestOptions): Map
The Converse request body for messages, system, tools and
options. system and any role: "system" messages become system;
tool results become toolResult blocks in a user turn; an empty tool
list leaves out toolConfig.
Example
body ::aws::bedrock::chat-tools/build-request(
[::ai::chat/user-message("Hi")],
"Be brief.",
null,
::aws::bedrock::chat-tools/DEFAULT_REQUEST_OPTIONS
)
body.system // [{text: "Be brief."}]
body.messages[0].role // "user"
chat-with-tools
fn (model: Str, messages: Vec<::ai::chat/Message>, system: Str?, tools: Vec<::ai::tool/Tool>?): ::ai::chat/ChatReply
fn (model: Str, messages: Vec<::ai::chat/Message>, system: Str?, tools: Vec<::ai::tool/Tool>?, opts: Map): ::ai::chat/ChatReply
Tools-aware chat function for ::ai::chat/run-loop, over Bedrock's
Converse API. Takes the ::ai::chat contract
(model, messages, system, tools), plus a trailing opts Map with
::aws::core/resolve keys (access-key-id, secret-access-key,
session-token, region, endpoint, ...). model is a Bedrock model
id or inference profile, with or without a bedrock/ prefix.
Example
reply ::aws::bedrock::chat-tools/chat-with-tools(
"us.amazon.nova-pro-v1:0",
[::ai::chat/user-message("Say hi.")],
"Be brief.",
null,
{region: "us-east-1"}
)
reply.text
chat-with-tools-options
fn (model: Str, messages: Vec<::ai::chat/Message>, system: Str?, tools: Vec<::ai::tool/Tool>?, options: ChatRequestOptions): ::ai::chat/ChatReply
fn (model: Str, messages: Vec<::ai::chat/Message>, system: Str?, tools: Vec<::ai::tool/Tool>?, options: ChatRequestOptions, opts: Map): ::ai::chat/ChatReply
chat-with-tools with explicit ChatRequestOptions (output ceiling,
sampling, tool mode, model fields such as thinking, a guardrail). Bind it
in a closure to keep the four-argument chat contract.
Example
options ::aws::bedrock::chat-tools/ChatRequestOptions({
max-tokens: 8192,
additional-fields: {thinking: {type: "enabled", budget_tokens: 2048}}
})
chat (model, messages, system, tools) {
::aws::bedrock::chat-tools/chat-with-tools-options(model, messages, system, tools, options)
}
opts ::ai::chat/ChatOptions({chat-fn: chat, model: "us.anthropic.claude-sonnet-4-5-20250929-v1:0"})
chat-with-tools-stream
fn (model: Str, messages: Vec<::ai::chat/Message>, system: Str?, tools: Vec<::ai::tool/Tool>?, on-delta: Fn): ::ai::chat/ChatReply
fn (model: Str, messages: Vec<::ai::chat/Message>, system: Str?, tools: Vec<::ai::tool/Tool>?, on-delta: Fn, opts: Map): ::ai::chat/ChatReply
Streaming chat-with-tools for ::ai::chat/run-loop-stream, over
Converse's stream endpoint. Calls on-delta with each
::ai::chat/ReplyDelta and returns the same ChatReply. The deltas are
sent once the whole stream is in. A trailing opts Map carries
::aws::core/resolve keys.
Example
opts ::ai::chat/ChatOptions({
chat-stream-fn: ::aws::bedrock::chat-tools/chat-with-tools-stream,
model: "us.amazon.nova-pro-v1:0"
})
::ai::chat/run-loop-stream(opts, "Tell me a joke.", (delta) { print(delta) })
chat-with-tools-stream-options
fn (model: Str, messages: Vec<::ai::chat/Message>, system: Str?, tools: Vec<::ai::tool/Tool>?, on-delta: Fn, options: ChatRequestOptions): ::ai::chat/ChatReply
fn (model: Str, messages: Vec<::ai::chat/Message>, system: Str?, tools: Vec<::ai::tool/Tool>?, on-delta: Fn, options: ChatRequestOptions, opts: Map): ::ai::chat/ChatReply
chat-with-tools-stream with explicit ChatRequestOptions, and an
optional trailing opts Map.
Example
options ::aws::bedrock::chat-tools/ChatRequestOptions({max-tokens: 2048})
reply ::aws::bedrock::chat-tools/chat-with-tools-stream-options(
"us.amazon.nova-pro-v1:0",
[::ai::chat/user-message("Count to three.")],
null,
null,
::ai::chat/noop-on-delta,
options
)
handle-event
fn (state: Map, message: ::aws::eventstream/Message, on-delta: Fn): Map
Fold one parsed Converse stream event into the stream state, sending its
ReplyDelta events to on-delta. An exception event is an Err holding
ReplyError (kind: "stream-exception").
Example
event ::aws::eventstream/Message({
headers: {":message-type": "event", ":event-type": "contentBlockDelta"},
payload: Bytes(to-json({contentBlockIndex: 0, delta: {text: "Hi"}}))
})
state ::aws::bedrock::chat-tools/handle-event(::aws::bedrock::chat-tools/EMPTY_STATE, event, ::ai::chat/noop-on-delta)
state.text // "Hi"
is-bedrock-model
fn (model: Str): Bool
True for ids written as bedrock/<model id> (case-insensitive). Bare
Bedrock ids (anthropic.claude-..., us.amazon.nova-...) aren't
claimed, so they don't take models from the Anthropic or OpenAI entries.
Example
::aws::bedrock::chat-tools/is-bedrock-model("bedrock/us.amazon.nova-pro-v1:0") // => true
::aws::bedrock::chat-tools/is-bedrock-model("claude-sonnet-4-5") // => false
model-id
fn (model: Str): Str
The id sent to Bedrock: model without a leading bedrock/.
Example
::aws::bedrock::chat-tools/model-id("bedrock/us.amazon.nova-pro-v1:0") // => "us.amazon.nova-pro-v1:0"
parse-response
fn (body: Map, model: Str): ::ai::chat/ChatReply
A Converse response body as a normalized ::ai::chat/ChatReply: text
blocks joined, toolUse blocks as calls, reasoning blocks kept on the
first call. An Err holding ReplyError when there is no text and no
call.
Example
body {
output: {message: {role: "assistant", content: [{text: "Hi there."}]}},
stopReason: "end_turn",
usage: {inputTokens: 5, outputTokens: 3, totalTokens: 8}
}
reply ::aws::bedrock::chat-tools/parse-response(body, "us.amazon.nova-micro-v1:0")
reply.text // "Hi there."
reply.usage.total-tokens // 8
parse-stream-body
fn (body: Any, model: Str, on-delta: Fn): ::ai::chat/ChatReply
Parse a Converse stream body (AWS event stream bytes) into a ChatReply,
sending each ReplyDelta to on-delta in order and a final
ReplyDelta.Stop.
Example
frame fn (event: Str, payload: Map): ::aws::eventstream/Message {
::aws::eventstream/Message({headers: {":message-type": "event", ":event-type": event}, payload: Bytes(to-json(payload))})
}
events [
frame("contentBlockDelta", {contentBlockIndex: 0, delta: {text: "Hi"}}),
frame("contentBlockStop", {contentBlockIndex: 0}),
frame("messageStop", {stopReason: "end_turn"})
]
reply ::aws::bedrock::chat-tools/reply-from-events(events, "us.amazon.nova-micro-v1:0", ::ai::chat/noop-on-delta)
reply.text // "Hi"
provider
fn (): ::ai::chat/ProviderRegistration
fn (options: ChatRequestOptions): ::ai::chat/ProviderRegistration
An ::ai::chat/ProviderRegistration for Bedrock, for
::ai::chat/with-providers. Its variant is Provider.Bedrock, and it
claims bedrock/<model id> models. Credentials and region resolve on
each call (ctx, or ChatOptions.provider-opts). Pass
ChatRequestOptions for another ceiling, thinking or a guardrail.
Example
opts ::ai::chat/ChatOptions({
model: "bedrock/us.amazon.nova-pro-v1:0",
providers: ::ai::chat/with-providers([::aws::bedrock::chat-tools/provider()])
})
answer ::ai::chat/run-loop(opts, "What is 17 + 25?")
reply-from-events
fn (events: Vec<::aws::eventstream/Message>, model: Str, on-delta: Fn): ::ai::chat/ChatReply
Fold parsed Converse stream events into a ChatReply, sending each
ReplyDelta to on-delta and a final ReplyDelta.Stop. See
parse-stream-body for an example.
Types
Bedrock
Bedrock type {
name: Str
}
Bedrock's identity in ::ai::chat/Provider.
ChatRequestOptions
ChatRequestOptions type {
max-tokens: Int?,
temperature: Dec?,
top-p: Dec?,
stop-sequences: Vec<Str>?,
tool-mode: Str?,
additional-fields: Map?,
guardrail: Map?
}
Per-request controls for the Bedrock adapter. Every field is optional and left out of the request when null.
max-tokens: output ceiling,inferenceConfig.maxTokens(default 4096).temperature,top-p,stop-sequences: the rest ofinferenceConfig.tool-mode:"auto","any"(the model must call a tool), or a tool name (the model must call that one). Sent astoolConfig.toolChoice.additional-fields:additionalModelRequestFields, for model settings Converse doesn't name, such as Claude's{thinking: {type: "enabled", budget_tokens: 2048}}.guardrail:guardrailConfig({guardrailIdentifier, guardrailVersion}).
ReplyError
ReplyError type {
kind: Str,
stop-reason: Str?,
message: Str
}
A Converse reply that can't become a ChatReply.
kind:"empty-reply"(no text and no call),"incomplete-stream"(the stream ended with no stop reason), or"stream-exception"(an exception event inside the stream).stop-reason: Bedrock'sstopReason, when there was one (for exampleguardrail_intervenedorcontent_filtered).message: what happened.