Skip to content

fix(bedrock): inference profile ID preservation + correct client rebuild on interrupt - #14680

Closed
bsgdigital wants to merge 2 commits into
NousResearch:mainfrom
bsgdigital:fix/bedrock-inference-profile-and-rebuild
Closed

fix(bedrock): inference profile ID preservation + correct client rebuild on interrupt#14680
bsgdigital wants to merge 2 commits into
NousResearch:mainfrom
bsgdigital:fix/bedrock-inference-profile-and-rebuild

Conversation

@bsgdigital

Copy link
Copy Markdown
Contributor

Bug Description

Two Bedrock-specific bugs that cause failures when running hermes-agent with AWS Bedrock as the inference provider.

Root Cause / Fix

1. Bedrock inference profile IDs mangled by normalize_model_name

Bedrock cross-region inference profile IDs use dots as namespace separators (us.anthropic.claude-haiku-4-5-20251001-v1:0). The existing normalize_model_name() function converted those dots to hyphens (OpenRouter compat path), turning the model ID into garbage and causing ValidationException from Bedrock.

Fix: add an early-return in normalize_model_name() for IDs that start with us., eu., ap., or global. — these are Bedrock inference profile namespaces and must be passed through unchanged.

2. Client rebuild after interrupt always uses direct Anthropic SDK

When a Ctrl-C interrupt is caught, the agent rebuilds self._anthropic_client. The original code always called build_anthropic_client(), which requires a direct Anthropic API key (ANTHROPIC_API_KEY). On Bedrock there is no such key — auth goes through AWS SDK — so the rebuilt client was misconfigured and subsequent requests failed.

Fix: extract a _rebuild_anthropic_client() method that checks self.provider == "bedrock" and calls build_anthropic_bedrock_client() via AnthropicBedrock instead. The three rebuild call sites in run_agent.py are updated to use it. Also adds the aws_sdk auth_type path to resolve_provider_client() in agent/auxiliary_client.py so the auxiliary client (used for vision/summarization) works with Bedrock too.

Files Changed

  • agent/anthropic_adapter.py — add early-return for Bedrock inference profile ID prefixes
  • run_agent.py — add _rebuild_anthropic_client(), update 3 rebuild call sites
  • agent/auxiliary_client.py — add aws_sdk auth_type branch to resolve_provider_client()

How to Verify

  1. Configure hermes with provider: bedrock and a cross-region inference profile model like us.anthropic.claude-haiku-4-5-20251001-v1:0
  2. Start a conversation — should connect without ValidationException
  3. Press Ctrl-C during a response to trigger an interrupt — subsequent messages should continue working
  4. Use any vision/image tool — should work without errors about missing Anthropic API key

Test Plan

  • Existing tests pass (no regressions)
  • Manually verified against live Bedrock endpoints

Risk Assessment

Low — changes are gated to Bedrock-specific paths only. The normalize_model_name early-return fires only for us./eu./ap./global. prefixes that no other provider uses. The _rebuild_anthropic_client refactor is a pure code-motion change with identical behaviour for non-Bedrock providers.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Apr 23, 2026
teknium1 pushed a commit that referenced this pull request Apr 24, 2026
…rupt

Three interrupt-recovery sites in run_agent.py rebuilt self._anthropic_client
with build_anthropic_client(self._anthropic_api_key, ...) unconditionally.
When provider=bedrock + api_mode=anthropic_messages (AnthropicBedrock SDK
path), self._anthropic_api_key is the sentinel 'aws-sdk' — build_anthropic_client
doesn't accept that and the rebuild either crashed or produced a non-functional
client.

Extract a _rebuild_anthropic_client() helper that dispatches to
build_anthropic_bedrock_client(region) when provider='bedrock', falling back
to build_anthropic_client() for native Anthropic and other anthropic_messages
providers (MiniMax, Kimi, Alibaba, etc.). Three inline rebuild sites now call
the helper.

Partial salvage of #14680 by @bsgdigital — only the _rebuild_anthropic_client
helper. The normalize_model_name Bedrock-prefix piece was subsumed by #14664,
and the aux client aws_sdk branch was subsumed by #14770 (both in the same
salvage PR as this commit).
justrhoto pushed a commit to justrhoto/hermes-agent that referenced this pull request Apr 24, 2026
…rupt

Three interrupt-recovery sites in run_agent.py rebuilt self._anthropic_client
with build_anthropic_client(self._anthropic_api_key, ...) unconditionally.
When provider=bedrock + api_mode=anthropic_messages (AnthropicBedrock SDK
path), self._anthropic_api_key is the sentinel 'aws-sdk' — build_anthropic_client
doesn't accept that and the rebuild either crashed or produced a non-functional
client.

Extract a _rebuild_anthropic_client() helper that dispatches to
build_anthropic_bedrock_client(region) when provider='bedrock', falling back
to build_anthropic_client() for native Anthropic and other anthropic_messages
providers (MiniMax, Kimi, Alibaba, etc.). Three inline rebuild sites now call
the helper.

Partial salvage of NousResearch#14680 by @bsgdigital — only the _rebuild_anthropic_client
helper. The normalize_model_name Bedrock-prefix piece was subsumed by NousResearch#14664,
and the aux client aws_sdk branch was subsumed by NousResearch#14770 (both in the same
salvage PR as this commit).
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for this contribution, @bsgdigital! All three fixes from this PR are now on main — closing as implemented.

This is an automated hermes-sweeper review.

What landed:

All changes verified present in agent/anthropic_adapter.py, agent/auxiliary_client.py, and run_agent.py on current main.

@teknium1 teknium1 closed this Apr 27, 2026
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 1, 2026
…rupt

Three interrupt-recovery sites in run_agent.py rebuilt self._anthropic_client
with build_anthropic_client(self._anthropic_api_key, ...) unconditionally.
When provider=bedrock + api_mode=anthropic_messages (AnthropicBedrock SDK
path), self._anthropic_api_key is the sentinel 'aws-sdk' — build_anthropic_client
doesn't accept that and the rebuild either crashed or produced a non-functional
client.

Extract a _rebuild_anthropic_client() helper that dispatches to
build_anthropic_bedrock_client(region) when provider='bedrock', falling back
to build_anthropic_client() for native Anthropic and other anthropic_messages
providers (MiniMax, Kimi, Alibaba, etc.). Three inline rebuild sites now call
the helper.

Partial salvage of NousResearch#14680 by @bsgdigital — only the _rebuild_anthropic_client
helper. The normalize_model_name Bedrock-prefix piece was subsumed by NousResearch#14664,
and the aux client aws_sdk branch was subsumed by NousResearch#14770 (both in the same
salvage PR as this commit).
donald131 pushed a commit to donald131/hermes-agent that referenced this pull request May 2, 2026
…rupt

Three interrupt-recovery sites in run_agent.py rebuilt self._anthropic_client
with build_anthropic_client(self._anthropic_api_key, ...) unconditionally.
When provider=bedrock + api_mode=anthropic_messages (AnthropicBedrock SDK
path), self._anthropic_api_key is the sentinel 'aws-sdk' — build_anthropic_client
doesn't accept that and the rebuild either crashed or produced a non-functional
client.

Extract a _rebuild_anthropic_client() helper that dispatches to
build_anthropic_bedrock_client(region) when provider='bedrock', falling back
to build_anthropic_client() for native Anthropic and other anthropic_messages
providers (MiniMax, Kimi, Alibaba, etc.). Three inline rebuild sites now call
the helper.

Partial salvage of NousResearch#14680 by @bsgdigital — only the _rebuild_anthropic_client
helper. The normalize_model_name Bedrock-prefix piece was subsumed by NousResearch#14664,
and the aux client aws_sdk branch was subsumed by NousResearch#14770 (both in the same
salvage PR as this commit).
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…rupt

Three interrupt-recovery sites in run_agent.py rebuilt self._anthropic_client
with build_anthropic_client(self._anthropic_api_key, ...) unconditionally.
When provider=bedrock + api_mode=anthropic_messages (AnthropicBedrock SDK
path), self._anthropic_api_key is the sentinel 'aws-sdk' — build_anthropic_client
doesn't accept that and the rebuild either crashed or produced a non-functional
client.

