Skip to content

feat(strands-memory): add converter injection and optional restored-tool filtering#288

Open
dharamendrak wants to merge 5 commits intoaws:mainfrom
dharamendrak:feat/strands-converter-injection
Open

feat(strands-memory): add converter injection and optional restored-tool filtering#288
dharamendrak wants to merge 5 commits intoaws:mainfrom
dharamendrak:feat/strands-converter-injection

Conversation

@dharamendrak
Copy link

Issue #, if available:
#254

Description of changes:

  • Added injectable message converter support in AgentCoreMemorySessionManager to remove hardcoded converter dependency and enable custom STM canonical formats.
  • Introduced MemoryConverter protocol with:
    • message_to_payload(...)
    • events_to_messages(...)
    • exceeds_conversational_limit(...)
  • Updated session manager constructor to accept optional converter and default to BedrockConverseConverter for backward compatibility.
  • Replaced hardcoded converter calls in write/read paths with self.converter.
  • Added converter modules under integrations/strands/converters/:
    • bedrock.py (default Strands-native shape adapter)
    • openai.py (OpenAI canonical format converter)
    • protocol.py (shared interface and size-limit utility)
  • Added optional config flag filter_restored_tool_context (default False) to strip historical toolUse/toolResult content blocks during restore when enabled.
  • Added tests for:
    • OpenAI converter behavior
    • session manager converter injection and restore filtering
  • Updated comments/docstrings to clarify wording as “Strands-native message shape”.

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

@dharamendrak dharamendrak requested a review from a team March 1, 2026 06:35
… and enhance OpenAI converter handling

- Added AutoConverseConverter to facilitate automatic converter selection based on agent model.
- Updated AgentCoreMemorySessionManager to support auto converter mode.
- Enhanced OpenAI converter to preserve reasoning content and handle oversized payloads.
- Updated tests to validate new auto converter functionality and reasoning content preservation.
- Changed module paths for OpenAI, Anthropic, and Gemini models in test files to align with the updated project structure.
- Ensured consistency across tests for accurate model identification.
@@ -0,0 +1,85 @@
"""Automatic converter selection for mixed-model sessions."""
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not convinced this is necessary. Although it may be possible that someone will have mixed messages, I see it as a really rare use case so I'm not convinced it's worth the tech debt.

Copy link
Author

Choose a reason for hiding this comment

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

I agree this is case is rare

@@ -0,0 +1,7 @@
"""Strands-native message-shape converter adapter."""
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should not be necessary as strands is natively bedrock. We can just leave the converter as None

Copy link
Author

Choose a reason for hiding this comment

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

Removed

@@ -0,0 +1,200 @@
"""Anthropic-format converter for AgentCore Memory.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would be in favor of progressively adding these converters only as we need them. I think we can leave this one out for now.

Copy link
Author

Choose a reason for hiding this comment

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

We can incrementally add it

self.converter = AutoConverseConverter
AutoConverseConverter.set_write_converter(BedrockConverseConverter)
else:
self.converter = converter or BedrockConverseConverter
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: consider just leaving it as None for bedrock (native) format

Copy link
Author

Choose a reason for hiding this comment

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

@afarntrog agree

Defaults to None.
**kwargs (Any): Additional keyword arguments.
"""
self._auto_converter_enabled = converter == "auto"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this _auto_converter_enabled is over engineering for now. consider yagni

Copy link
Author

Choose a reason for hiding this comment

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

I agree, thanks @afarntrog

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.

2 participants