[Workshop] AI Pipelines and Agents in Pure TypeScript with Mastra.ai — Nick Nisi, Zack Proser

By AI Engineer

AITechnologyStartup
Share:

Key Concepts

  • AI Pipelines: Composable and typed sequences of steps for AI tasks.
  • Workflows: Discrete sets of steps to accomplish a task, allowing data transfer and error handling.
  • Tools: Functions that agents can call for tasks like file access, API calls, or database queries.
  • Agents: Interfaces (often chatbots) that interact with humans using natural language to trigger workflows.
  • MCP (Model Context Protocol): An open standard for universal plugins or tools that AI agents can call.
  • Zod: A TypeScript library for schema validation and coercion, ensuring reliable output from LLMs.
  • ImageFlip: An API used for finding base memes and creating new captions.
  • Mastra: A framework for building production AI applications in an agentic manner.

Introduction and Concepts (20 minutes)

  • The workshop focuses on building an AI-powered meme generator using TypeScript and the Mastra framework.
  • The patterns used are applicable to production AI applications.
  • The format includes introductions, concept explanations, collaborative coding, and a wrap-up with Q&A.
  • Workshop materials are available in the AI Engineer Slack channel under "workshop AI agents with Mastra".
  • Work OS is a company that builds developer tools for enterprise features like SSO, SAML, directory sync, audit logs, and fine-grained off.
  • Work OS is expanding into AI, focusing on securing AI and attaching identity to agents.
  • Mastra is a framework for building production AI applications in an agentic manner.
  • Key components of Mastra include workflows, tools, and agents.
  • Mastra offers built-in persistence, memory, observability, and evaluation.

Workflows: Composable Pipelines

  • Workflows are composable pipelines of discrete steps.
  • They allow chaining multiple steps together to complete a task.
  • Data can be passed between steps.
  • Zod is used to validate inputs and coerce outputs, ensuring reliability.
  • Workflows provide a deterministic set of steps for a task.
  • The API is similar to RxJS, starting with one thing and then mapping to something else.

Tools: Functions for Agents

  • Tools are functions that agents can call.
  • They provide access to file systems, APIs, databases, and custom business logic.
  • Tools give LLMs the ability to act on behalf of the user and access data.
  • In the workshop, the agent calls a workflow rather than individual tools.

Agents: Ideal Human Interfaces

  • Agents are considered ideal human interfaces, often in the form of chatbots.
  • They allow users to describe their needs in natural language.
  • The system can then use workflows to complete the task.
  • Agents combine prompts with workflows or tools to perform specialized tasks.
  • Agents can introspect the state and make decisions.

MCP (Model Context Protocol)

  • MCP is an open standard for bringing universal plugins or tools to AI agents.
  • It was developed by Anthropic and is used in Claude, Cursor, Windsurf, and OpenAI.
  • MCP provides an easy-to-use API for tools to interact with AI agents.
  • Example: Using the GitHub MCP server in Claude to access issue context and suggest solutions.
  • mcp.shop is a demo where you can order a shirt using MCP.
  • MCP Night was held at the Exploratorium, indicating growing interest in the protocol.

AI Meme Generator: Workshop Project

  • The workshop project is an AI meme generator.
  • The input is a user's frustration.
  • The workflow finds the best base meme, edits captions, and publishes a new meme.
  • The project uses OpenAI for understanding and ImageFlip for image manipulation.
  • The patterns used are production-ready.

Workshop Structure and Setup

  • The workshop is self-paced.
  • The workshop.md file in the repo contains the entire course.
  • Git branch checkpoints are provided for each phase.
  • Assistance is available from the presenters and the Mastra core team.
  • Understanding is prioritized over completion.
  • The workshop is a snapshot in time due to the rapidly changing nature of AI tools.
  • Step zero branch provides the baseline to start from.
  • The goal of the first step is to see the Mastra playground.

Step 1: Creating a Basic Workflow

  • The goal is to create a basic workflow with a single step.
  • The workflow will extract the type of frustration from user input.
  • The Mastra playground allows testing the workflow.
  • The playground shows agents, networks, tools, MCP servers, workflows, and runtime context.
  • The playground provides a URL (localhost:411) to access the interface.

Step 2: Building the Full Workflow

  • The goal is to create all workflow steps and chain them together with data mapping.
  • The steps include extracting frustration, finding a base meme, generating captions, and generating the meme.
  • The workflow will generate a meme and upload it to ImageFlip.
  • The Mastra playground allows testing the full workflow.
  • ImageFlip requires a username and password for a higher rate limit.

Step 3: Integrating with an Agent

  • The goal is to create an agent that can call the workflow.
  • The agent is given a prompt and knowledge of the workflow.
  • The agent provides a chat interface for users to interact with the workflow.
  • The Mastra playground allows testing the agent.
  • The agent can provide human feedback and show the image inline.

Key Takeaways and Next Steps

  • The workshop covered workflows, agents, type safety, error handling, and structured generation.
  • Mastra provides benefits such as easy debugging and rapid iteration.
  • Next steps include exploring tool creation, adding a vector database, and implementing RAG.
  • mcp.shop is a demo to order a t-shirt using MCP.

Q&A and Discussion

  • Discussion on the use of Vim and AI integrations.
  • Discussion on the use of cursor rules and MCP doc server.
  • Discussion on the use of durable execution for agents.
  • Discussion on deployment platforms and strategies.
  • Discussion on schema validation and error handling.
  • Discussion on the use of DAGs and Airflow.
  • Discussion on caching with Mastra.
  • Discussion on the use of agents in production.
  • Discussion on the potential for non-technical users to use AI tools.
  • The Mastra team thanked the participants for attending the workshop.
  • The presenters thanked the Mastra team for creating the framework.

Chat with this Video

AI-Powered

Hi! I can answer questions about this video "[Workshop] AI Pipelines and Agents in Pure TypeScript with Mastra.ai — Nick Nisi, Zack Proser". What would you like to know?

Chat is based on the transcript of this video and may not be 100% accurate.

Related Videos

Ready to summarize another video?

Summarize YouTube Video