The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bedrock): an unresolved application-profile ARN issuer is unknown, not foreign
Victor Kyriazakos93286ffd8749
diff --git a/agent/bedrock_adapter.py b/agent/bedrock_adapter.pyindex f02350c7c1a..3f6e724195d 100644--- a/agent/bedrock_adapter.py+++ b/agent/bedrock_adapter.py@@ -905,7 +905,13 @@ def _converse_replay_policy(model: Optional[str]) -> str:def _minted_outside_claude(issuer: Optional[str]) -> bool:- return issuer is not None and _converse_replay_policy(issuer) != "signed"+ if issuer is None:+ return False+ if _APPLICATION_PROFILE_ARN_RE.search(issuer) and _resolve_inference_profile_model_id(issuer) == issuer:+ # An application profile names no model, and without bedrock:GetInferenceProfile it stays+ # unresolved: the issuer is unknown, not foreign, so its reasoning keeps the answering policy.+ return False+ return _converse_replay_policy(issuer) != "signed"def reasoning_minted_outside_claude(msg: dict) -> bool:diff --git a/tests/agent/test_bedrock_anthropic_foreign_reasoning.py b/tests/agent/test_bedrock_anthropic_foreign_reasoning.pyindex ac9d00d9338..21bed6bcf42 100644--- a/tests/agent/test_bedrock_anthropic_foreign_reasoning.py+++ b/tests/agent/test_bedrock_anthropic_foreign_reasoning.py@@ -114,6 +114,48 @@ def test_unstamped_redacted_thinking_still_replays():assert {"type": "redacted_thinking", "data": GPT_BLOB} in _wire_thinking(wire)+PROFILE_ARN = "arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123"+++def _converse_assistant_reasoning(wire: list[dict]) -> list[dict]:+ return [b for m in wire if m["role"] == "assistant" for b in m["content"] if "reasoningContent" in b]++[email protected]("wire", ["anthropic", "converse"])+def test_unresolved_profile_arn_stamp_keeps_claudes_own_thinking(monkeypatch, wire):+ """A Claude configured by application-profile ARN stamps its Converse turns with the ARN. When+ GetInferenceProfile is not granted the ARN stays unresolved: that issuer is unknown, not foreign, so a+ switch to a plain Claude id keeps the turn's signed thinking on both Bedrock wires."""+ import agent.bedrock_adapter as bedrock+ from agent.bedrock_adapter import convert_messages_to_converse++ monkeypatch.setitem(bedrock._inference_profile_model_cache, PROFILE_ARN, PROFILE_ARN)+ history = [{"role": "user", "content": "q1"}, _claude_turn("a1", "claude-sig-1", issuer=PROFILE_ARN),+ {"role": "user", "content": "q2"}]+ if wire == "anthropic":+ assert {"type": "thinking", "thinking": "claude chain", "signature": "claude-sig-1"} in _wire_thinking(_convert(history))+ else:+ _system, msgs = convert_messages_to_converse(history, model=CLAUDE)+ assert _converse_assistant_reasoning(msgs)++[email protected]("wire", ["anthropic", "converse"])+def test_profile_arn_resolving_to_gpt_still_drops_its_reasoning(monkeypatch, wire):+ import agent.bedrock_adapter as bedrock+ from agent.bedrock_adapter import convert_messages_to_converse++ monkeypatch.setitem(bedrock._inference_profile_model_cache, PROFILE_ARN,+ "arn:aws:bedrock:us-east-1::foundation-model/openai.gpt-6.1-sol")+ turn = _gpt_turn("a1", stamped=False)+ turn["reasoning_details"].append({"type": CONVERSE_ISSUER_TYPE, "model": PROFILE_ARN})+ history = [{"role": "user", "content": "q1"}, turn, {"role": "user", "content": "q2"}]+ if wire == "anthropic":+ assert GPT_BLOB not in json.dumps(_convert(history))+ else:+ _system, msgs = convert_messages_to_converse(history, model=CLAUDE)+ assert _converse_assistant_reasoning(msgs) == []++# --- Safety net: the rejection reaches the thinking_signature recovery ---------------------------------------