Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mastra.ai template #349

Merged
merged 4 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/js-langgraph-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ To do this, go to **Actor settings** → **Source** → **Code**, then scroll do

## Monetization

This template uses the [Pay Per Event](https://docs.apify.com/sdk/js/docs/next/guides/pay-per-event) (PPE) monetization model, which provides flexible pricing based on defined events.
This template uses the [Pay Per Event](https://docs.apify.com/platform/actors/publishing/monetize#pay-per-event-pricing-model) (PPE) monetization model, which provides flexible pricing based on defined events.

To charge users, define events in JSON format and save them on the Apify platform. Here is an example of [pay_per_event.json](.actor/pay_per_event.json) with the `task-completed` event:

Expand Down
24 changes: 22 additions & 2 deletions templates/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,12 @@
{
"id": "ts-bee-agent",
"name": "ts-bee-agent",
"label": "🐝 Bee Framework Agent",
"label": "🐝 Bee Framework agent",
"category": "typescript",
"technologies": [
"beeai"
],
"description": "Example of how to use Bee Agent Framework with Apify Actors to create a social media analysis tool-calling agent.",
"description": "Example of how to use Bee Agent Framework with Apify Actors to create a social media analysis agent.",
"archiveUrl": "https://github.com/apify/actor-templates/blob/master/dist/templates/ts-bee-agent.zip?raw=true",
"defaultRunOptions": {
"build": "latest",
Expand All @@ -818,6 +818,26 @@
"src/main.ts"
]
},
{
"id": "ts-mastraai",
"name": "ts-mastraai",
"label": "Mastra agent",
"category": "typescript",
"technologies": [
"mastraai"
],
"description": "Example of how to use Mastra with Apify Actors to create a social media analysis agent.",
"archiveUrl": "https://github.com/apify/actor-templates/blob/master/dist/templates/ts-mastraai.zip?raw=true",
"defaultRunOptions": {
"build": "latest",
"memoryMbytes": 512,
"timeoutSecs": 600
},
"showcaseFiles": [
"src/main.ts",
"src/tools.ts"
]
},
{
"id": "cli-start",
"name": "cli-start",
Expand Down
2 changes: 1 addition & 1 deletion templates/python-crewai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This approach allows you to programmatically charge users directly from your Act

To set up the PPE model for this Actor:
- **Configure the OpenAI API key environment variable**: provide your OpenAI API key to the `OPENAI_API_KEY` in the Actor's **Environment variables**.
- **Configure Pay Per Event**: establish the Pay Per Event pricing schema in the Actor's **Admin settings**. First, set the **Pricing model** to `Pay per event` and add the schema. An example schema can be found in [pay_per_event.json](.actor/pay_per_event.json).
- **Configure Pay Per Event**: establish the Pay Per Event pricing schema in the Actor's **Monetization settings**. First, set the **Pricing model** to `Pay per event` and add the schema. An example schema can be found in [pay_per_event.json](.actor/pay_per_event.json).

## Included features

Expand Down
30 changes: 30 additions & 0 deletions templates/python-langgraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@ Add or modify the agent tools in the `src/tools.py` file, and make sure to inclu

For a more advanced multi-agent example, see the [Finance Monitoring Agent actor](https://github.com/apify/actor-finance-monitoring-agent) or visit the [LangGraph documentation](https://langchain-ai.github.io/langgraph/concepts/multi_agent/).

#### Pay Per Event

This template uses the [Pay Per Event (PPE)](https://docs.apify.com/platform/actors/publishing/monetize#pay-per-event-pricing-model) monetization model, which provides flexible pricing based on defined events.

To charge users, define events in JSON format and save them on the Apify platform. Here is an example schema with the `task-completed` event:

```json
[
{
"task-completed": {
"eventTitle": "Task completed",
"eventDescription": "Cost per query answered.",
"eventPriceUsd": 0.1
}
}
]
```

In the Actor, trigger the event with:

```python
await Actor.charge(event_name='task-completed')
```

This approach allows you to programmatically charge users directly from your Actor, covering the costs of execution and related services, such as LLM input/output tokens.

To set up the PPE model for this Actor:
- **Configure the OpenAI API key environment variable**: provide your OpenAI API key to the `OPENAI_API_KEY` in the Actor's **Environment variables**.
- **Configure Pay Per Event**: establish the Pay Per Event pricing schema in the Actor's **Monetization settings**. First, set the **Pricing model** to `Pay per event` and add the schema. An example schema can be found in [pay_per_event.json](.actor/pay_per_event.json).

## Included features

- **[Apify SDK](https://docs.apify.com/sdk/python/)** for Python - a toolkit for building Apify [Actors](https://apify.com/actors) and scrapers in Python
Expand Down
2 changes: 1 addition & 1 deletion templates/python-llamaindex-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ To run this template locally or on the Apify platform, you need:

## Monetization

This template uses the [Pay Per Event](https://docs.apify.com/sdk/js/docs/next/guides/pay-per-event) (PPE) monetization model, which provides flexible pricing based on defined events.
This template uses the [Pay Per Event](https://docs.apify.com/platform/actors/publishing/monetize#pay-per-event-pricing-model) (PPE) monetization model, which provides flexible pricing based on defined events.

To charge users, define events in JSON format and save them on the Apify platform. Here is an example of [pay_per_event.json](.actor/pay_per_event.json) with the `task-completed` event:

Expand Down
4 changes: 2 additions & 2 deletions templates/ts-bee-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Add or modify tools in the `src/tool_calculator.ts` and `src/tool_instagram.ts`

#### Pay Per Event

This template uses the [Pay Per Event](https://docs.apify.com/sdk/js/docs/next/guides/pay-per-event) (PPE) monetization model, which provides flexible pricing based on defined events.
This template uses the [Pay Per Event](https://docs.apify.com/platform/actors/publishing/monetize#pay-per-event-pricing-model) (PPE) monetization model, which provides flexible pricing based on defined events.

To charge users, define events in JSON format and save them on the Apify platform. Here is an example schema with the `task-completed` event:

Expand All @@ -38,7 +38,7 @@ This approach allows you to programmatically charge users directly from your Act

To set up the PPE model for this Actor:
- **Configure the OpenAI API key environment variable**: provide your OpenAI API key to the `OPENAI_API_KEY` in the Actor's **Environment variables**.
- **Configure Pay Per Event**: establish the Pay Per Event pricing schema in the Actor's **Admin settings**. First, set the **Pricing model** to `Pay per event` and add the schema. An example schema can be found in [pay_per_event.json](.actor/pay_per_event.json).
- **Configure Pay Per Event**: establish the Pay Per Event pricing schema in the Actor's **Monetization settings**. First, set the **Pricing model** to `Pay per event` and add the schema. An example schema can be found in [pay_per_event.json](.actor/pay_per_event.json).

### Included Features

Expand Down
55 changes: 55 additions & 0 deletions templates/ts-mastraai/.actor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Specify the base Docker image. You can read more about
# the available images at https://docs.apify.com/sdk/js/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM apify/actor-node:22 AS builder

# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY package*.json ./

# Install all dependencies. Don't audit to speed up the installation.
RUN npm install --include=dev --audit=false

# Next, copy the source files using the user set
# in the base image.
COPY . ./

# Install all dependencies and build the project.
# Don't audit to speed up the installation.
RUN npm run build

# Create final image
FROM apify/actor-node:22

# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY package*.json ./

# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN npm --quiet set progress=false \
&& npm install --omit=dev --omit=optional \
&& echo "Installed NPM packages:" \
&& (npm list --omit=dev --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version \
&& rm -r ~/.npm

# Copy built JS files from builder image
COPY --from=builder /usr/src/app/dist ./dist

# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./

# Create and run as a non-root user.
RUN adduser -h /home/apify -D apify && \
chown -R apify:apify ./
USER apify

# Run the image.
CMD npm run start:prod --silent
16 changes: 16 additions & 0 deletions templates/ts-mastraai/.actor/actor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"actorSpecification": 1,
"name": "ts-mastraai",
"title": "Mastra Agent TypeScript",
"description": "Mastra Agent in TypeScript",
"version": "0.0",
"buildTag": "latest",
"storages": {
"dataset": "./dataset_schema.json"
},
"meta": {
"templateId": "ts-mastraai"
},
"input": "./input_schema.json",
"dockerfile": "./Dockerfile"
}
24 changes: 24 additions & 0 deletions templates/ts-mastraai/.actor/dataset_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"actorSpecification": 1,
"views": {
"overview": {
"title": "Overview",
"transformation": {
"fields": ["query", "response"]
},
"display": {
"component": "table",
"properties": {
"query": {
"label": "Query",
"format": "text"
},
"response": {
"label": "Response",
"format": "text"
}
}
}
}
}
}
27 changes: 27 additions & 0 deletions templates/ts-mastraai/.actor/input_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"title": "Mastra Agent TypeScript",
"type": "object",
"schemaVersion": 1,
"properties": {
"query": {
"title": "Query",
"type": "string",
"description": "Query for the agent.",
"editor": "textfield",
"prefill": "Analyze the posts of the @openai and @googledeepmind and summarize me current trends in the AI.",
"default": "This is a fallback test query, do nothing and !!do not call any tools!!. If asked to generate structured response, create a dummy one without optional fields, and empty lists - keep it as minimal as possible."
},
"modelName": {
"title": "OpenAI model",
"type": "string",
"description": "The OpenAI model to use. Currently supported models are gpt-4o and gpt-4o-mini.",
"enum": [
"gpt-4o",
"gpt-4o-mini"
],
"default": "gpt-4o-mini",
"prefill": "gpt-4o-mini"
}
},
"required": ["query", "modelName"]
}
12 changes: 12 additions & 0 deletions templates/ts-mastraai/.actor/pay_per_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"actor-start": {
"eventTitle": "Price for Actor start",
"eventDescription": "Flat fee for starting an Actor run.",
"eventPriceUsd": 0.1
},
"task-completed": {
"eventTitle": "Price for completing the task",
"eventDescription": "Flat fee for completing the task.",
"eventPriceUsd": 0.4
}
}
17 changes: 17 additions & 0 deletions templates/ts-mastraai/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# configurations
.idea
.vscode

# crawlee and apify storage folders
apify_storage
crawlee_storage
storage

# installed files
node_modules

# git folder
.git

# dist folder
dist
9 changes: 9 additions & 0 deletions templates/ts-mastraai/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
20 changes: 20 additions & 0 deletions templates/ts-mastraai/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,
"env": {
"browser": true,
"es2020": true,
"node": true
},
"extends": [
"@apify/eslint-config-ts"
],
"parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": 2020
},
"ignorePatterns": [
"node_modules",
"dist",
"**/*.d.ts"
]
}
10 changes: 10 additions & 0 deletions templates/ts-mastraai/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tells Git which files shouldn't be added to source control

.idea
.vscode
storage
apify_storage
crawlee_storage
node_modules
dist
tsconfig.tsbuildinfo
56 changes: 56 additions & 0 deletions templates/ts-mastraai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## TypeScript Mastra agent template

A template for [Mastra](https://mastra.ai/) projects in TypeScript for building AI agents with [Apify Actors](https://apify.com/actors). The template provides a basic structure and an example [agent](https://mastra.ai/docs/agents/00-overview) that calls [Actors](https://apify.com/actors) as tools in a workflow.

## How it works

An [agent](https://blog.apify.com/what-are-ai-agents/) is created and given a set of tools to accomplish a task. The agent receives a query from the user and decides which tools to use and in what order to complete the task. In this case, the agent is provided with an [Instagram Scraper Actor](https://apify.com/apify/instagram-scraper) to scrape Instagram profile posts. The agent produces textual output, which is saved to a dataset.

## How to use

Add or modify the agent tools in the `src/tools.ts` file, and make sure to include new tools in the agent tools list in `src/agents.ts`. Additionally, you can update the agent prompts in `src/agents.ts`. For more information, refer to the [Mastra agent documentation](https://mastra.ai/docs/agents/00-overview) and the [Mastra tools documentation](https://mastra.ai/docs/agents/02-adding-tools).

#### Pay Per Event

This template uses the [Pay Per Event (PPE)](https://docs.apify.com/platform/actors/publishing/monetize#pay-per-event-pricing-model) monetization model, which provides flexible pricing based on defined events.

To charge users, define events in JSON format and save them on the Apify platform. Here is an example schema with the `task-completed` event:

```json
[
{
"task-completed": {
"eventTitle": "Task completed",
"eventDescription": "Cost per query answered.",
"eventPriceUsd": 0.1
}
}
]
```

In the Actor, trigger the event with:

```typescript
await Actor.charge({ eventName: 'task-completed' });
```

This approach allows you to programmatically charge users directly from your Actor, covering the costs of execution and related services, such as LLM input/output tokens.

To set up the PPE model for this Actor:
- **Configure the OpenAI API key environment variable**: provide your OpenAI API key to the `OPENAI_API_KEY` in the Actor's **Environment variables**.
- **Configure Pay Per Event**: establish the Pay Per Event pricing schema in the Actor's **Monetization settings**. First, set the **Pricing model** to `Pay per event` and add the schema. An example schema can be found in [pay_per_event.json](.actor/pay_per_event.json).

## Included features

- **[Apify SDK](https://docs.apify.com/sdk/js/)** for JavaScript - a toolkit for building Apify [Actors](https://apify.com/actors) and scrapers in JavaScript
- **[Input schema](https://docs.apify.com/platform/actors/development/input-schema)** - define and easily validate a schema for your Actor's input
- **[Dataset](https://docs.apify.com/sdk/js/docs/guides/result-storage#dataset)** - store structured data where each object stored has the same attributes
- **[Key-value store](https://docs.apify.com/platform/storage/key-value-store)** - store any kind of data, such as JSON documents, images, or text files

## Resources

- [What are AI agents?](https://blog.apify.com/what-are-ai-agents/)
- [TypeScript tutorials in Academy](https://docs.apify.com/academy/node-js)
- [Apify SDK documentation](https://docs.apify.com/sdk/js/)
- [Mastra documentation](https://mastra.ai/docs)
- [Integration with Make, GitHub, Zapier, Google Drive, and other apps](https://apify.com/integrations)
Loading
Loading