fix(anthropic): auto-detect Bedrock model IDs in normalize_model_name (#12295) - #14664
Closed
qike-ms wants to merge 1 commit into
Closed
fix(anthropic): auto-detect Bedrock model IDs in normalize_model_name (#12295)#14664qike-ms wants to merge 1 commit into
qike-ms wants to merge 1 commit into
Conversation
…#12295) Bedrock model IDs use dots as namespace separators (anthropic.claude-opus-4-7, us.anthropic.claude-sonnet-4-5-v1:0), not version separators. normalize_model_name() was unconditionally converting all dots to hyphens, producing invalid IDs that Bedrock rejects with HTTP 400/404. This affected both the main agent loop (partially mitigated by _anthropic_preserve_dots in run_agent.py) and all auxiliary client calls (compression, session_search, vision, etc.) which go through _AnthropicCompletionsAdapter and never pass preserve_dots=True. Fix: add _is_bedrock_model_id() to detect Bedrock namespace prefixes (anthropic., us., eu., ap., jp., global.) and skip dot-to-hyphen conversion for these IDs regardless of the preserve_dots flag.
Collaborator
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).
Contributor
|
This fix has already landed on Automated hermes-sweeper review:
Thanks @qike-ms for the well-scoped fix and thorough test coverage — the approach of centralising detection inside |
2 tasks
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
normalize_model_name()unconditionally converts dots to hyphens, mangling Bedrock model IDs likeanthropic.claude-opus-4-7intoanthropic-claude-opus-4-7. Bedrock rejects these with HTTP 400/404.The existing mitigation (
_anthropic_preserve_dots()inrun_agent.py) only covers the main agent loop. All auxiliary client calls (compression, session_search, vision, flush_memories, title_generation) go through_AnthropicCompletionsAdapterwhich callsbuild_anthropic_kwargs()withoutpreserve_dots=True. These calls have been silently broken for Bedrock users -- context compression fails, session search fails, etc.This fix puts the detection inside
normalize_model_name()itself so it covers all call sites without requiring callers to know about Bedrock.Why fix it here instead of threading
preserve_dotsthrough every call site?There are 10+ open PRs for #12295, all modifying
_anthropic_preserve_dots()inrun_agent.py. That approach:preserve_dots=TrueFixing at the
normalize_model_namelevel is defense-in-depth: Bedrock IDs are structurally recognizable and should never have their dots mangled regardless of how the caller is configured.Related Issue
Fixes #12295
Type of Change
Changes Made
agent/anthropic_adapter.py: Added_is_bedrock_model_id()helper that detects Bedrock namespace prefixes (anthropic.,us.,eu.,ap.,jp.,global.).normalize_model_name()now skips dot-to-hyphen conversion for detected Bedrock IDs.tests/agent/test_bedrock_integration.py: Updated two canary tests that asserted the broken behavior. AddedTestBedrockModelIdDetectionclass with 10 tests covering bare IDs, regional prefixes, negative cases, and end-to-endbuild_anthropic_kwargsverification.How to Test
python -m pytest tests/agent/test_bedrock_integration.py tests/agent/test_anthropic_adapter.py -x -q-- 186 passedpython -m pytest tests/hermes_cli/test_model_normalize.py -x -q-- 55 passedChecklist
Code
pytest tests/ -qand all tests passDocumentation & Housekeeping
normalize_model_nameand new_is_bedrock_model_id) -- or N/A