# AI Pipelines and Agents in Pure TypeScript with Mastra.ai

Nick Nisi & Zachary Proser, WorkOS | AI Engineer World's Fair 2025 | 1:51:14

Source: https://www.youtube.com/watch?v=FWlRHPZWyHE
Channel: AI Engineer (https://www.youtube.com/@aiDotEngineer). Summarised by AIE Talks.
Page: https://aietalks.com/talks/ai-pipelines-and-agents-in-pure-typescript-with-mastra-ai
Published: 2025-07-12
Tags: agents, structured-outputs, tool-use, workflows

## TL;DR
- Mastra uses typed, composable workflows to make multi-step AI pipelines more predictable than letting an agent choose every tool call.
- An agent can provide a conversational interface to a deterministic workflow, while Mastra's playground lets developers inspect inputs, outputs, schemas, and tool calls locally.
- Pure TypeScript, schema validation, evaluations, memory, observability, and deployment adapters make Mastra suitable for building internal AI tools.

## Summary
Nick Nisi and Zachary Proser teach Mastra by building an AI meme generator in TypeScript. The example takes a workplace frustration, identifies a suitable meme template, generates captions, and publishes the result through the Imgflip API. The workshop separates the system into workflows, steps, tools, and agents. Workflows handle ordered, typed operations, while agents let a colleague describe a task in natural language and call the workflow. The speakers spend time in Mastra's local playground, where developers can run workflows, inspect step inputs and outputs, view graphs, adjust model settings, and debug without deploying. They also discuss MCP, schema validation with Zod, workflow backends, deployment targets, memory, evaluations, and internal tooling. The practical argument is that teams should use a shared framework with explicit software structures instead of collecting bespoke prompt scripts. The speakers are also honest about non-determinism, API-key problems, schema limits, and the need to review generated code.

## Key ideas
### Mastra organizes production AI applications around workflows, tools, and agents
[02:48](https://www.youtube.com/watch?v=FWlRHPZWyHE&t=168s)
Mastra is introduced as a TypeScript framework for building production AI applications. Its main pieces are workflows, tools, and agents. Workflows are composable and typed pipelines. Tools are functions an agent can call for filesystem access, API calls, database queries, or business logic. Agents provide a chat interface for people. Mastra also includes a playground, persistence, memory, observability, and evaluations. The workshop does not cover every feature, but uses these building blocks to create a meme generator and show how the pieces fit together.

### Workflows give non-deterministic model calls an explicit sequence and typed boundaries
[04:10](https://www.youtube.com/watch?v=FWlRHPZWyHE&t=250s)
The speakers describe a workflow as a discrete sequence of steps, such as scraping a site, downloading interesting people, looking up their information, selecting an image, and writing an email. Data moves between steps, and transforms can shape it in the middle. Since LLM output is non-deterministic, the workflow uses Zod schemas to validate and coerce values at runtime, then handles errors. Mastra also supports a fluent style for more complex control flow, including branching, conditionals, loops, and while operations. A simple step array covers linear pipelines.

### Tools let agents choose actions, while workflows preserve a fixed order
[05:36](https://www.youtube.com/watch?v=FWlRHPZWyHE&t=336s)
Tools are functions that agents can call, and MCP exposes tools that give models access to information outside their training data. The speakers distinguish this from a workflow. With separate tools, an agent can decide at runtime which function to call. With a workflow, the developer specifies that the system must proceed through particular steps and transforms in a particular sequence. Mastra lets an agent call a workflow as well as tools. This distinction matters when giving an agent many possible actions, because a fixed pipeline can make the overall behavior easier to reason about.

### Agents combine a natural-language interface with specialized workflows
[06:47](https://www.youtube.com/watch?v=FWlRHPZWyHE&t=407s)
The speakers define an agent as a prompt combined with workflows or tools that let it perform specialized work. A workflow may complete a discrete task for a colleague, while the agent lets that colleague describe what they need in ordinary language. The agent can understand the request, invoke the workflow, and return a human-readable response instead of exposing only JSON. In the workshop, the meme generator agent receives instructions, knows which workflow it can call, and presents the generated image and link in a chat interface.

### The meme generator demonstrates a reusable internal-tool pattern
[10:47](https://www.youtube.com/watch?v=FWlRHPZWyHE&t=647s)
The workshop's example accepts a workplace frustration as input. The workflow analyzes the frustration, finds a suitable existing meme template through Imgflip, generates captions, and publishes a meme at a stable URL. The speakers call this a toy because of the limited workshop time, but say the underlying pattern applies to production applications. They also explain why schemas matter: later steps need to know facts such as how many caption boxes a selected meme has. Those fields can be defined in the schema and passed through the pipeline.

### Mastra's local playground makes each step inspectable before deployment
[32:42](https://www.youtube.com/watch?v=FWlRHPZWyHE&t=1962s)
After installation, the developers run the project locally and open Mastra's playground at localhost 411. The interface exposes agents, networks, tools, MCP servers, workflows, and runtime context. A basic workflow appears as a graph, accepts raw work-frustration text, and shows its JSON output. Later, the four-step meme workflow displays each stage, including extracting the frustration, finding a base meme, generating captions, and generating the final meme. Developers can inspect each step's input and output, change prompts and schemas, adjust temperature and model settings, and iterate without deploying.

### MCP documentation can improve coding tools across different editors
[20:03](https://www.youtube.com/watch?v=FWlRHPZWyHE&t=1203s)
Nick describes installing Mastra's MCP documentation server in Claude Code and Claude Desktop. He says his tools became more aware of Mastra and that the documentation server helped him avoid hallucinated APIs. The speakers compare this with editor-specific rules, which are tied to tools such as Cursor. Their view is that an MCP documentation server can provide the latest project documentation to different clients. They also demonstrate mcp.shop, where an MCP client authenticates a user and orders a shirt through a deployed MCP server.

### Mastra supports alternate workflow engines and several deployment targets
[43:05](https://www.youtube.com/watch?v=FWlRHPZWyHE&t=2585s)
A Mastra team member explains that workflows v-next keeps the Mastra workflow syntax while allowing the underlying workflow engine to change. The first integration was built with XState, and the team is adding integrations such as Inngest and Temporal. Inngest support is described as experimental because it had shipped only about a week earlier. For deployment, Mastra normally bundles into a Hono server that can run in a Docker container on infrastructure such as EC2 or DigitalOcean. Adapters are also available for Cloudflare, Netlify, Vercel, and Mastra Cloud, and the framework can be used with Express or inside a Next.js application.

### Internal AI tools can remove small manual tasks, but generated code still needs review
[1:34:00](https://www.youtube.com/watch?v=FWlRHPZWyHE&t=5640s)
Near the end, the speakers describe internal uses such as automating repetitive SDK changes, building tools for marketing and sales, and creating interfaces for infrastructure questions. Nick recounts using Claude to make a GitHub Action that creates pull requests across SDK repositories after a change is labeled, although he says it was an experiment and had not shipped. Zachary and Nick repeatedly advise reviewing generated code. They mention GitGuardian before committing and describe the risk of accepting a large generated change without understanding it. Their suggested next steps are to add tools, connect a vector database, implement RAG, and deploy an MCP server.

## Notable quotes
- "Workflows are composable pipelines." (04:10)
- "Tools are just functions that agents can call." (05:36)
- "The local playground was one of my favorite things about Mastra." (33:49)
- "It's faster to create the tool that your colleague needs than it is to continue talking about the tool that your colleague needs." (1:37:49)
- "Always review the code, please." (1:34:49)

## Tools & references mentioned
- Mastra.ai
- WorkOS
- LangChain
- TypeScript
- Vercel AI SDK
- MCP
- Model Context Protocol
- Anthropic
- Claude
- OpenAI
- Cursor
- Windsurf
- Claude Code
- Claude Desktop
- Zod
- Imgflip
- XState
- Inngest
- Temporal
- Cloudflare
- Netlify
- Vercel
- Hono
- SQLite
- Postgres
- GitGuardian
- Dagger
- Vercel v0
- 12 Factor Agents
- HumanLayer
- Gatsby

## Who should watch
- You are building an internal assistant and need a way to separate predictable multi-step operations from the chat interface people use.
- Your current AI application is a collection of prompt scripts and API calls, and you want typed schemas, local inspection, memory, and evaluations in one TypeScript framework.
- You want to understand where MCP, tools, workflows, and agents fit together before deploying an AI application.

## Related talks

- [Pragmatic AI with TypeChat](https://aietalks.com/talks/pragmatic-ai-with-typechat) (Daniel Rosenwasser, Microsoft, 18:34)
- [A Song of Types and Agents](https://aietalks.com/talks/a-song-of-types-and-agents) (Roberto Stagi, Ratel, 14:16)
- [AI Agents, Meet Test Driven Development](https://aietalks.com/talks/ai-agents-meet-test-driven-development) (Anita, Vellum, 29:10)
- [Building Durable Agents with Workflow DevKit & AI SDK](https://aietalks.com/talks/building-durable-agents-with-workflow-devkit-ai-sdk) (Peter Wielander, Vercel, 1:09:49)
- [Tool Calling Is Not Just Plumbing for AI Agents](https://aietalks.com/talks/tool-calling-is-not-just-plumbing-for-ai-agents) (Roy Derks, IBM, 25:18)
