Skip to content
Closed
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
1 change: 1 addition & 0 deletions frameworks/mastra/dynamic-agents/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This file is used to store development environment variables
103 changes: 103 additions & 0 deletions frameworks/mastra/dynamic-agents/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Dependencies
node_modules/
.pnp
.pnp.js

# Testing
coverage/

# Production
build/
dist/

# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Coverage directory used by tools like istanbul
coverage/
*.lcov

# nyc test coverage
.nyc_output

# Dependency directories
node_modules/
jspm_packages/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
public

# Storybook build outputs
.out
.storybook-out

# Temporary folders
tmp/
temp/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# Agentuity
.agentuity/
74 changes: 74 additions & 0 deletions frameworks/mastra/dynamic-agents/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Mastra Dynamic Agents

## Overview
The Dynamic Agents example demonstrates how to create agents that adapt their behavior and capabilities at runtime based on contextual input. Instead of relying on fixed configurations, these agents adjust to users, environments, or scenarios, enabling a single agent to serve personalized, context-aware responses.

This example shows how to:
- Create agents with dynamic instructions based on runtime context
- Set and use runtime context variables (user tier, language preferences)
- Adapt agent behavior based on contextual input
- Integrate dynamic Mastra agents with Agentuity's platform

## Features

- **Dynamic Context**: Agent behavior changes based on user tier (free, pro, enterprise)
- **Language Support**: Responds in different languages based on context
- **Runtime Adaptation**: Instructions and responses adapt to the current context
- **Agentuity Integration**: Wrapped in Agentuity's structure with proper error handling

## Prerequisites

This example uses the `openai` model. Make sure to add `OPENAI_API_KEY` to your `.env` file.

```env
OPENAI_API_KEY=<your-api-key>
```

## Local Development

```bash
# Navigate to the agent directory
cd mastra-dynamic-agents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix path to the package directory.

Commands should cd into the framework subfolder; current path will fail.

-cd mastra-dynamic-agents
+cd frameworks/mastra/dynamic-agents

Apply in both Local Development and Deployment sections.

Also applies to: 44-44

🤖 Prompt for AI Agents
In frameworks/mastra/dynamic-agents/README.md around lines 31 and 44, the cd
command points to the repo root (cd mastra-dynamic-agents) instead of the
framework subfolder; update both occurrences to cd into the correct package
directory (the framework subfolder) so the commands run from the package path
used by Local Development and Deployment sections, e.g., replace the existing cd
instruction with the framework subfolder path for both line 31 and line 44.


# Install dependencies
bun install

# Start the development server
agentuity dev
```

## Deployment

```bash
# Navigate to the agent directory
cd mastra-dynamic-agents

# Deploy the agent
agentuity deploy
```

## How It Works

The agent dynamically adjusts its behavior based on contextual input:

1. **Context Detection**: Analyzes user input to determine context (user tier, language)
2. **Dynamic Instructions**: Agent instructions change based on the detected context
3. **Contextual Response**: Provides appropriate level of support based on user tier
4. **Language Adaptation**: Responds in the user's preferred language

## Example Interactions

- **Free Tier User**: "I'm a free tier user, can you help me with basic documentation?"
- **Pro User**: "I'm a pro user, provide detailed technical support"
- **Enterprise**: "I'm an enterprise customer, I need priority assistance"
- **Language**: "Can you help me in Japanese? (ja)"

## Technical Details

The agent demonstrates:
- Dynamic context detection from user input
- Contextual prompt modification based on user tier and language preferences
- Adaptive agent instructions that change behavior based on detected context
- Integration with Agentuity's platform for logging and error handling

This example preserves all original Mastra framework functionality while providing Agentuity's platform integration, error handling, and logging capabilities.
73 changes: 73 additions & 0 deletions frameworks/mastra/dynamic-agents/agentuity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/agentuity/cli/refs/heads/main/agentuity.schema.json

# ------------------------------------------------
# This file is generated by Agentuity
# You should check this file into version control
# ------------------------------------------------

# The version semver range required to run this project
version: '>=0.0.130'
# The ID of the project which is automatically generated
project_id: proj_5a86503e606e2faa6e68bb4efa32fb95
# The name of the project which is editable
name: mastra-dynamic-agents
# The description of the project which is editable
description: A Mastra dynamic agents example that demonstrates how agents can adapt their behavior and capabilities at runtime based on contextual input, wrapped in Agentuity's structure.
# The development configuration for the project
development:
# The port to run the development server on which can be overridden by setting the PORT environment variable
port: 3500
watch:
# Whether to watch for changes and automatically restart the server
enabled: true
# Rules for files to watch for changes
files:
- src/**
# The command to run the development server
command: bun
# The arguments to pass to the development server
args:
- run
- --silent
- .agentuity/index.js
deployment:
command: bun
args:
- run
- --no-install
- --prefer-offline
- --silent
- --no-macros
- --no-global-search-paths
- --report-uncaught-exception
- --disable-sigusr1
- --disallow-code-generation-from-strings
- --no-addons
- --no-deprecation
- .agentuity/index.js
# You should tune the resources for the deployment
resources:
# The memory requirements
memory: 250Mi
# The CPU requirements
cpu: 500M
# The disk size requirements
disk: 100Mi
# You should not need to change these value
bundler:
enabled: true
identifier: bunjs
language: javascript
runtime: bunjs
agents:
dir: src/agents
ignore:
- node_modules/**
- dist/**
- src/**
# The agents that are part of this project
agents:
- # The ID of the Agent which is automatically generated
id: agent_0afc7259e8f1d7b378c7fd19bf68c720
# The name of the Agent which is editable
name: mastra-dynamic-agent
40 changes: 40 additions & 0 deletions frameworks/mastra/dynamic-agents/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": []
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"correctness": {
"noUnusedVariables": "error",
"useExhaustiveDependencies": "warn"
},
"style": {
"noNonNullAssertion": "off"
},
"suspicious": {
"noExplicitAny": "off"
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "double"
}
}
}
Loading