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:
6 Replies
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?
📝 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!
Hi @Carlos T, yes we will take a look!
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...
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
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!