Black Friday Deals For Authors Are On Now!

Leanpub Header

Skip to main content

Agents for Frontend Developers

Build, Ship and Secure Agent-Powered UIs with React, TypeScript and the Model Context Protocol

Agents for Frontend Developers
This book is 100% completeLast updated on 2026-11-30

Your product is about to get an assistant that calls tools, streams its answers and sometimes gets things wrong. This book shows frontend developers how to build the interface around it: streaming, approvals, undo, MCP, evals and security, with code that runs against a local mock model and needs no API key.

Minimum price

$10.00

$12.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

Buying multiple copies for your team? See below for a discount!

PDF
EPUB
About

About

About the Book

Every product is about to get an AI assistant. Someone has to build the interface around it: the streaming answer, the tool call in progress, the approval before something irreversible happens. That job lands on the frontend developer.

Agents for Frontend Developers is a hands-on guide to building that interface with React and TypeScript. You follow one project, Dash Assistant, an assistant inside an analytics dashboard, from a streaming chat box to a hardened, production-ready feature with tools, approvals, evals and a rollout plan. Every chapter ends at a checkpoint in the companion repository, with a command that runs it.

What you will learn

  • The agent loop: write it yourself, with tool schemas, tool calls, stop conditions and error recovery, in about 100 lines of TypeScript.
  • Streaming UIs: render partial text, tool calls and charts without re-rendering the page, with cancel, retry and resume.
  • Trust and control: approval gates, undo, and honest states for progress, errors and limits.
  • Generative UI: turn model output into interface from an allow-listed component registry.
  • MCP and protocols: build and consume MCP servers and MCP Apps, and choose between MCP, AG-UI and A2A.
  • Quality and security: test agents with evals, defend against prompt injection and data exfiltration, and track cost and latency.
  • Coding agents: use them on frontend work, from design to code to browser automation and large refactors.

Who it is for

Frontend developers who are comfortable with React and TypeScript. You do not need to have built an agent or called a language model API before.

Team Discounts

Team Discounts

Get a team discount on this book!

  • Up to 3 members

    Minimum price
    $25.00
    Suggested price
    $30.00
  • Up to 5 members

    Minimum price
    $40.00
    Suggested price
    $48.00
  • Up to 10 members

    Minimum price
    $70.00
    Suggested price
    $84.00
  • Up to 15 members

    Minimum price
    $100
    Suggested price
    $120
  • Up to 25 members

    Minimum price
    $150
    Suggested price
    $180

Author

About the Author

Sandeep Kumar Patel

Sandeep Kumar Patel is a senior web developer with more than 17 years of experience building web applications in object-oriented JavaScript and JSON. In 2012 he founded tutorialsavvy, a programming blog that developers have been reading ever since.

He is GATE-2005 Information Technology (IT) qualified and holds a Master's degree from VIT University, Vellore.

Contents

