Autonomous AI agents: how they work and where to limit them
What an autonomous AI agent is, how it differs from a scripted LLM workflow, and how to scope permissions, add approvals and test it before trusting it.
“Autonomous agent” gets used for almost anything that puts a language model next to a tool. That makes it hard to decide how much to trust one. This explainer sticks to what the vendors who build agent tooling actually document: what separates an agent from a scripted workflow, what the agent loop looks like, how to limit what an agent can do, where it tends to go wrong and how to test it. Sources are Anthropic’s engineering posts, the OpenAI Agents SDK docs, Claude Code’s permissions docs and the OWASP entry on excessive agency, all linked below.
Workflows versus agents
Anthropic’s post Building effective agents groups everything under the label “agentic systems” and then splits them in two:
| Workflow | Agent | |
|---|---|---|
| Who decides the steps | Your code; the path is fixed in advance | The model, step by step, at run time |
| Good fit | Tasks that break cleanly into known subtasks | Open-ended problems where the step count can’t be predicted |
| Main strength | Predictable, consistent results | Flexibility |
| Main cost | Breaks on inputs the path didn’t foresee | Higher cost and errors that can compound |
The workflow patterns the post describes are prompt chaining (each call feeds the next, with optional checks between steps), routing (classify an input, then send it to a specialised handler), parallelization (split work into independent pieces, or run the same task several times and vote), orchestrator-workers (one model breaks a task down and hands pieces to others) and evaluator-optimizer (one call drafts, another critiques, repeat).
The practical advice is to pick the simplest option that works. Anthropic notes that agentic systems usually buy better results at the price of extra latency and cost, and that for many products a single well-prompted call with retrieval and a few examples is all you need. If you do reach for a framework, the post’s warning is that layers of abstraction can hide the actual prompts and responses, which makes debugging harder. For a side-by-side of the main frameworks, see our AI agent frameworks comparison.
The agent loop
Underneath, most agents are a loop: the model reads the task, either answers or asks for a tool call, your code runs the tool, the result goes back to the model, and it goes round again. Anthropic describes agents as models using tools in a loop based on feedback from their environment, and stresses that each step should get real feedback (a test result, a tool’s output) rather than the model’s own guess about progress.
The OpenAI Agents SDK spells the same loop out in its running agents docs. On each pass the runner calls the model and then:
- If the output counts as a final answer (text of the expected type, no tool calls), the run ends.
- If the model asks to hand off to another agent, the runner switches agent and loops again.
- If the model asks for tools, the runner executes them, adds the results and loops again.
- If the number of turns goes past
max_turns, it raisesMaxTurnsExceeded.
That last point matters for autonomy. A turn cap is the simplest stopping rule there is, and Anthropic also recommends a maximum iteration count as a way to keep control. You can switch the limit off in the SDK, but think twice before you do.
How much autonomy is wise
Autonomy is not a single switch. It is the sum of three things you control: which tools the agent can see, what permissions those tools carry, and which actions need a person to sign off. OWASP’s entry on excessive agency (LLM06) names the same three as root causes of damage: excessive functionality, excessive permissions and excessive autonomy.
Scope the tools and permissions
OWASP’s mitigations translate into a short checklist:
- Give the agent only the tools the job needs, and remove tools left over from experiments.
- Prefer narrow tools (“write this file”) over open-ended ones (“run any shell command”, “fetch any URL”).
- Connect tools to other systems with the least privilege that works. A recommendation agent that only reads a products table should not hold an account that can update or delete rows.
- Act as the user, not as a shared admin account, so an agent can only touch what that user could.
- Enforce authorization in the downstream system rather than trusting the model to decide what it is allowed to do.
Claude Code is a useful worked example of permission scoping. Its permissions docs describe allow, ask and deny rules, checked in that strict order of deny first, then ask, then allow, so a broad deny can’t be undone by a narrower allow. File reads in the working directory need no approval, while shell commands and web fetches prompt unless a rule covers them. The docs make one point that applies to any agent: the rules are enforced by the tool, not the model, so instructions in a prompt shape what the agent tries but don’t change what it is permitted to do. The most permissive mode, which skips prompts, is meant only for isolated containers or VMs.
Put people at the checkpoints that matter
Anthropic describes agents pausing for human input at checkpoints or when they get stuck. OWASP is more direct: high-impact actions should require a human’s approval before they run. In the OpenAI Agents SDK this is a per-tool setting. Here is the example from its human-in-the-loop guide:
from agents import Agent
from agents.decorators import tool
@tool(needs_approval=True)
async def cancel_order(order_id: int) -> str:
return f"Cancelled order {order_id}"
async def requires_review(_ctx, params, _call_id) -> bool:
return "refund" in params.get("subject", "").lower()
@tool(needs_approval=requires_review)
async def send_email(subject: str, body: str) -> str:
return f"Sent '{subject}'"
agent = Agent(
name="Support agent",
instructions="Handle tickets and ask for approval when needed.",
tools=[cancel_order, send_email],
)
When a gated tool is called, the run stops and returns the pending calls as interruptions. Your app shows them to a reviewer, records approve or reject on the saved run state, and resumes. If the approval function can’t parse the arguments, the SDK falls back to asking a human. Two details in those docs are easy to miss. An “always approve” decision can carry over to other shell or file-edit tools with the same name after a handoff, so per-call approvals are safer when agents have different permissions. And approval does not mean a tool runs exactly once: after a crash, resuming from an older snapshot can repeat an action such as a payment, so consequential tools need idempotency keys.
Guardrails are the automated counterpart. The SDK’s guardrails can check the user’s input, the final output, or each call to a specific tool, and a tripped guardrail stops the run with an exception. By default an input guardrail runs alongside the agent, which means tokens may already be spent and tools already called when it fires; blocking mode makes the agent wait for the check instead.
For how this division of labour between people and agents plays out in teams, see human-AI collaboration.
Where agents go wrong
- Compounding errors. Over many turns, an early mistake feeds every later step. Anthropic names this as the main risk of autonomy and recommends heavy testing in sandboxes with guardrails in place.
- Bad tool design. Anthropic says its SWE-bench agent needed more work on its tools than on its prompt. One fix was making a file tool demand absolute paths after the model kept getting relative ones wrong.
- Manipulated or confused output. OWASP lists hallucination and prompt injection, including injection relayed by another tool or a compromised peer agent, as triggers for harmful actions. Its example is an email assistant meant to summarise mail that also had a send function and got tricked into sending messages.
- Saying versus doing. An agent can report that a task is finished when it isn’t. Anthropic’s eval guidance separates the transcript from the outcome: a booking agent saying the flight is booked is not the same as a reservation existing in the database.
Logging, monitoring and rate limits won’t prevent these, OWASP notes, but they limit the damage and give you time to spot a problem.
Testing before you widen autonomy
Anthropic’s guide to agent evals is the most practical reference here. Its main points:
- Start small. A few dozen simple tasks drawn from real failures is a reasonable first suite.
- Write unambiguous tasks. If the grader expects something the task never asked for, the agent fails for reasons that aren’t its fault.
- Isolate trials. Each run should start from a clean environment so leftover files or cached data don’t skew results.
- Grade the result, not the route. Checking for an exact sequence of tool calls tends to punish valid approaches the designer didn’t expect.
- Mix graders. Code checks are fast and objective, model-based graders handle nuance but need calibrating against people, and human review is the gold standard but slow.
- Read transcripts. A failing score can come from a buggy grader as easily as from a bad agent.
The same guide separates capability evals (what can the agent do?) from regression evals (does it still do what it used to?), and two scoring views: pass@k, where at least one of k tries succeeds, and pass^k, where every one of k tries must succeed. For an agent that acts on customers’ behalf, consistency is the bar, so pass^k is the more honest number. If you are looking at agents that change their own behaviour over time, our piece on self-improving AI agents covers that next step, and it makes evals even more important.
A sensible path is to begin with a workflow, add an agent loop only where fixed paths keep failing, start it with read-only tools and approvals on anything that writes, and remove a checkpoint only once your evals show it is no longer catching problems.
Written by AI Agents Directory
Editorial team
Facts in this guide are checked against official documentation and repositories, which are linked in the article.