generateTitle API broken in Beta ?

Hey all! I can no longer specify a custom generateTitle config for my agent in Beta: memory: new Memory({ options: { generateTitle: { model: anthropic.languageModel('claude-3-5-haiku-20241022'), instructions: 'Generate a concise, descriptive title for this conversation (max 60 characters). Focus on the main topic or intent. Never exceed 60 characters.', }, }, }), I get a compiler error:
Type 'LanguageModelV2' is not assignable to type 'DynamicArgument<MastraLanguageModel>'.
Type 'LanguageModelV2' is not assignable to type 'MastraLanguageModelV2 | (({ requestContext, mastra }: { requestContext: RequestContext<unknown>; mastra?: Mastra<Record<string, Agent<any, ToolsInput>>, ... 7 more ..., Record<...>> | undefined; }) => MastraLanguageModel | Promise<...>)'.
Type 'LanguageModelV2' is not assignable to type 'MastraLanguageModelV2'.
Type 'LanguageModelV2' is not assignable to type '{ doGenerate: (options: LanguageModelV2CallOptions) => DoStreamResultPromise; doStream: (options: LanguageModelV2CallOptions) => DoStreamResultPromise; }'.
The types returned by 'doGenerate(...)' are incompatible between these types.
Type 'PromiseLike<{ content: LanguageModelV2Content[]; finishReason: LanguageModelV2FinishReason; usage: LanguageModelV2Usage; providerMetadata?: SharedV2ProviderMetadata | undefined; request?: { ...; } | undefined; response?: (LanguageModelV2ResponseMetadata & { ...; }) | undefined; warnings: LanguageModelV2CallWarning[]...' is not assignable to type 'DoStreamResultPromise'.
Type 'LanguageModelV2' is not assignable to type 'DynamicArgument<MastraLanguageModel>'.
Type 'LanguageModelV2' is not assignable to type 'MastraLanguageModelV2 | (({ requestContext, mastra }: { requestContext: RequestContext<unknown>; mastra?: Mastra<Record<string, Agent<any, ToolsInput>>, ... 7 more ..., Record<...>> | undefined; }) => MastraLanguageModel | Promise<...>)'.
Type 'LanguageModelV2' is not assignable to type 'MastraLanguageModelV2'.
Type 'LanguageModelV2' is not assignable to type '{ doGenerate: (options: LanguageModelV2CallOptions) => DoStreamResultPromise; doStream: (options: LanguageModelV2CallOptions) => DoStreamResultPromise; }'.
The types returned by 'doGenerate(...)' are incompatible between these types.
Type 'PromiseLike<{ content: LanguageModelV2Content[]; finishReason: LanguageModelV2FinishReason; usage: LanguageModelV2Usage; providerMetadata?: SharedV2ProviderMetadata | undefined; request?: { ...; } | undefined; response?: (LanguageModelV2ResponseMetadata & { ...; }) | undefined; warnings: LanguageModelV2CallWarning[]...' is not assignable to type 'DoStreamResultPromise'.
6 Replies
Carlos T
Carlos TOP2w ago
GPT gave me a nice explanation: Cause of that TypeScript error What’s happening anthropic.languageModel('claude-3-5-haiku-20241022') returns a LanguageModelV2 from @ai-sdk/provider-v5. The Memory constructor’s options.generateTitle.model expects a DynamicArgument<MastraLanguageModel>, and MastraLanguageModelV2 is defined by Mastra as a specialization of LanguageModelV2 where both doGenerate and doStream return a DoStreamResultPromise that includes a stream property. You can see that in @mastra/core/dist/llm/model/shared.types.d.ts: shared.types.d.tsLines 28-35 type DoStreamResultPromise = PromiseLike<Awaited<ReturnType<LanguageModelV2['doStream']>>>;export type MastraLanguageModelV2 = Omit<LanguageModelV2, 'doGenerate' | 'doStream'> & { doGenerate: (options: LanguageModelV2CallOptions) => DoStreamResultPromise; doStream: (options: LanguageModelV2CallOptions) => DoStreamResultPromise;}; Why the error The raw Anthropic model’s doGenerate returns a non‑streaming call result (no stream field), while Mastra’s MastraLanguageModelV2 requires doGenerate to return the same shape as doStream, which does include stream: ReadableStream<LanguageModelV2StreamPart>. So TypeScript says your LanguageModelV2 is not assignable to MastraLanguageModelV2 and complains that the stream property is missing in the generated result. In short: after upgrading Mastra, Memory’s generateTitle.model type was tightened to MastraLanguageModel, but you’re passing a plain AI SDK LanguageModelV2 from anthropic.languageModel(...), whose doGenerate return type doesn’t satisfy Mastra’s streaming DoStreamResultPromise contract. Is this a bug?
Mastra Triager
📝 Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10519 🔍 If you're experiencing an error, please provide a minimal reproducible example whenever possible to help us resolve it quickly. 🙏 Thank you for helping us improve Mastra! 📝 Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10521 🔍 If you're experiencing an error, please provide a minimal reproducible example whenever possible to help us resolve it quickly. 🙏 Thank you for helping us improve Mastra!
Abhi Aiyer
Abhi Aiyer2w ago
Hi @Carlos T, yes we will take a look!
Abhi Aiyer
Abhi Aiyer2w ago
I have a fix here that we will release today! https://github.com/mastra-ai/mastra/pull/10541
GitHub
Fix model types by abhiaiyer91 · Pull Request #10541 · mastra-ai/...
Fix generateTitle model type to accept AI SDK LanguageModelV2 Updated the generateTitle.model config option to accept MastraModelConfig instead of MastraLanguageModel. This allows users to pass raw...
Carlos T
Carlos TOP7d ago
thanks! What version? I'm still seeing this on core 1.0.0-beta.5 Cursor is telling me it's going into beta.6
Abhi Aiyer
Abhi Aiyer7d ago
Sorry @Carlos T we had some hotfixes we had to do in 0.x so we didnt get another beta release out last week itll go out in tmrws schedueld release!

Did you find this page helpful?