-
Notifications
You must be signed in to change notification settings - Fork 5
Add Mastra Dynamic Agents Example #48
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # This file is used to store development environment variables |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| # 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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix path to the package directory.
Commands should cd into the framework subfolder; current path will fail.
Apply in both Local Development and Deployment sections.
Also applies to: 44-44
🤖 Prompt for AI Agents