# AI SDK Patterns — Building agents from first principles > A free TypeScript course on how agents work with the Vercel AI SDK v6. > Every term is defined on first use. Code is provider-agnostic via getModel(). - Course index: https://ai-sdk-patterns.dev/learn - Labs (installable patterns): https://ai-sdk-patterns.dev/patterns - Author: Akash Panchal (https://github.com/akashp1712) - Full site context: https://ai-sdk-patterns.dev/llms.txt - AI catalog: https://ai-sdk-patterns.dev/.well-known/ai-catalog.json Prefer the markdown twin (`.md`) when you need the full lesson without HTML. The HTML page is canonical for humans and citation. ## How to cite Use the lesson HTML URL as the source. Example: https://ai-sdk-patterns.dev/learn/fundamentals/day-1/what-is-llm ## Tracks ### The model A language model predicts the next token. This chapter is how you talk to one — in TypeScript, with the AI SDK. #### Day 1: How AI apps work You'll learn what an LLM is, how OpenAI-style APIs work, and why we use the Vercel AI SDK instead of raw HTTP. https://ai-sdk-patterns.dev/learn/fundamentals/day-1/what-is-llm - What is an LLM?: A large language model predicts the next chunk of text. It is not a database and it does not 'know' your app. HTML: https://ai-sdk-patterns.dev/learn/fundamentals/day-1/what-is-llm Markdown: https://ai-sdk-patterns.dev/learn/fundamentals/day-1/what-is-llm.md - OpenAI APIs and the others: Providers expose HTTP APIs. You send JSON, they return a completion. You pay per token. HTML: https://ai-sdk-patterns.dev/learn/fundamentals/day-1/provider-apis Markdown: https://ai-sdk-patterns.dev/learn/fundamentals/day-1/provider-apis.md - What the AI SDK is (and why): The Vercel AI SDK is a TypeScript library: generateText, streamText, tools, structured output — provider-agnostic. HTML: https://ai-sdk-patterns.dev/learn/fundamentals/day-1/why-ai-sdk Markdown: https://ai-sdk-patterns.dev/learn/fundamentals/day-1/why-ai-sdk.md #### Day 2: Your first chat response You'll send a prompt, wait for the full reply, then send a real chat: system + user + assistant messages. https://ai-sdk-patterns.dev/learn/fundamentals/day-2/messages-and-roles - Messages, roles, and a reply: A chat is an array of messages. Roles tell the model who is speaking. The next assistant message is the response. HTML: https://ai-sdk-patterns.dev/learn/fundamentals/day-2/messages-and-roles Markdown: https://ai-sdk-patterns.dev/learn/fundamentals/day-2/messages-and-roles.md - generateText — wait for the answer: The smallest useful AI SDK call: pick a model, send a prompt, read text. HTML: https://ai-sdk-patterns.dev/learn/fundamentals/day-2/generate-text Markdown: https://ai-sdk-patterns.dev/learn/fundamentals/day-2/generate-text.md #### Day 3: Streaming text You'll learn why chat UIs stream tokens, and how streamText pipes them to the browser. https://ai-sdk-patterns.dev/learn/fundamentals/day-3/why-streaming - Why streaming beats waiting: Users perceive speed when tokens arrive incrementally — even if total latency is similar. HTML: https://ai-sdk-patterns.dev/learn/fundamentals/day-3/why-streaming Markdown: https://ai-sdk-patterns.dev/learn/fundamentals/day-3/why-streaming.md - streamText in a route handler: A minimal API route that streams chat completions to the client. HTML: https://ai-sdk-patterns.dev/learn/fundamentals/day-3/stream-text-api Markdown: https://ai-sdk-patterns.dev/learn/fundamentals/day-3/stream-text-api.md #### Day 4: Structured output You'll learn to get type-safe JSON from models using Zod schemas — no regex parsing. https://ai-sdk-patterns.dev/learn/fundamentals/day-4/structured-json - Structured outputs with Zod: generateText with Output.object enforces a Zod schema so the model returns JSON you can trust in TypeScript. HTML: https://ai-sdk-patterns.dev/learn/fundamentals/day-4/structured-json Markdown: https://ai-sdk-patterns.dev/learn/fundamentals/day-4/structured-json.md #### Day 5: Embeddings primer You'll learn what embeddings are and why they power search and RAG before you build a pipeline. https://ai-sdk-patterns.dev/learn/fundamentals/day-5/embeddings - Vectors and similarity: Embeddings turn text into numbers so you can find similar documents mathematically. HTML: https://ai-sdk-patterns.dev/learn/fundamentals/day-5/embeddings Markdown: https://ai-sdk-patterns.dev/learn/fundamentals/day-5/embeddings.md ### The loop An agent is that model, calling your code, until it can answer. You'll write the tools and the stop condition. #### Day 1: Agent loops You'll learn how agents call tools in a loop until they have enough information to answer — the pattern behind every production agent. https://ai-sdk-patterns.dev/learn/agents/day-1/what-is-agent-loop - What is an agent loop?: An agent loop lets the model call tools repeatedly until it can produce a final answer. HTML: https://ai-sdk-patterns.dev/learn/agents/day-1/what-is-agent-loop Markdown: https://ai-sdk-patterns.dev/learn/agents/day-1/what-is-agent-loop.md - The tool loop in a route: Match the Tool Calling lab: streamText, Zod tool schemas, and stopWhen in one API route. HTML: https://ai-sdk-patterns.dev/learn/agents/day-1/tool-loop-route Markdown: https://ai-sdk-patterns.dev/learn/agents/day-1/tool-loop-route.md #### Day 2: Tool design You'll learn how tool schemas and descriptions determine whether agents succeed or hallucinate calls. https://ai-sdk-patterns.dev/learn/agents/day-2/tool-schemas - Tool schemas that models follow: The model reads tool descriptions and Zod schemas to decide when and how to call your functions. HTML: https://ai-sdk-patterns.dev/learn/agents/day-2/tool-schemas Markdown: https://ai-sdk-patterns.dev/learn/agents/day-2/tool-schemas.md #### Day 3: Multi-step agents You'll learn stopWhen, step limits, and human-in-the-loop patterns for longer tasks. https://ai-sdk-patterns.dev/learn/agents/day-3/multi-step - Controlling agent runs: Production agents need caps, approvals, and visibility into each step. HTML: https://ai-sdk-patterns.dev/learn/agents/day-3/multi-step Markdown: https://ai-sdk-patterns.dev/learn/agents/day-3/multi-step.md ### Context The model only sees what you send it. You'll decide what stays in the window when the chat gets long. #### Day 1: Context windows You'll learn why context limits break long chats and the strategies teams use in production. https://ai-sdk-patterns.dev/learn/context/day-1/context-window - Why context windows matter: Models only see a finite amount of text — memory, cost, and quality all depend on how you manage it. HTML: https://ai-sdk-patterns.dev/learn/context/day-1/context-window Markdown: https://ai-sdk-patterns.dev/learn/context/day-1/context-window.md - Sliding and token-based strategies: Drop oldest messages or trim by token count before each model call. HTML: https://ai-sdk-patterns.dev/learn/context/day-1/sliding-window Markdown: https://ai-sdk-patterns.dev/learn/context/day-1/sliding-window.md #### Day 2: Summarization and observational memory You'll learn when to summarize threads and how observational memory tracks facts across turns. https://ai-sdk-patterns.dev/learn/context/day-2/summarization - Summarization techniques: Compress older context instead of deleting it blindly. HTML: https://ai-sdk-patterns.dev/learn/context/day-2/summarization Markdown: https://ai-sdk-patterns.dev/learn/context/day-2/summarization.md