SerializedMemoryConfig
SerializedMemoryConfig 是 Memory 配置中可进行 JSON 序列化的子集,存储在 Agent 记录中。运行时会根据已配置的 Mastra 实例解析 vector 和 embedder ID,并将其还原为 Memory 实例。
它是 BuilderAgentDefaults.memory 和 EditorAgentNamespace.create({ memory }) 使用的类型。
使用示例使用示例的直接链接
src/mastra/index.ts
import { MastraEditor } from '@mastra/editor'
new MastraEditor({
builder: {
enabled: true,
configuration: {
agent: {
memory: {
observationalMemory: true,
options: { lastMessages: 50 },
},
},
},
},
})
属性属性的直接链接
vector?:
string | false
Vector store 标识符。必须在 Mastra 实例中注册对应的 vector 实例,才能通过此 ID 解析。设为
false 可禁用向量搜索。embedder?:
string
格式为
"provider/model" 的 Embedding 模型 ID(例如 "openai/text-embedding-3-small")。embedderOptions?:
Omit<MastraEmbeddingOptions, 'telemetry'>
传递给 embedder 的选项。Telemetry 选项会被移除。
options?:
SerializedMemoryOptions
Memory 行为配置。省略 working memory 和 threads 等不可序列化字段。
SerializedMemoryOptions
readOnly?:
boolean
将 memory 视为只读,不存储新消息。
lastMessages?:
number | false
要包含在上下文中的最近消息数量;设为
false 可完全禁用消息历史记录(消息既不会加载,也不会保存)。semanticRecall?:
boolean | SemanticRecall
Semantic recall 配置。完整结构请参阅 Memory class 参考文档。
generateTitle?:
boolean | { model: ModelRouterModelId; instructions?: string }
标题生成配置。传入包含
model(格式为 "provider/model")和可选 instructions 的对象。observationalMemory?:
boolean | SerializedObservationalMemoryConfig
长期事实提取。传入
true 可使用默认设置启用,或传入对象以覆盖 Observer/Reflector 模型、作用域和激活行为。SerializedObservationalMemoryConfigserializedobservationalmemoryconfig的直接链接
model?:
string
Observer 和 Reflector 共同使用的模型 ID(例如
"google/gemini-2.5-flash")。scope?:
'resource' | 'thread'
观察结果的作用域是 resource 还是单个 thread。
activateAfterIdle?:
ObservationalMemoryActivationTTL
强制激活已缓冲观察结果前的非活动 TTL。
activateOnProviderChange?:
boolean
当 actor 模型发生变化时,强制激活已缓冲的观察结果。
temporalMarkers?:
boolean
为消息之间的长时间停顿持久化内联时间间隔标记。
retrieval?:
boolean | { vector?: boolean; scope?: 'thread' | 'resource' }
启用检索模式的观察组,作为指向原始消息历史记录的持久指针。
observation?:
SerializedObservationalMemoryObservationConfig
Observer 步骤配置(模型、token 阈值、缓冲)。
reflection?:
SerializedObservationalMemoryReflectionConfig
Reflector 步骤配置(模型、观察 token 阈值、缓冲)。
相关相关的直接链接
- Memory class:此配置还原得到的运行时类型。
- Observational memory:完整的 Observational memory 参考文档。
- BuilderAgentDefaults:此类型被固定为 Builder 默认值的位置。
- Agent Builder:Memory:概念和完整示例。