Skip to content

fix: Properly handle prompt=None & avoid agent hanging #643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ test-integ = [
"hatch test tests_integ {args}"
]
prepare = [
"hatch fmt --linter",
"hatch fmt --formatter",
"hatch fmt --linter",
"hatch run test-lint",
"hatch test --all"
]
Expand Down
12 changes: 6 additions & 6 deletions src/strands/models/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,14 @@ def _stream(
ContextWindowOverflowException: If the input exceeds the model's context window.
ModelThrottledException: If the model service is throttling requests.
"""
logger.debug("formatting request")
request = self.format_request(messages, tool_specs, system_prompt)
logger.debug("request=<%s>", request)
try:
logger.debug("formatting request")
request = self.format_request(messages, tool_specs, system_prompt)
logger.debug("request=<%s>", request)

logger.debug("invoking model")
streaming = self.config.get("streaming", True)
logger.debug("invoking model")
streaming = self.config.get("streaming", True)

try:
logger.debug("got response from model")
if streaming:
response = self.client.converse_stream(**request)
Expand Down
9 changes: 9 additions & 0 deletions tests/strands/models/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,15 @@ async def test_stream_throttling_exception_from_event_stream_error(bedrock_clien
)


@pytest.mark.asyncio
async def test_stream_with_invalid_content_throws(bedrock_client, model, alist):
# We used to hang on None, so ensure we don't regress: https://github.com/strands-agents/sdk-python/issues/642
messages = [{"role": "user", "content": None}]

with pytest.raises(TypeError):
await alist(model.stream(messages))


@pytest.mark.asyncio
async def test_stream_throttling_exception_from_general_exception(bedrock_client, model, messages, alist):
error_message = "ThrottlingException: Rate exceeded for ConverseStream"
Expand Down
Loading