Everyone reaches for the SDK's tool runner because it hides the agentic loop. I wrote the loop by hand instead, for a small tool that edits files based on instructions. It was more code, and it taught me exactly what an agent is doing under the hood, which paid off the first time I needed human approval before a destructive action. Here is the manual loop, and what controlling it directly buys you.
What the loop actually is
An "agent" sounds mysterious. It is a while loop. The model responds, and either it is done (end_turn) or it wants to call a tool (tool_use). If it wants a tool, you run the tool, feed the result back, and call the model again. Repeat until done.
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();






