Browse documentation
Learn
On this page

Crafting Coding Agents

Learn the engineering decisions involved in building a coding agent, then examine Wisp as a concrete, evolving answer to those decisions.

A model can suggest a fix. A coding agent must find the relevant code, make a change, check it, and keep the developer informed and in control. Doing that well requires more than a model API and a shell command: someone must own the conversation, bound tool output, handle interruption, and decide what survives a restart.

This book builds those mechanisms one at a time. Wisp is our production case study. Its choices have benefits and costs; they are examples to reason about, not requirements for every agent you build.

Who this is for

You should be comfortable with Python functions, dataclasses, exceptions, and basic async/await. You do not need to know Wisp or any agent framework. We introduce model/tool vocabulary before using it.

If you want to run Wisp rather than build an agent, start with the quickstart. The architecture guide is a companion for navigating Wisp’s current source.

One agent, one continuing task

Our running task is small: fix a broken addition function in a fixture project. The small bug lets us inspect the whole interaction instead of spending a chapter understanding the application being edited.

We begin with an in-memory file and a model/tool loop. Next we give that same loop a disposable directory, an exact-match editor, and a test runner. Chapter 3 adds request context and on-demand file discovery. Chapter 4 introduces streaming, failure replays, and an opt-in live provider. Chapter 5 closes Part I by separating host policy, per-operation approval, and filesystem/process guarantees. Each layer solves a problem the previous version makes visible.

The first three checkpoints use a scripted provider: a fixed sequence of model decisions with checks on the observations between them. This makes the examples repeatable and runnable without credentials. It demonstrates execution mechanics, not a model discovering a solution or evidence of coding ability. Chapter 4 adds authored provider-event replays plus an optional live adapter; the offline path remains the default.

Run the available checkpoints

From a source checkout with Python 3.11 or newer:

python3 -m examples.crafting_agents.checkpoint_01
python3 -m examples.crafting_agents.checkpoint_02
python3 -m examples.crafting_agents.checkpoint_02 --deny-edits
python3 -m examples.crafting_agents.checkpoint_03
python3 -m examples.crafting_agents.checkpoint_04
python3 -m examples.crafting_agents.checkpoint_05
python3 -m examples.crafting_agents.checkpoint_05 --scenario stale-input

These commands use only the Python standard library. Chapter 1 reads an in-memory fixture. Chapter 2 creates and removes a temporary directory; it does not edit your checkout. Chapters 3–5 extend that fixture with context, discovery, stream handling, and host-side approval boundaries (the final --scenario stale-input experiment shows how the host blocks an approved edit when the file changes during approval). Their test tool executes the supplied fixture with the current Python interpreter. The separate live command in chapter 4 requires the OpenAI SDK and credentials; live edits and test execution require an explicit opt-in.

How to read a chapter

Each chapter follows the same progression:

  1. Encounter a problem. What can our agent not yet do reliably?
  2. Build the mechanism. Add a small, runnable capability to the teaching agent.
  3. Inspect the trace. See the requests, observations, and resulting state.
  4. Break an assumption. Try a failure with an observable outcome.
  5. Study Wisp’s choice. Connect the mechanism to implementation entry points, costs, alternatives, and tests.
  6. Complete a checkpoint. Make a focused change and verify its behavior.

Chapter code listings are included from the runnable sources so the book and examples share the same implementation. Pages that explain Wisp’s own source, such as Inside Wisp’s built-in tools, use shortened excerpts instead and say so at the top. The teaching agent is intentionally smaller than Wisp; each chapter names the guarantees it has yet to earn.

Part I — Build a tool-using agent

Part I is a complete, five-chapter arc that takes a coding agent from a single-file loop to controlled, verified side effects:

ChapterWhat you buildWisp connection
1. The smallest coding agentThe model/action/observation cycle, correlated tool results, explicit stoppingrun_agent_loop
2. Reading, editing, and testing codeValidated tool dispatch, exact-match edits, test feedback, output limits (companion: Inside Wisp’s built-in tools)Built-in tools and typed results
3. Giving the model useful contextInstruction assembly, repository discovery, selecting relevant informationPrompt builder, project context, skills
4. Talking to models reliablyA live provider adapter, streaming, completion signals, safe retriesProvider adapters and lifecycle validation
5. Controlling side effectsExposure, policy, approval, trust, filesystem and process boundariesTool policies, secure files, process supervisor

Wisp case studies

After Part I—or alongside Chapter 2 and Chapter 5—these case studies examine how Wisp handles production boundaries and performance trade-offs:

Future Part II chapters are scoped around runtime control and durability: live steering and cancellation (AgentHarness), append-only JSONL sessions and replay (CodingSession), context compaction, multi-interface RPC, and task evaluation. To inspect how Wisp implements and verifies those layers today, read Agent runtime, Rust TUI boundary, and Evals and reliability.

Begin with Chapter 1: The smallest coding agent.