adk-go-bedrock

module
v1.5.10 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0

README

adk-go-bedrock banner showing Agent Development Kit connected to Amazon Bedrock

adk-go-bedrock

Amazon Bedrock Converse / ConverseStream implementation of the model.LLM interface for adk-go, so you can run agents on Claude, Nova, and other Bedrock chat models with the same ADK APIs you use for Gemini.

Other providers: adk-go-ollama · adk-go-kronk

Requirements

  • Go 1.25+ (aligned with google.golang.org/adk/v2)
  • AWS account with Bedrock model access in your chosen region
  • Credentials via the default AWS chain (environment variables, shared config, IAM role, etc.)
  • A region where Bedrock is available: AWS_REGION, or region in ~/.aws/config for your profile
  • IAM permission to call inference, for example:
    • bedrock:InvokeModel for Converse
    • bedrock:InvokeModelWithResponseStream for ConverseStream (when ADK uses SSE streaming)

Install

go get github.com/craigh33/adk-go-bedrock

Replace the module path with your fork or published path if you rename the module in go.mod.

Usage

ctx := context.Background()
llm, err := converse.New(ctx, "us.anthropic.claude-3-5-sonnet-20241022-v2:0", &converse.Options{
    Region: os.Getenv("AWS_REGION"),
})
if err != nil {
    log.Fatal(err)
}

agent, err := llmagent.New(llmagent.Config{
    Name:  "assistant",
    Model: llm,
    Instruction: "You are helpful.",
})
// Wire agent into runner.New(...) as usual.

converse.New accepts a model ID or inference profile ARN as documented by AWS. LLMRequest.Model can override the model ID at runtime (e.g. from ADK callbacks).

The bedrock/mappers package holds genai ↔ Bedrock conversions (requests, responses, tools, usage). Import it if you need the same mappings outside the default converse package. It also exports MIMETypeFromExtension for inferring MIME types from a filename when building genai parts. The Bedrock Runtime API abstraction used by converse.go is exported from converse (RuntimeAPI, StreamReader, and NewRuntimeAPI).

Examples

These runnable programs show how to wire adk-go-bedrock into ADK agents: chat runners, tools, streaming, multimodal and document flows, guardrails, and provider-specific options. Each example has its own README.md and Makefile:

All examples load AWS configuration with config.LoadDefaultConfig and require BEDROCK_MODEL_ID plus region configuration (AWS_REGION or profile region).

export BEDROCK_MODEL_ID=us.anthropic.claude-3-5-sonnet-20241022-v2:0
export AWS_REGION=us-east-1   # optional if your profile already defines region
make -C examples/bedrock-chat run

Run streaming example:

make -C examples/bedrock-stream run

How it maps to Bedrock

  • Messages: genai roles user and model map to Bedrock user and assistant. Optional system role entries in the conversation are mapped to Bedrock system blocks.
  • System instruction: GenerateContentConfig.SystemInstruction is sent as Bedrock system content.
  • Tools: the mapper converts GenerateContentConfig.Tools entries:
    • FunctionDeclarations → Bedrock ToolSpecification (custom function tools)
    • Nova Web Grounding (Bedrock-only): the reserved sentinel from tools/novagrounding maps to Bedrock Converse types.SystemTool{Name: "nova_grounding"} (not a custom ToolSpecification; see Amazon Nova Web Grounding)
    • Non-function ADK variants (Google Search, Code Execution, Retrieval, MCP Servers, Computer Use, File Search, Google Maps, URL Context, etc.) are rejected early with a clear provider error because they are not currently mapped to Bedrock Converse
    • MCP: use ADK mcptoolset so MCP tools become function declarations before they reach this provider (MCP support). Other genai.Tool variants (Google Search, code execution, etc.) are not supported here.
  • Multimodal parts: ADK Part text, thoughts/reasoning, inline/file-backed images, audio, video, and documents are mapped on the Bedrock-compatible subset. Rich user media is sent as Bedrock content blocks; assistant reasoning is preserved as Bedrock reasoning content.
  • Function responses: JSON tool output still maps as before, and image/video/document FunctionResponse.Parts are preserved through Bedrock tool-result content blocks.
  • Streaming: When ADK uses SSE streaming, the provider calls ConverseStream, emits partial text responses, and buffers streamed tool calls, reasoning blocks, image blocks, citation deltas (for grounded responses), usage, and guardrail metadata into the final TurnComplete response.
  • Guardrails / safety results: Bedrock guardrail stop reasons and trace metadata are mapped back into ADK FinishReason and CustomMetadata, including synthesized safety_ratings derived from Bedrock guardrail assessments when available.

Nova Web Grounding