Table of Contents

  • Chapter 1. What an Agent Actually Is
    • The agent loop
    • Who is who: three actors
    • Call, workflow or agent?
    • What the frontend owns
    • Your role is changing, in two directions
    • Common misconceptions
    • Further reading
  • Chapter 2. An LLM API Crash Course for Web Developers
    • The shape of a request
    • Tokens: the unit of everything
    • Streaming
    • Structured output
    • Keys, trust and where code runs
    • Further reading
  • Chapter 3. Your First Agent in 100 Lines
    • What a tool is
    • Reading a tool call
    • Implementing the tools
    • The loop
    • Rules the loop must follow
    • Stop conditions
    • Errors the model can recover from
    • Further reading
  • Chapter 4. Streaming UIs
    • Choosing a transport
    • Design your own event protocol
    • The server: a streaming agent loop
    • The client: parsing the stream
    • Modeling the turn in state
    • Rendering tokens efficiently
    • Streaming tool calls and partial JSON
    • Cancel
    • Retry
    • Reconnect and resume
    • Backpressure
    • Accessibility, briefly
    • Further reading
  • Chapter 5. Beyond Chat: Agent UX Patterns
    • Where the agent lives
    • Show the plan
    • The steps timeline
    • Progress without lying
    • Approval gates, previewed
    • Undo beats confirm when you can afford it
    • Ambient versus invoked agents
    • Empty states
    • Error and partial states
    • Limits reached
    • The pattern catalog
    • Further reading
  • Chapter 6. Generative UI
    • The generative UI spectrum
    • The registry
    • From registry to tools
    • Validate on the server, emit, validate again
    • Data by reference
    • Interactive components: forms
    • Layout, loading and accessibility
    • Three approaches compared
    • Further reading
  • Chapter 7. Human in the Loop
    • Risk tiers
    • What the user needs to see to decide
    • Pausing the loop
    • The approval card
    • Editable plans
    • Undo
    • Interruptibility
    • Approval fatigue and policy
    • Further reading
  • Chapter 8. Accessibility, Latency and Trust
    • Why agent UIs are hard for assistive technology
    • Live regions: announce status, not tokens
    • Focus management
    • Keyboard access
    • Generated content must be accessible too
    • Motion
    • Perceived latency
    • Expressing uncertainty
    • Showing sources
    • Designing against over-trust
    • Further reading
  • Chapter 9. Tools Done Well
    • The tool is an interface for a reader you cannot watch
    • Names
    • Descriptions
    • Schemas that are hard to get wrong
    • Few tools or many
    • Results the model can use
    • Large results: summarize, paginate or send by reference
    • Errors the model can recover from
    • A typed tool registry
    • Idempotency for side-effecting tools
    • Metadata the rest of the system uses
    • The UI angle
    • Further reading
  • Chapter 10. State and Memory
    • Three kinds of state
    • Store two views of each conversation
    • The server becomes the source of truth
    • The context budget
    • Building the context: trimming old tool results
    • Compaction
    • Prompt caching
    • Per-user memory
    • The UI angle
    • Further reading
  • Chapter 11. MCP and MCP Apps
    • The mental model: hosts, clients, servers
    • What a server offers: tools, resources, prompts
    • Capability negotiation
    • Serving Dash Assistant over MCP
    • Hosting versus serving, and who the caller is
    • MCP Apps: returning UI as well as text
    • Consuming MCP servers from your own agent
    • Security: an MCP server is code that talks to your model
    • Further reading
  • Chapter 12. The Protocol Stack: MCP vs AG-UI vs A2A
    • Three boundaries, three protocols
    • MCP, briefly
    • AG-UI: the agent-to-frontend layer
    • A2A: the agent-to-agent layer
    • How the layers compose
    • From AgentEvent to AG-UI
    • When to adopt each
    • Lock-in and interoperability
    • Further reading
  • Chapter 13. Where the Loop Runs
    • Three places a loop can live
    • Browser-side agents, done safely
    • Client-side tools: the useful hybrid
    • Auth and multi-tenancy
    • Long-running runs: the stream is a view
    • The worker
    • Accepting client tool results
    • The browser: watch, resume, answer
    • Further reading
  • Chapter 14. Multi-Step and Multi-Agent
    • Start with one agent
    • The patterns
    • Passing context between agents
    • Shared state
    • The cost of coordination
    • Building the research sub-agent
    • Nested events and the step timeline
    • Further reading
  • Chapter 15. Agentic Coding for Frontend
    • A coding agent is the loop, pointed at your repo
    • Project context files
    • Verification: give the agent a check to run
    • Task sizing
    • Plan, then implement
    • Test-first prompts
    • Review discipline
    • Failure modes specific to UI
    • Safety on your own machine
    • When not to delegate
    • Worked example: suggested prompts in the empty chat
    • Further reading
  • Chapter 16. Design-to-Code Against Your Design System
    • Three layers: tell, forbid, check
    • Tokens as agent context
    • Component docs as agent context
    • Constraining output: the design-system lint
    • From a design file to code
    • Visual verification
    • Further reading
  • Chapter 17. Browser Automation and Computer Use
    • Three ways an agent can use a browser
    • What the agent sees: accessibility tree vs pixels
    • Driving a browser live with Playwright MCP
    • Make the agent app deterministic first
    • Generating E2E tests with an agent
    • Reviewing an agent-written test
    • The checkpoint test
    • Flakiness
    • Computer use, conceptually
    • Sandboxing and credentials
    • Further reading
  • Chapter 18. Agent-Driven Refactors and Migrations
    • Codemods, agents or both
    • The shape of a campaign
    • Inventory: know what you are migrating
    • Define the target pattern before touching code
    • The codemod
    • The agent pass for leftovers
    • Verification gates
    • Small, incremental PRs
    • Tracking progress
    • Rollback
    • Dependency upgrades are campaigns too
    • Further reading
  • Chapter 19. Evals for Agents
    • What an eval is, and how it differs from a test
    • Make the agent runnable outside the route
    • A dataset from real logs
    • Capturing a run
    • Kind 1: final-answer checks
    • Kind 2: trajectory and tool-call assertions
    • Kind 3: UI and part-level checks on the event stream
    • Kind 4: LLM-as-judge, and its limits
    • Humans in the review loop
    • Many trials, pass rates and noise
    • Regression gating in CI
    • The cost of evals
    • Do the evals catch anything?
    • Further reading
  • Chapter 20. Security
    • A threat model for an agentic frontend
    • Prompt injection
    • XSS from model output
    • Data exfiltration through URLs and images
    • Tool permissions, least privilege and the confused deputy
    • Secrets and the system prompt
    • Sandboxing iframes for third-party UI
    • Rate limiting and abuse
    • Audit logs
    • Red-team cases as evals
    • Further reading
  • Chapter 21. Observability, Cost and Shipping
    • What to observe: the run, not the request
    • OpenTelemetry for agents
    • Dashboards: the four views you need
    • Token budgets
    • Caching
    • Rate limits and backoff
    • Model choice as a cost lever
    • Feature flags and staged rollout
    • Fallbacks and kill switches
    • When not to use an agent
    • Closing note
    • Further reading
  • Appendix A. Glossary
  • Appendix B. Framework Comparison
  • Appendix C. Tool-Schema and Prompt Cheat Sheet
  • Appendix D. Launch Checklist
  • Appendix E. Angular and Vue Notes

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub