Reliable AI agent tool calling depends less on giving a model more tools and more on designing clear boundaries around planning, permissions, validation, execution, and recovery. This checklist explains how to build an LLM agent workflow that selects tools deliberately, handles failed or duplicate calls, preserves state, and asks for human approval when the consequences require it.
Overview
An AI agent is a software system that uses a language model to decide what to do next, often by selecting from tools such as search, database queries, calculators, ticketing systems, or deployment APIs. The model may propose a tool call, but your application should remain responsible for validating the request, enforcing permissions, executing the action, and recording the result.
A dependable function-calling workflow usually separates five concerns:
- Intent and routing: determine whether the request needs a tool, a response from existing context, or clarification.
- Planning: break a multi-step request into explicit, bounded actions rather than allowing an open-ended loop.
- Validation and authorization: check arguments, user permissions, resource scope, and approval requirements before execution.
- Execution: call the tool with timeouts, idempotency controls, logging, and a defined error contract.
- Recovery: classify the failure, preserve useful state, retry only when safe, and stop when the agent cannot proceed reliably.
For implementation details, pair this guide with a structured outputs and JSON Schema guide, especially when tool arguments must be machine-validated. Treat the model as a planner or decision component—not as an authority that can bypass application controls.
Choose an architecture deliberately
| Pattern | Best fit | Strength | Primary risk |
|---|---|---|---|
| Single agent | Small tool set and short tasks | Simple state and fewer coordination layers | Tool confusion as capabilities grow |
| Router | Distinct request categories | Directs work to a specialized path | Misrouting can prevent the right workflow from starting |
| Supervisor | Several specialist agents or domains | Central coordination and delegation | More model calls, state complexity, and failure points |
| Workflow-based | Predictable, consequential, or auditable tasks | Explicit transitions, approvals, and recovery paths | Requires more upfront design and maintenance |
Start with the least complex design that satisfies the task. A fixed workflow is often preferable when the sequence, permissions, and outcomes are known in advance. Use broader agent autonomy only where the variation in user requests justifies it.
Checklist by scenario
When defining a new tool
- Give the tool one narrow, observable responsibility and a name that describes an action rather than an outcome.
- Define every argument with a type, description, allowed values, format, and whether it is required.
- Use restrictive schemas. Prefer an enumeration of permitted values to a free-form string when the domain is known.
- Separate read operations from write operations. The agent should not need broad permissions to answer a question.
- Document side effects, expected latency, failure modes, and whether the operation is safe to retry.
- Return structured results with a stable status, human-readable message, and machine-readable fields.
A reusable tool-definition template can look like this:
{
"name": "lookup_order_status",
"description": "Read the status of one order for the authenticated customer.",
"input_schema": {
"type": "object",
"properties": {
"order_id": { "type": "string", "pattern": "^ORD-[0-9]+$" }
},
"required": ["order_id"],
"additionalProperties": false
},
"risk": "read",
"retry_policy": "safe_to_retry"
}Adapt the exact field names to the model or framework you use. The important properties are a precise contract, limited inputs, explicit risk, and a known retry policy.
When routing a request
- Classify the request as answer-only, retrieval, read action, write action, or unsupported.
- Check whether the user has supplied enough information. Ask a clarifying question instead of allowing the model to guess an identifier, amount, recipient, or scope.
- Expose only the tools relevant to the current task where your integration supports tool filtering.
- Set a maximum number of tool calls, planning steps, or elapsed time for one run.
- Keep the original request, routing decision, and selected tool visible in trace data for later review.
When executing a single tool call
- Parse the model output using the provider's supported tool-calling format rather than extracting arguments from prose.
- Validate the arguments against a schema and apply server-side authorization independently of the model.
- Confirm that resource ownership, tenant boundaries, and requested scope match the authenticated user.
- Use an idempotency key for operations that create, send, charge, publish, or otherwise change state.
- Apply a timeout and return a bounded error. Do not leave the agent waiting indefinitely.
- Record the tool name, validated arguments or a redacted equivalent, request identifier, result status, and latency.
When planning multiple steps
- Represent the plan as explicit steps with dependencies, expected inputs, and completion criteria.
- Persist state outside the model context so a retry or handoff does not depend on an untrusted conversation alone.
- Mark each step as pending, running, succeeded, failed, skipped, or awaiting approval.
- Allow parallel execution only for independent, read-only operations. Serialize steps that affect the same resource.
- Re-check permissions and important facts at execution time, not only during planning.
When a tool call fails
- Classify the error as invalid arguments, authentication, authorization, not found, rate limit, timeout, transient service failure, or unknown.
- For invalid arguments, return the validation feedback to a bounded correction step or ask the user for missing information.
- Retry only errors that are plausibly transient and only when the operation is safe or protected by idempotency.
- Do not retry authorization failures, rejected business rules, or malformed requests without changing the cause.
- After the retry budget is exhausted, stop with a clear status and a human-actionable explanation.
For queues, concurrency limits, and retry design across many tasks, see the batch LLM processing guide.
When human approval is required
- Define approval thresholds before implementation, based on action type, data sensitivity, financial or operational impact, and reversibility.
- Show the approver the intended action, validated parameters, affected resources, and relevant evidence.
- Expire stale approvals and bind an approval to one specific action or plan version.
- Record who approved, what changed after approval, and whether execution matched the approved request.
- Provide a cancel or rollback path where the underlying system supports one.
What to double-check
Permissions and security
Tool access should follow least privilege. Keep secrets, tokens, and privileged operations outside prompts and model-visible text whenever possible. Use the application identity and authorization layer to decide what can happen. Review external content as untrusted input: retrieved pages, documents, emails, and tool results can contain instructions that should not override system controls. The prompt injection defense guide provides a focused review for this risk.
State and context
Decide what belongs in durable state, short-term working memory, and the final user response. Store identifiers and step status in structured records rather than relying on the model to remember them. Keep tool results concise and scoped to the next decision. If retrieval supports the workflow, test chunking and retrieval quality separately using the RAG tuning guide.
Evaluation and observability
Test more than whether the model selected the expected tool. Include cases for missing fields, ambiguous requests, unauthorized resources, duplicate requests, stale data, tool timeouts, malformed results, prompt injection, and partial completion. Track success by workflow outcome, not by model confidence or fluent explanations. A prompt test matrix can help compare models and prompt changes consistently; use the prompt testing playbook as a starting point.
Production readiness checklist
- Tool schemas reject unknown and out-of-range arguments.
- Server-side authorization is independent of model output.
- Read and write tools have different permissions and review paths.
- Timeouts, retry limits, concurrency limits, and cancellation are implemented.
- Duplicate calls are detected or made safe through idempotency.
- Every run has a correlation ID and an auditable state trail.
- Failures produce useful user-facing messages without exposing secrets or internal data.
- Evaluation cases cover normal, adversarial, and recovery scenarios.
- Model, framework, tool format, context limit, and parallel-call assumptions are documented.
Common mistakes
- Giving the agent too many tools: a large catalog increases ambiguity. Filter tools by route, user, task, or stage.
- Using descriptions as security controls: telling a model not to access a resource does not replace authorization checks.
- Retrying every failure: repeated writes can duplicate actions, while repeated permission errors add delay without improving the result.
- Allowing unbounded loops: set step, token, time, and cost limits, then fail safely when they are reached.
- Hiding partial completion: tell the user which steps succeeded, which failed, and what can be retried.
- Passing raw tool output back into the prompt: normalize, limit, and label results so external text cannot silently become instructions.
- Changing models without regression tests: tool-call syntax, supported features, context behavior, and output tendencies can vary. Review the model migration checklist before switching.
When to revisit
Review this architecture before adding a tool, changing a workflow, introducing a write action, or allowing the agent to operate across tenants or systems. Revisit it after a notable failure, especially a duplicate action, unauthorized access attempt, silent partial completion, or recovery loop that required manual intervention.
Plan a quarterly implementation review even when the workflow appears stable. Confirm the current model and framework tool-calling format, context limits, supported parallel calls, timeout behavior, permission patterns, and logging fields. Repeat the test matrix after prompt, schema, model, retrieval, or orchestration changes. Also review seasonal planning cycles and other periods when request volume, data freshness, or approval requirements change.
For the next implementation, take these actions in order: inventory each tool and its side effects; assign a risk and permission level; validate schemas with negative cases; define retry and idempotency behavior; write approval rules; model state transitions; then run failure-injection tests before exposing the workflow to production users. Keep the resulting checklist beside the code so future tool additions are reviewed as architecture changes, not merely prompt edits.