ai

Agentic Loops and Agent Graphs: Security Risks You Need to Know

Most AI agent security advice focuses on the model. But the real risks come from the architecture choices you make as a developer: whether to use an agentic loop or a multi-agent graph. Here's what changes when you do.

Most of the conversation around AI agent security focuses on the model: is it aligned, is it hallucinating, and is it safe? But the risks that actually determine blast radius are not about the model. They're about the architecture around it.

Two choices in particular change your security surface: whether your agent runs in a loop, and whether it uses a graph. Neither is inherently dangerous. But both are frequently added without understanding what they unlock for an attacker.

Here's what they are, whether you actually need them, and what changes when you use them.

What a Loop Actually Is

An agentic loop is the iterative execution cycle that separates an AI agent from a standard LLM call. Instead of one prompt in, one response out, the agent cycles: think, use a tool, observe the result, think again, and repeat until done.

Simon Willison's one-sentence definition is hard to beat: "Something that runs tools in a loop to achieve a goal." The loop is what makes an agent capable of multi-step tasks: searching the web, writing code, running tests, and filing a ticket, all in sequence.

What an Agent Graph Actually Is

An agent graph is a multi-agent system where agents are nodes and communication or delegation relationships are edges. One orchestrator agent receives a task, breaks it down, delegates to specialist sub-agents, and collects their outputs. Frameworks like LangGraph model this pattern explicitly.

Do You Actually Need Them?

Often no.

If you can fit the relevant data into a single call, a loop just adds latency, cost, and failure modes. Models with large context windows can handle a lot without iteration. Extended thinking models go further, they can reason iteratively inside the model, so you get multi-step reasoning without orchestrating a loop yourself.

Multi-agent graphs are the easiest to over-engineer. The data suggests they help when tasks are genuinely parallelizable and hurt on sequential tasks. Most tasks are sequential.

Us developers have a bias toward complex architectures because they're interesting to build. The boring answer, one well-structured LLM call with clean inputs, solves more than it gets credit for.

That said, loops and graphs are genuinely necessary for real-world agentic systems. The question is whether you're using them because the task requires it, and whether you understand what they do to your security model when you do.

How Loops Change Your Security Surface

The loop's value is autonomy which is what makes it dangerous.

Prompt injection scales with iterations. In a single-turn LLM call, a malicious payload in the input can redirect that one response. In a loop, the agent reads from external sources (websites, documents, and API responses) and feeds those results back into context every iteration. Each tool call is an opportunity for attacker-controlled text to re-enter the agent's reasoning.

Irreversible actions compound. A loop that sends an email, posts a message, makes an API call, or submits a form does so before any human sees the full execution trace. By the time you notice something is wrong, several of those actions can't be undone.

Accumulated context is an attack surface. A false premise established early in a long loop persists. The agent carries it forward and acts on it for the rest of the session. This is distinct from a single-turn injection: it's slow, quiet, and compounds across reasoning steps.

How Graphs Change Your Security Surface

Agent graphs introduce a different class of problems.

Multi-agent graphs have trust boundary problems. When agent A's output becomes agent B's input, compromising A compromises everything downstream. A 2024 paper, "Prompt Infection: LLM-to-LLM Prompt Injection within Multi-Agent Systems" demonstrated that a single injected prompt can self-replicate across a network of connected agents: each infected agent executes the attacker's instructions and propagates the malicious prompt to the next one.

What to Do About It

Contain the loop. Set hard step budgets and time limits. Make "ask the user" a first-class outcome rather than a fallback. Identify the irreversible actions in your agent's tool set and add explicit approval gates before them. CIBA-based asynchronous authorization is one pattern for this: the agent can't proceed on a high-impact action until the user approves it on a separate trusted device, with a binding message that says exactly what they're approving.

Scope tools to the task. The blast radius of a successful injection is proportional to what the agent is allowed to do. Task-based authorization (where permissions are scoped to a short-lived task ID and deleted when the task completes) limits how far any single compromise can reach. An agent that only holds the permissions it needs for the current task can't be manipulated into using permissions it shouldn't have.

Treat tool outputs as untrusted. Anything the agent reads from an external source during a loop iteration should be validated before it re-enters context. This is hard because feeding observations back into reasoning is the whole point of a loop. But it's where injection enters, so it's where validation needs to happen.

Treat multi-agent delegation as a trust boundary. Don't inherit permissions from orchestrator to sub-agent without explicit scoping. Validate that agent-to-agent messages come from where they claim. Log the full delegation chain. If you can't audit what one agent told another, you can't investigate a compromise.

The Short Version

Loops make agents capable of multi-step work. Agent graphs let that work scale across multiple specialized agents. Both expand what a single malicious input can do, in specific, nameable ways. Prompt injection is a problem that we might not fix 100% but how much damage a successful injection can do is almost entirely determined by your architecture, not the model.

About the author

Carla Urrea Stabile

Carla Urrea Stabile

Staff Developer Advocate

I've been working as a software engineer since 2014, particularly as a backend engineer and doing system design. I consider myself a language-agnostic developer but if I had to choose, I like to work with Ruby and Python.

After realizing how fun it was to create content and share experiences with the developer community I made the switch to Developer Advocacy. I like to learn and work with new technologies.

When I'm not coding or creating content you could probably find me going on a bike ride, hiking, or just hanging out with my dog, Dasha.

View profile