Skip to content

feat(memory): AgentCoreMemory plugin for Strands SDK#142

Open
aidandaly24 wants to merge 1 commit intofeat/agentcore-memoryfrom
feat/memory-plugin-impl
Open

feat(memory): AgentCoreMemory plugin for Strands SDK#142
aidandaly24 wants to merge 1 commit intofeat/agentcore-memoryfrom
feat/memory-plugin-impl

Conversation

@aidandaly24
Copy link
Copy Markdown
Contributor

Description

Implements the AgentCoreMemory plugin for the Strands TypeScript SDK, providing LTM extraction (store conversation messages as memory events) and LTM injection (retrieve insights into the agent's system prompt). This is the TypeScript equivalent of the Python SDK's memory integration, designed from the ground up to avoid the accumulation bug documented in #420.

What's included

  • AgentCoreMemory — Strands Plugin (SDK >=0.7.0) with:
    • Extraction pipeline: MessageAddedEvent → buffer messages → batched flush via createEvent() with Promise.allSettled + clientToken idempotent retries
    • Injection pipeline: BeforeInvocationEvent → strip stale <agentcore_memory> sentinel → retrieve fresh LTM per namespace in parallel → format → inject into systemPrompt
    • search_memory tool: opt-in via searchTool: true, registered through getTools()
    • Multi-agent helpers: withActor(actorId), withMetadataProvider(fn)
  • createSearchMemoryTool — standalone tool factory for advanced composability
  • 89 unit tests (44 format, 9 search tool, 36 plugin) + integration test scaffold
  • Export path: bedrock-agentcore/experimental/memory/strands

Key design decisions

  • Extraction and injection are decoupled — customers opt into each independently
  • Ephemeral system prompt injection — strip and re-inject each turn, never mutate persisted messages (fixes the Python SDK's O(N×K) accumulation bug)
  • Batching on by defaultbatchSize: 10, batchTimeoutMs: 5000ms
  • extraction: / injection: naming — replaces storeMessages: / injectContext: per team review
  • automatic + searchTool booleans — replaces mode: 'tool' per team review
  • Plugin interface (SDK >=0.7.0) — uses initAgent() + getTools(), one-line registration via plugins: [memoryPlugin]

API shape

import { AgentCoreMemory } from 'bedrock-agentcore/experimental/memory/strands'

const memoryPlugin = new AgentCoreMemory({
  memoryId: 'mem-1',
  actorId: 'user-1',
  sessionId: 'session-1',
  extraction: true,  // or { batchSize: 20, messageFilter: (msg) => ... }
  injection: {
    namespaces: {
      '/users/{actorId}/facts': { topK: 5 },
      '/users/{actorId}/preferences': { topK: 3 },
    },
    searchTool: true,
  },
})

const agent = new Agent({
  model,
  plugins: [memoryPlugin],
})

Related Issues

Design doc: https://quip-amazon.com/odNFAWZ9XaS9

Type of Change

New feature

Testing

Unit tests (489/489 pass)

  • npm run check passes (lint, format, type-check, build, tests)
  • 96% line coverage on new files
  • Format utilities: 44 tests covering all edge cases (regex escaping, SystemContentBlock[] handling, truncation, etc.)
  • Plugin class: 36 tests covering hook registration, injection pipeline, extraction pipeline, error handling, multi-agent helpers
  • Search tool: 9 tests covering namespace search, filtering, error resilience

E2E testing (deployed agent)

Deployed a real TypeScript agent to AgentCore with the plugin and verified:

  • Extraction — messages stored as events, processed into LTM facts by the service
  • Injection — cross-session recall of user facts (name, job, preferences) via system prompt injection
  • search_memory tool — agent autonomously searched memory to find "TypeScript over Python" preference
  • STM (SessionManager + S3) — conversation history persisted to S3 via Strands SessionManager, restored on next turn
  • Cross-session LTM — brand new session recalled facts from prior sessions

Test project: ~/workplace/cli-typescript/memorytest/

  • I ran npm run check

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Note: @strands-agents/sdk peer dependency bumped from >=0.1.0 to >=0.7.0 for the Plugin interface. Existing browser/code-interpreter integrations use tool() which exists in both versions, so this is backward compatible for those subpaths.


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

Implements the AgentCoreMemory plugin providing LTM extraction
(store conversation messages as events) and LTM injection (retrieve
insights into system prompt) for Strands TypeScript SDK agents.

- Plugin implements Strands Plugin interface (SDK >=0.7.0)
- Extraction: MessageAddedEvent buffering, batched flush with
  Promise.allSettled + clientToken idempotent retries
- Injection: BeforeInvocationEvent strip/retrieve/inject into systemPrompt
- search_memory tool factory (opt-in via searchTool: true)
- Multi-agent helpers: withActor(), withMetadataProvider()
- 89 unit tests, integration test scaffold
- Export path: bedrock-agentcore/experimental/memory/strands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant