Skip to content

The agent that grows with you

test(bedrock): pin stream-path cap omission; document truthiness edge

kshitij8b58f9f68f01
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 0f163f38efc..d49a797ed8a 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -2218,6 +2218,9 @@ class _BedrockCompletionsAdapter:
# allowed output, matching the no-cap-by-default policy every
# other aux wire already follows (#10809: vision descriptions
# stayed capped at the shim's old hardcoded 4096 on Bedrock).
+ # Truthiness (not `is None`) is deliberate — it matches the
+ # sibling Anthropic shim's reading of max_tokens above, so a
+ # nonsense explicit 0 is treated as "no cap" on both wires.
max_tokens=int(max_tokens) if max_tokens else None,
temperature=kwargs.get("temperature"),
top_p=kwargs.get("top_p"),
diff --git a/tests/agent/test_bedrock_adapter.py b/tests/agent/test_bedrock_adapter.py
index 8d6acf2ede4..e6c2c3c3c48 100644
--- a/tests/agent/test_bedrock_adapter.py
+++ b/tests/agent/test_bedrock_adapter.py
@@ -423,6 +423,27 @@ class TestBuildConverseKwargs:
)
assert "inferenceConfig" not in kwargs
+ def test_call_converse_stream_omits_cap_for_none(self):
+ """The streaming entry point funnels through the same builder — pin
+ that max_tokens=None omits the cap there too."""
+ from unittest.mock import MagicMock, patch as mock_patch
+ from agent.bedrock_adapter import call_converse_stream
+ boto3_client = MagicMock()
+ boto3_client.converse_stream.return_value = {"stream": []}
+ with mock_patch(
+ "agent.bedrock_adapter._get_bedrock_runtime_client",
+ return_value=boto3_client,
+ ):
+ call_converse_stream(
+ region="us-east-1",
+ model="test-model",
+ messages=[{"role": "user", "content": "Hi"}],
+ max_tokens=None,
+ temperature=0.2,
+ )
+ wire_kwargs = boto3_client.converse_stream.call_args.kwargs
+ assert "maxTokens" not in wire_kwargs.get("inferenceConfig", {})
+