TimoBy Amotion AI

Timo LabsGuides

A production Claude tool loop validates every call, limits retries and records every action.

The application owns execution. Claude chooses a tool and supplies structured arguments; the application validates permission and business rules, executes the call, returns a tool result and stops when the outcome or budget is reached.

Treat each tool call as an untrusted action request. Validate schema, identity, permission, business rules and idempotency before execution. Return structured results and cap the loop by turns, time, cost and action risk.

Production loop

1

Model requests a tool

Claude returns a structured tool-use block containing the tool name and arguments.

2

Application validates the request

Check the schema, caller identity, permissions, entity state, amount limits and approval requirements.

3

Executor runs once

Use an idempotency key so retries cannot duplicate a payment, order or message.

4

Application returns a tool result

Return a typed success or error with safe fields the model can use for the next step.

5

Loop stops at a defined boundary

Stop on completed outcome, user approval request, terminal error or exhausted budget.

Worked example: approve a supplier invoice

A fictional accounts-payable agent receives “Approve invoice INV-2048 for $12,400.” It can read invoices and request approval. It cannot release payment.

Tool contract

name: request_invoice_approval

required: invoice_id, amount_usd, cost_centre, evidence_ids

server checks: caller role, invoice status, amount match, vendor match, duplicate request

side effect: create approval task only

StageInput or stateControlOutcome
1. ReadINV-2048 shows $12,400 and vendor V-77Read-only invoice toolEvidence IDs E1 and E2 returned
2. RequestClaude asks for approval with matching valuesStrict schema accepts shapeRequest moves to business validation
3. ValidateInvoice is open; amount and vendor matchPolicy requires finance approval above $10,000Human approval task created
4. ResumeFinance approver accepts task A-901Signed approval token linked to invoiceAgent reports approved for downstream payment
5. StopPayment tool is absent from the agent allowlistLeast privilegeNo payment can be released by this loop

Error path

If Claude requests $12,450, the application returns a typed AMOUNT_MISMATCH error with the recorded amount of $12,400. Claude may repair the request once. A second mismatch stops the loop and routes the case to a person.

Controls at each boundary

BoundaryRequired controlWhat it prevents
Tool definitionSpecific name, description, strict schema and narrow purposeAmbiguous selection and malformed arguments
AuthorisationCaller identity, role and task-scoped allowlistCapability escalation
Business validationLive entity, state, limits and policy checksValid JSON that requests an invalid action
ExecutionIdempotency key, timeout and transaction boundaryDuplicate or partial side effects
Error handlingTyped recoverable and terminal errorsBlind retries and invented fixes
Loop budgetMaximum turns, tool calls, elapsed time and costRunaway loops
TraceModel version, inputs, calls, results and approvalsUnexplained production actions

Stop conditions belong in code

Public sources

Related Timo Labs guides

Prepare for Developer Foundations

CCDV-F is the certification track for engineers building Claude applications and agents.

View CCDV-F