跳到主要内容

AWS Bedrock

Hermes Agent 原生支持把 Amazon Bedrock 作为 provider 使用,并且接的是 Converse API,不是 OpenAI 兼容接口。这意味着你可以完整使用 Bedrock 生态:IAM 认证、Guardrails、跨区域 inference profiles,以及所有 foundation models。

前置条件

  • AWS credentials —— 任何 boto3 credential chain 支持的来源都可以:
    • IAM instance role(EC2、ECS、Lambda,无需额外配置)
    • AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY 环境变量
    • AWS_PROFILE(用于 SSO 或命名 profile)
    • 本地开发时使用 aws configure
  • boto3 —— 通过 pip install hermes-agent[bedrock] 安装
  • IAM 权限 —— 至少需要:
    • bedrock:InvokeModelbedrock:InvokeModelWithResponseStream(用于推理)
    • bedrock:ListFoundationModelsbedrock:ListInferenceProfiles(用于模型发现)
EC2 / ECS / Lambda

如果你运行在 AWS 计算环境中,只需给实例或任务挂上带 AmazonBedrockFullAccess 的 IAM role 即可。无需 API key,也不需要配置 .env。Hermes 会自动识别实例角色。

快速开始

# Install with Bedrock support
pip install hermes-agent[bedrock]

# Select Bedrock as your provider
hermes model
# → Choose "More providers..." → "AWS Bedrock"
# → Select your region and model

# Start chatting
hermes chat

配置

运行 hermes model 后,你的 ~/.hermes/config.yaml 中会出现类似内容:

model:
default: us.anthropic.claude-sonnet-4-6
provider: bedrock
base_url: https://bedrock-runtime.us-east-2.amazonaws.com

bedrock:
region: us-east-2

区域

AWS 区域会按以下优先级解析(从高到低):

  1. config.yaml 中的 bedrock.region
  2. AWS_REGION 环境变量
  3. AWS_DEFAULT_REGION 环境变量
  4. 默认值:us-east-1

Guardrails

如果你想把 Amazon Bedrock Guardrails 应用到所有模型调用上,可以这样配置:

bedrock:
region: us-east-2
guardrail:
guardrail_identifier: "abc123def456" # From the Bedrock console
guardrail_version: "1" # Version number or "DRAFT"
stream_processing_mode: "async" # "sync" or "async"
trace: "disabled" # "enabled", "disabled", or "enabled_full"

模型发现

Hermes 会通过 Bedrock control plane 自动发现可用模型。你也可以自定义发现行为:

bedrock:
discovery:
enabled: true
provider_filter: ["anthropic", "amazon"] # Only show these providers
refresh_interval: 3600 # Cache for 1 hour

可用模型

Bedrock 在按需调用时使用的是 inference profile IDhermes model 选择器会自动展示这些 ID,并把推荐模型放在最上面:

ModelIDNotes
Claude Sonnet 4.6us.anthropic.claude-sonnet-4-6推荐,速度与能力平衡最好
Claude Opus 4.6us.anthropic.claude-opus-4-6-v1能力最强
Claude Haiku 4.5us.anthropic.claude-haiku-4-5-20251001-v1:0Claude 系列中最快
Amazon Nova Prous.amazon.nova-pro-v1:0Amazon 旗舰模型
Amazon Nova Microus.amazon.nova-micro-v1:0最快、最便宜
DeepSeek V3.2deepseek.v3.2很强的开放模型
Llama 4 Scout 17Bus.meta.llama4-scout-17b-instruct-v1:0Meta 最新系列
Cross-Region Inference

us. 为前缀的模型使用的是跨区域 inference profile,通常拥有更好的容量,并能在 AWS 区域之间自动故障切换。以 global. 为前缀的模型则会在全球所有可用区域中进行路由。

在会话中切换模型

你可以在对话中直接使用 /model

/model us.amazon.nova-pro-v1:0
/model deepseek.v3.2
/model us.anthropic.claude-opus-4-6-v1

诊断

hermes doctor

doctor 会检查:

  • AWS credentials 是否可用(环境变量、IAM role、SSO)
  • boto3 是否已安装
  • Bedrock API 是否可访问(ListFoundationModels
  • 当前区域里可用模型的数量

Gateway(消息平台)

Bedrock 能和所有 Hermes 网关平台配合使用(Telegram、Discord、Slack、Feishu 等)。只要把 Bedrock 配成 provider,然后像平常一样启动 gateway:

hermes gateway setup
hermes gateway start

gateway 会读取 config.yaml,并使用同一套 Bedrock provider 配置。

故障排除

"No API key found" / "No AWS credentials"

Hermes 会按以下顺序查找凭据:

  1. AWS_BEARER_TOKEN_BEDROCK
  2. AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY
  3. AWS_PROFILE
  4. EC2 instance metadata(IMDS)
  5. ECS container credentials
  6. Lambda execution role

如果这些都不存在,请运行 aws configure,或者给你的 AWS 计算实例绑定 IAM role。

"Invocation of model ID ... with on-demand throughput isn't supported"

请使用 inference profile ID(带 us.global. 前缀),而不是裸 foundation model ID。例如:

  • anthropic.claude-sonnet-4-6
  • us.anthropic.claude-sonnet-4-6

"ThrottlingException"

这表示你碰到了 Bedrock 针对该模型的限流。Hermes 会自动使用退避重试。如果你需要更高额度,请到 AWS Service Quotas console 申请提升配额。