mastra-ai/mastra · error · Error
No active thread context and no cursor or threadId was provi
Error message
No active thread context and no cursor or threadId was provided for mode="messages". Pass a threadId (use mode="threads" to discover thread IDs) or a message ID as cursor.
What it means
For mode="messages", Mastra needs a thread to read from: either an explicitly passed threadId, a cursor, or the agent's current thread. When none can be resolved (resource scope, no default thread), it throws with guidance to pass a threadId or message-ID cursor.
Source
Thrown at packages/memory/src/tools/om-tools.ts:1450
currentThreadId: currentThreadId || '',
page: page ?? 0,
limit: limit ?? 20,
before,
after,
});
}
const usedDefaultThreadId = !explicitThreadId && !cursor && Boolean(currentThreadId);
const defaultThreadNote =
usedDefaultThreadId && isResourceScope ? `threadId wasn't passed so used default ${currentThreadId}.\n\n` : '';
// Reuse the shared `resolvedExplicitThreadId` ('current' -> currentThreadId) mapping,
// falling back to the current thread when no threadId or cursor was provided.
const resolvedThreadId = resolvedExplicitThreadId || (usedDefaultThreadId ? currentThreadId : undefined);
const hasResolvedThreadId = typeof resolvedThreadId === 'string' && resolvedThreadId.length > 0;
const hasCursor = typeof cursor === 'string' && cursor.length > 0;
if (!hasResolvedThreadId && !hasCursor) {
throw new Error(
isResourceScope
? 'No active thread context and no cursor or threadId was provided for mode="messages". Pass a threadId (use mode="threads" to discover thread IDs) or a message ID as cursor.'
: 'No active thread context for mode="messages". This tool is limited to the current thread and no current thread could be resolved.',
);
}
let targetThreadId: string | undefined;
let threadScope: string | undefined;
if (!isResourceScope) {
targetThreadId = currentThreadId;
threadScope = currentThreadId || undefined;
} else if (hasResolvedThreadId) {
if (!resourceId) {
throw new Error('Resource ID is required for recall');
}
if (!memory.getThreadById) {
throw new Error('Memory instance cannot verify thread access for recall');View on GitHub (pinned to 75dd419e61)
Solutions
- Pass an explicit threadId to the tool call (discover one with mode="threads").
- Provide a message ID as cursor to continue browsing from that point.
- Invoke the tool within an agent run where threadId is supplied so currentThreadId resolves.
Example fix
// before
const res = await recallTool.execute({ context: { mode: 'messages' } });
// after
const res = await recallTool.execute({ context: { mode: 'messages', threadId: 'thread-abc' } }); Defensive patterns
Strategy: validation
Validate before calling
const hasThread = typeof threadId === 'string' && threadId.length > 0;
const hasCursor = typeof cursor === 'string' && cursor.length > 0;
if (!hasThread && !hasCursor && !currentThreadId) {
throw new Error('Provide threadId or cursor for mode="messages"');
} Type guard
function canRecallMessages(args: { threadId?: string; cursor?: string; currentThreadId?: string }): boolean {
return Boolean(args.threadId || args.cursor || args.currentThreadId);
} Try / catch
try {
return await recall({ mode: 'messages', threadId });
} catch (err) {
if (err instanceof Error && err.message.includes('No active thread context')) {
const threads = await recall({ mode: 'threads', resourceId });
return recall({ mode: 'messages', threadId: threads.threads[0]?.id });
}
throw err;
} Prevention
- Pass threadId explicitly when calling recall tools outside an agent run.
- Discover thread IDs with mode="threads" first.
- Ensure agent runs supply threadId so currentThreadId resolves.
When it happens
Trigger: mode="messages" called with no threadId, no cursor, and no currentThreadId resolvable in the run context (usedDefaultThreadId with empty currentThreadId).
Common situations: Invoking the recall tool outside an agent run so no 'current thread' exists; agent run without threadId while the tool needs conversation history; asking 'show messages' before any conversation started.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- AGENT_MEMORY_THREAD_RESOURCE_MISMATCH
- resourceId and threadId are required to queue a message
- resourceId and threadId are required to send a state signal
- resourceId and threadId are required to persist an active si
- The threads.generateTitle option has been moved. Use the top
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/6a9793576726ddff.
Report an issue: GitHub.