Skip to content

Commit 058b8b3

Browse files
committed
add mastra tool based gen ui
1 parent 6e152d6 commit 058b8b3

File tree

8 files changed

+93
-48
lines changed

8 files changed

+93
-48
lines changed

typescript-sdk/apps/dojo/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
"@ag-ui/server-starter-all-features": "workspace:*",
2121
"@ag-ui/vercel-ai-sdk": "workspace:*",
2222
"@ai-sdk/openai": "^1.3.22",
23-
"@copilotkit/react-core": "0.0.0-mme-fix-remote-results-20250717113906",
24-
"@copilotkit/react-ui": "0.0.0-mme-fix-remote-results-20250717113906",
25-
"@copilotkit/runtime": "0.0.0-mme-fix-remote-results-20250717113906",
26-
"@copilotkit/runtime-client-gql": "0.0.0-mme-fix-remote-results-20250717113906",
27-
"@copilotkit/shared": "0.0.0-mme-fix-remote-results-20250717113906",
23+
"@copilotkit/react-core": "0.0.0-mme-fix-remote-results-20250717143107",
24+
"@copilotkit/react-ui": "0.0.0-mme-fix-remote-results-20250717143107",
25+
"@copilotkit/runtime": "0.0.0-mme-fix-remote-results-20250717143107",
26+
"@copilotkit/runtime-client-gql": "0.0.0-mme-fix-remote-results-20250717143107",
27+
"@copilotkit/shared": "0.0.0-mme-fix-remote-results-20250717143107",
2828
"@mastra/client-js": "^0.10.9",
2929
"@mastra/core": "^0.10.10",
3030
"@mastra/libsql": "^0.11.0",

typescript-sdk/apps/dojo/src/app/[integrationId]/feature/tool_based_generative_ui/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function Haiku() {
4848

4949
useCopilotAction({
5050
name: "generate_haiku",
51-
available: "remote",
51+
available: "frontend",
5252
parameters: [
5353
{
5454
name: "japanese",

typescript-sdk/apps/dojo/src/mastra/index.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Agent } from "@mastra/core/agent";
33
import { Memory } from "@mastra/memory";
44
import { LibSQLStore } from "@mastra/libsql";
55
import { Mastra } from "@mastra/core";
6+
import { createTool } from "@mastra/core";
67
import { z } from "zod";
78

89
// import { weatherTool } from "../tools/weather-tool";
@@ -112,14 +113,23 @@ export const mastra = new Mastra({
112113
`,
113114
model: openai("gpt-4o"),
114115
tools: {
115-
generate_haiku: {
116-
description: "Generate a haiku",
117-
parameters: z.object({
118-
japanese: z.string().describe("The japanese haiku"),
119-
english: z.string().describe("The english haiku"),
120-
image_names: z.array(z.string()).describe("The names of the images"),
116+
generate_haiku: createTool({
117+
id: "generate_haiku",
118+
description:
119+
"Generate a haiku in Japanese and its English translation. Also select exactly 3 relevant images from the provided list based on the haiku's theme.",
120+
inputSchema: z.object({
121+
japanese: z
122+
.array(z.string())
123+
.describe("An array of three lines of the haiku in Japanese"),
124+
english: z
125+
.array(z.string())
126+
.describe("An array of three lines of the haiku in English"),
121127
}),
122-
},
128+
outputSchema: z.string(),
129+
execute: async ({ context }) => {
130+
return "Haiku generated.";
131+
},
132+
}),
123133
},
124134
}),
125135
},

typescript-sdk/apps/dojo/src/menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const menuIntegrations: MenuIntegrationConfig[] = [
2626
{
2727
id: "mastra",
2828
name: "Mastra",
29-
features: ["agentic_chat"],
29+
features: ["agentic_chat", "tool_based_generative_ui"],
3030
},
3131
{
3232
id: "mastra-agent-local",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { openai } from "@ai-sdk/openai";
2+
import { Agent } from "@mastra/core/agent";
3+
import { Memory } from "@mastra/memory";
4+
import { LibSQLStore } from "@mastra/libsql";
5+
import { createTool } from "@mastra/core";
6+
import z from "zod";
7+
8+
export const toolBasedGenerativeUIAgent = new Agent({
9+
name: "Haiku Agent",
10+
instructions: `
11+
You are a helpful haiku assistant that provides the user with a haiku.
12+
`,
13+
model: openai("gpt-4o-mini"),
14+
tools: {
15+
generate_haiku: createTool({
16+
id: "generate_haiku",
17+
description:
18+
"Generate a haiku in Japanese and its English translation. Also select exactly 3 relevant images from the provided list based on the haiku's theme.",
19+
inputSchema: z.object({
20+
japanese: z.array(z.string()).describe("An array of three lines of the haiku in Japanese"),
21+
english: z.array(z.string()).describe("An array of three lines of the haiku in English"),
22+
}),
23+
outputSchema: z.string(),
24+
execute: async ({ context }) => {
25+
return "Haiku generated.";
26+
},
27+
}),
28+
},
29+
memory: new Memory({
30+
storage: new LibSQLStore({
31+
url: "file:../mastra.db", // path is relative to the .mastra/output directory
32+
}),
33+
}),
34+
});

typescript-sdk/integrations/mastra/example/src/mastra/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { Mastra } from "@mastra/core/mastra";
22
import { PinoLogger } from "@mastra/loggers";
33
import { LibSQLStore } from "@mastra/libsql";
44

5-
import { agenticChatAgent } from "./agents/weather-agent";
5+
import { agenticChatAgent } from "./agents/agentic-chat";
6+
import { toolBasedGenerativeUIAgent } from "./agents/tool-based-generative-ui";
67

78
export const mastra = new Mastra({
8-
agents: { agentic_chat: agenticChatAgent },
9+
agents: { agentic_chat: agenticChatAgent, tool_based_generative_ui: toolBasedGenerativeUIAgent },
910
storage: new LibSQLStore({
1011
// stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
1112
url: ":memory:",

typescript-sdk/pnpm-lock.yaml

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)