bedrock

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package bedrock provides a model.Client implementation backed by the AWS Bedrock Converse API. It mirrors the inference-engine request pipeline used in production systems: split system vs. conversational messages, encode tool schemas into Bedrock's ToolConfiguration, and translate Converse responses (text + tool_use blocks) back into planner-friendly structures.

Package bedrock wires AWS Bedrock model clients into loom-mcp planners.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTemporalLedgerSource

func NewTemporalLedgerSource(c WorkflowQuerier) ledgerSource

NewTemporalLedgerSource constructs a ledger source backed by a workflow querier. It queries the running workflow for provider-ready messages via the "ledger_messages" query.

func SanitizeToolName

func SanitizeToolName(in string) string

SanitizeToolName maps a canonical tool identifier (for example, "atlas.read.get_time_series") to a Bedrock-compatible tool name.

Bedrock imposes stricter tool name constraints than other providers. The tool name string surfaced to the model (and echoed back in tool_use blocks) must match the name registered in the tool configuration. This function implements the exact mapping used by the Bedrock adapter when constructing tool configurations.

Contract:

  • The mapping is deterministic.
  • The mapping preserves canonical namespace information (".") by replacing dots with underscores.
  • The result contains only characters allowed by Bedrock: [a-zA-Z0-9_-]+. Any other rune is replaced with '_'.
  • The result is at most 64 bytes long. If the sanitized name exceeds the limit, it is truncated and a stable hash suffix is appended to preserve uniqueness.

Note: Callers should treat the output as provider-visible. Internally, loom-mcp continues to use canonical tool identifiers; the adapter translates tool_use names back to canonical IDs using the per-request reverse map.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements model.Client on top of AWS Bedrock Converse.

func New

func New(aws *bedrockruntime.Client, opts Options, ledger ledgerSource) (*Client, error)

New initializes a Bedrock-powered model client configured for chat completion and streaming requests. The provided ledgerSource allows the client to prepend provider-verified messages for a specific run ID during request encoding, ensuring transcript continuity across completions.

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, req *model.Request) (*model.Response, error)

Complete issues a chat completion request to the configured Bedrock model using the Converse API and translates the response into planner-friendly structures (assistant messages + tool calls).

func (*Client) CountTokens added in v1.2.0

func (c *Client) CountTokens(ctx context.Context, req *model.Request) (model.TokenCount, error)

CountTokens asks Bedrock to count the exact input tokens for req using the same Converse request preparation path as Complete, except that replayed thinking blocks are omitted per the model.TokenCounter contract.

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, req *model.Request) (model.Streamer, error)

Stream invokes the Bedrock ConverseStream API and adapts incremental events into model.Chunks so planners can surface partial responses.

type Options

type Options struct {
	// Runtime provides access to the Bedrock runtime. Required.
	Runtime RuntimeClient

	// DefaultModel is the default model identifier (e.g., Sonnet).
	DefaultModel string

	// HighModel is the high-reasoning model identifier (e.g., Opus/Sonnet-Reasoning).
	HighModel string

	// SmallModel is the small/cheap model identifier (e.g., Haiku).
	SmallModel string

	// MaxTokens sets the default completion cap when a request does not specify
	// MaxTokens. When zero or negative, the client omits MaxTokens so Bedrock
	// uses its own default.
	MaxTokens int

	// Temperature is used when a request does not specify Temperature.
	Temperature float32

	// ThinkingBudget defines the thinking token budget when thinking is enabled
	// for streaming calls. When zero or negative, the client omits
	// budget_tokens so Bedrock uses its own default budget.
	ThinkingBudget int

	// Logger is used for non-fatal diagnostics inside the Bedrock adapter.
	// When nil, defaults to a no-op logger.
	Logger telemetry.Logger
}

Options configures the Bedrock client adapter.

type RuntimeClient

type RuntimeClient interface {
	Converse(ctx context.Context, params *bedrockruntime.ConverseInput, optFns ...func(*bedrockruntime.Options)) (*bedrockruntime.ConverseOutput, error)
	ConverseStream(ctx context.Context, params *bedrockruntime.ConverseStreamInput, optFns ...func(*bedrockruntime.Options)) (*bedrockruntime.ConverseStreamOutput, error)
}

RuntimeClient mirrors the subset of the AWS Bedrock runtime client required by the adapter. It matches *bedrockruntime.Client so callers can pass either the real client or a mock in tests.

type StreamOutput

type StreamOutput interface {
	GetStream() *bedrockruntime.ConverseStreamEventStream
}

StreamOutput is the subset of the AWS ConverseStream output type required by the adapter. It is satisfied by *bedrockruntime.ConverseStreamOutput and simplifies unit testing by allowing fake implementations.

type WorkflowQuerier

type WorkflowQuerier interface {
	QueryWorkflow(ctx context.Context, workflowID, queryType string, args ...any) (converter.EncodedValue, error)
}

WorkflowQuerier captures the only workflow-query capability the Bedrock ledger bridge needs from a durable engine. The workflowID identifies the durable workflow, while queryType selects the engine-specific query handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL