Building AI Agents in Go
by Dayna Blackwell
$29
Build AI agents in Go. Know how they actually work.
An agent is a model in a loop. This book has you build the loop.
Start with 30 lines of Go. Finish with a working AI agent that investigates crash reports for a real Go web service, reproduces bugs, fixes them, and files one issue per root cause.
Along the way, you'll build every part yourself: the model calls, tool execution, context management, evaluation, safety controls, and crash recovery. One tested piece at a time.
No machine learning background. No agent framework. Just Go.
Go beyond the agent demo.
Getting a model to call a tool is easy. Building an agent that knows which tool to call, stays on task, handles failure, and doesn't repeat expensive or dangerous actions is where the engineering begins.
You'll learn how to:
Build the loop from scratch. Connect model calls, tools, and decisions into an agent you can understand, test, and extend.
Make tools the model actually uses well. Discover why changing one sentence in a tool description can change an agent's behavior.
Keep long runs on track. Manage growing context, control token costs, and prevent the agent from losing sight of its goal.
Measure what works. Evaluate nondeterministic behavior with hidden tests, compare models, and distinguish real improvements from random variation.
Give agents boundaries. Sandbox their access, defend against prompt injection, and require human approval before risky actions.
Recover from failure. Build a durable loop that survives a crash and resumes without filing duplicate issues.
Understand frameworks before choosing one. Learn what they provide, what they hide, and which problems you've already solved yourself.
No hand-waving. Actual measurements.
Every result is measured.
You'll see what worked, what failed, and what each experiment cost.
The examples can run offline using recorded model interactions, so you can reproduce results without paying for API calls. The evaluation harness uses hidden tests to compare agent behavior across models.
You'll see the surprising results, too: the simpler design that beats the clever one, the tool description that changes everything, and the improvement that disappears under proper testing.
This isn't a collection of prompts that happened to work once. It's a practical guide to building agents you can evaluate and trust within their tested limits.
One project. From 30 lines to a working service.
The book builds toward triage, an agent that investigates real crash reports for a Go web service.
By the end, you'll have a working command-line tool and service, an evaluation harness, a crash-safe execution loop, and your own reusable library of tools with sandboxing and human approval.
More importantly, you'll understand how every piece works, why it's there, and how to change it.
Everything you need is included.
The complete 762-page book, available in five fully themed PDF editions:
Light · Dark · Tokyo Night · Gruvbox Dark · Catppuccin Latte
Each edition includes the complete text, code, diagrams, and illustrations, with the entire book colored to match your reading theme.
You also get the EPUB, the complete chapter-by-chapter source code, and every future update to this edition delivered by email.
The code is also available free and open source under Apache 2.0.
Written for Go developers, not ML researchers.
If you know the basics of Go, you're ready.
You don't need machine learning, advanced math, prior LLM experience, or an agent framework.
Start with a loop. Finish with an agent you know how to build, test, and operate.
The Go gopher was designed by Renée French (CC BY 4.0). This book is not affiliated with or endorsed by Google or the Go project.