November 12, 2026 

Best Practices for Building Reliable Agents

AI agent workflow reviewed with a reliability checklist and validated components

Executive summary

  • Smarter models won't make your agents reliable. Recent capability gains produced only small reliability improvements across 15 models (Rabanser et al., ICML 2026), and more capable models are better at working around their constraints (Smarter Models Make Your Agents Less Safe). Reliability has to be built into the system around the model.
  • Most failures start in the code. Vague tools, missing timeouts, unbounded loops and broad permissions cause many of the failures teams later see in production.
  • Ten practices prevent them. Each one maps to rules you can apply while coding and test on every commit.

What are the best practices for building reliable agents?

The best practices for building reliable agents are mostly about what goes into the code: clear tool definitions, timeouts, bounded loops, structured errors and the least access the task needs. Most teams find out their agent isn't reliable the same way. It works in the demo, then loops, calls the wrong tool or does something it was never supposed to do in production. A newer model release won't close that gap on its own.

The ten practices below come from the open Agent Reliability Rules, with an example rule for each. For the full definition of agent reliability, see our guide.

PracticeWhat reliable agents do
1. Clear tool definitionsDescribe every tool specifically and type its parameters
2. TimeoutsPut a timeout on every network call
3. Loop and turn limitsCap turns and iterations
4. Structured errorsReturn errors the model can act on
5. Idempotent actionsMake data-changing tools safe to retry
6. Least privilegeGrant only the tools and permissions the task needs
7. Guardrails on risky toolsCheck inputs before shell, file and network actions
8. Safe paths and URLsValidate file paths and URLs from the model
9. Agent instructions in the repoShip an AGENTS.md or CLAUDE.md
10. TracingEmit traces that show what happened and why

1. Clear tool definitions

The model picks tools based on their descriptions, so vague descriptions lead to inconsistent choices. A Queen's University audit of 856 MCP tools found 97.1% had at least one description flaw, and rewriting descriptions raised task success by a median of about 6 percentage points across four models. For GPT-4.1, success rose from 18% to 29% (Hasan et al., 2026). A good description reads like "Refund an order by ID. Max $500. Fails if the order is older than 90 days." A bad one reads "Handles refunds." Example rule: CSDK-001, tool has no description.

2. Timeouts

One slow API can stall a whole run. ReliabilityBench found rate limiting was the most damaging fault it injected into agents (Gupta, 2026). Set a timeout on every network call and decide what the agent should do when it fires. Example rule: CSDK-003, network call has no timeout.

3. Loop and turn limits

Without a cap, an agent that gets stuck keeps trying, and your bill grows with it. Step repetition showed up in nearly 16% of multi-agent failure traces in UC Berkeley's MAST study (Cemri et al., NeurIPS 2025). Set an explicit max-turns or max-iterations limit on every agent. Example rule: LC-102, AgentExecutor has no max_iterations limit.

4. Structured errors

A raw stack trace tells the model nothing useful. A structured error, such as "order not found" or "rate limited, retry in 30 seconds", lets the agent recover or stop cleanly instead of guessing. Example rule: CSDK-005, tool raises exceptions without a structured error contract.

5. Idempotent actions

Agents retry. If a tool that charges a card or sends an email runs twice, the customer pays twice or gets two emails. An idempotency key makes a retry safe. Example rule: CSDK-006, mutating tool has no idempotency key.

6. Least privilege

An agent with fewer tools has fewer ways to go wrong, and it behaves more consistently. In April 2026, a coding agent used a root-level API token it found in its environment to delete a company's production data and backups in about nine seconds (The Register). A support bot doesn't need a shell, and nothing should run with bypassPermissions. The same goes for network access: the Agent Network Access Probe records which destinations a tool actually contacts in an OpenShell or Docker sandbox and drafts a policy that allows only those. Example rule: CSDK-103, permissionMode set to bypassPermissions.

7. Guardrails on risky tools

Shell, file and network tools can do the most damage when the agent is wrong or manipulated. Put input checks or approval callbacks in front of them. Example rule: OAI-101, agent has no input_guardrails and wires shell or file tools.

8. Safe paths and URLs

When the model chooses a file path or URL, validate it before use. Otherwise a bad value can read the wrong file or call an internal service. Example rule: CSDK-004, path parameter used in I/O without validation.

9. Agent instructions in the repo

Most agent code is now written with help from a coding agent. An AGENTS.md or CLAUDE.md tells that coding agent how your project works, so its output is consistent from the start. Example rule: CSDK-203, repo ships agent code without an AGENTS.md or CLAUDE.md.

10. Tracing

When an agent fails, you need to see what it did and why. Configure tracing deliberately instead of relying on defaults, and send traces to the observability tool your team already uses. Example rule: OAI-201, project uses default OpenAI tracing.

How do you apply these practices automatically?

You apply these practices automatically by giving them to your coding agent while it writes code, then testing for them on every commit.

While you code: Forge agent reliability skills generate a skill for your repo from the rules for the agent SDKs you use. Claude Code and Cursor read it and get tool descriptions, timeouts, loop limits and permissions right the first time.

Before you ship: the open-source Agent Reliability Analyzer tests for all ten practices across nine agent SDKs with deterministic static analysis. It runs locally with no LLM and no code upload. For why this works best before deployment, see Reliable Agents Start Before Runtime.

brew install trustabl/tap/trustabl
trustabl scan .

Add the GitHub Action and every pull request gets a reliability check. Once agents are live, track them with the agent reliability metrics that matter, and put the production controls for reliable agents in place.

FAQ

What are reliable agents?

Reliable agents consistently complete their intended task within the authority they've been given, hold up when inputs change or tools fail, and fail in ways that are visible, contained and recoverable.

Which best practice should I start with?

Start with clear tool definitions, timeouts and loop limits. They are the cheapest to fix, they remove the most common failure causes, and a static analyzer can check all three before you ship.

What is Trustabl Forge?

Trustabl Forge generates a reliability skill for coding agents. It reads a repository's dependencies, identifies the agent SDKs in use and writes a SKILL.md from the matching Trustabl rules, so Claude Code and Cursor apply those rules while they write agent code.


Share Now!

Like what you see? Share it with your network.

Related Blogs

Agent Reliability Resources

Agent Reliability Engineering
Explore the open discipline for reliable, governable autonomous AI agents.
Visit ARE →
Agent Reliability Engineering Tools
Explore Trustabl's open-source agent reliability tools on GitHub.
View Tools →
downloadchevron-down