Guide · Agent Architecture · Updated Nov 2026

Designing Reliable Tool-Use Loops

Most agent failures happen at tool boundaries—ambiguous parameter descriptions, unbounded outputs that flood the context window, or silent partial writes. Treating tools like typed RPC contracts fixes the majority of flakes.

1. Narrow, Self-Documenting Schemas

Prefer three focused tools over one Swiss-army tool with fifteen optional flags. Include units, accepted formats, and side-effect notes directly in each field description.

2. Actionable Error Payloads

{
  "ok": false,
  "error": "line_range_out_of_bounds",
  "detail": "Requested lines 400-450, but file has 284 lines.",
  "hint": "Call read_file with end_line <= 284."
}

Returning the exact constraint violation lets the model self-correct on the next turn instead of retrying identical broken arguments.

3. Truncate Large Outputs Deterministically

Cap raw command stdout and include head + tail lines along with a pointer to a saved log file. Never let a single verbose build dump wipe out earlier architectural decisions.

Next: Context Hygiene & Evals →