Does Runtime Context is persistent across Messages
Lets say I set a value in runtime Context and in the next message I get the value from runtime context will that work ?


14 Replies
@619napster what do you mean exactly with 'next message'? It feels from your example like these could be workflow steps, in which case the runtimeContext is passed through and therefore variables are persisted. But if these are completely separately invoked calls, the runtimeContext is not the same. That is exactly the point of the runtimeContext: to give context of the runtime that the workflow/agent is currently running in

I hope my image explains
You are using an agent, which means every time you send a message you do a completely fresh invokation of the mastra agent
So in your case, the runtimeContext is (and should be) reset every time
oh, so is there anything if i set it on the thread level it stays there
If you want your agent to persist data accross messages, you will either need to look into a workflow that stores it as state (and have the agent use the workflow internally) or if you want to just use an agent: look into Mastra's Memory solutions
memory: new Memory({
storage: new PostgresStore({
connectionString: process.env.DATABASE_URL!,
}),
options: {
threads: {
generateTitle: true,
},
workingMemory: {
enabled: true,
}
},
}),
so if I set this
it will still reset the context on each message ?
no, memory is not reset per message. Memory is on thread-level
You can also use a working memory template:
which might be nice in your case, since you want the agent to remember a specific bit of information
Just need a little more help
I am able to set the template and its updating


so how to use this value in tool call ?
if you ask for currentAdvertiserId in your tool input schema the agent can pass it as a parameter because it has it in memory
I am Blown Away ! it works !
Coming from LangChain Python,
it feels like LangChain is 1995 while Mastra lives in 2030
š Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10548
š 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!
Thank you for the compliment @619napster !
And thank you so much @Vulcano for the assist!!