The Gopher reaches up for the last curved piece of a toy train track that the kneeling Ghost, a stone android, holds out, to close a loop where four small cars wait, each carrying one tool.

Section

Basics

How AI agents work, from the ground up: what an agent is, the loop at its center, calling a model from Go, tool calling, what each turn costs, and how a model picks its next token.

  1. Getting set up Go 1.27, the companion code, offline and live runs, and the newer Go features the code uses.
  2. What an agent is What makes a program an agent, followed through one run that fixes a failing test.
  3. The agent loop The whole agent loop in about 30 lines of Go, read stage by stage.
  4. Your first model call An API key, one request with curl, and every part of the reply, including what it cost.
  5. Messages and roles The four roles in a conversation, the Go type that holds them, and how to write a system prompt.
  6. Calling a model from Go A chat completions client in standard-library Go, with deadlines, error checks, and finish reasons.
  7. Common first errors A missing key, no credit, a bad model ID, rate limits, cut-off replies, and two Go traps.
  8. Tool calling on the wire A tool call as raw JSON, how a Go client sends and reads one, and the rules that keep it valid.
  9. Tokens, cost, and context How an agent’s requests grow each turn, what a run costs, and why the context window misleads.
  10. How models pick the next token A toy model in Go shows why answers vary, what temperature does, and why a tool call is text.
  11. Choosing a model Tool support, cost per finished task, reasoning models, local models, and how to compare.

Start here if you are new to agents or to LLM APIs. The pages build on each other in the order listed, and each one points at runnable Go code.