Title generation model switching not working

I am using runtimeContext/dynamic stuff to set the title generation model in threads/memory on an agent and looking at my logs it is ALWAYS using the same model as the agent itself and never even calling my function that sets the model. Example code:
memory: ({ runtimeContext }) =>
new Memory({
storage: store,
processors: [
new ToolCallFilter({
exclude: ["giteaOps", "fileOps", "repoInventory", "outdatedPackages"],
}),
new TokenLimiter(32000),
],
options: {
lastMessages: 50,
threads: {
generateTitle: {
model: ({ runtimeContext }) => {
return getTitleModel();
},
instructions:
"Generate a SHORT, punchy title for this chat. Max 6 words. DO NOT just rephrase the user's question.\n\nBAD: 'What is Walker Package', 'Outdated Packages Query', 'Package Information Request'\nGOOD: 'Walker Deep Dive', 'Package Update Hunt', 'Hyprland Bump', 'Finding Stale Packages'\n\nDrop filler words (what/is/the/a). Use package names. Use action words like: Hunt, Bump, Fix, Check, Explore, Debug.",
},
},
},
}),
memory: ({ runtimeContext }) =>
new Memory({
storage: store,
processors: [
new ToolCallFilter({
exclude: ["giteaOps", "fileOps", "repoInventory", "outdatedPackages"],
}),
new TokenLimiter(32000),
],
options: {
lastMessages: 50,
threads: {
generateTitle: {
model: ({ runtimeContext }) => {
return getTitleModel();
},
instructions:
"Generate a SHORT, punchy title for this chat. Max 6 words. DO NOT just rephrase the user's question.\n\nBAD: 'What is Walker Package', 'Outdated Packages Query', 'Package Information Request'\nGOOD: 'Walker Deep Dive', 'Package Update Hunt', 'Hyprland Bump', 'Finding Stale Packages'\n\nDrop filler words (what/is/the/a). Use package names. Use action words like: Hunt, Bump, Fix, Check, Explore, Debug.",
},
},
},
}),
getTitleModel has logging/tracing inside it and it never gets called
7 Replies
_roamin_
_roamin_7d ago
Hi @Ferreo ! Thanks for reporting this bug!!
Mastra Triager
GitHub
[DISCORD:1427654090757902437] Title generation model switching not ...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1427654090757902437 I am using runtimeContext/dynamic stuff to set the title generation model in threads/m...
Daniel Lew
Daniel Lew5d ago
@Ferreo I can't reproduce this, it looks like I am able to use runtime context to switch the model. I see in the code you provided you're not actually passing runtimeContext into your genTitleModel function, could that be why the model is always the same? Does that fn return a deafult model?
Ferreo
FerreoOP5d ago
No it was originally running off the runtime context value And it made no difference The model getting used is only set as the model for the agent nowhere else And it's not even calling the function If it helps this is nextjs not Mastra server
Daniel Lew
Daniel Lew5d ago
Are you able to provide a repro? That would help a lot!
_roamin_
_roamin_5d ago
Hey @Ferreo ! Can you make sure you're setting the memory option when calling generate/stream?
const result = await agent.generate("...", {
memory: {
resource: "...",
thread: "...",
}
});
const result = await agent.generate("...", {
memory: {
resource: "...",
thread: "...",
}
});
If that still doesn't work, as Daniel mentioned, please provide a minimal repro example. Thanks 🙏
Ferreo
FerreoOP5d ago
Looks like the last release fixed this somehow, feel free to close and thanks!

Did you find this page helpful?