Dynamically Reload Prompt/Agents
Hi team, is there a way to dynamically reload the agent instructions (or the agent itself)? We're using Langfuse for prompt management and would love to automate the propagation of prompt changes from Langfuse to Mastra.
Our current workaround is to simply trigger an infra-level restart of the pod (we don't have much volume yet so it's fine). I'm wondering if there was a way to do this without manual intervention? I'm picturing a simple custom route implementation:
Thank you!
7 Replies
š Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10212
š If you're experiencing an error, please provide a minimal reproducible example to help us resolve it quickly.
š Thank you @DuhKneeL for helping us improve Mastra!
Hi @DuhKneeL are you passing the instructions within a function? or passing it straight up?
new Agent({ instructions: () => langfuse.prompt() })
or new Agent({ instructions: langfuse.prompt() })Hi @Abhi Aiyer, thanks for taking a look!. I'm passing the instructions straight up. Are you suggesting that with a dynamic instruction resolver, remote Langfuse updates would automatically propagate to the Mastra agent?
@DuhKneeL if you give the instructions as a function, you can change them based on the runtimeContext, which is only available at the time of doing the request to the agent, which would of course pull your latest prompt from Langfuse
(you could also have a beta tag/version for your Langfuse prompts and provide those in your frontend in the runtimeContext, so users on the production prompt dont get a broken product)
@DuhKneeL yeah i'm suggesting putting it in the instructions as a function so it gets evaluated.
And @Vulcano 's point is good too! It can give you some more control in the future based on runtimeContext
Wow, this is amazing! Wasn't aware of the functional approach. Thanks so much everyone! šāāļø
Anytime dude!