Enable real-time web search for supported Nova models by adding novagrounding.Tool() to GenerateContentConfig.Tools. This tool is Bedrock-specific. Use an applicable Bedrock region and an inference profile that supports Web Grounding (for example us.amazon.nova-2-lite-v1:0; see AWS docs for current model IDs). For current regional availability, check Amazon Bedrock pricing. Converse request payloads use SystemTool name nova_grounding, while IAM policies for bedrock:InvokeTool may reference the resource identifier amazon.nova_grounding.

import (
    "context"

    "google.golang.org/adk/v2/model"
    "google.golang.org/genai"

    "github.com/craigh33/adk-go-bedrock/tools/novagrounding"
)

func groundedAsk(ctx context.Context, llm model.LLM, question string) (*model.LLMResponse, error) {
    req := &model.LLMRequest{
        Contents: []*genai.Content{
            genai.NewContentFromText(question, genai.RoleUser),
        },
        Config: &genai.GenerateContentConfig{
            Tools:           []*genai.Tool{novagrounding.Tool()},
            MaxOutputTokens: 1024,
        },
    }
    var last *model.LLMResponse
    for resp, e := range llm.GenerateContent(ctx, req, false) {
        if e != nil {
            return nil, e
        }
        last = resp
    }
    return last, nil
}

Grounded replies include citation payloads under genai.Part.PartMetadata with key "bedrock_citations" (each entry may include location.url, location.domain, etc.). Retain and surface those citations in user-facing output per AWS guidance.

A runnable CLI lives at examples/bedrock-nova-grounding.

Limitations

  • Bedrock role restrictions: Rich media input still follows Bedrock Converse constraints (for example, user turns are the interoperable place for images/documents/audio/video, while model turns are reserved for text/tool use/reasoning).
  • Request-side generic guardrails: ADK SafetySettings / ModelArmorConfig are not currently supported for Bedrock Converse. Because they do not contain the Bedrock guardrail identifier + version required by Converse, the request builder returns an explicit error instead of silently dropping them, and there is currently no supported way to provide GuardrailIdentifier / GuardrailVersion through this provider.
  • Provider surface mismatch: Bedrock-specific features that require pre-provisioned AWS resources or have no generic ADK equivalent are exposed back through ADK-friendly CustomMetadata, but cannot always be reconstructed into first-class genai request fields.
  • Unsupported tool types: Tool variants not supported by Bedrock or the target model cause a request-time error with details about which variants are unsupported.

Contributing

See CONTRIBUTING.md for Makefile targets, required pre-commit setup, commit message conventions, and pull request guidelines. For new issues, use the bug report or feature request templates.

License

Apache 2.0 — see LICENSE.

Contributing · Issues · Security

Directories

Path Synopsis
artifact
s3
Package s3artifact provides an Amazon S3 implementation of ADK's artifact.Service.
Package s3artifact provides an Amazon S3 implementation of ADK's artifact.Service.
bedrock
examples
bedrock-a2a command
bedrock-agentcore-gateway command
Bedrock AgentCore Gateway example for adk-go: set AGENTCORE_GATEWAY_ENDPOINT, AGENTCORE_GATEWAY_ACCESS_TOKEN, BEDROCK_MODEL_ID, and authenticate with AWS using the default credential chain.
Bedrock AgentCore Gateway example for adk-go: set AGENTCORE_GATEWAY_ENDPOINT, AGENTCORE_GATEWAY_ACCESS_TOKEN, BEDROCK_MODEL_ID, and authenticate with AWS using the default credential chain.
bedrock-agentcore-session command
Bedrock AgentCore session example for adk-go: set BEDROCK_MODEL_ID and authenticate with AWS using the default credential chain.
Bedrock AgentCore session example for adk-go: set BEDROCK_MODEL_ID and authenticate with AWS using the default credential chain.
bedrock-artifact-s3 command
S3 artifact service example for adk-go-bedrock: wires the artifact/s3 artifact.Service into an ADK runner so agent/tool artifacts persist in Amazon S3 instead of process memory, then saves, reloads, and generates a pre-signed download URL for an artifact to show the full round trip.
S3 artifact service example for adk-go-bedrock: wires the artifact/s3 artifact.Service into an ADK runner so agent/tool artifacts persist in Amazon S3 instead of process memory, then saves, reloads, and generates a pre-signed download URL for an artifact to show the full round trip.
bedrock-chat command
Bedrock chat example for adk-go: set BEDROCK_MODEL_ID and authenticate with AWS using the default credential chain (environment variables, shared config ~/.aws/credentials and ~/.aws/config, SSO / AWS_PROFILE, web identity, EC2/ECS/Lambda role, etc.).
Bedrock chat example for adk-go: set BEDROCK_MODEL_ID and authenticate with AWS using the default credential chain (environment variables, shared config ~/.aws/credentials and ~/.aws/config, SSO / AWS_PROFILE, web identity, EC2/ECS/Lambda role, etc.).
bedrock-data-automation command
Bedrock Data Automation example for adk-go.
Bedrock Data Automation example for adk-go.
bedrock-document command
Bedrock document upload example for debugging genai → Converse mapping and model calls.
Bedrock document upload example for debugging genai → Converse mapping and model calls.
bedrock-function-tool command
Bedrock function-tool example for adk-go: uses ADK functiontool with a typed handler (ParametersJsonSchema) and the Bedrock Converse provider.
Bedrock function-tool example for adk-go: uses ADK functiontool with a typed handler (ParametersJsonSchema) and the Bedrock Converse provider.
bedrock-guardrails command
Bedrock guardrails example for adk-go: demonstrates how to work with Bedrock guardrails, including safety assessments, content filtering, and custom metadata.
Bedrock guardrails example for adk-go: demonstrates how to work with Bedrock guardrails, including safety assessments, content filtering, and custom metadata.
bedrock-image-gen command
Bedrock image generation example for adk-go: demonstrates how to use the imagegenerator tool with the ADK runner to generate images via Amazon Nova Canvas.
Bedrock image generation example for adk-go: demonstrates how to use the imagegenerator tool with the ADK runner to generate images via Amazon Nova Canvas.
bedrock-mcp command
Bedrock MCP example for adk-go: demonstrates how to use ADK's MCP toolset with the Bedrock Converse provider.
Bedrock MCP example for adk-go: demonstrates how to use ADK's MCP toolset with the Bedrock Converse provider.
bedrock-multimodal command
Bedrock multimodal example for adk-go: demonstrates image analysis, document processing, vision-based reasoning, tool calling with rich media, and other multimodal content with the Bedrock Converse provider.
Bedrock multimodal example for adk-go: demonstrates image analysis, document processing, vision-based reasoning, tool calling with rich media, and other multimodal content with the Bedrock Converse provider.
bedrock-nova-grounding command
Nova Web Grounding example: set BEDROCK_MODEL_ID to a US inference profile that supports Web Grounding (see AWS docs), AWS_REGION to a US Bedrock region, and authenticate with AWS.
Nova Web Grounding example: set BEDROCK_MODEL_ID to a US inference profile that supports Web Grounding (see AWS docs), AWS_REGION to a US Bedrock region, and authenticate with AWS.
bedrock-prompt-cache command
Bedrock prompt caching example for adk-go: demonstrates WithCacheSystemPrompt, which appends a Bedrock CachePoint after the system prompt so that repeated requests reuse the cached prompt tokens instead of re-processing them.
Bedrock prompt caching example for adk-go: demonstrates WithCacheSystemPrompt, which appends a Bedrock CachePoint after the system prompt so that repeated requests reuse the cached prompt tokens instead of re-processing them.
bedrock-request-guardrail command
Bedrock request guardrail example for adk-go: attaches a preconfigured Bedrock guardrail to one Converse request.
Bedrock request guardrail example for adk-go: attaches a preconfigured Bedrock guardrail to one Converse request.
bedrock-stream command
bedrock-system-instruction command
Bedrock system instruction example for adk-go: demonstrates how to use system instructions for role definition, output formatting, and behavioral control.
Bedrock system instruction example for adk-go: demonstrates how to use system instructions for role definition, output formatting, and behavioral control.
bedrock-tool-calling command
Bedrock tool-calling agent example for adk-go: demonstrates how to define and use tools with the Bedrock model.
Bedrock tool-calling agent example for adk-go: demonstrates how to define and use tools with the Bedrock model.
bedrock-tool-variants command
Bedrock tool variants example for adk-go: demonstrates how to use non-function tool variants including Google Search, Code Execution, Retrieval, MCP Servers, and combinations with function declarations.
Bedrock tool variants example for adk-go: demonstrates how to use non-function tool variants including Google Search, Code Execution, Retrieval, MCP Servers, and combinations with function declarations.
bedrock-video-gen command
Bedrock video generation example for adk-go: demonstrates the videogenerator tool with the ADK runner and Amazon Nova Reel async inference.
Bedrock video generation example for adk-go: demonstrates the videogenerator tool with the ADK runner and Amazon Nova Reel async inference.
bedrock-web-ui command
internal/exampletrace
Package exampletrace provides a small OpenTelemetry setup for examples.
Package exampletrace provides a small OpenTelemetry setup for examples.
internal
mappers
Package mappers converts between ADK/genai types and Amazon Bedrock Converse API types.
Package mappers converts between ADK/genai types and Amazon Bedrock Converse API types.
tools
novagrounding
Package novagrounding enables Amazon Nova Web Grounding for the Bedrock Converse provider only: the sentinel function declaration is mapped to Bedrock's SystemTool name "nova_grounding".
Package novagrounding enables Amazon Nova Web Grounding for the Bedrock Converse provider only: the sentinel function declaration is mapped to Bedrock's SystemTool name "nova_grounding".

Jump to

Keyboard shortcuts

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