What's the best way to trim the context of a long running agent (50 steps or more)?

I am trying to make an autonomous cloud AI Agent where I want the agent to run on its own, without user interaction. Currently the longer (max steps) agent runs, the context gets bloated, is it possible to automatically delete or filter the old messages while the agent is running?
5 Replies
メグディップ
メグディップOP2mo ago
https://mastra.ai/en/docs/memory/memory-processors#tokenlimiter I am aware that this exists but it only works after the agent stops and the user inputs a new message to the agent
Memory Processors | Memory | Mastra Docs
Learn how to use memory processors in Mastra to filter, trim, and transform messages before they're sent to the language model to manage context window limits.
メグディップ
メグディップOP2mo ago
Is it possible to trim the older messages while the agent is running?
Mastra Triager
Mastra Triager2mo ago
GitHub
[DISCORD:1432741300267913248] What's the best way to trim the conte...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1432741300267913248 I am trying to make an autonomous cloud AI Agent where I want the agent to run on its ...
_roamin_
_roamin_2mo ago
Hey @Meghdip Karmakar ! You should look into using prepareStep
const result = await myagent.generate("...", {
prepareStep: async ({ messages, }) => {
// modify messages here...
return {
messages
};
},
});
const result = await myagent.generate("...", {
prepareStep: async ({ messages, }) => {
// modify messages here...
return {
messages
};
},
});
メグディップ
メグディップOP2mo ago
oh nice, this is nicer. I was using a transformParams middleware to trim the messages the issue is the agent performance degrades rapidly when trimming the messages, having semantic recall fetch related messages from the history during runtime, while the agent is running Is it possible to do a RAG query to fetch past messages similar to what semantic recall does with user input but for autonomous agents?? maybe using the last message or last 10 messages as query text?

Did you find this page helpful?