Agents Overview
Agents are the core building blocks of Mastra. They provide a high-level abstraction for AI interactions, managing language models, tools, memory, and workflows in a cohesive way.What is an Agent?
An agent in Mastra is an AI entity that can:- Respond to user messages with text or structured data
- Use tools to perform actions and access external systems
- Delegate tasks to other agents or workflows
- Remember conversations across sessions using memory
- Work with files through workspace integration
- Execute workflows for complex multi-step operations
Core Capabilities
Language Model Integration
Agents wrap language models (LLMs) from various providers:Tool Usage
Agents can use tools to extend their capabilities:Memory & Conversations
Agents can persist conversations and recall context:Multi-Agent Collaboration
Agents can delegate work to specialized sub-agents:Agent Execution Methods
Generate (Non-Streaming)
Get a complete response in one call:Stream (Real-time)
Stream responses token-by-token for better UX:Network (Multi-Primitive)
Orchestrate complex workflows with agents, tools, and workflows:Agent Configuration Options
| Option | Type | Description |
|---|---|---|
id | string | Unique identifier for the agent |
name | string | Human-readable name |
instructions | string | object | function | System prompt defining behavior |
model | string | object | array | Language model configuration |
tools | object | function | Tools the agent can use |
agents | object | function | Sub-agents for delegation |
workflows | object | function | Workflows the agent can execute |
memory | Memory | function | Memory for conversation persistence |
workspace | Workspace | function | File system and code execution |
inputProcessors | array | Pre-process messages before LLM |
outputProcessors | array | Post-process messages after LLM |
maxRetries | number | Retry attempts for failed calls |
Dynamic Configuration
Many agent options support dynamic resolution using functions:Next Steps
Creating Agents
Learn how to create and configure agents
Tools
Add tools to extend agent capabilities
Streaming
Stream responses in real-time
Structured Output
Get typed, validated responses