sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

docs: add memory manager docs

Open opieter-aws opened this issue 5 months ago • 4 comments

Description

Documents the long-term memory feature (MemoryManager) and the injection plugin for the TypeScript SDK. The implementation shipped across #2544 (memory manager) and #2631 (injection), along with the Bedrock Knowledge Base store and extraction work, but had no user-facing documentation. Agents that should remember a user across sessions had a supported API and no page explaining it.

Adds a collapsible Memory section under Concepts, plus a vended-plugin page (all TypeScript-only, since the features are TS-only today):

  • Memory > Overview (concepts/memory/overview.mdx) covers the MemoryManager and MemoryStore interface: multi-store routing, the search_memory / add_memory tools, programmatic search/add, automatic extraction (triggers and ModelExtractor), and context injection. It opens by distinguishing memory from the adjacent session-management and conversation-management features, since the three are easy to conflate.
  • Memory > Bedrock Knowledge Base (concepts/memory/bedrock-knowledge-base.mdx) documents the vended BedrockKnowledgeBaseStore: prerequisites for provisioning a knowledge base, the split connection/store config, CUSTOM vs S3 vs OTHER writability, search/ingestion, scope-based namespacing, eventual-consistency and S3-sync caveats, and the IAM permissions a writable store needs.
  • Context Injector (concepts/plugins/context-injector.mdx) documents the vended ContextInjector plugin, the generic injection engine that the memory feature's injection config specializes. It covers the renderContent callback, triggers ('userTurn' / 'everyTurn' / predicate), the ephemeral-injection semantics, and stacking.

Navigation: a collapsible Memory section under Concepts holds the Overview page and one subpage per store implementation (currently just Bedrock Knowledge Base), so future stores drop in alongside it. The ContextInjector page is listed under Plugins next to the Context Offloader.

Code examples live in runnable, type-checked snippet files (*.ts plus sibling *_imports.ts) and are pulled into the pages via --8<-- includes, so every rendered block carries its imports and is copy-paste runnable.

The PR also adds a memory tag to site/src/config/tags.yml and reconciles the terminology lock (.agents/references/terminology.md): "memory" was previously listed only as a banned synonym for session management, which collides with the shipped MemoryManager feature name. The lock now carves out "long-term memory" as the canonical term for the feature, distinct from session persistence.

Related Issues

Documents: #2544, #2631

Documentation PR

This PR is the documentation. New pages registered in site/src/config/navigation.yml under the Concepts > Memory section and under Plugins.

Type of Change

Documentation update

Testing

Built the docs site against the SDK source (astro build): all new pages render, every --8<-- snippet region resolves, and the broken-links checker passes across all 659 pages. The snippet sources type-check against the SDK via the site/test-snippets harness (tsc --noEmit). Reviewed each page with the docs-writer and docs-reviewer voice/terminology passes plus a multi-lens review (API accuracy, IA, snippet runnability, completeness); findings were addressed, and every documented API was verified field-by-field against the on-disk SDK source.

Checklist

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

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

opieter-aws avatar Jun 12 '26 17:06 opieter-aws

Documentation Preview Ready

Your documentation preview has been successfully deployed!

Changed pages:

Updated at: 2026-06-17T12:59:43.822Z

github-actions[bot] avatar Jun 12 '26 20:06 github-actions[bot]

Assessment: Approve

Thorough, well-structured docs for the MemoryManager, the Bedrock Knowledge Base store, and the ContextInjector plugin. I verified the documented APIs field-by-field against the on-disk SDK source and they match closely — defaults, type names, exports, and behavior all line up. Only one minor terminology-lock nit (inline).

Review notes
  • API accuracy: Verified against source — manager search default (3) vs. store default (10) asymmetry, injection defaults (userTurn / maxEntries: 5 / <memory> block), extraction triggers and the IntervalTrigger interval of 5, add()'s validate-then-AggregateError semantics, flush(), and BedrockKnowledgeBaseConfig/StoreConfig/S3Config fields. The injection fail-open, S3 sidecar, eventual-consistency, and sync-deletion caveats all match the source's own doc comments.
  • Snippets: All 39 --8<-- regions resolve with no missing or unused regions, so the build's snippet checker passes. Imports and InjectionContext subpath export are correct; Agent model is optional, so the injector snippets without a model type-check.
  • Navigation / tags / links: New memory tag added and used; nav entries and all relative links resolve to real pages. The token-management tag on Context Injector is a reasonable fit.
  • Terminology: One cross-reference drift in terminology.md (inline comment).

Nicely done — the field-by-field verification against source clearly paid off, and the caveat callouts (eventual consistency, sync deletion, at-least-once extraction) are exactly the sharp edges users need flagged.

github-actions[bot] avatar Jun 12 '26 20:06 github-actions[bot]

/strands review

notowen333 avatar Jun 15 '26 18:06 notowen333

Re-review (/strands review): Approve — no new findings.

The PR branch is unchanged since my prior review (still at d7126360), and I confirmed the memory / injection / context-injector SDK source is byte-identical between this branch and current main, so the field-by-field API accuracy verification from the last pass still holds in full. Re-ran the snippet-include check: all 39 --8<-- regions across the three pages still resolve cleanly.

One item remains open from the prior review:

  • Terminology cross-reference (terminology.md:16): the pointer still reads "see 'long-term knowledge' below" while the entry below is labeled "Durable knowledge…" / canonical "long-term memory". Minor, non-blocking — suggest aligning the wording. (Original thread is still open.)

No other changes needed. Good to merge once the nit is addressed (or consciously left as-is).

github-actions[bot] avatar Jun 15 '26 18:06 github-actions[bot]

Re-review (/strands review): Approve.

The terminology nit from the prior pass is resolved — the awkward "see 'long-term knowledge' below" pointer is gone, replaced by three clean canonical rows (memory / memory manager / memory store). Nicely done; this reads better than a patched cross-reference would have.

Re-verified after the force-push (5c7a7a7):

  • Snippets: all includes across the three pages resolve, with zero missing and zero unused regions (overview 17, bedrock-kb 12, context-injector 8).
  • API accuracy: the memory / injection / context-injector SDK source is unchanged from my earlier field-by-field verification, so those findings still hold.

One minor, non-blocking observation (your call): the session-management row still lists memory as a banned synonym with no qualifier (context persistence, memory, conversation history), while the new row makes memory the canonical term for the feature. A reader scanning only the session row could read "memory" as always-banned. If you want the lock to be self-consistent, a short parenthetical on the session row (e.g. "'memory' only when it means conversation persistence — see the long-term memory rows below") would close that gap. Not blocking.

LGTM — good to merge.

github-actions[bot] avatar Jun 16 '26 14:06 github-actions[bot]

Re-review (/strands review): Approve — no new findings.

Branch is now at d014838 (squashed) with a substantial editorial pass since my last review. Re-verified the moving parts:

  • API accuracy still holds (re-checked the rewrite). The reworked bedrock-knowledge-base.mdx config tables match the SDK source field-for-field: BedrockKnowledgeBaseStoreConfig (config / scope / filter, extending MemoryStoreConfig) and BedrockKnowledgeBaseConfig (knowledgeBaseId, dataSourceType, dataSourceId, s3, scopeMetadataKey, runtimeClient/agentClient) are all real exports with the documented purposes. The writability rule (writable && (CUSTOM || S3)), the S3 .metadata.json sidecar + non-transactional-upload caveat, the sync-reconciliation deletion caveat, eventual consistency, and the 10 direct-call default vs. the manager's per-call cap all still match the source's own doc comments.
  • Snippets: all includes resolve with zero missing and zero unused regions after the edits (overview 20, bedrock-kb 12, context-injector 6).

The 8 still-open threads are all @notowen333's editorial/IA feedback on bedrock-knowledge-base.mdx, and the current rewrite appears to address them (console recommendation dropped, ingestion-API name out of the intro, credentials prose trimmed, the "split into two objects" line removed, :::note promoted to a ### How S3 writes work subheader). Those threads are the human reviewer's to resolve — flagging only that the code already reflects the requested changes.

Nothing blocking from my side. LGTM.

github-actions[bot] avatar Jun 16 '26 20:06 github-actions[bot]

Re-review (/strands review): Approve — no new findings.

Branch is now at e914eb8. All previously-open editorial threads from @opieter-aws's batch on bedrock-knowledge-base.mdx are resolved, and the rewrite landed cleanly. I re-verified the parts that changed:

  • New factual claims check out against source. The Extraction section now says automatic extraction "runs every 5 turns, distilling facts client-side with a ModelExtractor that uses the agent's own model" and uses the extraction: true / extraction=True shorthand. All three match memory/types.ts: extraction?: boolean | ExtractionConfig (boolean shorthand is real), the 5-turn default, and ModelExtractor calling the agent's model for client-side distillation. The TS snippet renders extraction: true, consistent with the Python tab.
  • Editorial requests applied. Intro folded to a single sentence with the Bedrock KB doc link, the redundant ## Getting Started header dropped, the read-only sentence reworded as requested, Scope moved to the top of Configuration, and the eventual-consistency note reduced to the single key sentence.
  • Snippets: all includes still resolve with zero missing and zero unused regions (overview 20, bedrock-kb 12, context-injector 6).

Nothing blocking. LGTM — good to merge.

github-actions[bot] avatar Jun 16 '26 20:06 github-actions[bot]

Re-review (/strands review): Comment — confirming @pgrayy's open finding against source; one substantive item to resolve.

Branch is now at 8b38373. Snippets remain healthy (all includes resolve, zero missing/unused: overview 22, bedrock-kb 12, context-injector 6). The two threads @pgrayy opened on overview.mdx are still open, and the flagged patterns are still present at HEAD. I verified the second one against the SDK source and it's a real cross-language inconsistency:

  • preferences.extraction = True post-construction (overview.mdx:58, and repeated at 213 / 241 / 284) — TS has no equivalent. In TypeScript, extraction is declared readonly (memory/types.ts:90 and vended-memory-stores/bedrock-knowledge-base/store.ts:161); the constructor sets it once (if (extraction !== undefined) this.extraction = extraction) but it cannot be reassigned afterward. So the Python tabs promote a mutate-after-construction pattern that doesn't round-trip to the TS API. @pgrayy's instinct is correct — recommend setting extraction at construction time in the Python examples too, for parity. (Note this pattern recurs in several places on the page, not just line 58.)

  • preferences variable name (overview.mdx:32) — editorial/readability; @pgrayy's store rename suggestion is reasonable. Non-blocking.

Everything else from my prior field-by-field verification still holds. Suggest addressing the readonly-parity item before merge; the rename is optional.

github-actions[bot] avatar Jun 17 '26 12:06 github-actions[bot]

Re-review (/strands review): Comment — one substantive open item to address.

Branch is now at 8b38373. New review from @pgrayy raised two threads on overview.mdx, both still open and not yet reflected in HEAD:

  • overview.mdx:58 — preferences.extraction = True (substantive). I verified this against source and it's a real cross-language parity gap: TS declares readonly extraction? (memory/types.ts:90, construction-only), while Python's attribute is mutable. The rendered TS tab sets extraction: true at construction, so the two tabs demonstrate divergent patterns. Left an inline comment with the source evidence and a fix suggestion (set it at construction in the Python tab too). Worth resolving.
  • overview.mdx:32 — preferences store name (minor/style). @pgrayy suggests a clearer name like store. Reasonable readability nit; author's call.

Everything else still checks out:

  • Snippets: all includes resolve with zero missing and zero unused regions (overview 22, bedrock-kb 12, context-injector 6).
  • API accuracy: prior field-by-field verification of the memory / injection / Bedrock-KB APIs still holds; no SDK-source-contradicting claims in the current text apart from the construction-vs-mutation framing above.

Not blocking from a correctness standpoint, but I'd recommend addressing the extraction construction-time point before merge for Python/TS consistency.

github-actions[bot] avatar Jun 17 '26 12:06 github-actions[bot]

Re-review (/strands review): Approve — prior findings resolved.

Branch is now at 49fb712 ("Slight refactor"). Both of @pgrayy's open items from the last pass are addressed:

  • readonly parity fixed. The post-construction store.extraction = True mutation is gone everywhere. All four extraction examples now set extraction= at construction time (overview.mdx:61, 222, 256, 305), with an explicit clarifying comment at line 218 ("Set extraction on the store at construction; True uses the defaults"). This now matches the TS readonly extraction? API (memory/types.ts:90) — the Python and TS tabs demonstrate the same pattern.
  • Variable naming. Examples use store rather than the standalone preferences. The remaining extraction = None / extraction = True at lines 407 / 456 are class-field declarations inside the custom-store class definitions (InMemoryStore / ServerSideStore), which is the correct idiomatic way to declare those attributes — not the mutate-after-construction pattern that was flagged.

Re-verified the rest:

  • Snippets: all includes resolve with zero missing and zero unused regions (overview 22, bedrock-kb 12, context-injector 6).
  • API accuracy: extraction defaults (every 5 turns, agent's model via ModelExtractor), the add vs. addMessages client-side/server-side split, and at-least-once retry semantics all still match the SDK source from prior verification.

Nothing blocking. LGTM — good to merge.

github-actions[bot] avatar Jun 17 '26 12:06 github-actions[bot]