{"record":{"id":"cae11ed228ea9eca","repo":"mastra-ai/mastra","slug":"either-message-or-messages-must-be-provided","errorCode":null,"errorMessage":"Either message or messages must be provided","messagePattern":"Either message or messages must be provided","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/agent.ts","lineNumber":3662,"sourceCode":"    // for storage/observability. Idempotent.\n    if (this.#mastra) {\n      llm.__registerMastra(this.#mastra);\n    }\n\n    let userContent: string;\n\n    if (messages && messages.length > 0) {\n      // Multi-message path: format all messages with roles\n      userContent = this.formatMessagesForTitle(messages);\n    } else if (message) {\n      // Single message path (backward compat): normalize and format\n      const normMessage = new MessageList().add(message, 'user').get.all.aiV5.ui().at(-1);\n      if (!normMessage) {\n        throw new Error(`Could not generate title from input ${JSON.stringify(message)}`);\n      }\n      userContent = this.formatMessagesForTitle([normMessage]);\n    } else {\n      throw new Error('Either message or messages must be provided');\n    }\n\n    if (!userContent) {\n      return undefined;\n    }\n\n    // Resolve instructions using the dedicated method\n    const systemInstructions = await this.resolveTitleInstructions(requestContext, instructions);\n\n    let text = '';\n\n    if (isSupportedLanguageModel(llm.getModel())) {\n      const messageList = new MessageList()\n        .add(\n          [\n            {\n              role: 'system',\n              content: systemInstructions,","sourceCodeStart":3644,"sourceCodeEnd":3680,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/agent.ts#L3644-L3680","documentation":"Thrown during agent title generation when neither a single `message` nor a `messages` array was supplied to the title-generation path. The library needs at least one user message to derive a conversation title from, so it fails fast instead of returning a meaningless or empty title.","triggerScenarios":"Calling the internal/indirect title generation flow (e.g. via agent configuration that auto-generates titles for threads) with both `message` and `messages` undefined or null; passing an explicit `messages: []` empty array can also route here with no usable input.","commonSituations":"Custom wrappers or middleware around `agent.generate()` that strip or forget to forward the input messages when title generation is enabled; programmatic thread creation with no initial user content; storage/memory integrations that invoke title generation with sanitized/emptied payloads.","solutions":["Ensure you pass either `message` (a single message object/string) or a non-empty `messages` array when invoking generation on an agent with title generation enabled","If wrapping generate/stream, forward the original user input into the title-generation options instead of dropping it","Check that the memory/thread integration isn't calling title generation with an empty payload; skip title generation when input is empty"],"exampleFix":"// before\nawait agent.generate('', { memory: { thread: threadId } });\n// after\nawait agent.generate('Plan my trip to Kyoto', { memory: { thread: threadId } });","handlingStrategy":"validation","validationCode":"function canGenerateTitle(input) {\n  const hasMessage = input?.message != null;\n  const hasMessages = Array.isArray(input?.messages) && input.messages.length > 0;\n  return hasMessage || hasMessages;\n}","typeGuard":"function hasTitleInput(opts) {\n  return (\n    opts != null &&\n    (('message' in opts && opts.message != null) ||\n      (Array.isArray(opts.messages) && opts.messages.length > 0))\n  );\n}","tryCatchPattern":"try {\n  await agent.generate(prompt, opts);\n} catch (e) {\n  if (e?.message === 'Either message or messages must be provided') {\n    logger.warn('skipping title generation: no input messages');\n    return;\n  }\n  throw e;\n}","preventionTips":["Never call generation with empty/undefined input when thread title generation is enabled","Forward the original user input through any wrappers/middleware","Skip title generation for empty conversations instead of invoking the agent"],"tags":["agent","title-generation","missing-input","validation"],"backgroundTag":"missing-required-input","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}