summarizeConversation()
The standalone summarizeConversation() function summarizes a conversation in one shot. It distills the messages you pass in with the same Observer plumbing that powers Observational Memory — without Observational Memory attached to an agent, and without reading from or writing to 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 you already have the messages in hand and want explicit control over what gets summarized. To summarize a stored thread by ID instead, use Memory.summarizeThread(), which loads the messages for you.
Usage exampleDirect link to Usage example
import { summarizeConversation } from '@mastra/memory'
const result = await summarizeConversation({
model: 'openai/gpt-5-mini',
messages,
instructions: 'Summarize this voicemail call for the business owner.',
})
ParametersDirect link to Parameters
model:
messages:
instructions?:
extract?:
onExtracted hook fires with the extracted value.threadId?:
threadId found on messages. Passed to extractor contexts.resourceId?:
resourceId found on messages. Passed to extractor contexts.memory?:
Memory.summarizeThread().mastra?:
Memory.summarizeThread().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 an in-flight voice session from messages the application already holds, and extracts a structured record:
import { summarizeConversation, Extractor } from '@mastra/memory'
import type { MastraDBMessage } from '@mastra/core/agent'
import { z } from 'zod'
import { sessionRecords } from './db'
const sessionSummary = new Extractor({
name: 'session-summary',
instructions: 'Return a concise summary of the session.',
schema: z.object({
summary: z.string(),
sentiment: z.enum(['positive', 'neutral', 'negative']),
followUps: z.array(z.string()),
}),
metadataKeyPath: false, // don't persist into memory metadata — the hook owns storage
onExtracted: async ({ current, threadId }) => {
await sessionRecords.upsert({ sessionId: threadId, record: current })
},
})
export async function onSessionEnd(messages: MastraDBMessage[]) {
const { summary, extracted, extractionFailures } = await summarizeConversation({
model: 'openai/gpt-5-mini',
messages,
instructions: 'Summarize this support session for the account manager.',
extract: [sessionSummary],
})
if (extractionFailures?.length) {
console.warn('Some extractors failed', extractionFailures)
}
return { summary, extracted }
}