@mastra/ai-sdk chatRoute with middleware context
Hey all, I'm trying to use the chatRoute from the mastra ai-sdk and I have middleware configured that is grabbing some additional metadata my backend sends and adding it to the runtime context. When the agent is called up with a users chat my middleware sees and sets the runtimeContext successfully but the agent runtimeContext is empty.
Is this a known issue or perhaps something I'm missing with this setup? This is from the docs here https://mastra.ai/en/docs/frameworks/agentic-uis/ai-sdk
14 Replies
Or is there another way when ineracting with this new
/chat endpoint to send along data i'd like to be put in runtimeContext automatically? my setup is basically react frontend -> NestJS backend server -> mastra API📝 Created GitHub issue: https://github.com/mastra-ai/mastra/issues/8609
GitHub
[DISCORD:1425287716114792499] @mastra/ai-sdk chatRoute with middlew...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1425287716114792499 Hey all, I'm trying to use the chatRoute from the mastra ai-sdk and I have middlew...
Hi @Incisiv3 ! I think that's because you're not setting the
runtimeContext back into the hono context, can you try adding c.set("runtimeContext", runtimeContext); after you're do setting up your runtimeContext?Oh fair point yes let me give it a try shortly and I’ll get back to you
@Romain I adjusted it to re-set the runtimeContext and my agent still is getting an empty object when it's invoked
Hmm, I think that's a bug in chatRoute... I think that the first code you shared should have been working. Let me check something.
Ok thanks
Could you try using the tag fix-runtimeContext-passing-chatRoute as your Mastra packages version and let me know if it's correctly passing the runtime context?
@Romain yep that seems to have fixed it! seems to work without me explicitly setting the runtime context back too with
c.set("runtimeContext", runtimeContext);Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Thanks @Omicrxn & @Incisiv3 for testing out the fix, I'll have the PR reviewed and merged asap.
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
You can use the snapshort version above for now btw, I'll try to have an alpha released today, but not sure we'll have another stable release before next tuesday
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Thanks all!