Skip to content

Commit 9aca686

Browse files
authored
Merge pull request #26 from knocklabs/add-mastra
feat: add mastra support
2 parents c40e2a4 + 7f59e92 commit 9aca686

File tree

8 files changed

+5507
-1235
lines changed

8 files changed

+5507
-1235
lines changed

.changeset/floppy-weeks-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@knocklabs/agent-toolkit": patch
3+
---
4+
5+
Adds support for Mastra agent framework

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [AI SDK](#ai-sdk)
1313
- [OpenAI](#openai)
1414
- [Langchain](#langchain)
15+
- [Mastra](#mastra)
1516

1617
## Getting started
1718

@@ -227,3 +228,44 @@ export async function POST(req: Request) {
227228
return LangChainAdapter.toDataStreamResponse(stream);
228229
}
229230
```
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

Comments
 (0)