You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: mastra-agents/README.md
+29-20Lines changed: 29 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,16 @@
1
1
# Mastra agents + Trigger.dev task orchestration example project:
2
2
3
-
> **ℹ️ Note:** This is a v4 project. If you are using v3 and want to upgrade, please refer to our [v4 upgrade guide](https://trigger.dev/docs/v4-upgrade-guide).
3
+
> **ℹ️ Note:** This is a Trigger.dev v4 project. If you are using v3 and want to upgrade, please refer to our [v4 upgrade guide](https://trigger.dev/docs/v4-upgrade-guide).
4
4
5
-
Enter a city and activity, and get a clothing recommendation generated based on the weather.
5
+
Enter a city and a activity, and get a clothing recommendation generated for you based on today's weather.
6
6
7
7
By combining Mastra's persistent memory system and agent orchestration with Trigger.dev's durable task execution, retries and observability, you get production-ready AI workflows that survive failures, scale automatically, and maintain context across long-running operations.
-[Mastra](https://mastra.ai) for AI agent orchestration and memory management
13
+
-[PostgreSQL](https://postgresql.org) for persistent storage and memory sharing
13
14
-[Trigger.dev](https://trigger.dev) for task orchestration, batching, and observability
14
15
-[OpenAI GPT-4](https://openai.com) for natural language processing
15
16
-[Open-Meteo API](https://open-meteo.com) for weather data (no API key required)
@@ -19,11 +20,12 @@ By combining Mastra's persistent memory system and agent orchestration with Trig
19
20
20
21
-**[Agent Memory Sharing](src/trigger/weather-task.ts)**: Efficient data sharing between agents using Mastra's working memory system
21
22
-**[Task Orchestration](src/trigger/weather-task.ts)**: Multi-step workflows with `triggerAndWait` for sequential agent execution
23
+
-**[Centralized Storage](src/mastra/index.ts)**: Single PostgreSQL storage instance shared across all agents to prevent connection duplication
22
24
-**[Custom Tools](src/mastra/tools/weather-tool.ts)**: External API integration with structured output validation
23
25
-**[Agent Specialization](src/mastra/agents/)**: Purpose-built agents with specific roles and instructions
24
26
-**[Schema Optimization](src/mastra/schemas/weather-data.ts)**: Lightweight data structures for performance
25
27
26
-
## 📁 Project Structure
28
+
## Project Structure
27
29
28
30
```
29
31
src/
@@ -48,38 +50,45 @@ src/
48
50
-[src/mastra/agents/clothing-advisor.ts](src/mastra/agents/clothing-advisor.ts) - Purpose-built agent that reads from working memory and generates natural language responses
49
51
-[src/mastra/tools/weather-tool.ts](src/mastra/tools/weather-tool.ts) - Custom Mastra tool with Zod validation for external API calls and error handling
50
52
-[src/mastra/schemas/weather-data.ts](src/mastra/schemas/weather-data.ts) - Optimized Zod schema for efficient memory storage and type safety
51
-
-[src/mastra/index.ts](src/mastra/index.ts) - Mastra configuration with LibSQL storage and agent registration
53
+
-[src/mastra/index.ts](src/mastra/index.ts) - Mastra configuration with PostgreSQL storage and agent registration
52
54
53
-
## Getting started
55
+
## Storage Architecture
56
+
57
+
This project uses a **centralized PostgreSQL storage** approach where a single database connection is shared across all Mastra agents. This prevents duplicate database connections and ensures efficient memory sharing between the weather analyst and clothing advisor agents.
58
+
59
+
### Storage Configuration
60
+
61
+
The storage is configured once in the main Mastra instance (`src/mastra/index.ts`) and automatically inherited by all agent Memory instances. This eliminates the "duplicate database object" warning that can occur with multiple PostgreSQL connections.
62
+
63
+
The PostgreSQL storage works seamlessly in both local development and serverless environments with any PostgreSQL provider, such as:
1. After cloning the repo, run `npm install` to install the dependencies.
56
74
2. Set up your environment variables (see `.env.example`)
57
75
3. If you haven't already, sign up for a free Trigger.dev account [here](https://cloud.trigger.dev/login) and create a new project.
58
76
4. Copy the project ref from the Trigger.dev dashboard and add it to the `trigger.config.ts` file.
59
-
5. In your terminal, run the Trigger.dev dev CLI command with `npx trigger.dev@latest dev`.
77
+
5. In your terminal, run the Trigger.dev dev CLI command with `npx trigger.dev@v4-beta dev`.
60
78
61
79
Now you should be able to visit your Trigger.dev dashboard and test any of the agent tasks with the example payloads provided in each task file.
62
80
63
-
## Testing locally
64
-
65
-
Use the Trigger.dev dashboard to test each task:
81
+
## Testing
66
82
67
83
### Example payload
68
84
69
85
```json
70
-
{ "city": "New York", "activity": "walking" }
86
+
{
87
+
"city": "New York",
88
+
"activity": "walking"
89
+
}
71
90
```
72
91
73
-
## Deployment
74
-
75
-
This project uses LibSQL as a local database for development, but **LibSQL doesn't work in serverless environments**. For production deployment, you'll need to switch to a serverless-compatible storage option:
76
-
77
-
-**Turso** (LibSQL-compatible): Set `TURSO_DATABASE_URL` and `TURSO_AUTH_TOKEN` in your environment variables. Create an account and database [here](https://turso.tech/signup).
78
-
-**PostgreSQL** (Supabase): Set `DATABASE_URL` in your environment variables. Create an account and database [here](https://supabase.com/dashboard/sign-in).
79
-
-**No persistence**: Remove storage from mastra config entirely.
80
-
81
-
Update `src/mastra/index.ts` with your chosen storage provider before deploying.
82
-
83
92
## Learn More
84
93
85
94
To learn more about the technologies used in this project, check out the following resources:
0 commit comments