Leanpub Header

Skip to main content

Building AI Agents in Go

Minimum price

$29.00

$39.00

You pay

Author earns

$

Also available for 2 book credits with a Reader Membership

PDF
About

About

About the Book

An agent is a model in a loop. This book has you build the loop.

You write an AI agent in Go one tested piece at a time, with the standard library: `net/http` for the API, `encoding/json/v2` for the wire format, and `context` for deadlines and cancellation. No framework sits between you and the model, so every request, reply, and tool call is code you wrote and can read, and you learn how agents work underneath.

You start with a 30-line loop and finish with an agent that triages crash reports for a small Go web service: it groups the reports by cause, reproduces each cause in a test, fixes what is safe to fix, and files one issue per cause, as a command and as a service.

You'll learn how to:

- Give a model tools it uses well, and see why one sentence in a tool description can decide its next move

- Keep long runs focused and affordable as the context fills up

- Test an agent whose answers vary, and tell a real improvement from chance

- Sandbox what it can touch, resist prompt injection, and ask a person before risky actions

- Survive a crash mid-run without filing anything twice

- Judge any agent framework against the parts you built yourself

Every result is measured. Each number comes from a recorded run, with its models, run count, and date, and the book reports what worked, what didn't, and what each run cost, including the times the obvious design lost. Every example runs offline with no API key, from replies recorded in real runs.

Who it's for: Go developers new to language models. Go basics are enough: no machine learning, no math, and no framework required.

What you finish with:

- `triage`, a crash-triage agent for a Go web service, as a command and as a service

- An eval harness that grades agents with hidden tests across models

- A crash-safe agent loop that resumes without repeating an action

- Your own small library of tools, with sandboxing and human approval

Formats: PDF, 776 pages, in five reading themes (Light, Dark, Tokyo Night, Gruvbox Dark, and Catppuccin Latte), and EPUB. Every update of this edition is free.

The code: every chapter's program, tested with Go's race detector, is free and open source under Apache 2.0 at https://github.com/blackwell-systems/go-agents-book-code. Free guides and a sample are at https://golang-agents.com.

The Go gopher was designed by Renée French (CC BY 4.0). Not affiliated with or endorsed by Google or the Go project.

Author

About the Author

Dayna Blackwell

Dayna Blackwell is a software architect, technical author, and the founder of Blackwell Systems. A "builder-first" advocate for developer experience, Dayna has shipped 10 open-source production tools ranging from unified secrets management (vaultmux) to modular development frameworks (blackdot), all maintained with the same rigor as the enterprise systems she architects.

With five years of experience in the high-stakes world of enterprise hospitality—designing APIs that serve millions and data pipelines processing billions of events—Dayna specializes in making complex, "high-consequence" systems accessible. She is the author of the 838-page deep dive You Don't Know JSON and a prolific technical writer with over 225,000 lines of published documentation. Dayna is 3x AWS Certified and a specialist in infrastructure-as-code (Terraform, CDK, Pulumi) and cloud architecture.

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