跳至主要內容

SerializedMemoryConfig

SerializedMemoryConfigMemory 設定中可序列化為 JSON 的子集,儲存於已保存的 agent 記錄上。runtime 會根據已設定的 Mastra instance 解析 vector 及 embedder ID,將其還原為 Memory instance。

這是 BuilderAgentDefaults.memoryEditorAgentNamespace.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 instance 中註冊該 vector instance,才能透過此 ID 解析。設為 false 可停用 vector search。

embedder?:

string
格式為 "provider/model" 的 embedding model 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
要加入 context 的近期訊息數目;設為 false 則完全停用訊息記錄(不會載入或儲存訊息)。

semanticRecall?:

boolean | SemanticRecall
Semantic recall 設定。完整結構請參閱 Memory class 參考資料。

generateTitle?:

boolean | { model: ModelRouterModelId; instructions?: string }
標題產生設定。傳入包含 model(格式為 "provider/model")及可選 instructions 的 object。

observationalMemory?:

boolean | SerializedObservationalMemoryConfig
長期事實擷取。傳入 true 可使用預設值啟用,或傳入 object 以覆寫 observer/reflector model、scope 及啟用行為。

SerializedObservationalMemoryConfig
serializedobservationalmemoryconfig 的直接連結

model?:

string
Observer 及 Reflector 共用的 model ID(例如 "google/gemini-2.5-flash")。

scope?:

'resource' | 'thread'
指定 observations 的 scope 是 resource 還是單一 thread。

activateAfterIdle?:

ObservationalMemoryActivationTTL
強制啟用已緩衝 observation 前的閒置 TTL。

activateOnProviderChange?:

boolean
當 actor model 變更時,強制啟用已緩衝的 observations。

shareTokenBudget?:

boolean
讓訊息與 observations 共用 token 預算。

temporalMarkers?:

boolean
當訊息之間相隔較長時間時,保留 inline 時間間隔標記。

retrieval?:

boolean | { vector?: boolean; scope?: 'thread' | 'resource' }
啟用 retrieval mode observation groups,作為指向原始訊息記錄的持久指標。

observation?:

SerializedObservationalMemoryObservationConfig
Observer 步驟設定(model、token threshold、buffering)。

reflection?:

SerializedObservationalMemoryReflectionConfig
Reflector 步驟設定(model、observation token threshold、buffering)。