Building an Agent Loop You Can Trust
Agent demos look magical. Reliable agents look boring: tight loops, tool contracts, and hard stop conditions.
An agent is not a personality. It is a loop: observe → decide → act → observe again — until a stop condition.
Keep the loop small
Start with one tool and one success criterion. Expand only when that loop is stable.
while not done:
plan = model(state)
result = tool(plan)
state = update(state, result)
if should_stop(state): break
Tool contracts beat clever reasoning
Define each tool with:
- Clear input schema
- Deterministic side effects where possible
- Explicit error returns the model can read
If the tool lies, the agent will too.
Stop conditions are a feature
Without them, agents burn tokens and dig holes. Cap:
- Max steps
- Max tool failures
- Wall-clock time
Observe everything
Log every thought, tool call, and result. Debugging agents without traces is archaeology.