Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Add long‑term memory to a Mastra agent (input/output processors, per‑user recall)

说明与用途

将 MemorySync 集成到 Mastra 代理中,可通过输入和输出处理器在模型调用前注入回忆,并在响应后提取新事实,实现每用户、每线程的长期记忆。

问题

Integrate durable per‑user memory into a Mastra agent so that facts are extracted and recalled across sessions without storing assistant replies.

结果

The agent now recalls durable facts per user and thread, extracts new facts after each response, and continues to function with existing Mastra memory. Recall is injected once per generate/stream call, and failures are logged via onError.

工作流

  • Install memorysync‑mastra via npm
  • Create inputProcessor and outputProcessor with createMemorySyncProcessors, passing userId and sessionId
  • Instantiate Agent with inputProcessors and outputProcessors
  • Resolve user identity per call using createMemorySyncProcessors with resolveIdentity or static ids or RequestContext
  • Generate agent calls; MemorySync injects recall and extracts facts
  • Optional: use withMemorySync wrapper to auto‑merge processors
  • Handle streaming by passing stream option to agent.generate

证据

Mastra agents already have memory. Give an agent a Memory from @mastra/memory and pass memory: { resource, thread } on each call

来源

If that's working for you, keep it. This post is for when you want durable facts about each user extracted and recalled by a hosted service, wired in through Mastra's own processor pipeline.

来源

Create inputProcessor and outputProcessor with createMemorySyncProcessors, passing userId and sessionId

来源

Prefer less wiring? withMemorySync(config, { userId }) wraps your agent config and merges both processors in, keeping any processors you already have

来源

  • 记录日期: 2026-10-24T17:26:12.048Z