Skip to content

Commit ec8b1e9

Browse files
authored
feat: integrate Mastra AI framework with Siren agent toolkit (#22)
* feat: integrate Mastra AI framework with Siren agent toolkit * chore: remove debug console log in message sending flow * feat: move @mastra/core to optional peer dependency and add mastra export path
1 parent c5b33be commit ec8b1e9

File tree

12 files changed

+2632
-151
lines changed

12 files changed

+2632
-151
lines changed

typescript/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Refer to our [examples directory](./examples) for detailed integration guides:
4242
| **OpenAI** | [View Example](./examples/openai/) | Complete OpenAI Assistant integration |
4343
| **LangChain** | [View Example](./examples/langchain/) | Agent with LangChain tools |
4444
| **Vercel AI SDK** | [View Example](./examples/ai-sdk/) | Next.js and Vercel AI SDK integration |
45+
| **Mastra** | [View Example](./examples/mastra/) | Mastra integration |
4546

4647
## 📋 Requirements
4748

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
OPENAI_API_KEY=your_openai_api_key_here
2+
SIREN_API_KEY=your_siren_api_key_here

typescript/examples/mastra/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Mastra integration with siren-agent-toolkit
2+
3+
This example shows how to use the siren-agent-toolkit with [Mastra](https://mastra.ai/).
4+
5+
## Setup
6+
7+
Copy the given `.env.template` and fill in the values.
8+
9+
```
10+
cp .env.template .env
11+
```
12+
13+
## Usage
14+
15+
```
16+
npm install
17+
npm start
18+
```

typescript/examples/mastra/index.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { openai } from '@ai-sdk/openai';
2+
import { Agent } from '@mastra/core/agent'
3+
import { SirenAgentToolkit } from '@trysiren/agent-toolkit/mastra';
4+
import 'dotenv/config';
5+
6+
const sirenToolkit = new SirenAgentToolkit({
7+
apiKey: process.env.SIREN_API_KEY!,
8+
configuration: {
9+
actions: {
10+
messaging: {
11+
create: true,
12+
read: true,
13+
},
14+
templates: {
15+
read: true,
16+
create: true,
17+
update: true,
18+
delete: true,
19+
},
20+
users: {
21+
create: true,
22+
update: true,
23+
delete: true,
24+
read: true,
25+
},
26+
workflows: {
27+
trigger: true,
28+
schedule: true,
29+
},
30+
},
31+
},
32+
});
33+
34+
async function main() {
35+
36+
const sirenAgent = new Agent({
37+
name: 'Siren Agent',
38+
instructions: 'You are a helpful assistant that can send notifications and manage templates using Siren.',
39+
model: openai('gpt-4o'),
40+
tools: {
41+
...sirenToolkit.getTools(),
42+
}
43+
})
44+
45+
const result = await sirenAgent.generate([
46+
{
47+
role: 'system',
48+
content: 'You are a helpful assistant that can send notifications and manage templates using Siren',
49+
},
50+
{
51+
role: 'user',
52+
content: 'Send a welcome message to user@example.com via EMAIL saying "Welcome to our platform!". ',
53+
},
54+
], { maxRetries: 0 });
55+
56+
console.log('Result:', result.text);
57+
console.log('Tool calls:', result.toolCalls);
58+
console.log('Tool results:', result.toolResults);
59+
}
60+
61+
main().catch(console.error);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "siren-mastra-example",
3+
"version": "1.0.0",
4+
"description": "Siren Agent Toolkit Mastra example",
5+
"type": "module",
6+
"scripts": {
7+
"start": "tsx index.ts",
8+
"dev": "tsx --watch index.ts"
9+
},
10+
"dependencies": {
11+
"@mastra/core": "^0.10.15",
12+
"@trysiren/agent-toolkit": "^0.1.4",
13+
"dotenv": "^16.4.5",
14+
"ai": "^4.0.0"
15+
},
16+
"devDependencies": {
17+
"tsx": "^4.0.0",
18+
"typescript": "^5.0.0"
19+
}
20+
}

0 commit comments

Comments
 (0)