|
12 | 12 | - [AI SDK](#ai-sdk) |
13 | 13 | - [OpenAI](#openai) |
14 | 14 | - [Langchain](#langchain) |
| 15 | + - [Mastra](#mastra) |
15 | 16 |
|
16 | 17 | ## Getting started |
17 | 18 |
|
@@ -227,3 +228,44 @@ export async function POST(req: Request) { |
227 | 228 | return LangChainAdapter.toDataStreamResponse(stream); |
228 | 229 | } |
229 | 230 | ``` |
| 231 | + |
| 232 | +### Mastra |
| 233 | + |
| 234 | +The agent toolkit provides a `createKnockToolkit` under the `/mastra` path for easily integrating into the Mastra framework and returning tools ready for use. |
| 235 | + |
| 236 | +1. Install the package: |
| 237 | + |
| 238 | +``` |
| 239 | +npm install @knocklabs/agent-toolkit |
| 240 | +``` |
| 241 | + |
| 242 | +2. Import the `createKnockToolkit` helper, configure it, and use it in your LLM calling: |
| 243 | + |
| 244 | +```typescript |
| 245 | +import { anthropic } from "@ai-sdk/anthropic"; |
| 246 | +import { Agent } from "@mastra/core/agent"; |
| 247 | +import { Memory } from "@mastra/memory"; |
| 248 | +import { LibSQLStore } from "@mastra/libsql"; |
| 249 | +import { createKnockToolkit } from "@knocklabs/agent-toolkit/mastra"; |
| 250 | + |
| 251 | +const toolkit = await createKnockToolkit({ |
| 252 | + serviceToken: "knock_st_", |
| 253 | + permissions: { |
| 254 | + // (optional but recommended): Set the permissions of the tools to expose |
| 255 | + workflows: { read: true, run: true, manage: true }, |
| 256 | + }, |
| 257 | + userId: "10", |
| 258 | +}); |
| 259 | + |
| 260 | +export const weatherAgent = new Agent({ |
| 261 | + name: "Weather Agent", |
| 262 | + instructions: `You are a helpful weather assistant that provides accurate weather information.`, |
| 263 | + model: anthropic("claude-3-5-sonnet-20241022"), |
| 264 | + tools: toolkit.getAllTools(), |
| 265 | + memory: new Memory({ |
| 266 | + storage: new LibSQLStore({ |
| 267 | + url: "file:../mastra.db", // path is relative to the .mastra/output directory |
| 268 | + }), |
| 269 | + }), |
| 270 | +}); |
| 271 | +``` |
0 commit comments