Skip to content

fix(memory): pass boto3 session to MemoryClient in AgentCoreMemorySessionManager - #682

Open
avneetbansal-aws wants to merge 1 commit into
aws:mainfrom
avneetbansal-aws:fix/memory-session-manager-boto-session
Open

avneetbansal-aws wants to merge 1 commit into
aws:mainfrom
avneetbansal-aws:fix/memory-session-manager-boto-session

Conversation

@avneetbansal-aws

Copy link
Copy Markdown

Fixes #681.

Problem

`AgentCoreMemorySessionManager.init` constructed its `MemoryClient` without a boto3 session:
```python
self.memory_client = MemoryClient(region_name=region_name) # no session
session = boto_session or boto3.Session(region_name=region_name)
```
Because no session is passed, `MemoryClient.init` builds its `gmcp_client`/`gmdp_client` from a default `boto3.Session()` — so a user-provided `boto_session` (named profile, custom credentials, etc.) is silently discarded on the `MemoryClient` itself. The manager then overwrites those two clients from the correct session, but the `MemoryClient` was still initialized against the wrong one.

Fix

Resolve the session first, then pass it into `MemoryClient`, which already accepts `boto3_session`:
```python
session = boto_session or boto3.Session(region_name=region_name)
self.memory_client = MemoryClient(region_name=region_name, boto3_session=session)
```
The existing `strands-agents` user-agent / `boto_client_config` override that follows is unchanged, so behavior for the overridden clients is identical — the fix just ensures the `MemoryClient` uses the correct session from the start.

Tests

  • Updated `test_init_basic` to assert `MemoryClient` receives `boto3_session`.
  • Added `test_init_passes_boto_session_to_memory_client` asserting a user-provided `boto_session` reaches `MemoryClient`.
  • Full `test_agentcore_memory_session_manager.py` suite passes (189 tests); ruff lint + format clean.

…sionManager

AgentCoreMemorySessionManager.__init__ built its MemoryClient without a boto3 session (MemoryClient then created its clients from a default session), before overwriting the clients from the user-provided session. This discarded the session on the MemoryClient itself. Compute the resolved session first and pass it into MemoryClient(boto3_session=...) so it uses the correct session from the start; the subsequent strands-agents user-agent override still applies. Fixes aws#681.

Signed-off-by: avneetbansal-aws <284363899+avneetbansal-aws@users.noreply.github.com>

This branch is waiting to be deployed

1 waiting deployment
manual-approval — e9d18abb Waiting Sep 28, 2026 by avneetbansal-aws via Test (payments) #1603
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AgentCoreMemorySessionManager discards the two boto3 clients MemoryClient builds; boto_session and boto_client_config are not passed through

1 participant