Class: ActiveAgent::Providers::BedrockProvider

Inherits:
AnthropicProvider show all
Defined in:
lib/active_agent/providers/bedrock_provider.rb

Overview

Provider for Anthropic models hosted on AWS Bedrock.

Inherits all functionality from AnthropicProvider (streaming, tool use, multimodal, JSON format emulation) and overrides only the client construction to use Anthropic::BedrockClient for AWS authentication.

Examples:

Configuration in active_agent.yml

bedrock:
  service: "Bedrock"
  aws_region: "eu-west-2"
  model: "eu.anthropic.claude-sonnet-4-5-20250929-v1:0"

Agent usage

class SummaryAgent < ApplicationAgent
  generate_with :bedrock, model: "eu.anthropic.claude-sonnet-4-5-20250929-v1:0"

  def summarize
    prompt(message: params[:message])
  end
end

See Also:

Constant Summary

Constants inherited from AnthropicProvider

AnthropicProvider::JSON_RESPONSE_FORMAT_LEAD_IN

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AnthropicProvider

#initialize

Methods inherited from BaseProvider

#embed, embed_request_type, #initialize, namespace, #preview, #prompt, tag_name

Methods included from ToolChoiceClearing

#prepare_prompt_request_tools

Methods included from Previewable

#preview_prompt

Methods included from Instrumentation

#instrumentation_prompt_payload

Methods included from ExceptionHandler

#configure_exception_handler, #rescue_with_handler, #with_exception_handling

Constructor Details

This class inherits a constructor from ActiveAgent::Providers::AnthropicProvider

Class Method Details

.options_klassClass

Returns:

  • (Class)


37
38
39
# File 'lib/active_agent/providers/bedrock_provider.rb', line 37

def self.options_klass
  Bedrock::Options
end

.prompt_request_typeActiveModel::Type::Value

Returns:

  • (ActiveModel::Type::Value)


42
43
44
# File 'lib/active_agent/providers/bedrock_provider.rb', line 42

def self.prompt_request_type
  Anthropic::RequestType.new
end

.service_nameString

Returns:

  • (String)


32
33
34
# File 'lib/active_agent/providers/bedrock_provider.rb', line 32

def self.service_name
  "Bedrock"
end

Instance Method Details

#clientBedrock::BearerClient, Anthropic::Helpers::Bedrock::Client

Returns a configured Bedrock client.

When a bearer token is available (via aws_bearer_token option or AWS_BEARER_TOKEN_BEDROCK env var), uses ActiveAgent::Providers::Bedrock::BearerClient which sends an Authorization: Bearer header.

Otherwise, falls back to Anthropic::BedrockClient which handles SigV4 signing, credential resolution, and Bedrock URL path rewriting.

Returns:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/active_agent/providers/bedrock_provider.rb', line 56

def client
  @client ||= if options.aws_bearer_token.present?
    Bedrock::BearerClient.new(
      aws_region:          options.aws_region,
      bearer_token:        options.aws_bearer_token,
      base_url:            options.base_url.presence,
      max_retries:         options.max_retries,
      timeout:             options.timeout,
      initial_retry_delay: options.initial_retry_delay,
      max_retry_delay:     options.max_retry_delay
    )
  else
    ::Anthropic::BedrockClient.new(
      aws_region:          options.aws_region,
      aws_access_key:      options.aws_access_key,
      aws_secret_key:      options.aws_secret_key,
      aws_session_token:   options.aws_session_token,
      aws_profile:         options.aws_profile,
      base_url:            options.base_url.presence,
      max_retries:         options.max_retries,
      timeout:             options.timeout,
      initial_retry_delay: options.initial_retry_delay,
      max_retry_delay:     options.max_retry_delay
    )
  end
end