MastraM
Mastra2mo ago
Kartik

How to stop agent midway during stream while preserving the output streamed till that point

Hi Folks,

I was wondering if its possible to stop agent stream midway while also preserving the tokens that were streamed till the time user stopped the stream.

So essentially:
  • User sends a message.
  • Lets say agent streams about 200 tokens and user clicks on stop.
  • Agent stops generating and we save these 200 tokens to the memory.
Currently, if I stop the stream from frontend and abort using abort controller on the backend, it does not persist the message to the backend.
Was this page helpful?