Building AI Agents in TypeScript: A Comprehensive Guide to Building AI Agents, book published

2026-11-30来源 dev.toEnglish

AI Engineering with TypeScript: A Comprehensive Guide to Building AI Agents is out, on Leanpub and Amazon, for developers who already know TypeScript and want to build AI products in familiar dev stack.

This post covers what the book is, who it's for, what you build chapter by chapter, and what it leaves out.

The Premise

For most teams, building AI products means calling a model provider's API, not training a model. You send an HTTP request, handle a streamed response, validate JSON, keep state, and deal with failures and cost. That's work TypeScript developers already do every day.

So the book uses the TypeScript stack end to end: Hono on the server, React on the client, PostgreSQL with pgvector for storage and retrieval, Drizzle for database access, and Zod to validate what comes back from the model. Types are shared between frontend and backend in a pnpm monorepo.

It's an engineering book. There's no Transformer math and no model training. It covers how to build an AI application that keeps working once real users and real bills arrive.

Who It's For

  • You're comfortable with TypeScript, async/await and modules.
  • You can run a Node script and know your way around npm or pnpm.
  • You understand HTTP requests, JSON and REST APIs.

You don't need backend experience or any background in machine learning. If you've done backend work before, you can start at Chapter 5 and use Part One as a reference.

What You Build

The book has 24 chapters in six parts. Each part ends with something that runs.

Part One: Full-Stack Foundation (Chapters 1–4)

The move from frontend to full stack. You set up a monorepo with TypeScript, ESM, tsx, Biome and Vitest. Then you learn the server-side patterns AI apps lean on: the Node.js event loop, streams, error handling and type-safe APIs. The part ends with a full-stack app with a database, migrations and authentication.

Part Two: LLM Integration (Chapters 5–8)

  • How LLMs work, at the level an engineer needs: tokens, sampling and hallucination.
  • Calling the API with streaming, retries and cost control.
  • Prompt engineering and structured JSON output.
  • A multi-turn chat system with context-window management, history compression and cross-tab sync.

Part Three: RAG (Chapters 9–12)

  • Embeddings and vector search.
  • A document ingestion pipeline with four chunking strategies.
  • Hybrid search (BM25 plus vectors), reranking and citations.
  • Production RAG: incremental updates, quality evaluation, hallucination detection, multi-tenant isolation, an embedding cache, and the point where graph-based retrieval starts to pay off.

Part Four: Agents (Chapters 13–17)

This is the core of the book.

  • The ReAct and plan-and-execute loops, and how agents fail.
  • Tool calling in depth: schema design, parallel execution, result validation and recursion limits.
  • Browser automation with Playwright, plus filesystem and command-execution tools.
  • Multi-agent systems: orchestrators, pipelines, timeouts and conflicting results.
  • An autonomous coding agent that reviews code and fixes failing tests.

Part Five: MCP (Chapters 18–21)

The Model Context Protocol, from the JSON-RPC layer up:

  • An MCP server with tools, resources and prompts, over both stdio and Streamable HTTP.
  • An MCP client that manages several servers and asks the user before a tool runs.
  • Two reusable servers (Notion and a database query server), tested and published to npm.

Part Six: Multimodal and Production (Chapters 22–24)

  • Image understanding, speech-to-text, text-to-speech and mixed-content PDFs.
  • Production concerns: tracing with LangFuse, rate limits and quotas, prompt injection defense, prompt A/B tests, cost alerts and agent evals.
  • A capstone AI workbench that combines RAG, agents, MCP and multimodal input, with real-time collaboration, deployed to Vercel and Railway.

The appendices cover a TypeScript server-side reference, a troubleshooting guide, a glossary, prompt/context/harness engineering, and current trends.

What It Doesn't Cover

  • Training or fine-tuning models. Most product problems are solved with retrieval and prompting, and the book stays there.
  • Python. Every example is TypeScript.
  • Any single framework's agent abstractions. The agent loop, tool registry and MCP client are written out, so you can see what a framework would be doing for you.

The Companion Code

Every chapter has runnable code in github.com/aiengineering-book/code, organized by chapter, with a server/ and usually a web/ directory. The code blocks in the book are synced from that repository, so what you read is what runs. You'll need an OpenAI API key, and Docker for PostgreSQL from Chapter 4 on.

Try Before You Buy

Several posts here are adapted from chapters, or start from a chapter and push further with a measurement:

If those are useful to you, the book goes into the same topics in more depth, and builds them into one system.

Where to Get It

Questions, corrections and "this didn't work for me" reports are all welcome in the comments.

原文:https://www.a8q9.cn/en/article/building-ai-agents-in-typescript-a-comprehensive-guide-to-building-ai-agents-boo-aa49d6.html

相关文章