Learn what Mastra is, how AI agents differ from workflows, and when to use each. Preview the support assistant you will build in this free Mastra course.
Mastra is an open source TypeScript framework designed to build AI agents and deterministic workflows. This lesson introduces core agent concepts, compares workflows against agent loops, and outlines the customer support assistant you will build throughout this course.
Next lesson: Setting Up Your First Mastra Project
An AI agent is a software program powered by a large language model that can perceive inputs, make decisions, and execute actions to reach a specific goal.
Traditional software requires developers to hardcode every branch and condition. In contrast, an agent uses a language model to decide which steps to take next. You give the agent instructions, access to external functions called tools, and an objective. The model inspects the user message, decides whether it needs extra information, calls the right tool, and interprets the tool result before generating a response.
Think of an agent like a chef who invents a dish on the fly based on whatever ingredients sit in the kitchen, while standard software follows a laminated recipe card with zero room for deviation.
Quick Insight: An agent is not just a chat model. An agent runs in an execution loop where it inspects tool outputs and decides whether to stop or take another action.
A workflow is a deterministic, step-by-step pipeline where operations run in a predefined order.
Workflows are structured as directed graphs. Each step takes typed inputs, performs an operation, and produces typed outputs for the next step. Workflows excel at repeatable business logic where you cannot afford unpredictable model behavior. Examples include processing a refund, sending an order confirmation email, or transforming database records.
Common Mistake: Trying to solve predictable business logic with an open-ended agent loop. If your task always requires step A, followed by step B, followed by step C, use a workflow instead of an agent.
Building reliable software with language models requires choosing the right pattern for each task. You can use agents for conversational adaptability and workflows for strict control.
| Dimension | AI Agent | Deterministic Workflow |
|---|---|---|
| Execution path | Dynamic and chosen by the model | Fixed and defined by code |
| Predictability | Lower, depends on model reasoning | High, reproducible every run |
| Best use case | Customer support chat, research, open triage | Data transformation, transaction processing, approval pipelines |
| Failure mode | Halts on bad reasoning or wrong tool calls | Fails on explicit exceptions or validation errors |
| Control flow | Model-driven loop | Sequential, parallel, and branching steps |
Mastra allows you to combine both patterns. You can place an agent inside a workflow step to classify a message, and then use standard code to route the ticket to the correct department.
Most AI frameworks were originally written in Python. Mastra is built specifically for TypeScript and Node.js developers.
Mastra builds directly on top of the Vercel AI SDK to provide model interoperability. It adds the higher-level infrastructure needed to run agents in production:
Here is a complete example showing how an agent is defined using Mastra:
tsCopy
Pro Tip: Mastra standardizes model provider names using a provider slash model pattern, such as openai/gpt-5-mini or anthropic/claude-sonnet-4-6.
Throughout this course, you will build a production-ready customer support assistant for an online retail store.
The project starts small and grows in complexity across each lesson:
Write down two features of an online store. For each feature, decide whether it should be built as an agent or as a workflow. For example, sending an order confirmation email after every purchase always follows the same steps, so it suits a workflow. Talking with a customer to understand a complaint needs flexible reasoning, so it suits an agent.
In the next lesson, Setting Up Your First Mastra Project, you will install the Mastra command-line interface, configure your environment variables, and launch Mastra Studio locally.
Was this lesson helpful?