A coding agent is, at its core, a short loop. Building a small one is the best way to understand how larger tools behave.
The loop in plain terms
- Send the task and the available tool descriptions to the model.
- If the model requests a tool, validate the request and run it.
- Add the result to the conversation.
- Repeat until the model gives a final answer or a limit is reached.
Why the bounds matter
Without limits, an agent can loop forever or burn through budget. Set a maximum number of steps, a time limit, and a cap on output size. When a limit is hit, stop and report clearly.
Validate every tool call
Models produce malformed or unexpected arguments. Check names and parameters against the tool schema, and return a clear error message so the model can try again.
Keep tools narrow
A tool that reads a file is safer and more predictable than one that runs arbitrary commands. Provide the smallest set of tools that gets the job done.
Handle failure explicitly
Record why each run ended: success, limit reached, tool error, or refusal. This makes failures easier to analyze.
Log everything
Store each step, tool call, and result. A readable transcript is your main debugging tool.
Takeaway
A well-bounded loop with narrow tools, validated inputs, and complete logs is more dependable than a clever but open-ended agent.
Continue with the book
Explore the full treatment, worked examples, and exercises in Agentic iOS App Development.
Adapted from Agentic iOS App Development, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.
