[Mastra] example toolkit project updated (#561)
## Summary Updated the Mastra example project to include leveraging multiple toolkits into one Mastra agent. Additionally, the `package.json` versions were pinned to the latest versions to avoid potential issues with breaking changes as Mastra progresses through v0.x.x packages. Also, by pinning the version, it demonstrates the latest confirmed arcade-js compatibility version. These changes were initiated when trying to debug an [issue](https://github.com/ArcadeAI/arcade-ai/issues/560) using Arcade toolkits with Mastra agents. Notably, I confirmed that there is no flaw in arcade-js, which was suspected in the issue, by successfully using the toolkits with the latest Mastra packages. ## Changes * inboxTravelAgent created showcasing `GoogleFlights`, `GoogleHotels`, and `Gmail` Arcade toolkits together * package.json versions pinned to the latest working versions. ## Testing Ran the Mastra project locally and invoked the tools via the agent chat interface.
This commit is contained in:
parent
766a262a25
commit
c7c485152f
8 changed files with 1769 additions and 3718 deletions
|
|
@ -15,14 +15,14 @@
|
|||
"dependencies": {
|
||||
"@ai-sdk/openai": "^1.3.22",
|
||||
"@arcadeai/arcadejs": "^1.8.1",
|
||||
"@mastra/core": "latest",
|
||||
"@mastra/libsql": "latest",
|
||||
"@mastra/memory": "latest",
|
||||
"@mastra/core": "0.16.3",
|
||||
"@mastra/libsql": "0.14.1",
|
||||
"@mastra/memory": "0.15.1",
|
||||
"zod": "^3.24.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.0.10",
|
||||
"mastra": "0.10.9",
|
||||
"mastra": "0.12.3",
|
||||
"typescript": "^5.8.3"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,64 +1,29 @@
|
|||
import { openai } from "@ai-sdk/openai";
|
||||
import { Arcade } from "@arcadeai/arcadejs";
|
||||
import {
|
||||
executeOrAuthorizeZodTool,
|
||||
toZodToolSet,
|
||||
} from "@arcadeai/arcadejs/lib";
|
||||
import { Agent } from "@mastra/core/agent";
|
||||
import { Memory } from "@mastra/memory";
|
||||
import { LibSQLStore } from "@mastra/libsql";
|
||||
|
||||
// Initialize Arcade
|
||||
const arcade = new Arcade();
|
||||
|
||||
// Get Gmail tools
|
||||
const gmailToolkit = await arcade.tools.list({ toolkit: "gmail", limit: 30 });
|
||||
|
||||
/**
|
||||
* Mastra requires tools to be defined using Zod, a TypeScript-first schema validation library
|
||||
* that has become the standard for runtime type checking. Zod is particularly valuable because it:
|
||||
* - Provides runtime type safety and validation
|
||||
* - Offers excellent TypeScript integration with automatic type inference
|
||||
* - Has a simple, declarative API for defining schemas
|
||||
* - Is widely adopted in the TypeScript ecosystem
|
||||
*
|
||||
* Arcade provides `toZodToolSet` to convert our tools into Zod format, making them compatible
|
||||
* with Mastra.
|
||||
*
|
||||
* The `executeOrAuthorizeZodTool` helper function simplifies authorization.
|
||||
* It checks if the tool requires authorization: if so, it returns an authorization URL,
|
||||
* otherwise, it runs the tool directly without extra boilerplate.
|
||||
*
|
||||
* Learn more: https://docs.arcade.dev/home/use-tools/get-tool-definitions#get-zod-tool-definitions
|
||||
*/
|
||||
export const gmailTools = toZodToolSet({
|
||||
tools: gmailToolkit.items,
|
||||
client: arcade,
|
||||
userId: "<YOUR_USER_ID>", // Your app's internal ID for the user (an email, UUID, etc). It's used internally to identify your user in Arcade
|
||||
executeFactory: executeOrAuthorizeZodTool, // Checks if tool is authorized and executes it, or returns authorization URL if needed
|
||||
});
|
||||
import { openai } from "@ai-sdk/openai"
|
||||
import { Agent } from "@mastra/core/agent"
|
||||
import { Memory } from "@mastra/memory"
|
||||
import { LibSQLStore } from "@mastra/libsql"
|
||||
import { gmailTools } from "../tools/gmailTools"
|
||||
|
||||
// Initialize memory
|
||||
const memory = new Memory({
|
||||
storage: new LibSQLStore({
|
||||
url: "file:../../memory.db",
|
||||
}),
|
||||
});
|
||||
storage: new LibSQLStore({
|
||||
url: "file:../../memory.db",
|
||||
}),
|
||||
})
|
||||
|
||||
// Create an agent with Gmail tools
|
||||
export const gmailAgent = new Agent({
|
||||
name: "gmailAgent",
|
||||
instructions: `You are a Gmail assistant that helps users manage their Gmail services.
|
||||
name: "gmailAgent",
|
||||
instructions: `You are a Gmail assistant that helps users manage their inbox.
|
||||
|
||||
When helping users:
|
||||
- Always verify their intent before performing actions
|
||||
- Keep responses clear and concise
|
||||
- Confirm important actions before executing them
|
||||
- Respect user privacy and data security
|
||||
- Specify which Google service you're working with
|
||||
|
||||
Use the gmailTools to interact with various Gmail services and perform related tasks.`,
|
||||
model: openai("gpt-4o-mini"),
|
||||
memory,
|
||||
tools: gmailTools,
|
||||
});
|
||||
model: openai("gpt-4o-mini"),
|
||||
memory,
|
||||
tools: gmailTools,
|
||||
})
|
||||
|
|
|
|||
33
examples/mastra/src/mastra/agents/inboxTravelSearch.ts
Normal file
33
examples/mastra/src/mastra/agents/inboxTravelSearch.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { openai } from "@ai-sdk/openai"
|
||||
import { Agent } from "@mastra/core/agent"
|
||||
import { Memory } from "@mastra/memory"
|
||||
import { LibSQLStore } from "@mastra/libsql"
|
||||
import { gmailTools } from "../tools/gmailTools"
|
||||
import { flightTools } from "../tools/flightSearchTools"
|
||||
import { hotelTools } from "../tools/hotelSearchTools"
|
||||
|
||||
// Initialize memory
|
||||
const memory = new Memory({
|
||||
storage: new LibSQLStore({
|
||||
url: "file:../../memory.db",
|
||||
}),
|
||||
})
|
||||
|
||||
// Create an agent with Gmail, FlightSearch, and HotelSearch tools
|
||||
export const inboxTravelSearchAgent = new Agent({
|
||||
name: "inboxTravelSearchAgent",
|
||||
instructions: `You are an assistant that helps users manage their Gmail inbox and can help with travel related tasks and planning.
|
||||
|
||||
When helping users:
|
||||
- Always verify their intent before performing actions
|
||||
- Keep responses clear and concise
|
||||
- Confirm important actions before executing them
|
||||
- Respect user privacy and data security
|
||||
|
||||
Use the gmailTools to interact with various Gmail services and perform related tasks.
|
||||
Use the flightTools to interact with various flight services and perform related tasks.
|
||||
Use the hotelTools to interact with various hotel services and perform related tasks.`,
|
||||
model: openai("gpt-4o-mini"),
|
||||
memory,
|
||||
tools: { ...gmailTools, ...flightTools, ...hotelTools },
|
||||
})
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
import { Mastra } from "@mastra/core";
|
||||
import { LibSQLStore } from "@mastra/libsql";
|
||||
import { gmailAgent } from "./agents/gmail";
|
||||
import { Mastra } from "@mastra/core"
|
||||
import { LibSQLStore } from "@mastra/libsql"
|
||||
import { inboxTravelSearchAgent } from "./agents/inboxTravelSearch"
|
||||
import { gmailAgent } from "./agents/gmail"
|
||||
|
||||
export const mastra = new Mastra({
|
||||
agents: { gmailAgent },
|
||||
storage: new LibSQLStore({
|
||||
url: "file:../mastra.db",
|
||||
}),
|
||||
});
|
||||
agents: { gmailAgent, inboxTravelSearchAgent },
|
||||
storage: new LibSQLStore({
|
||||
url: "file:../mastra.db",
|
||||
}),
|
||||
})
|
||||
|
|
|
|||
33
examples/mastra/src/mastra/tools/flightSearchTools.ts
Normal file
33
examples/mastra/src/mastra/tools/flightSearchTools.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { Arcade } from "@arcadeai/arcadejs"
|
||||
import { executeOrAuthorizeZodTool, toZodToolSet } from "@arcadeai/arcadejs/lib"
|
||||
|
||||
// Initialize Arcade
|
||||
const arcade = new Arcade()
|
||||
|
||||
// Get Arcade GoogleFlights Toolkit
|
||||
// Toolkit names can be found in the Arcade dashboard via Tools > view > Toolkit or via the CLI `arcade workers list`
|
||||
const flightToolkit = await arcade.tools.list({ toolkit: "GoogleFlights", limit: 30 })
|
||||
|
||||
/**
|
||||
* Mastra requires tools to be defined using Zod, a TypeScript-first schema validation library
|
||||
* that has become the standard for runtime type checking. Zod is particularly valuable because it:
|
||||
* - Provides runtime type safety and validation
|
||||
* - Offers excellent TypeScript integration with automatic type inference
|
||||
* - Has a simple, declarative API for defining schemas
|
||||
* - Is widely adopted in the TypeScript ecosystem
|
||||
*
|
||||
* Arcade provides `toZodToolSet` to convert our tools into Zod format, making them compatible
|
||||
* with Mastra.
|
||||
*
|
||||
* The `executeOrAuthorizeZodTool` helper function simplifies authorization.
|
||||
* It checks if the tool requires authorization: if so, it returns an authorization URL,
|
||||
* otherwise, it runs the tool directly without extra boilerplate.
|
||||
*
|
||||
* Learn more: https://docs.arcade.dev/home/use-tools/get-tool-definitions#get-zod-tool-definitions
|
||||
*/
|
||||
export const flightTools = toZodToolSet({
|
||||
tools: flightToolkit.items,
|
||||
client: arcade,
|
||||
userId: "<YOUR_USER_ID>", // Your app's internal ID for the user (an email, UUID, etc). It's used internally to identify your user in Arcade
|
||||
executeFactory: executeOrAuthorizeZodTool, // Checks if tool is authorized and executes it, or returns authorization URL if needed
|
||||
})
|
||||
33
examples/mastra/src/mastra/tools/gmailTools.ts
Normal file
33
examples/mastra/src/mastra/tools/gmailTools.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { Arcade } from "@arcadeai/arcadejs"
|
||||
import { executeOrAuthorizeZodTool, toZodToolSet } from "@arcadeai/arcadejs/lib"
|
||||
|
||||
// Initialize Arcade
|
||||
const arcade = new Arcade()
|
||||
|
||||
// Get Arcade Gmail Toolkit
|
||||
// Toolkit names can be found in the Arcade dashboard via Tools > view > Toolkit or via the CLI `arcade workers list`
|
||||
const gmailToolkit = await arcade.tools.list({ toolkit: "Gmail", limit: 30 })
|
||||
|
||||
/**
|
||||
* Mastra requires tools to be defined using Zod, a TypeScript-first schema validation library
|
||||
* that has become the standard for runtime type checking. Zod is particularly valuable because it:
|
||||
* - Provides runtime type safety and validation
|
||||
* - Offers excellent TypeScript integration with automatic type inference
|
||||
* - Has a simple, declarative API for defining schemas
|
||||
* - Is widely adopted in the TypeScript ecosystem
|
||||
*
|
||||
* Arcade provides `toZodToolSet` to convert our tools into Zod format, making them compatible
|
||||
* with Mastra.
|
||||
*
|
||||
* The `executeOrAuthorizeZodTool` helper function simplifies authorization.
|
||||
* It checks if the tool requires authorization: if so, it returns an authorization URL,
|
||||
* otherwise, it runs the tool directly without extra boilerplate.
|
||||
*
|
||||
* Learn more: https://docs.arcade.dev/home/use-tools/get-tool-definitions#get-zod-tool-definitions
|
||||
*/
|
||||
export const gmailTools = toZodToolSet({
|
||||
tools: gmailToolkit.items,
|
||||
client: arcade,
|
||||
userId: "<YOUR_USER_ID>", // Your app's internal ID for the user (an email, UUID, etc). It's used internally to identify your user in Arcade
|
||||
executeFactory: executeOrAuthorizeZodTool, // Checks if tool is authorized and executes it, or returns authorization URL if needed
|
||||
})
|
||||
33
examples/mastra/src/mastra/tools/hotelSearchTools.ts
Normal file
33
examples/mastra/src/mastra/tools/hotelSearchTools.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { Arcade } from "@arcadeai/arcadejs"
|
||||
import { executeOrAuthorizeZodTool, toZodToolSet } from "@arcadeai/arcadejs/lib"
|
||||
|
||||
// Initialize Arcade
|
||||
const arcade = new Arcade()
|
||||
|
||||
// Get Arcade GoogleHotels Toolkit
|
||||
// Toolkit names can be found in the Arcade dashboard via Tools > view > Toolkit or via the CLI `arcade workers list`
|
||||
const hotelToolkit = await arcade.tools.list({ toolkit: "GoogleHotels", limit: 30 })
|
||||
|
||||
/**
|
||||
* Mastra requires tools to be defined using Zod, a TypeScript-first schema validation library
|
||||
* that has become the standard for runtime type checking. Zod is particularly valuable because it:
|
||||
* - Provides runtime type safety and validation
|
||||
* - Offers excellent TypeScript integration with automatic type inference
|
||||
* - Has a simple, declarative API for defining schemas
|
||||
* - Is widely adopted in the TypeScript ecosystem
|
||||
*
|
||||
* Arcade provides `toZodToolSet` to convert our tools into Zod format, making them compatible
|
||||
* with Mastra.
|
||||
*
|
||||
* The `executeOrAuthorizeZodTool` helper function simplifies authorization.
|
||||
* It checks if the tool requires authorization: if so, it returns an authorization URL,
|
||||
* otherwise, it runs the tool directly without extra boilerplate.
|
||||
*
|
||||
* Learn more: https://docs.arcade.dev/home/use-tools/get-tool-definitions#get-zod-tool-definitions
|
||||
*/
|
||||
export const hotelTools = toZodToolSet({
|
||||
tools: hotelToolkit.items,
|
||||
client: arcade,
|
||||
userId: "<YOUR_USER_ID>", // Your app's internal ID for the user (an email, UUID, etc). It's used internally to identify your user in Arcade
|
||||
executeFactory: executeOrAuthorizeZodTool, // Checks if tool is authorized and executes it, or returns authorization URL if needed
|
||||
})
|
||||
Loading…
Reference in a new issue