Set on_error: "return-to-model" when the model can recover from a tool failure. The error becomes a tool result and the agent can choose another action. Keep fail-run behavior for unsafe or unrecoverable operations.
Ruby consumes model streams through normal synchronous iteration. Use explicit timeouts for network and process tools, and avoid blocking lifecycle callbacks with slow persistence work.
Every pending call needs an approval, rejection, or externally supplied output keyed by its tool-call ID. Persist the complete returned run state before showing an approval UI.
Capture run ID, step index, request ID, provider, model, finish reason, tool-call ID, and stop reason. Prefer lifecycle hooks or DevTools to raw prompt logging.