WEEK 1 · TASKS VS. AGENTS WEEK 2 · HELLO, MASTRA WEEK 3 · THE ACCESS AGENT
Advanced · Week 2

Hello, Mastra

Week 1 ended with a toy: an access agent simulated in your browser. Before we build the real one, we need a workbench. This week: scaffold a Mastra project, meet the example weather agent in Studio, and rewire its brain to Anduin's LiteLLM proxy.

1Scaffold a project

Following the Mastra quickstart:

npm create mastra@latest

The wizard asks a few questions — pick the same answers:

The create-mastra wizard with the answers to pick: OpenAI as provider, skip the API key, no observability, Skills + Claude Code, init git
Why "OpenAI" when we don't use OpenAI directly? At Anduin, all model access goes through the company LiteLLM proxy — one gateway that holds the real API keys and puts every model (Claude, GPT, and the rest) behind a single endpoint. The wizard has no LiteLLM option, and it doesn't need one: LiteLLM speaks the OpenAI wire protocol, so any tool's "OpenAI" setting can talk to it. Pick OpenAI, skip the API key (you don't have an OpenAI key, and you don't need one) — in step 3 we'll point the project at the proxy instead.

When it finishes you get a src/mastra/ folder with a sample weather agent, tool, and workflow — a working example app we'll poke at before writing our own.

There's also a gallery of templates — pre-built projects (deep research, PDF Q&A, browser agents) you can start from instead of the blank scaffold. Worth a browse later; this track builds from the bare scaffold so you see every piece.

Why Mastra, and not something else?
  • Why any framework: the vanilla loop is easy to write and easy to write wrong — a framework gives a named place for agents, tools, and instructions, typed inputs, and Studio instead of console logs.
  • Vercel AI SDK — great for AI inside a web app (Mastra uses it under the hood), but no memory, evals, or Studio.
  • LangChain / LangGraph — most proven, most painful: Python-first heritage, heavy graph abstraction, API churn.
  • OpenAI Agents SDK — simplest loop, but OpenAI-shaped; we route through a LiteLLM proxy.
  • CrewAI / Pydantic AI / smolagents — Python; our audience lives in TypeScript.
  • Mastra's tenets: TypeScript-native and typed end-to-end (Zod on every tool), one opinionated API, agents vs. workflows as an explicit distinction, batteries included (memory, evals, tracing, MCP), model-agnostic, local-first via Studio.
  • Cheap to reverse: tools arrive over MCP, which is framework-agnostic — switching later is a port, not a rewrite.

2Boot Studio

npm run dev

Studio comes up at localhost:4111 — Mastra's local workbench. The scaffold's Weather Agent is already in the agents list, because the scaffold registered it in src/mastra/index.ts. Registration is what makes things visible here.

Mastra Studio agents list showing the scaffold's Weather Agent

Try chatting with it, though, and you'll hit a wall: the agent has no working model — you skipped the OpenAI key in the wizard, remember? The body needs a brain. That's step 3.

3Switch the model to LiteLLM

Two small changes point the scaffold at Anduin's proxy. First, replace the contents of .env:

# Anduin LiteLLM proxy — OpenAI-compatible gateway; holds the real provider keys
LITELLM_BASE_URL=https://litellm.anduin.center/v1
LITELLM_API_KEY=sk-…        # ask your instructor for a key — never commit it
LITELLM_MODEL=anthropic.claude-sonnet-5-global

Then, in src/mastra/agents/weather-agent.ts, swap the one-line model string (model: 'openai/gpt-5-mini') for a gateway object:

model: {
  id: `litellm/${process.env.LITELLM_MODEL ?? 'anthropic.claude-sonnet-5-global'}`,
  url: process.env.LITELLM_BASE_URL,
  apiKey: process.env.LITELLM_API_KEY,
},

Mastra's model router takes any OpenAI-compatible endpoint as url + apiKey; the id prefix (litellm/) is just a label, and the part after the slash is the model name the proxy expects. Note what the model actually is now: Claude, served through a gateway that talks the OpenAI protocol. mastra dev hot-reloads — no restart needed.

4Talk to the agent

Back in Studio, open the Weather Agent and ask: "What's the weather in Tokyo?" Now it thinks: the agent decides to call its weatherTool, gets real data back (the tool hits a free weather API), and composes an answer.

The Weather Agent in Studio answering a Tokyo weather question, with the weatherTool call visible

That's the whole agent loop from week 1, live: model picks a tool, tool runs, model reads the result, answers. The difference from a plain chatbot is that the model chose to make that call.

5Meet the workflow

The scaffold also ships a weather-workflow — same weather domain, opposite philosophy. A workflow is a fixed sequence of steps: fetch forecast, then plan activities. No model decides what happens next; the graph does.

The weather workflow graph in Studio, with a run's step results

This is one of Mastra's core distinctions: agents when the model should decide what to do next, workflows when the steps must be predictable. You'll pick between them constantly, and the scaffold hands you one of each to compare.

6Read the traces

Studio's Traces view shows what actually happened on every run — each model call, each tool call, inputs, outputs, and timing. When an agent misbehaves, this is where you look first.

Mastra Studio traces view showing the LLM and tool spans for the weather agent run
A workbench, not a chat window: chat, traces, evals — all pointed at the agent you're building.

That's the tour: a scaffolded project, a live agent on the company proxy, a workflow to contrast it with, and traces to see inside. Next week we put our own agent on this bench — the GitHub access agent from week 1, for real.