Strands Agents pull request 4313 makes AgentResult.to_dict() safe for json.dumps when a Bedrock message contains raw bytes. I wrote it, and it was merged on 14 Sep 2026.
Making Strands AgentResult.to_dict JSON safe with bytes
The pull request is strands-agents/harness-sdk #4313, titled fix(agent): make AgentResult.to_dict JSON-serializable with bytes. It fixes issue #4167.
The problem
In the Strands Agents Python SDK, AgentResult.to_dict() is documented as converting the result "to JSON-serializable dictionary". Issue #4167 reported that it was not, for some messages. With a Bedrock model that called a tool and then answered, the final assistant message contained a reasoningContent block whose redactedContent was raw bytes. json.dumps(result.to_dict()) then raised TypeError: Object of type bytes is not JSON serializable.
The reporter ran the agent inside a Bedrock AgentCore runtime. That runtime falls back to str(obj) when an object does not serialize, so the consumer received a Python repr inside a JSON string instead of a JSON object, and failed while parsing it.
Root cause
The Bedrock Converse API types redactedContent as a blob, so it arrives in Python as bytes. to_dict() put self.message into the dictionary unchanged. The SDK's session persistence already handled bytes in messages with its own helpers. to_dict() did not use them, so the gap was specific to that method.
The fix
I reused the helpers session persistence already uses, instead of writing a second encoder. In strands-py/src/strands/agent/agent_result.py, to_dict() now passes message through encode_bytes_values:
return {
"type": "agent_result",
- "message": self.message,
+ "message": encode_bytes_values(self.message),
"stop_reason": self.stop_reason,
"checkpoint": self.checkpoint.to_dict() if self.checkpoint else None,
}
from_dict() passes it back through decode_bytes_values, so a round trip restores the original bytes. The docstring now says that binary values in message are base64 encoded. GitHub records 2 files changed, 30 additions and 2 deletions, in one commit.
How it was tested and reviewed
The regression test test_to_dict_json_serializable_with_redacted_content_bytes in strands-py/tests/strands/agent/test_agent_result.py builds a message with a text block and a redactedContent block holding bytes. It runs to_dict(), json.dumps, json.loads and from_dict(), then checks that the text and the original bytes both come back.
The pull request reports hatch test tests/strands/agent/test_agent_result.py with 30 passed, including the new test, and hatch fmt --linter with all checks passed. Codecov reported that all modified and coverable lines are covered by tests. A maintainer approved it and merged it on 14 Sep 2026 (UTC), which closed issue #4167.
What this shows if you are hiring an AI agent engineer
- I work on agent output, not only prompts. A result that does not serialize breaks every API, queue or UI that consumes the agent.
- I work with the AWS agent stack: Bedrock Converse content types and the Strands Agents SDK.
- I keep fixes small and consistent with the codebase. This one reuses existing helpers and adds a round trip test.
- If you need an agent built end to end, see full stack AI developer, LangGraph developer or all services.
I did not start Strands Agents and I am not a maintainer. This is one merged fix. The other merged fixes are on the open source page, including Genkit #6346 and Pipecat #5760.
Working with a team abroad? See United States, United Kingdom, Europe or UAE and Saudi Arabia. More writing is on the blog.