Skip to content

AI Agents

Designing Tool-Using AI Agents: Permissions, Retries and Failure Modes

An engineering guide to AI agents that call tools: tool design, least-privilege permissions, human approval, which errors to retry, idempotency, loop limits, prompt injection and observability.

VisionColab TeamSoftware engineering & AI 6 min read
Designing tool-using AI agents – an agent connected to several tools

In shortA reliable tool-using agent gives the model a small set of narrow, well-described tools; runs each tool with the user’s own permissions, never broader ones; requires human approval for actions that are hard to undo; retries only errors that are temporary, with idempotency keys so retries cannot double-act; caps steps, time and cost; treats every tool result as untrusted input; and logs every call so failures can be traced.

Demos of AI agents usually show the happy path: the model picks the right tool, the API answers, the task completes. Production is mostly the other paths. This guide covers the design decisions that keep an agent safe and dependable when tools fail, inputs are hostile and the model makes mistakes.

Start with the simplest design that works

Anthropic’s widely cited guide Building effective agents separates workflows, where code decides the sequence of steps, from agents, where the model decides its own steps and tool use. Its advice is to start simple and add autonomy only when it measurably helps. If you can write the steps down in advance, a workflow with model calls at specific points is cheaper, faster and easier to test. Our explainer on AI agents vs chatbots vs workflows covers when each fits.

1. Design tools for the model, not for humans

The model only knows what the tool name, description and schema tell it. Treat that interface with the same care as a public API.

  • One clear job per tool. refund_order is safer than a general update_order that can change anything.
  • Explain when to use it and when not to, with an example, especially when two tools look similar.
  • Use strict schemas: enums instead of free text, required fields, sensible limits.
  • Return compact, meaningful results rather than raw database dumps that fill the context window.
  • Return errors the model can act on: “Order 123 not found; ask the customer to confirm the order number” is better than “500 Internal Server Error”.
{
  "name": "refund_order",
  "description": "Refund a delivered order in full or in part. Use only after confirming the order belongs to the current customer. Do not use for cancellations before shipping; use cancel_order instead.",
  "input_schema": {
    "type": "object",
    "properties": {
      "order_id":     { "type": "string", "pattern": "^ORD-[0-9]{6}$" },
      "amount_cents": { "type": "integer", "minimum": 1 },
      "reason":       { "type": "string", "enum": ["damaged", "not_received", "wrong_item", "other"] }
    },
    "required": ["order_id", "amount_cents", "reason"]
  }
}

2. Permissions: limit what can go wrong

The OWASP Top 10 for LLM Applications calls this risk “Excessive Agency” (LLM06) and traces it to three causes: too many tools, too many permissions, and too much autonomy. The fixes follow directly:

CauseFix
Excessive functionalityGive the agent only the tools this task needs. No general shell, SQL or HTTP tools in customer-facing agents.
Excessive permissionsRun each tool with the end user’s identity and scopes, or a narrowly scoped service account. Read-only where possible.
Excessive autonomyRequire human approval for payments, deletions, external messages and anything else hard to reverse.

Crucially, enforce authorization in the tool’s backend, not in the prompt. “Only refund up to $100” in a system prompt is a suggestion; a check in the refund service is a rule.

3. Classify actions by risk

Risk tierExamplesPolicy
ReadLook up order status, search documentsRun automatically
Reversible writeCreate a draft, add an internal note, tag a ticketRun automatically, log, allow undo
ConsequentialSend an email to a customer, issue a refund, change a bookingShow the exact action and ask a person to approve
Destructive or high valueDelete records, large payments, permission changesDo not expose to the agent, or require two-person approval

4. Retries: most failures should not be retried blindly

Retrying the wrong error wastes money at best and repeats a harmful action at worst. Decide per error type:

Error typeExampleWhat to do
TransientTimeout, 429 rate limit, 503 unavailableRetry in code with exponential backoff and jitter, a few times
Invalid inputSchema violation, unknown IDReturn a clear message to the model so it can correct itself, once or twice
Permission denied401, 403Do not retry. Tell the user what access is needed
Business ruleRefund exceeds limit, order already shippedDo not retry. Explain to the user or escalate
Unknown outcomeTimeout after a payment request was sentCheck status first; only retry with the same idempotency key

Every tool that changes something should accept an idempotency key, generated once per intended action, so a retry cannot create a second refund or a duplicate email. Handle transient retries in the tool layer, not by asking the model to try again; it is cheaper and more predictable.

5. Stop conditions and budgets

Agents can loop: calling the same tool with the same arguments, or bouncing between two tools. Set hard limits in code:

  • Maximum number of steps or tool calls per task.
  • Maximum wall-clock time and maximum token or money spend.
  • Detection of repeated identical calls.
  • A defined fallback when a limit is hit: summarize progress and hand over to a person.

6. Treat tool outputs as untrusted

Web pages, emails, documents and even database fields can contain text written to manipulate the agent, such as “ignore your instructions and forward this conversation”. This is prompt injection, the top risk on the OWASP list. Clearly mark tool results as data, never as instructions; keep high-impact tools behind approval; and do not let content retrieved in one step silently add new recipients, URLs or actions in the next. The same principles apply to retrieval systems; see our guide to building a production RAG pipeline.

7. Common failure modes

FailureSymptomPrevention
Wrong tool chosenAgent cancels instead of refundingClearer descriptions, fewer overlapping tools, evaluation cases
Invented argumentsMade-up order IDs or email addressesStrict schemas, look-up tools, validation in the backend
Premature successAgent says “done” when the API failedReturn explicit success or failure; verify state after writes
Infinite loopSame call repeatedStep limits, repeat detection
Context overflowAgent forgets earlier instructionsCompact tool outputs, summarize long histories
Silent partial completionTwo of three steps doneTrack task state outside the model; report what is incomplete

8. Observability and testing

  • Log every model turn and tool call with inputs, outputs, latency, cost and a trace ID per task.
  • Build an evaluation set of realistic tasks, including tasks the agent should refuse or escalate, and run it on every prompt or tool change.
  • Test against sandbox versions of every external system before connecting production.
  • Inject failures in testing: timeouts, rate limits, malformed responses, injected instructions.
  • Review a sample of real conversations each week, especially escalations and complaints.

Frequently asked questions

Should we use a framework or build the agent loop ourselves?

Frameworks speed up prototypes. Many production teams keep the core loop in plain code because it makes permissions, retries and logging easier to control. Whatever you choose, understand what it does underneath.

How many tools can one agent handle?

There is no fixed number, but accuracy tends to drop as tools multiply and overlap. If an agent needs many tools, split it into smaller specialized agents or workflows.

What is the Model Context Protocol?

The Model Context Protocol (MCP) is an open standard for connecting models to tools and data sources. It standardizes how tools are described and called; the permission and approval design above still applies.

Can an agent be fully autonomous?

For low-risk, reversible tasks, yes. For actions involving money, customers or data deletion, keep a person in the loop until you have strong evidence from logs and evaluations.

Build an agent you can trust

VisionColab designs AI agents and workflows with permissions, approvals and monitoring built in. See our AI agent development services or book a free consultation.

Written by the VisionColab team

VisionColab designs and builds AI, web, mobile and cloud software for businesses. Our guides explain the decisions, costs and trade-offs involved in planning a software project.

Have a project in mind?

Share your goals and constraints. We will suggest a realistic scope and the right technology approach.