The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bedrock): omit sampling params for xAI Grok on Converse
liuhao1024796aeede6a91
diff --git a/agent/bedrock_adapter.py b/agent/bedrock_adapter.pyindex d2a42ba43eb..c71e59d1f77 100644--- a/agent/bedrock_adapter.py+++ b/agent/bedrock_adapter.py@@ -67,6 +67,10 @@ BEDROCK_OPENAI_RESPONSES_MODEL_IDS: Tuple[str, ...] = ("openai.gpt-5.5", "openai.gpt-5.6-sol", "openai.gpt-5.6-terra", "openai.gpt-5.6-luna",)_BEDROCK_OPENAI_HOST_RE = re.compile(r"^bedrock-mantle\.([a-z0-9-]+)\.api\.aws$", re.IGNORECASE)+# Bedrock-hosted xAI Grok (any regional inference-profile prefix) rejects temperature/topP in Converse+# with a hard 400 ("This model doesn't support the temperature field"); reasoning-first, same+# restriction as Claude Opus 4.6+ but _forbids_sampling_params is Claude-only, so it needs its own gate.+_BEDROCK_XAI_GROK_NO_SAMPLING_RE = re.compile(r"^(?:[a-z]+\.)?xai\.grok", re.IGNORECASE)_MIN_BOTO3_VERSION = (1, 34, 59)@@ -897,7 +901,7 @@ def build_converse_kwargs(if system_prompt:kwargs["system"] = system_prompt + [dict(_CACHE_POINT)] if "system" in cache_at else system_promptfrom agent.anthropic_adapter import _forbids_sampling_params- if not _forbids_sampling_params(model):+ if not _forbids_sampling_params(model) and not _BEDROCK_XAI_GROK_NO_SAMPLING_RE.match(model or ""):inference_config.update({k: v for k, v in (("temperature", temperature), ("topP", top_p)) if v is not None})if stop_sequences:inference_config["stopSequences"] = stop_sequencesdiff --git a/tests/agent/test_bedrock_adapter.py b/tests/agent/test_bedrock_adapter.pyindex 93c3b6fc892..a48f9ae82d2 100644--- a/tests/agent/test_bedrock_adapter.py+++ b/tests/agent/test_bedrock_adapter.py@@ -556,6 +556,24 @@ class TestBuildConverseKwargs:)assert "inferenceConfig" not in kwargs+ def test_bedrock_xai_grok_models_never_receive_sampling_params(self):+ """Bedrock-hosted xAI Grok rejects temperature/topP in Converse with a hard 400+ (ValidationException: "This model doesn't support the temperature field"); the+ _forbids_sampling_params guard is Claude-only, so Grok needs its own denylist.+ Sibling Bedrock models keep receiving sampling params."""+ from agent.bedrock_adapter import build_converse_kwargs+ msgs = [{"role": "user", "content": "Hi"}]+ for model in ("us.xai.grok-4.6", "global.xai.grok-4.6"):+ cfg = build_converse_kwargs(+ model=model, messages=msgs, temperature=0.3, top_p=0.9+ )["inferenceConfig"]+ assert "temperature" not in cfg and "topP" not in cfg, model+ for model in ("test-model", "qwen.qwen3-vl-235b-a22b"):+ cfg = build_converse_kwargs(+ model=model, messages=msgs, temperature=0.3, top_p=0.9+ )["inferenceConfig"]+ assert cfg["temperature"] == 0.3 and cfg["topP"] == 0.9, model+def test_cache_point_added_for_supported_model(self):"""Claude and Nova on the Converse path get cachePoint markers onsystem, tools, and the message before the newest turn."""