M
Mastraβ€’4w ago
kosukeoya

The resourceId and threadId for chatRoute and copilotkit integration should be able to contain authe

In the integration with the AI SDK, memory information is passed from the frontend. However, when using session authentication, it becomes possible to view other users' messages. https://mastra.ai/docs/frameworks/agentic-uis/ai-sdk#streaming With copilotkit's integration, the resourceId is fixed, so in applications used by multiple users, all users can view the same message history. https://mastra.ai/docs/frameworks/agentic-uis/copilotkit
Integrate CopilotKit with Mastra | Frameworks | Mastra Docs
Learn how Mastra leverages the CopilotKit's AGUI library and how you can leverage it to build user experiences
Using Vercel AI SDK | Frameworks | Mastra Docs
Learn how Mastra leverages the Vercel AI SDK library and how you can leverage it further with Mastra
8 Replies
kosukeoya
kosukeoyaOPβ€’4w ago
I specify resourceId and threadId using the following rules: resourceId: ${agentId}-${c.get(β€˜user’).id} threadId: ${agentId}-${c.get(β€˜user’).id}-${threadId}
Mastra Triager
Mastra Triagerβ€’4w ago
πŸ“ Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10214 πŸ” If you're experiencing an error, please provide a minimal reproducible example to help us resolve it quickly. πŸ™ Thank you @kosukeoya for helping us improve Mastra!
_roamin_
_roamin_β€’4w ago
Hey @kosukeoya ! What copilotkit call the resourceId it's actually the agentId, e.g. weatherAgent. To pass a mastra resourceId and threadId you can use the runtimeContext like this:
registerCopilotKit<WeatherRuntimeContext>({
path: "/copilotkit",
resourceId: "weatherAgent",
setContext: (c, runtimeContext) => {
runtimeContext.set(
"resourceId",
"...",
);
runtimeContext.set("threadId", "...");
},
}),
registerCopilotKit<WeatherRuntimeContext>({
path: "/copilotkit",
resourceId: "weatherAgent",
setContext: (c, runtimeContext) => {
runtimeContext.set(
"resourceId",
"...",
);
runtimeContext.set("threadId", "...");
},
}),
kosukeoya
kosukeoyaOPβ€’4w ago
Thanks @Romain . I understand that runtimeContext can be passed, but when passing agent.stream in the copilotkit handler, are threadId and resourceId already referenced from runtimeContext? https://github.com/ag-ui-protocol/ag-ui/blob/35e409b0390e8eb8eff233098caf58ea6811a7d7/integrations/mastra/typescript/src/mastra.ts#L280
GitHub
ag-ui/integrations/mastra/typescript/src/mastra.ts at 35e409b0390e8...
AG-UI: the Agent-User Interaction Protocol. Bring Agents into Frontend Applications. - ag-ui-protocol/ag-ui
_roamin_
_roamin_β€’4w ago
Oh yeah, that seems wrong. Could you open a GH issue on the ag-ui repo?
kosukeoya
kosukeoyaOPβ€’4w ago
GitHub
Rewrite the stream option in registerCopilotKit by Mastra according...
Current Situation The threadId is passed from RunAgentInput, and the resourceId becomes either a fixed agent ID or the threadId passed from RunAgentInput. In my use case, I want to include informat...
_roamin_
_roamin_β€’3w ago
Thanks @kosukeoya for creating the issue on the ag-ui repo, I see it was closed as duplicate in favor of https://github.com/ag-ui-protocol/ag-ui/issues/307 I linked it to our issue πŸ˜‰
GitHub
Mastra Integration: Enable passing agent stream options when using ...
I would like to be able to pass AgentStreamOptions when calling agent.stream. This is primarily for passing along telemetry metadata, such as a userid, but could be useful for other cases as well. ...

Did you find this page helpful?