Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 separates host policy, per-operation approval, and resource guarantees. Later chapters will add steering, persistence, and compaction. Each layer should solve 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.12 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

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 and 4 extend that fixture with context, discovery, and stream handling. 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.

Code listings are included from the runnable sources so the book and examples share the same implementation. The teaching agent is intentionally smaller than Wisp; each chapter names the guarantees it has yet to earn.

Curriculum

Only chapters marked available have been written. Planned chapters describe the intended progression, not capabilities already present in the checkpoints.

ChapterWhat you will build or understandWisp connectionStatus
1. The smallest coding agentThe model/action/observation cycle, correlated tool results, explicit stoppingrun_agent_loopAvailable
2. Reading, editing, and testing codeValidated tool dispatch, exact-match edits, test feedback, output limitsBuilt-in tools and typed resultsAvailable
3. Giving the model useful contextInstruction assembly, repository discovery, selecting relevant informationPrompt builder, project context, skillsAvailable
4. Talking to models reliablyA live provider adapter, streaming, completion signals, safe retriesProvider adapters and lifecycle validationAvailable
5. Controlling side effectsExposure, policy, approval, trust, filesystem and process boundariesTool policies, secure files, process supervisorAvailable
6. Keeping the user in controlSteering, follow-ups, cancellation, request boundariesAgentHarnessPlanned
7. Remembering and resuming workTranscript versus audit log, durable writes, replay, repair, branchingCodingSession and JSONL sessionsPlanned
8. Working within a context windowBudgets, retained history, compaction, overflow recoveryContext estimates and session-owned compactionPlanned
9. One engine, multiple interfacesCommands, events, presentation state, transport compatibilityCommand host, SDK, CLI, Rust TUIPlanned
10. Knowing whether it worksFault injection, task evaluation, latency, cost, profilingReliability tests and benchmark evidencePlanned

Context construction comes before compaction; replay comes before replacing the history that gets replayed. Tests accompany each mechanism, while chapter 10 will distinguish runtime correctness from live-model task success.

Wisp case studies

These deeper readings preserve implementation detail without making it a prerequisite for the first working agent:

Begin with Chapter 1: The smallest coding agent.