Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import logging
from typing import Any, Tuple

from strands.types.session import SessionMessage
from strands.types.session import SessionMessage, decode_bytes_values, encode_bytes_values

from .protocol import exceeds_conversational_limit

Expand Down Expand Up @@ -45,7 +45,7 @@ def _bedrock_to_openai(message: dict) -> dict:
elif "reasoningContent" in item:
# OpenAI message shape does not have a stable multi-turn reasoning block field.
# Preserve original block(s) in storage-only extension field for lossless restore.
reasoning_blocks.append(item)
reasoning_blocks.append(encode_bytes_values(item))
elif "toolUse" in item:
tu = item["toolUse"]
tool_calls.append(
Expand Down Expand Up @@ -120,7 +120,7 @@ def _openai_to_bedrock(openai_msg: dict) -> dict:

for rc in openai_msg.get("_strands_reasoning_content", []):
if isinstance(rc, dict) and "reasoningContent" in rc:
reasoning_items.append(rc)
reasoning_items.append(decode_bytes_values(rc))

bedrock_role = "assistant" if role == "assistant" else "user"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ def test_reasoning_content_round_trips_in_openai_converter():
assert any("reasoningContent" in block for block in restored_content)


def test_redacted_reasoning_bytes_round_trip_in_openai_converter():
msg = SessionMessage(
message={
"role": "assistant",
"content": [
{"reasoningContent": {"redactedContent": b"rsn_abc"}},
{"text": "208"},
],
},
message_id=8,
)

payload_json, _ = OpenAIConverseConverter.message_to_payload(msg)[0]
events = [{"payload": [{"conversational": {"content": {"text": payload_json}}}]}]
restored = OpenAIConverseConverter.events_to_messages(events)

assert restored[0].message["content"] == [
{"reasoningContent": {"redactedContent": b"rsn_abc"}},
{"text": "208"},
]


def test_openai_converter_round_trips_from_blob_payload():
msg = SessionMessage(
message={
Expand Down
Loading