The tutorial version of an agent is ten lines: call the model, run whatever tools it asks for, append the results, repeat until it stops. That loop is fine in a notebook. Inside a product it is a while (true) that spends money on every pass, can take actions on a customer's data, and has no idea that a person is waiting for an answer.
Most of the code I write for an agent feature is not the loop. It is the fence around it. This post walks through that fence using a teaching example: an assistant inside a roofing company's scheduling app that can find a job, look up open inspection slots and move an inspection when a customer asks.
Every exit from the loop is a decision I made, not one the model made.
The code uses the Anthropic TypeScript SDK with a hand-written loop. The SDK also ships a tool runner that drives the loop for you and has hooks for approvals.…