Skip to content

Commit f685c66

Browse files
authored
Added Mastra + Trigger example (#2278)
* Added mastra agent docs * Added links in the ai agents section * Caught typos all thanks to coderabbit. Thanks coderabbit
1 parent 1dbcf66 commit f685c66

File tree

4 files changed

+173
-6
lines changed

4 files changed

+173
-6
lines changed

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@
333333
"guides/example-projects/batch-llm-evaluator",
334334
"guides/example-projects/claude-thinking-chatbot",
335335
"guides/example-projects/human-in-the-loop-workflow",
336+
"guides/example-projects/mastra-agents-with-memory",
336337
"guides/example-projects/meme-generator-human-in-the-loop",
337338
"guides/example-projects/openai-agent-sdk-guardrails",
338339
"guides/example-projects/openai-agents-sdk-typescript-playground",

docs/guides/ai-agents/overview.mdx

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,80 @@ description: "Real world AI agent example tasks using Trigger.dev"
66

77
## Overview
88

9-
This guide will show you how to set up different types of AI agent workflows with Trigger.dev. The examples take inspiration from Athropic's blog post on [building effective agents](https://www.anthropic.com/research/building-effective-agents).
9+
These guides will show you how to set up different types of AI agent workflows with Trigger.dev. The examples take inspiration from Anthropic's blog post on [building effective agents](https://www.anthropic.com/research/building-effective-agents).
1010

1111
<CardGroup cols={2}>
12-
<Card title="Prompt chaining" img="/guides/ai-agents/prompt-chaining.png" href="/guides/ai-agents/generate-translate-copy">Chain prompts together to generate and translate marketing copy automatically</Card>
13-
<Card title="Routing" img="/guides/ai-agents/routing.png" href="/guides/ai-agents/route-question">Send questions to different AI models based on complexity analysis</Card>
14-
<Card title="Parallelization" img="/guides/ai-agents/parallelization.png" href="/guides/ai-agents/respond-and-check-content">Simultaneously check for inappropriate content while responding to customer inquiries</Card>
15-
<Card title="Orchestrator" img="/guides/ai-agents/orchestrator-workers.png" href="/guides/ai-agents/verify-news-article">Coordinate multiple AI workers to verify news article accuracy</Card>
16-
<Card title="Evaluator-optimizer" img="/guides/ai-agents/evaluator-optimizer.png" href="/guides/ai-agents/translate-and-refine">Translate text and automatically improve quality through feedback loops</Card>
12+
<Card
13+
title="Prompt chaining"
14+
img="/guides/ai-agents/prompt-chaining.png"
15+
href="/guides/ai-agents/generate-translate-copy"
16+
>
17+
Chain prompts together to generate and translate marketing copy automatically
18+
</Card>
19+
<Card title="Routing" img="/guides/ai-agents/routing.png" href="/guides/ai-agents/route-question">
20+
Send questions to different AI models based on complexity analysis
21+
</Card>
22+
<Card
23+
title="Parallelization"
24+
img="/guides/ai-agents/parallelization.png"
25+
href="/guides/ai-agents/respond-and-check-content"
26+
>
27+
Simultaneously check for inappropriate content while responding to customer inquiries
28+
</Card>
29+
<Card
30+
title="Orchestrator"
31+
img="/guides/ai-agents/orchestrator-workers.png"
32+
href="/guides/ai-agents/verify-news-article"
33+
>
34+
Coordinate multiple AI workers to verify news article accuracy
35+
</Card>
36+
<Card
37+
title="Evaluator-optimizer"
38+
img="/guides/ai-agents/evaluator-optimizer.png"
39+
href="/guides/ai-agents/translate-and-refine"
40+
>
41+
Translate text and automatically improve quality through feedback loops
42+
</Card>
43+
</CardGroup>
44+
45+
## Example projects using AI agents
46+
47+
<CardGroup cols={2}>
48+
<Card
49+
icon="hand"
50+
title="Human-in-the-loop workflow"
51+
href="/guides/example-projects/human-in-the-loop-workflow"
52+
>
53+
Create audio summaries of newspaper articles using a human-in-the-loop workflow built with
54+
ReactFlow and Trigger.dev waitpoint tokens.
55+
</Card>
56+
<Card
57+
title="Mastra agents with memory"
58+
icon="database"
59+
href="/guides/example-projects/mastra-agents-with-memory"
60+
>
61+
Use Mastra to create a weather agent that can collect live weather data and generate clothing
62+
recommendations.
63+
</Card>
64+
<Card
65+
title="OpenAI Agent Python SDK guardrails"
66+
icon="snake"
67+
href="/guides/example-projects/openai-agent-sdk-guardrails"
68+
>
69+
Use the OpenAI Agent SDK to create a guardrails system for your AI agents.
70+
</Card>
71+
<Card
72+
title="OpenAI Agent TypeScript SDK playground"
73+
icon="rocket"
74+
href="/guides/example-projects/openai-agents-sdk-typescript-playground"
75+
>
76+
A playground containing 7 AI agents using the OpenAI Agent SDK for TypeScript with Trigger.dev.
77+
</Card>
78+
<Card
79+
title="Vercel AI SDK deep research agent"
80+
icon="triangle"
81+
href="/guides/example-projects/vercel-ai-sdk-deep-research"
82+
>
83+
Use the Vercel AI SDK to generate comprehensive PDF reports using a deep research agent.
84+
</Card>
1785
</CardGroup>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: "Mastra agents with memory sharing + Trigger.dev task orchestration"
3+
sidebarTitle: "Mastra agents with memory"
4+
description: "Multi-agent workflow with persistent memory sharing using Mastra and Trigger.dev for clothing recommendations based on weather data."
5+
tag: "v4"
6+
---
7+
8+
import UpgradeToV4Note from "/snippets/upgrade-to-v4-note.mdx";
9+
10+
<UpgradeToV4Note />
11+
12+
## Overview
13+
14+
Enter a city and an activity, and get a clothing recommendation generated for you based on today's weather.
15+
16+
![Generated clothing recommendations](https://github.com/user-attachments/assets/edfca304-6b22-4fa8-9362-71ecb3fe4903)
17+
18+
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.
19+
20+
## Tech stack
21+
22+
- **[Node.js](https://nodejs.org)** runtime environment
23+
- **[Mastra](https://mastra.ai)** for AI agent orchestration and memory management (Mastra is a Typescript framework for building AI agents, and uses Vercel's AI Agent SDK under the hood.)
24+
- **[PostgreSQL](https://postgresql.org)** for persistent storage and memory sharing
25+
- **[Trigger.dev](https://trigger.dev)** for task orchestration, batching, and observability
26+
- **[OpenAI GPT-4](https://openai.com)** for natural language processing
27+
- **[Open-Meteo API](https://open-meteo.com)** for weather data (no API key required)
28+
- **[Zod](https://zod.dev)** for schema validation and type safety
29+
30+
## GitHub repo
31+
32+
<Card
33+
title="View the Mastra agents with memory repo"
34+
icon="GitHub"
35+
href="https://github.com/triggerdotdev/examples/tree/main/mastra-agents"
36+
>
37+
Click here to view the full code for this project in our examples repository on GitHub. You can
38+
fork it and use it as a starting point for your own project.
39+
</Card>
40+
41+
## Featured patterns
42+
43+
- **[Agent Memory Sharing](https://github.com/triggerdotdev/examples/blob/main/mastra-agents/src/trigger/weather-task.ts)**: Efficient data sharing between agents using Mastra's working memory system
44+
- **[Task Orchestration](https://github.com/triggerdotdev/examples/blob/main/mastra-agents/src/trigger/weather-task.ts)**: Multi-step workflows with `triggerAndWait` for sequential agent execution
45+
- **[Centralized Storage](https://github.com/triggerdotdev/examples/blob/main/mastra-agents/src/mastra/index.ts)**: Single PostgreSQL storage instance shared across all agents to prevent connection duplication
46+
- **[Custom Tools](https://github.com/triggerdotdev/examples/blob/main/mastra-agents/src/mastra/tools/weather-tool.ts)**: External API integration with structured output validation
47+
- **[Agent Specialization](https://github.com/triggerdotdev/examples/blob/main/mastra-agents/src/mastra/agents/)**: Purpose-built agents with specific roles and instructions
48+
- **[Schema Optimization](https://github.com/triggerdotdev/examples/blob/main/mastra-agents/src/mastra/schemas/weather-data.ts)**: Lightweight data structures for performance
49+
50+
## Project Structure
51+
52+
```
53+
src/
54+
├── mastra/
55+
│ ├── agents/
56+
│ │ ├── weather-analyst.ts # Weather data collection
57+
│ │ ├── clothing-advisor.ts # Clothing recommendations
58+
│ ├── tools/
59+
│ │ └── weather-tool.ts # Enhanced weather API tool
60+
│ ├── schemas/
61+
│ │ └── weather-data.ts # Weather schema
62+
│ └── index.ts # Mastra configuration
63+
├── trigger/
64+
│ └── weather-task.ts # Trigger.dev tasks
65+
```
66+
67+
## Relevant code
68+
69+
- **[Multi-step task orchestration](https://github.com/triggerdotdev/examples/blob/main/mastra-agents/src/trigger/weather-task.ts)**: Multi-step task orchestration with `triggerAndWait` for sequential agent execution and shared memory context
70+
- **[Weather analyst agent](https://github.com/triggerdotdev/examples/blob/main/mastra-agents/src/mastra/agents/weather-analyst.ts)**: Specialized agent for weather data collection with external API integration and memory storage
71+
- **[Clothing advisor agent](https://github.com/triggerdotdev/examples/blob/main/mastra-agents/src/mastra/agents/clothing-advisor.ts)**: Purpose-built agent that reads from working memory and generates natural language responses
72+
- **[Weather tool](https://github.com/triggerdotdev/examples/blob/main/mastra-agents/src/mastra/tools/weather-tool.ts)**: Custom Mastra tool with Zod validation for external API calls and error handling
73+
- **[Weather data schema](https://github.com/triggerdotdev/examples/blob/main/mastra-agents/src/mastra/schemas/weather-data.ts)**: Optimized Zod schema for efficient memory storage and type safety
74+
- **[Mastra configuration](https://github.com/triggerdotdev/examples/blob/main/mastra-agents/src/mastra/index.ts)**: Mastra configuration with PostgreSQL storage and agent registration
75+
76+
## Storage Architecture
77+
78+
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.
79+
80+
### Storage Configuration
81+
82+
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.
83+
84+
The PostgreSQL storage works seamlessly in both local development and serverless environments with any PostgreSQL provider, such as:
85+
86+
- [Local PostgreSQL instance](https://postgresql.org)
87+
- [Supabase](https://supabase.com) - Serverless PostgreSQL
88+
- [Neon](https://neon.tech) - Serverless PostgreSQL
89+
- [Railway](https://railway.app) - Simple PostgreSQL hosting
90+
- [AWS RDS](https://aws.amazon.com/rds/postgresql/) - Managed PostgreSQL
91+
92+
## Learn More
93+
94+
To learn more about the technologies used in this project, check out the following resources:
95+
96+
- [Mastra docs](https://mastra.ai/en/docs) - learn about AI agent orchestration and memory management
97+
- [Mastra working memory](https://mastra.ai/en/docs/memory/overview) - learn about efficient data sharing between agents

docs/guides/introduction.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Example projects are full projects with example repos you can fork and use. Thes
4848
| [Batch LLM Evaluator](/guides/example-projects/batch-llm-evaluator) | Evaluate multiple LLM models and stream the results to the frontend. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/batch-llm-evaluator) |
4949
| [Claude thinking chatbot](/guides/example-projects/claude-thinking-chatbot) | Use Vercel's AI SDK and Anthropic's Claude 3.7 model to create a thinking chatbot. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/claude-thinking-chatbot) |
5050
| [Human-in-the-loop workflow](/guides/example-projects/human-in-the-loop-workflow) | Create audio summaries of newspaper articles using a human-in-the-loop workflow built with ReactFlow and Trigger.dev waitpoint tokens. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/article-summary-workflow) |
51+
| [Mastra agents with memory](/guides/example-projects/mastra-agents-with-memory) | Use Mastra to create a weather agent that can collect live weather data and generate clothing recommendations. || [View the repo](https://github.com/triggerdotdev/examples/tree/main/mastra-agents) |
5152
| [OpenAI Agents SDK for Python guardrails](/guides/example-projects/openai-agent-sdk-guardrails) | Use the OpenAI Agents SDK for Python to create a guardrails system for your AI agents. || [View the repo](https://github.com/triggerdotdev/examples/tree/main/openai-agent-sdk-guardrails-examples) |
5253
| [OpenAI Agents SDK for TypeScript playground](/guides/example-projects/openai-agents-sdk-typescript-playground) | A playground containing 7 AI agents using the OpenAI Agents SDK for TypeScript with Trigger.dev. || [View the repo](https://github.com/triggerdotdev/examples/tree/main/openai-agents-sdk-with-trigger-playground) |
5354
| [Python web crawler](/guides/python/python-crawl4ai) | Use Python, Crawl4AI and Playwright to create a headless web crawler with Trigger.dev. || [View the repo](https://github.com/triggerdotdev/examples/tree/main/python-crawl4ai) |

0 commit comments

Comments
 (0)