Skip to content

feat: add read_only flag to AgentCoreMemorySessionManager to disable ACM persistence#389

Open
mohanasudhan wants to merge 1 commit intoaws:mainfrom
mohanasudhan:feat/read-only-session-manager
Open

feat: add read_only flag to AgentCoreMemorySessionManager to disable ACM persistence#389
mohanasudhan wants to merge 1 commit intoaws:mainfrom
mohanasudhan:feat/read-only-session-manager

Conversation

@mohanasudhan
Copy link
Copy Markdown

Description

Add a read_only option to AgentCoreMemoryConfig that disables persistence to AgentCore Memory (create_event calls) while keeping local session/agent state management and memory injection (LTM retrieval) working.

Motivation

Resolves strands-agents/sdk-python#2020

The AgentCoreMemorySessionManager currently persists agent state and injects memories. Customers who only need memory injection into agent context (without persisting agent state) had no way to opt out of persistence. This adds a read_only=True flag so existing customers can disable persistence with a single config change.

Changes

  • config.py: Added read_only: bool = Field(default=False) to AgentCoreMemoryConfig
  • session_manager.py: Guarded ACM write calls (create_event, delete_event) behind read_only check while preserving local state management (validation, caching, append_message tracking)
  • Tests: 20 new tests covering all read_only behavior

What's guarded (ACM writes skipped when read_only=True)

  • create_session — skips create_event, still validates and returns session
  • create_agent — skips create_event/buffering, still caches created_at
  • update_agent — delegates to create_agent, cache lookup still works
  • create_message — skips create_event/buffering, returns {} so append_message tracks local state
  • _flush_messages_only / _flush_agent_states_only — no-op
  • Legacy migration paths — skips create_event + delete_event, still reads data

What's unaffected

  • All read operations (read_session, read_agent, list_messages)
  • LTM retrieval (retrieve_customer_context)

Usage

config = AgentCoreMemoryConfig(
    memory_id="my-mem",
    session_id="sess-1",
    actor_id="user-1",
    read_only=True,  # no writes to AgentCore Memory
)
session_manager = AgentCoreMemorySessionManager(agentcore_memory_config=config)

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

…l ACM persistence

Add PersistenceMode enum (FULL | NONE) and persistence_mode config option
to AgentCoreMemoryConfig. When set to NONE, disables persistence to
AgentCore Memory (create_event calls) while keeping local session/agent
state management and memory injection (LTM retrieval) working.

This allows customers who only need memory injection into agent context
without persisting agent state to set persistence_mode=PersistenceMode.NONE
on their existing configuration.
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.

[FEATURE] Add read-only access mode to SessionManager for multi-tenant safety

2 participants