Skip to content

fix: resolve {memoryStrategyId} in retrieval_config namespace templates - #761

Open
yqecea wants to merge 1 commit into
aws:mainfrom
yqecea:fix-memory-strategy-id-template
Open

yqecea wants to merge 1 commit into
aws:mainfrom
yqecea:fix-memory-strategy-id-template

Conversation

@yqecea

@yqecea yqecea commented Nov 28, 2026

Copy link
Copy Markdown

Summary

MemorySessionManager.process_turn_with_llm (and process_turn_with_llm_async, plus the MemorySession wrappers) raise KeyError: 'memoryStrategyId' when a retrieval_config namespace contains {memoryStrategyId}.

The docstring of both methods documents {memoryStrategyId} as a template variable resolved at runtime, and every default namespace the SDK creates uses it (memory/constants.py, e.g. /strategies/{memoryStrategyId}/actors/{actorId}/). So passing the namespace of a strategy created with the SDK fails before any search request is built.

Root cause

_retrieve_memories_for_llm resolves namespaces with namespace.format(actorId=..., sessionId=..., strategyId=...) but never passes memoryStrategyId, so str.format raises KeyError on the documented variable.

Fix

Pass memoryStrategyId=config.strategy_id or "" alongside the existing strategyId, keeping both spellings working during the field-name deprecation.

Tests

New regression test test_process_turn_with_llm_resolves_memory_strategy_id using the exact default namespace shape with strategy_id set, asserting search_long_term_memories receives the fully resolved namespace.

Red-green verified: the test fails with KeyError: 'memoryStrategyId' on unpatched main and passes with the fix. Full memory unit suite (test_session.py + test_client.py): 283 passed. ruff check and ruff format clean.

Fixes #759

The docstring of process_turn_with_llm documents {memoryStrategyId} as a
supported template variable, and every default namespace the SDK creates
in memory/constants.py uses it, but _retrieve_memories_for_llm only
passed actorId, sessionId and strategyId to str.format(), so any
namespace using the documented variable raised KeyError before the
search request was even built.

Fixes aws#759

This branch is waiting to be deployed

1 waiting deployment
manual-approval — f3a30542 Waiting Nov 28, 2026 by yqecea via Test (runtime) #1742
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.

MemorySessionManager.process_turn_with_llm raises KeyError: 'memoryStrategyId' for the default namespace templates

2 participants