Memory.summarizeThread()
The .summarizeThread() method summarizes a thread's conversation in one shot. It loads the thread's messages from storage and distills them with the same Observer plumbing that powers Observational Memory — as a standalone call, without Observational Memory attached to an agent.
Messages load page-by-page starting from the newest, bounded by lastMessages and maxInputTokens, so summarizing a long thread doesn't read its entire history from storage.
Nothing is written back to memory. The summary and extracted values are returned to you (and to each extractor's onExtracted hook), so you decide where they go — for example your own database.
Use this when a session ends and you want a summary or structured extraction of the whole conversation, such as a voice call at hang-up. To summarize messages you already have in hand (without loading them from a thread), use the standalone summarizeConversation() function instead — it takes the same options with messages in place of threadId.
Usage exampleDirect link to Usage example
const result = await memory.summarizeThread({
model: 'openai/gpt-5-mini',
threadId: 'thread-123',
instructions: 'Summarize this voicemail call for the business owner.',
})
ParametersDirect link to Parameters
threadId:
model:
resourceId?:
lastMessages?:
maxInputTokens.maxInputTokens?:
instructions?:
extract?:
onExtracted hook fires with the extracted value.requestContext?:
abortSignal?:
ReturnsDirect link to Returns
summary:
extracted:
extract extractors, keyed by extractor slug.extractionFailures:
usage:
Extended usage exampleDirect link to Extended usage example
The following example summarizes a finished voice call and stores a structured record in the application's own database:
import { Extractor } from '@mastra/memory'
import { z } from 'zod'
import { memory } from './mastra/memory'
import { callRecords } from './db'
const callSummary = new Extractor({
name: 'call-summary',
instructions: 'Return a concise summary of the call.',
schema: z.object({
summary: z.string(),
sentiment: z.enum(['positive', 'neutral', 'negative']),
requestedServices: z.array(z.string()),
}),
metadataKeyPath: false, // don't persist into memory metadata — the hook owns storage
onExtracted: async ({ current, threadId, resourceId }) => {
await callRecords.upsert({ callId: threadId, callerId: resourceId, record: current })
},
})
export async function onCallEnd(threadId: string, resourceId: string) {
await memory.summarizeThread({
model: 'openai/gpt-5-mini',
threadId,
resourceId,
instructions: 'Summarize this voicemail call for the business owner.',
extract: [callSummary],
})
}