From 5c4655130daafb17ddaa42e118409ce4c28fff08 Mon Sep 17 00:00:00 2001 From: taxfree-python Date: Wed, 29 Apr 2026 22:08:44 +0900 Subject: [PATCH] Fix research sub-agent ignoring main model's Bedrock region prefix The sub-agent hard-coded `bedrock/us.anthropic.claude-sonnet-4-6`, which AWS Bedrock rejects with "The provided model identifier is invalid" whenever the user runs in a region that can't reach the `us.*` cross-region inference profile (e.g. `ap-northeast-1`). Inherit the prefix the user already chose for the main model so the sub-agent picks `jp.`, `apac.`, `global.`, ... matching whatever the main agent is successfully using. --- agent/tools/research_tool.py | 7 ++++++- tests/unit/test_cli_rendering.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/agent/tools/research_tool.py b/agent/tools/research_tool.py index c4480b97..1ab8fd49 100644 --- a/agent/tools/research_tool.py +++ b/agent/tools/research_tool.py @@ -224,7 +224,12 @@ def _get_research_model(main_model: str) -> str: if main_model.startswith("anthropic/"): return "anthropic/claude-sonnet-4-6" if main_model.startswith("bedrock/") and "anthropic" in main_model: - return "bedrock/us.anthropic.claude-sonnet-4-6" + # Mirror the main model's Bedrock inference-profile prefix so the + # user's explicit profile choice carries through to the sub-agent + # instead of being silently overridden by a hard-coded one. + head = main_model.split("/", 1)[1] + region_prefix = head.split(".", 1)[0] + return f"bedrock/{region_prefix}.anthropic.claude-sonnet-4-6" # For non-Anthropic models (HF router etc.), use the same model return main_model diff --git a/tests/unit/test_cli_rendering.py b/tests/unit/test_cli_rendering.py index ff633c06..f7d34b7d 100644 --- a/tests/unit/test_cli_rendering.py +++ b/tests/unit/test_cli_rendering.py @@ -22,6 +22,17 @@ def test_bedrock_anthropic_research_model_stays_on_bedrock(): ) +def test_bedrock_research_model_inherits_main_region_prefix(): + assert ( + _get_research_model("bedrock/global.anthropic.claude-opus-4-7") + == "bedrock/global.anthropic.claude-sonnet-4-6" + ) + assert ( + _get_research_model("bedrock/apac.anthropic.claude-sonnet-4-20250514-v1:0") + == "bedrock/apac.anthropic.claude-sonnet-4-6" + ) + + def test_non_anthropic_research_model_is_unchanged(): assert _get_research_model("openai/gpt-5.4") == "openai/gpt-5.4"