save message to memory
I've got a setup where a user hits a chat interface (ai sdk useChat setup). I'm using initial messags to populate the feed BUT, those messages aren't saved to memory. I generate them from an agent.generate call.
I tried to add memory to that but I don't want the prompt to land in memory, just the response from the LLM, as if it was starting the conversation.
Does anyone have a solution for this using Mastra sdk or do I need to create my own function to write to memory?
9 Replies
Hey @rogueturnip ! You can manually save messages into the agent memory, see https://mastra.ai/en/reference/client-js/memory#save-messages
Mastra Client Memory API
Learn how to manage conversation threads and message history in Mastra using the client-js SDK.
Thanks! I was looking at this. i noticed no option for the resource id. is that not need?
Are you trying to save the messages from the client sdk or from your backend?
I'm checking for the client sdk, but from the backend you should be providing the resource and thread id:
perfect!! thanks. i’m doing it at backend
Just for reference, could you point me to the doc url that shows the getMemory/saveMessage? I could found deleteMessage and others but not saveMessage off the agent memory.

It's missing at the moment 😢 We're working on improving the docs this month though and automate our reference docs
wonderful thanks! This is probably why I didn't find it on my own.. Honest I looked!
Thanks for trying to look, a lot of people don't even bother 🤣
You guys are busy, I have deliverables.. so I can't expect you to be on my timelines :). I do really really apreciate you taking the time to help