mastra-ai/mastra · error

Resource ID is required for recall

Error message

Resource ID is required for recall

What it means

The memory recall tool's search mode requires a resourceId to scope the semantic search to a specific resource (user). Mastra throws this when mode="search" is invoked without a resourceId in the tool context. The library cannot safely search messages without knowing which resource's data to search.

Source

Thrown at packages/memory/src/tools/om-tools.ts:1389

      if (explicitThreadId === 'current' && !currentThreadId) {
        throw new Error('Could not resolve current thread.');
      }

      // Search mode
      if (mode === 'search') {
        // Schema validation rejects mode="search" when search is disabled, but
        // validation is skipped for resumed runs and builder-validated input —
        // a stale search call on those paths would otherwise reach
        // Memory.searchMessages and throw. Return guidance instead.
        if (!searchEnabled) {
          return { results: SEARCH_NOT_CONFIGURED_MESSAGE, count: 0 };
        }
        if (!query) {
          throw new Error('query is required for mode="search"');
        }
        if (!resourceId) {
          throw new Error('Resource ID is required for recall');
        }
        return searchMessagesForResource({
          memory,
          resourceId,
          currentThreadId: currentThreadId || undefined,
          query,
          topK: limit ?? 10,
          before,
          after,
          threadScope: !isResourceScope ? currentThreadId || undefined : resolvedExplicitThreadId || undefined,
        });
      }

      // Thread listing mode
      if (mode === 'threads') {
        const requestedCurrentThread = explicitThreadId === 'current';

        // Thread scope: return current thread info only

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Pass a resourceId when creating the Memory instance or when invoking the agent (e.g. agent.stream(..., { resourceId: 'user-123' })).
  2. If calling the tool directly, include resourceId in the tool context object.
  3. Verify the resourceId isn't an empty string or being read from an unset env/config variable before the call.

Example fix

// before
await agent.stream('what did I say about cats?');
// after
await agent.stream('what did I say about cats?', { resourceId: 'user-123', threadId: 'thread-abc' });
Defensive patterns

Strategy: validation

Validate before calling

if (!resourceId || typeof resourceId !== 'string' || resourceId.length === 0) {
  throw new Error('resourceId must be provided before calling memory search');
}

Type guard

function hasResourceId(ctx: unknown): ctx is { resourceId: string } {
  return typeof (ctx as any)?.resourceId === 'string' && (ctx as any).resourceId.length > 0;
}

Try / catch

try {
  await agent.stream(query, { resourceId, threadId });
} catch (err) {
  if (err instanceof Error && err.message === 'Resource ID is required for recall') {
    // re-init with resourceId or prompt user to authenticate
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling the om-memory tool with mode="search" and a non-empty query, but context.resourceId is undefined or an empty string (e.g. agent invoked without resourceId in its memory options, or caller omitted it in the tool's run context).

Common situations: Agents constructed without passing resourceId to Memory or the agent's memory options; standalone agents where the caller forgot to supply resourceId in the execution context; multi-tenant apps where the resourceId is set later in the request lifecycle than the tool call.

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


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/531f51ceb71c0d42. Report an issue: GitHub.