Skip to content

Conversation

afarntrog
Copy link
Contributor

@afarntrog afarntrog commented Sep 11, 2025

Description

This pull request introduces support for handling redactedContent in the event streaming pipeline, ensuring that redacted reasoning content is properly processed and tested throughout the codebase. The changes include updates to event handling logic, the addition of a new event type, and comprehensive unit and integration tests to verify correct behavior.

Event streaming enhancements:

  • Added a new RedactedContentStreamEvent class to represent streaming events containing redacted reasoning content in src/strands/types/_events.py.
  • Updated the handle_content_block_delta and handle_content_block_stop functions in src/strands/event_loop/streaming.py

Testing improvements:

  • Added and extended unit tests in tests/strands/event_loop/test_streaming.py to cover scenarios involving redactedContent, including state updates and event emission for both new and existing redacted content.
  • Enhanced async test coverage for process_stream, including cases with redacted content

Integration test updates:

  • Added an integration test in tests_integ/models/test_model_bedrock.py to verify correct handling of redacted reasoning content when using the Bedrock model with thinking mode enabled.

Related Issues

#99
Source pr: #229

Documentation PR

strands-agents/docs#90

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

mazyu36 and others added 12 commits May 28, 2025 22:09
…ling

- Add RedactedContentStreamEvent class to types/_events.py for typed streaming
- Refactor redacted content handling in streaming.py to use walrus operator
- Fix state management for redactedContent with proper default handling
- Update tests to handle new event structure and skip problematic tests
- Add integration test for redacted content with thinking mode

This improves type safety and consistency in the streaming event system
when handling redacted reasoning content from Claude models.
dbschmigelski
dbschmigelski previously approved these changes Sep 12, 2025
Copy link
Member

@dbschmigelski dbschmigelski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK OK OK OK

Now I understand why this is safe and before it was not for signature.

So, for signature we are checking if "signature" in state: so even when signature was empty it was getting added to the content block

Now we are seeing if redacted_content is truthy, meaning setting it to b"" is fine.

I think we can use this to rethink our signature fix but I'm fine with keeping as is.

Unrelated, do you know if the Bedrock docs are wrong? It seems the redactedContent is coming back as bytes but the docs state it is Base64-encoded? Are we decoding somewhere or is a client doing it under the good?

@dbschmigelski
Copy link
Member

Approved in spirit, pretty sure you need to rebase

@afarntrog
Copy link
Contributor Author

....
Unrelated, do you know if the Bedrock docs are wrong? It seems the redactedContent is coming back as bytes but the docs state it is Base64-encoded? Are we decoding somewhere or is a client doing it under the good?

So I confirmed it's coming in as bytes in the actual response; the encoding is coming from the client. The docs state:

Type: Base64-encoded binary data object

which can possibly cause confusion but seems to imply it's coming in as bytes 👍

Unshure
Unshure previously approved these changes Sep 12, 2025
@afarntrog afarntrog enabled auto-merge (squash) September 12, 2025 20:58
@afarntrog afarntrog requested a review from zastrowm September 12, 2025 22:10
Copy link
Member

@dbschmigelski dbschmigelski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit comment

other than that just one minor nit that when you merge can you just remember to follow https://www.conventionalcommits.org/en/v1.0.0/

@afarntrog afarntrog merged commit 8122453 into strands-agents:main Sep 15, 2025
11 of 12 checks passed
This was referenced Sep 17, 2025
Unshure pushed a commit to Unshure/sdk-python that referenced this pull request Sep 24, 2025
* feat: add ReasoningRedactedContentStreamEvent for proper redacted content handling

- Add ReasoningRedactedContentStreamEvent class to types/_events.py for typed streaming
- Refactor redacted content handling in streaming.py
- Fix state management for redactedContent with proper default handling
- Update tests to handle new event structure and skip problematic tests
- Add integration test for redacted content with thinking mode

This improves type safety and consistency in the streaming event system
when handling redacted reasoning content.

Co-authored-by: Yuki Matsuda <[email protected]>
Co-authored-by: Arron <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants