Skip to content

feat(agent-memory): Phase 10 — AgentMemory facade#258

Open
jamby77 wants to merge 2 commits into
feature/agent-memory-phase9-observabilityfrom
feature/agent-memory-phase10-facade
Open

feat(agent-memory): Phase 10 — AgentMemory facade#258
jamby77 wants to merge 2 commits into
feature/agent-memory-phase9-observabilityfrom
feature/agent-memory-phase10-facade

Conversation

@jamby77

@jamby77 jamby77 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #257 (Phase 9 — observability).

What

Phase 10 of @betterdb/agent-memory: the AgentMemory convenience facade so a caller gets all four tiers from one construct.

const mem = new AgentMemory({
  client, embedFn,
  tierDefaults: { session: { ttl: 1800 } },
  memory: { defaultThreshold: 0.25, recall: { weights, halfLifeSeconds }, maxItemsPerScope: 5000 },
});
await mem.initialize();
mem.llm / mem.tool / mem.session   // short-term, delegated to AgentCache (unchanged)
mem.memory                         // long-term MemoryStore
  • Wraps AgentCache (exposing .llm/.tool/.session) + a MemoryStore (.memory), sharing the client, the resolved name prefix, and the telemetry registry.
  • Requires embedFn — throws a clear error if missing (checked before any resource is constructed).
  • Maps the memory sub-config onto MemoryStore (verified end-to-end via currentConfig()).
  • initialize() awaits discovery readiness for both tiers; close() tears down both (memory first, cache.shutdown() in a finally).

Design / review notes (fixes applied)

  • Single resolved name: the name is resolved once (options.name ?? 'betterdb_ac') and passed explicitly to both AgentCache and MemoryStore, so their key prefixes / discovery markers / stats keys can never drift even if AgentCache's internal default changes.
  • Symmetric discovery: AgentCache discovers by default, so the facade now discovers the memory tier by default too (opt-out via memory.discovery: false). Standalone MemoryStore stays opt-in. Added MemoryStore.ensureDiscoveryReady() so initialize() can await it.
  • Leak-safe close: close() runs cache.shutdown() in a finally, so a failing memory.close() can't leave cache timers/heartbeats running.
  • Distinct metric namespaces (agent_cache_* vs agent_memory_*) are intentional; only the prom registry is shared.

Tests (AgentMemory.test.ts, 9)

exposes 4 tiers · embedFn-missing throws · memory wired to shared client+prefix · custom name prefix · sub-config mapping via currentConfig() · initialize()/close() drive both (spy) · memory marker registered by default · memory discovery opt-out · one shared prom registry (agent_cache_* + agent_memory_*).

95/95 package tests green · tsc clean · prettier clean.


Note

Low Risk
New facade and lifecycle wiring with no changes to core recall/storage algorithms; risk is mainly integration (shared client/name, dual teardown) covered by tests.

Overview
Introduces AgentMemory, a single entry point that exposes short-term llm / tool / session tiers (via AgentCache) and long-term memory (MemoryStore) from one constructor.

Construction requires embedFn, resolves name once for both tiers (default betterdb_ac), maps the memory sub-config (threshold, recall weights/half-life, caps, discovery, config refresh), and optionally shares one Prometheus registry across cache and memory metrics.

initialize() awaits discovery readiness for cache and memory; close() shuts down memory first and always runs cache.shutdown() in a finally to avoid timer/heartbeat leaks. Memory discovery defaults on in the facade (opt out with memory.discovery: false); MemoryStore.ensureDiscoveryReady() is added so initialization can await registration.

Package exports and a new AgentMemory.test.ts suite cover wiring, prefixes, config mapping, discovery markers ({name}:mem), and shared telemetry.

Reviewed by Cursor Bugbot for commit a0accf8. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 268b946. Configure here.

Comment thread packages/agent-memory/src/AgentMemory.ts
@jamby77 jamby77 force-pushed the feature/agent-memory-phase9-observability branch from abeea66 to 339567e Compare June 17, 2026 14:51
@jamby77 jamby77 force-pushed the feature/agent-memory-phase10-facade branch from 268b946 to a409ab0 Compare June 17, 2026 14:52
@jamby77 jamby77 force-pushed the feature/agent-memory-phase9-observability branch from 339567e to 312772a Compare June 17, 2026 14:58
@jamby77 jamby77 force-pushed the feature/agent-memory-phase10-facade branch from a409ab0 to aa75783 Compare June 17, 2026 14:58
@jamby77 jamby77 force-pushed the feature/agent-memory-phase9-observability branch from 312772a to 22b6f78 Compare June 18, 2026 06:57
@jamby77 jamby77 force-pushed the feature/agent-memory-phase10-facade branch from aa75783 to 7a0812f Compare June 18, 2026 06:57
@jamby77 jamby77 force-pushed the feature/agent-memory-phase9-observability branch from 22b6f78 to b160dd0 Compare June 18, 2026 07:19
@jamby77 jamby77 force-pushed the feature/agent-memory-phase10-facade branch from 7a0812f to 65a592a Compare June 18, 2026 07:19
@jamby77 jamby77 force-pushed the feature/agent-memory-phase9-observability branch from b160dd0 to b29dd7e Compare June 18, 2026 07:28
@jamby77 jamby77 force-pushed the feature/agent-memory-phase10-facade branch from 65a592a to 8915dfe Compare June 18, 2026 07:28
jamby77 added 2 commits June 18, 2026 10:35
- AgentMemory wraps AgentCache (.llm/.tool/.session, unchanged) and a
  MemoryStore (.memory) behind one construct, sharing the client, the
  resolved name prefix, and the telemetry registry
- Require embedFn for the memory tier (clear error if missing)
- Map the memory sub-config (defaultThreshold, recall.weights/halfLife,
  maxItemsPerScope, discovery, configRefresh) onto MemoryStore
- initialize() awaits discovery readiness for both tiers; close() tears
  down both (memory first, cache in finally so neither leak)
- Discover the memory tier by default in the facade (opt-out via
  memory.discovery:false); add MemoryStore.ensureDiscoveryReady()
@jamby77 jamby77 force-pushed the feature/agent-memory-phase9-observability branch from b29dd7e to 4ea754e Compare June 18, 2026 07:35
@jamby77 jamby77 force-pushed the feature/agent-memory-phase10-facade branch from 8915dfe to a0accf8 Compare June 18, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant