Skip to content

The agent that grows with you

fix(bedrock): align auxiliary region resolution with runtime + document Mantle route

Vinay Shah41ca67c5b134
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index c4366732689..7322a14b9a4 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -7006,7 +7006,7 @@ def resolve_provider_client(
from agent.bedrock_adapter import (
has_aws_credentials,
is_anthropic_bedrock_model,
- resolve_bedrock_region,
+ resolve_bedrock_runtime_region,
is_openai_bedrock_model,
bedrock_openai_base_url,
resolve_bedrock_bearer_token,
@@ -7023,7 +7023,11 @@ def resolve_provider_client(
"no AWS credentials found")
return None, None
- region = resolve_bedrock_region()
+ # Region must match the main runtime's resolution (bedrock.region in
+ # config.yaml first, then env/profile) — see review on #53880/#65076:
+ # a bare resolve_bedrock_region() here let auxiliary calls (compression,
+ # memory, vision) leave the primary runtime's configured region.
+ region = resolve_bedrock_runtime_region()
default_model = "anthropic.claude-haiku-4-5-20251001-v1:0"
final_model = _normalize_resolved_model(model or default_model, provider) or default_model
diff --git a/agent/bedrock_adapter.py b/agent/bedrock_adapter.py
index fbb908d0482..d39767fcc4a 100644
--- a/agent/bedrock_adapter.py
+++ b/agent/bedrock_adapter.py
@@ -543,6 +543,36 @@ def resolve_bedrock_region(env: Optional[Dict[str, str]] = None) -> str:
return "us-east-1"
+def resolve_bedrock_runtime_region(config: Optional[Dict[str, Any]] = None) -> str:
+ """Resolve the Bedrock region with the same priority as the main runtime.
+
+ Priority (matches the runtime provider resolver in
+ ``hermes_cli/runtime_provider.py``):
+ 1. ``bedrock.region`` in config.yaml
+ 2. ``resolve_bedrock_region()`` (AWS_REGION / AWS_DEFAULT_REGION /
+ botocore profile / us-east-1)
+
+ Callers that already hold a loaded config dict should pass it to avoid a
+ disk read; when *config* is None the config is loaded read-only. Every
+ non-runtime call site that constructs a Bedrock endpoint (auxiliary
+ client resolution, model discovery for the picker) must use this helper —
+ using bare ``resolve_bedrock_region()`` there lets auxiliary calls leave
+ the primary runtime's configured region when ``bedrock.region`` and the
+ ambient AWS env/profile disagree.
+ """
+ if config is None:
+ try:
+ from hermes_cli.config import load_config_readonly
+ config = load_config_readonly()
+ except Exception:
+ config = {}
+ bedrock_cfg = (config or {}).get("bedrock") or {}
+ cfg_region = str(bedrock_cfg.get("region") or "").strip()
+ if cfg_region:
+ return cfg_region
+ return resolve_bedrock_region()
+
+
def bedrock_model_ids_or_none() -> Optional[List[str]]:
"""Live-discover Bedrock model IDs for the active region.
diff --git a/hermes_cli/runtime_provider.py b/hermes_cli/runtime_provider.py
index d3d54e3ed5c..2058f9d642e 100644
--- a/hermes_cli/runtime_provider.py
+++ b/hermes_cli/runtime_provider.py
@@ -2257,7 +2257,9 @@ def resolve_runtime_provider(
)
# Read bedrock-specific config from config.yaml
_bedrock_cfg = load_config().get("bedrock", {})
- # Region priority: config.yaml bedrock.region → env var → us-east-1
+ # Region priority: config.yaml bedrock.region → env var → us-east-1.
+ # Same resolution as resolve_bedrock_runtime_region() in
+ # agent/bedrock_adapter.py — auxiliary calls must agree with this.
region = (_bedrock_cfg.get("region") or "").strip() or resolve_bedrock_region()
auth_source = resolve_aws_auth_env_var() or "aws-sdk-default-chain"
# Build guardrail config if configured
diff --git a/tests/agent/test_bedrock_integration.py b/tests/agent/test_bedrock_integration.py
index c8ef491e6be..890f51fe2b5 100644
--- a/tests/agent/test_bedrock_integration.py
+++ b/tests/agent/test_bedrock_integration.py
@@ -208,7 +208,7 @@ class TestRuntimeProvider:
Responses route as GPT-5.5 — none of them are Converse models."""
from hermes_cli.runtime_provider import resolve_runtime_provider
- monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAIO...MPLE")
+ monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
monkeypatch.setenv("AWS_REGION", "us-east-2")
@@ -472,8 +472,88 @@ class TestAuxiliaryClientBedrockResolution:
assert client is None
assert model is None
+ def test_bedrock_config_region_beats_env_region(self, monkeypatch):
+ """bedrock.region in config.yaml must win over AWS_REGION for auxiliary
+ calls — the same priority the main runtime resolver uses.
+
+ Regression for the #65076 review: auxiliary resolution derived its
+ region with bare resolve_bedrock_region() (env-first), so when
+ config.yaml pinned bedrock.region to a different region than the
+ ambient AWS env, auxiliary calls (compression, memory, vision) left
+ the primary runtime's region.
+ """
+ monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE")
+ monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
+ monkeypatch.setenv("AWS_REGION", "eu-central-1")
+
+ with patch("hermes_cli.config.load_config_readonly",
+ return_value={"bedrock": {"region": "us-west-2"}}), \
+ patch("agent.anthropic_adapter.build_anthropic_bedrock_client",
+ return_value=MagicMock()):
+ from agent.auxiliary_client import resolve_provider_client
+ client, _ = resolve_provider_client("bedrock", None)
+
+ assert client is not None
+ assert "us-west-2" in client.base_url, (
+ "auxiliary Bedrock client ignored config.yaml bedrock.region — "
+ "it must match the main runtime's region priority"
+ )
+
+ def test_bedrock_mantle_config_region_beats_env_region(self, monkeypatch):
+ """Same config-over-env priority for the Mantle (OpenAI Responses) path."""
+ monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE")
+ monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
+ monkeypatch.setenv("AWS_REGION", "eu-central-1")
+ monkeypatch.setenv("AWS_BEARER_TOKEN_BEDROCK", "test-bearer")
+
+ captured = {}
+
+ class _FakeOpenAI:
+ def __init__(self, **kwargs):
+ captured.update(kwargs)
+ self.api_key = kwargs.get("api_key")
+ self.base_url = kwargs.get("base_url")
+
+ def close(self):
+ pass
+
+ with patch("hermes_cli.config.load_config_readonly",
+ return_value={"bedrock": {"region": "us-west-2"}}), \
+ patch("agent.auxiliary_client.OpenAI", _FakeOpenAI):
+ from agent.auxiliary_client import resolve_provider_client
+ client, model = resolve_provider_client("bedrock", "openai.gpt-5.6-sol")
+
+ assert client is not None
+ assert "us-west-2" in captured.get("base_url", ""), (
+ "Mantle auxiliary base_url ignored config.yaml bedrock.region"
+ )
+
+ def test_bedrock_respects_explicit_model(self, monkeypatch):
+ """When caller passes an explicit model, it should be used."""
+ monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE")
+ monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
+
+ with patch("agent.anthropic_adapter.build_anthropic_bedrock_client",
+ return_value=MagicMock()):
+ from agent.auxiliary_client import resolve_provider_client
+ _, model = resolve_provider_client(
+ "bedrock", "us.anthropic.claude-sonnet-4-5-20250929-v1:0"
+ )
+
+ assert "claude-sonnet" in model
+
+ def test_bedrock_async_mode(self, monkeypatch):
+ """Async mode should return an AsyncAnthropicAuxiliaryClient."""
+ monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE")
+ monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
+ with patch("agent.anthropic_adapter.build_anthropic_bedrock_client",
+ return_value=MagicMock()):
+ from agent.auxiliary_client import resolve_provider_client, AsyncAnthropicAuxiliaryClient
+ client, model = resolve_provider_client("bedrock", None, async_mode=True)
+ assert client is not None
+ assert isinstance(client, AsyncAnthropicAuxiliaryClient)
def test_bedrock_default_model_is_haiku(self, monkeypatch):
"""Default auxiliary model for Bedrock should be Haiku (fast, cheap)."""
@@ -490,11 +570,61 @@ class TestAuxiliaryClientBedrockResolution:
+ def test_bedrock_claude_model_still_uses_anthropic_client(self, monkeypatch):
+ """Claude Bedrock IDs should keep the Anthropic SDK auxiliary path."""
+ monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE")
+ monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
+
+ mock_anthropic_bedrock = MagicMock()
+ with patch("agent.anthropic_adapter.build_anthropic_bedrock_client",
+ return_value=mock_anthropic_bedrock):
+ from agent.auxiliary_client import (
+ AnthropicAuxiliaryClient,
+ resolve_provider_client,
+ )
+ client, model = resolve_provider_client(
+ "bedrock", "us.anthropic.claude-sonnet-4-5-20250929-v1:0"
+ )
+
+ assert isinstance(client, AnthropicAuxiliaryClient)
+ assert "claude-sonnet" in model
+
+ def test_bedrock_non_claude_async_mode(self, monkeypatch):
+ """Async mode for non-Claude Bedrock should return AsyncBedrockAuxiliaryClient."""
+ monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE")
+ monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
+
+ with patch("agent.anthropic_adapter.build_anthropic_bedrock_client"):
+ from agent.auxiliary_client import (
+ AsyncBedrockAuxiliaryClient,
+ resolve_provider_client,
+ )
+ client, _ = resolve_provider_client(
+ "bedrock", "openai.gpt-oss-20b-1:0", async_mode=True
+ )
+
+ assert isinstance(client, AsyncBedrockAuxiliaryClient)
+
+ def test_bedrock_converse_shim_normalizes_string_stop(self, monkeypatch):
+ """OpenAI callers may pass stop='STR'; Converse requires a list."""
+ monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE")
+ monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
+
+ from agent.auxiliary_client import BedrockAuxiliaryClient
+
+ client = BedrockAuxiliaryClient("us-east-1", "openai.gpt-oss-20b-1:0")
+ with patch("agent.bedrock_adapter.call_converse") as mock_converse:
+ client.chat.completions.create(
+ model="openai.gpt-oss-20b-1:0",
+ messages=[{"role": "user", "content": "hi"}],
+ stop="STOP",
+ )
+ assert mock_converse.call_args.kwargs["stop_sequences"] == ["STOP"]
def test_bedrock_converse_shim_stream_returns_complete_response(self, monkeypatch):
"""stream=True is not supported by the shim — a complete response comes
back and call_llm's streaming consumer downgrades gracefully."""
- monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAIO...MPLE")
+ monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
from agent.auxiliary_client import BedrockAuxiliaryClient
diff --git a/tests/hermes_cli/test_bedrock_model_picker.py b/tests/hermes_cli/test_bedrock_model_picker.py
index 7802592c476..7d8024bad03 100644
--- a/tests/hermes_cli/test_bedrock_model_picker.py
+++ b/tests/hermes_cli/test_bedrock_model_picker.py
@@ -99,12 +99,6 @@ class TestProviderModelIdsBedrock:
assert _m in us_result
assert eu_result != us_result
-
-
- # Should fall back to static table (may be empty or populated depending on
- # the current static list, but must not crash and must be a list).
- assert isinstance(result, list)
-
def test_falls_back_to_static_list_on_exception(self, monkeypatch):
"""When discover_bedrock_models() raises, fall back gracefully."""
from hermes_cli.models import provider_model_ids
@@ -137,12 +131,6 @@ class TestProviderModelIdsBedrock:
class TestListAuthenticatedProvidersBedrock:
"""Bedrock should appear in the /model picker when AWS creds are present."""
-
-
-
- bedrock = next((p for p in providers if p["slug"] == "bedrock"), None)
- assert bedrock is not None, "bedrock should appear when AWS credentials are present"
-
def test_bedrock_uses_live_discovery_not_static_list(self, monkeypatch):
"""Model IDs come from discover_bedrock_models(), not the static _PROVIDER_MODELS table."""
from hermes_cli.model_switch import list_authenticated_providers
diff --git a/website/docs/guides/aws-bedrock.md b/website/docs/guides/aws-bedrock.md
index ec7b1224fce..4aed045cef8 100644
--- a/website/docs/guides/aws-bedrock.md
+++ b/website/docs/guides/aws-bedrock.md
@@ -1,12 +1,22 @@
---
sidebar_position: 14
title: "AWS Bedrock"
-description: "Use Hermes Agent with Amazon Bedrock — native Converse API, IAM authentication, Guardrails, and cross-region inference"
+description: "Use Hermes Agent with Amazon Bedrock — native Converse API, Anthropic SDK routing, OpenAI models via Bedrock Mantle, IAM authentication, Guardrails, and cross-region inference"
---
# AWS Bedrock
-Hermes Agent supports Amazon Bedrock as a native provider using the **Converse API** — not the OpenAI-compatible endpoint. This gives you full access to the Bedrock ecosystem: IAM authentication, Guardrails, cross-region inference profiles, and all foundation models.
+Hermes Agent supports Amazon Bedrock as a native provider. This gives you full access to the Bedrock ecosystem: IAM authentication, Guardrails, cross-region inference profiles, and all foundation models.
+
+Hermes routes each model family through the API that serves it best:
+
+| Model family | API route | Why |
+|---|---|---|
+| Anthropic Claude | Anthropic SDK (`AnthropicBedrock`) | Prompt caching, thinking budgets, adaptive thinking — features not exposed via Converse |
+| OpenAI GPT-5.5 / GPT-5.6 (Sol, Terra, Luna) | Bedrock Mantle **OpenAI Responses** endpoint (`bedrock-mantle.<region>.api.aws/openai/v1`) | These models are Mantle-only — their model cards list bedrock-runtime/Converse as unsupported |
+| Everything else (Nova, DeepSeek, Llama, GPT-OSS, …) | Native **Converse API** (`bedrock-runtime`) | Full Bedrock feature set: Guardrails, inference profiles, streaming |
+
+All three routes share the same AWS credential chain and region resolution — no separate configuration is needed. Requests to the Mantle endpoint are authenticated with `AWS_BEARER_TOKEN_BEDROCK` when set, or SigV4-signed via the standard boto3 credential chain otherwise.
## Prerequisites
@@ -105,13 +115,17 @@ Bedrock models use **inference profile IDs** for on-demand invocation. The `herm
| Claude Sonnet 4.6 | `us.anthropic.claude-sonnet-4-6` | Recommended — best balance of speed and capability |
| Claude Opus 4.6 | `us.anthropic.claude-opus-4-6-v1` | Most capable |
| Claude Haiku 4.5 | `us.anthropic.claude-haiku-4-5-20251001-v1:0` | Fastest Claude |
+| OpenAI GPT-5.6 Sol | `openai.gpt-5.6-sol` | OpenAI frontier model (via Bedrock Mantle) |
+| OpenAI GPT-5.6 Terra | `openai.gpt-5.6-terra` | Balanced (via Bedrock Mantle) |
+| OpenAI GPT-5.6 Luna | `openai.gpt-5.6-luna` | Fast, affordable (via Bedrock Mantle) |
+| OpenAI GPT-5.5 | `openai.gpt-5.5` | Previous OpenAI flagship (via Bedrock Mantle) |
| Amazon Nova Pro | `us.amazon.nova-pro-v1:0` | Amazon's flagship |
| Amazon Nova Micro | `us.amazon.nova-micro-v1:0` | Fastest, cheapest |
| DeepSeek V3.2 | `deepseek.v3.2` | Strong open model |
| Llama 4 Scout 17B | `us.meta.llama4-scout-17b-instruct-v1:0` | Meta's latest |
:::info Cross-Region Inference
-Models prefixed with `us.` use cross-region inference profiles, which provide better capacity and automatic failover across AWS regions. Models prefixed with `global.` route across all available regions worldwide.
+Models prefixed with `us.` use cross-region inference profiles, which provide better capacity and automatic failover across AWS regions. Models prefixed with `global.` route across all available regions worldwide. OpenAI `openai.*` model IDs are served by Bedrock Mantle in the configured region and don't use inference-profile prefixes.
:::
## Switching Models Mid-Session