mastra-ai/mastra · error · HTTPException

conversation_id requires the target agent to have memory con

Error message

conversation_id requires the target agent to have memory configured

What it means

conversation_id implies server-side conversation persistence, which only works when the target agent has memory configured. resolveThreadExecutionContext checks agent.getMemory(); if no memory is configured and conversation_id was supplied, it rejects the request with this 400 instead of silently dropping the conversation.

Source

Thrown at packages/server/src/server/handlers/responses.ts:201

  if (previousResponseTurnRecord) {
    return {
      threadId: previousResponseTurnRecord.thread.id,
      resourceId: previousResponseTurnRecord.thread.resourceId,
    };
  }

  const effectiveThreadId = getEffectiveThreadId(requestContext, undefined);
  const effectiveResourceId = getEffectiveResourceId(requestContext, undefined);

  if (!store && !conversationId && !effectiveThreadId) {
    return null;
  }

  const memory = await agent.getMemory({ requestContext });
  if (!memory) {
    if (conversationId) {
      throw new HTTPException(400, {
        message: 'conversation_id requires the target agent to have memory configured',
      });
    }

    return null;
  }

  if (conversationId) {
    const existingThread = await memory.getThreadById({ threadId: conversationId });
    if (!existingThread) {
      throw new HTTPException(404, { message: `Conversation ${conversationId} was not found` });
    }

    await enforceThreadAccess({
      mastra: agent.getMastraInstance(),
      requestContext,
      threadId: conversationId,
      thread: existingThread,

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Configure memory on the agent: new Memory({ storage }) passed in the Agent constructor
  2. Remove conversation_id from the request if persistence is not needed
  3. Verify agent.getMemory() resolves for the agent_id you are targeting (it is resolved per-request via requestContext)
  4. Confirm you are hitting the agent you think — agent_id typos can resolve a different, memory-less agent

Example fix

// before
new Agent({ name: 'support', instructions: '...', model: 'openai/gpt-4o' });
// after
new Agent({ name: 'support', instructions: '...', model: 'openai/gpt-4o', memory: new Memory({ storage: new LibSQLStore({ url: process.env.DATABASE_URL }) }) });
Defensive patterns

Strategy: validation

Validate before calling

const memory = await agent.getMemory({ requestContext });
if (!memory && body.conversation_id) throw new Error('conversation_id set but agent has no memory');

Type guard

function supportsConversation(agent) { return typeof agent.getMemory === 'function'; }

Try / catch

null

Prevention

When it happens

Trigger: POST /api/responses with body.conversation_id set while the resolved agent (from body.agent_id) was created without a memory instance.

Common situations: Adding conversation_id to an existing client call after switching to an agent that has no Memory configured; forgetting to pass memory when constructing the Agent; an agent defined in a config file where memory wiring was omitted.

Related errors


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