Extract a _rebuild_anthropic_client() helper that dispatches to
build_anthropic_bedrock_client(region) when provider='bedrock', falling back
to build_anthropic_client() for native Anthropic and other anthropic_messages
providers (MiniMax, Kimi, Alibaba, etc.). Three inline rebuild sites now call
the helper.

Partial salvage of NousResearch#14680 by @bsgdigital — only the _rebuild_anthropic_client
helper. The normalize_model_name Bedrock-prefix piece was subsumed by NousResearch#14664,
and the aux client aws_sdk branch was subsumed by NousResearch#14770 (both in the same
salvage PR as this commit).
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…rupt

Three interrupt-recovery sites in run_agent.py rebuilt self._anthropic_client
with build_anthropic_client(self._anthropic_api_key, ...) unconditionally.
When provider=bedrock + api_mode=anthropic_messages (AnthropicBedrock SDK
path), self._anthropic_api_key is the sentinel 'aws-sdk' — build_anthropic_client
doesn't accept that and the rebuild either crashed or produced a non-functional
client.

Extract a _rebuild_anthropic_client() helper that dispatches to
build_anthropic_bedrock_client(region) when provider='bedrock', falling back
to build_anthropic_client() for native Anthropic and other anthropic_messages
providers (MiniMax, Kimi, Alibaba, etc.). Three inline rebuild sites now call
the helper.

Partial salvage of NousResearch#14680 by @bsgdigital — only the _rebuild_anthropic_client
helper. The normalize_model_name Bedrock-prefix piece was subsumed by NousResearch#14664,
and the aux client aws_sdk branch was subsumed by NousResearch#14770 (both in the same
salvage PR as this commit).
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…rupt

Three interrupt-recovery sites in run_agent.py rebuilt self._anthropic_client
with build_anthropic_client(self._anthropic_api_key, ...) unconditionally.
When provider=bedrock + api_mode=anthropic_messages (AnthropicBedrock SDK
path), self._anthropic_api_key is the sentinel 'aws-sdk' — build_anthropic_client
doesn't accept that and the rebuild either crashed or produced a non-functional
client.

Extract a _rebuild_anthropic_client() helper that dispatches to
build_anthropic_bedrock_client(region) when provider='bedrock', falling back
to build_anthropic_client() for native Anthropic and other anthropic_messages
providers (MiniMax, Kimi, Alibaba, etc.). Three inline rebuild sites now call
the helper.

Partial salvage of NousResearch#14680 by @bsgdigital — only the _rebuild_anthropic_client
helper. The normalize_model_name Bedrock-prefix piece was subsumed by NousResearch#14664,
and the aux client aws_sdk branch was subsumed by NousResearch#14770 (both in the same
salvage PR as this commit).
prmartinow pushed a commit to prmartinow/hermes-agent that referenced this pull request Aug 26, 2026
…rupt

Three interrupt-recovery sites in run_agent.py rebuilt self._anthropic_client
with build_anthropic_client(self._anthropic_api_key, ...) unconditionally.
When provider=bedrock + api_mode=anthropic_messages (AnthropicBedrock SDK
path), self._anthropic_api_key is the sentinel 'aws-sdk' — build_anthropic_client
doesn't accept that and the rebuild either crashed or produced a non-functional
client.

Extract a _rebuild_anthropic_client() helper that dispatches to
build_anthropic_bedrock_client(region) when provider='bedrock', falling back
to build_anthropic_client() for native Anthropic and other anthropic_messages
providers (MiniMax, Kimi, Alibaba, etc.). Three inline rebuild sites now call
the helper.

Partial salvage of NousResearch#14680 by @bsgdigital — only the _rebuild_anthropic_client
helper. The normalize_model_name Bedrock-prefix piece was subsumed by NousResearch#14664,
and the aux client aws_sdk branch was subsumed by NousResearch#14770 (both in the same
salvage PR as this commit).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants