Skip to content

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

Open
dharamendrak wants to merge 6 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 6 commits intoaws:mainfrom
dharamendrak:feat/strands-converter-injection

Conversation

@dharamendrak
Copy link

@dharamendrak dharamendrak commented Mar 1, 2026

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 AgentCoreMemoryConverter for backward compatibility.
  • Replaced hardcoded converter calls in write/read paths with self.converter.
  • Added converter modules under integrations/strands/converters/:
    • 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.
  • Streamlined converter initialization — default AgentCoreMemoryConverter is now set once in init instead of repeated self.converter or AgentCoreMemoryConverter fallbacks in each method.
  • 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.

Testing

Validated the AgentCoreMemorySessionManager with and without OpenAIConverseConverter use below snippet

from bedrock_agentcore.memory.integrations.strands.converters import OpenAIConverseConverter
from bedrock_agentcore.memory.integrations.strands.session_manager import AgentCoreMemorySessionManager

  session_manager = AgentCoreMemorySessionManager(
      agentcore_memory_config=config,
      converter=OpenAIConverseConverter,
      region_name="us-west-2",
  )

Listed event from agent core memory: Raw AgentCore event confirming TOOL role is correctly persisted:

  {
    "memoryId": "strands_agentcore_memory_20260228_155315-R7WGNA4qCH",
    "actorId": "math_specialist",
    "sessionId": "math_20260304_181716",
    "eventId": "0000001772677043559#7ab31b1a",
    "eventTimestamp": "2026-03-04 18:17:23.559000-08:00",
    "payload": [
      {
        "conversational": {
          "content": {
            "text": "{\"role\": \"tool\", \"tool_call_id\": \"call_cRscVeeLyRbImBK4aQZcyCEG\", \"content\": \"Result: 425\", \"status\": \"success\"}"
          },
          "role": "TOOL"
        }
      }
    ],
    "branch": {
      "name": "main"
    }
  }

@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.
Copy link
Contributor

@afarntrog afarntrog left a comment

Choose a reason for hiding this comment

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

Have you had a chance to test this against some of the data to ensure it's working e2e?

- Updated the AgentCoreMemorySessionManager to directly use the instance's converter, removing unnecessary fallback logic.
- Ensured consistent handling of message conversion and size checks across methods.
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