@@ -116,7 +116,7 @@ function processMemoryRecords(
116116 records : MemoryRecordSummary [ ] ,
117117 out : string [ ] ,
118118 repo : string ,
119- namespace : string ,
119+ namespacePath : string ,
120120 recordType : string ,
121121) : void {
122122 for ( const record of records ) {
@@ -129,7 +129,7 @@ function processMemoryRecords(
129129 // CloudWatch alarms can detect spikes (genuine tampering or write bugs).
130130 logger . warn ( 'Memory record hash mismatch (expected for extracted records)' , {
131131 repo,
132- namespace ,
132+ namespace_path : namespacePath ,
133133 record_type : recordType ,
134134 expected_hash : record . metadata ?. content_sha256 ?. stringValue ?? '(none)' ,
135135 actual_hash : hashContent ( sanitized ) ,
@@ -164,7 +164,10 @@ function getClient(): BedrockAgentCoreClient {
164164 *
165165 * Namespaces match the templates configured on the extraction strategies:
166166 * - Semantic: `/{actorId}/knowledge/` (actorId = repo)
167- * - Episodic: `/{actorId}/episodes/` (prefix matches all sessions)
167+ * - Episodic: `/{actorId}/episodes/` (covers all sessions and reflections)
168+ *
169+ * Both calls use `namespacePath` for hierarchical retrieval — episodic per-task
170+ * records live at `/{actorId}/episodes/{sessionId}/`, which is below the read path.
168171 *
169172 * Results are trimmed to a 2000-token budget (knowledge is prioritized before episodes;
170173 * entries beyond the budget are dropped).
@@ -183,14 +186,11 @@ export async function loadMemoryContext(
183186 try {
184187 const client = getClient ( ) ;
185188
186- // Namespaces derived from the strategy templates configured in agent-memory.ts:
187- // Semantic: /{actorId}/knowledge/
188- // Episodic: /{actorId}/episodes/{sessionId}/
189- // Events are written with actorId = repo (e.g. "krokoko/agent-plugins"),
190- // so extracted records land at /{repo}/knowledge/ and /{repo}/episodes/{taskId}/.
191- // Reads use these paths as namespace prefixes.
192- const semanticNamespace = `/${ repo } /knowledge/` ;
193- const episodicNamespace = `/${ repo } /episodes/` ;
189+ // Namespace paths derived from the strategy templates configured in agent-memory.ts.
190+ // Events are written with actorId = repo, so extracted records land at
191+ // /{repo}/knowledge/ and /{repo}/episodes/{taskId}/.
192+ const semanticNamespacePath = `/${ repo } /knowledge/` ;
193+ const episodicNamespacePath = `/${ repo } /episodes/` ;
194194
195195 // Run semantic and episodic searches in parallel
196196 // eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
@@ -199,7 +199,7 @@ export async function loadMemoryContext(
199199 taskDescription
200200 ? client . send ( new RetrieveMemoryRecordsCommand ( {
201201 memoryId,
202- namespace : semanticNamespace ,
202+ namespacePath : semanticNamespacePath ,
203203 searchCriteria : {
204204 searchQuery : taskDescription ,
205205 topK : 5 ,
@@ -212,7 +212,7 @@ export async function loadMemoryContext(
212212 // Episodic search — recent task episodes (prefix matches all sessions)
213213 client . send ( new RetrieveMemoryRecordsCommand ( {
214214 memoryId,
215- namespace : episodicNamespace ,
215+ namespacePath : episodicNamespacePath ,
216216 searchCriteria : {
217217 searchQuery : 'recent task episodes' ,
218218 topK : 3 ,
@@ -227,11 +227,11 @@ export async function loadMemoryContext(
227227 const pastEpisodes : string [ ] = [ ] ;
228228
229229 if ( semanticResult ?. memoryRecordSummaries ) {
230- processMemoryRecords ( semanticResult . memoryRecordSummaries , repoKnowledge , repo , semanticNamespace , 'repo_knowledge' ) ;
230+ processMemoryRecords ( semanticResult . memoryRecordSummaries , repoKnowledge , repo , semanticNamespacePath , 'repo_knowledge' ) ;
231231 }
232232
233233 if ( episodicResult ?. memoryRecordSummaries ) {
234- processMemoryRecords ( episodicResult . memoryRecordSummaries , pastEpisodes , repo , episodicNamespace , 'past_episode' ) ;
234+ processMemoryRecords ( episodicResult . memoryRecordSummaries , pastEpisodes , repo , episodicNamespacePath , 'past_episode' ) ;
235235 }
236236
237237 if ( repoKnowledge . length === 0 && pastEpisodes . length === 0 ) {
0 commit comments