---
title: Infinite Agentic Loops in LLM Systems
url: https://www.emergentmind.com/topics/infinite-agentic-loops-ials
type: topic
---

# Infinite Agentic Loops in LLM Systems

Infinite Agentic Loops (IALs) are failures of iterative large-language-model systems in which recursive feedback is not effectively bounded, so model calls, tool invocations, workflow transitions, or agent handoffs continue without a terminal halt. In Tacheny’s geometric formulation, the same phenomenon can be analyzed as a discrete dynamical system over text artifacts and semantic embeddings, where successive outputs define an agentic trajectory that may contract toward an attractor or diverge without cluster formation. Recent work therefore treats IALs at two closely related levels: as unbounded execution traces in agent frameworks, and as divergent semantic trajectories in iterative LLM transformations with no emergent bounded region [2607.01641] [2512.10350].

## 1. Formal scope and definitions

At the level of iterative text transformation, an agentic loop is modeled as a discrete dynamical system on the artifact space \(A\), the set of all text strings. With a fixed transformation \(F:A\to A\) induced by a prompt template and an LLM call, the loop evolves as
$$
a_{t+1}=F(a_t).
$$
In embedding space \(E\subset\mathbb{R}^d\), with normalized representation \(x_t=\psi(a_t)\), the update becomes
$$
x_{t+1}=f(x_t),
$$
and the resulting sequence \(T=\{x_0,x_1,\dots,x_T\}\subset E\) is the agentic trajectory. Pairwise displacements \(\|x_{t+1}-x_t\|_2\) and similarities \(s(x_t,x_{t+1})\) quantify instantaneous loop dynamics [2512.10350].

At the level of agent orchestration, one formalization takes \(A\) to be the finite set of agent or tool nodes in a multi-agent system and \(R\subseteq A\times A\) to be the routing relation. An execution trace is a sequence
$$
T=[a_0,a_1,a_2,\dots]
$$
such that \(\forall i:(a_i\to a_{i+1})\in R\). An IAL exists if \(T\) is infinite and no terminal node ever halts the sequence. In graph-theoretic terms, for the directed graph \(G=(A,R)\), an IAL exists iff \(G\) contains a directed cycle and the orchestrator has no external termination guard to break that cycle; equivalently,
$$
\text{IAL}\iff \exists v\in A \text{ such that } v\in \mathrm{Reach}_+(v).
$$
[2605.13848]

IAL-Scan generalizes this idea beyond explicit source-level loops by constructing an Agent IR and an Agentic Loop Dependence Graph (ALDG). In that framework, an IAL exists when a feedback-relevant strongly connected component contains costly operations or state growth and lacks an effective bound that semantically covers every cycle in the component. Formally, for a cycle \(L\),
$$
\exists L\subseteq V \text{ forming a cycle in } G_{\mathrm{cycle}},\quad
\mathrm{Cost}(L)\cup \mathrm{Growth}(L)\neq\varnothing,\quad
\neg\exists b\in \mathrm{Bound}(L)\text{ such that } b \text{ guards the cycle } c^n \text{ for all } n\in\mathbb{N}.
$$
This criterion makes explicit that IALs are not restricted to syntactic `for` or `while` constructs; they can arise from framework transitions, tool dispatch, agent reentry, and model-dependent termination semantics [2607.01641].

## 2. Geometric theory of divergent trajectories

Tacheny distinguishes the artifact space \(A\), where linguistic transformations occur, from the embedding space \(E\subset S^{d-1}\), where geometric measurements are performed. The embedding is defined by applying a pretrained encoder \(\phi(a)\in\mathbb{R}^d\) and normalizing:
$$
\psi(a)=\frac{\phi(a)}{\|\phi(a)\|_2}.
$$
Distances, similarities, clusters, and attractors are then measured in \(E\), not in \(A\). Because raw cosine similarity
$$
s^{(m)}(e_1,e_2)=\langle e_1,e_2\rangle
$$
is biased by anisotropy and concentrates around a high mean \((\approx 0.8)\), the paper introduces an isotonic calibration \(g:[-1,1]\to[0,1]\) learned from human-judged sentence pairs. The calibrated similarity
$$
\tilde{s}(e_1,e_2)=g(s^{(m)}(e_1,e_2))
$$
eliminates mean bias \((\mathrm{MBE}\to 0)\), drives Expected Calibration Error to \(0\), and increases Pearson \(r\) and Spearman \(\rho\) by \(\approx 2\%\), while preserving high local stability [2512.10350].

Within this framework, two regimes are identified. In the contraction regime \(\mathcal{R}_{\mathrm{ctr}}\), an effective contraction rate \(L<1\) emerges in embedding space:
$$
\|f(x_1)-f(x_2)\|_2\le L\cdot \|x_1-x_2\|_2,\qquad L<1.
$$
The trajectory remains in a bounded semantic region, interpreted as an attractor. In the expansion regime \(\mathcal{R}_{\mathrm{exp}}\), no such bounding cluster exists; distances \(\|x_t-x_0\|_p\) grow or remain large, and no time window satisfies the cluster-validity constraints. Operationally, unbounded divergence is detected by persistently high local displacements, very low calibrated local similarity \(\tilde{s}(x_t,x_{t-1})<0.5\), and failure of cluster detection over the finite trajectory.

The canonical divergent example is the exploratory summarize-and-negate loop defined by the prompt: “Summarize the current text in one sentence, then negate its main idea completely in an abstract way. Current sentence: {TEXT} Provide only the new sentence.” Run for \(50\) steps with temperature \(0.8\), this loop yields local Euclidean distances \(\|x_t-x_{t-1}\|_2\) fluctuating around \(1.0\)–\(1.3\), local similarity oscillating between \(\approx 0.2\) and \(0.6\) and often near zero, and global drift \(\|x_t-x_0\|_2\) rapidly rising to \(\approx 1.3\) and staying there, with global similarity \(\tilde{s}(x_t,x_0)\) below \(0.2\). A cluster-detection attempt with similarity threshold \(\lambda\in\{0.8\}\), dispersion \(\rho\in\{0.1,0.2,0.3\}\), and patience \(\kappa=2\) detects zero clusters; semantic dispersion remains high \((>0.5)\) and shows no decay over time. The reported geometric signatures include large non-decaying trajectory radius, low-similarity bands in heat maps of \(\tilde{s}(x_t,x_{t-1})\), and cluster-timeline plots with no horizontal bands. The paper’s central conclusion is that prompt design directly governs the dynamical regime of an agentic loop [2512.10350].

## 3. Failure mechanisms and common misconceptions

A central misconception is to equate IALs with ordinary programming loops. The recent systems literature explicitly rejects that equation. IALs arise from the interaction between agent logic, framework semantics, runtime observations, and termination mechanisms; they traverse multiple layers of code, framework behavior, and model output, and they may be hidden in decorators, callbacks, agent handoffs, or tool-dispatch APIs rather than visible in a single syntactic loop [2607.01641].

In prompted orchestration systems such as LangChain, LangGraph, and AutoGen, the LLM itself decides “what to do next” by reading natural-language descriptions of available agents and tools. Two failure modes are identified as direct causes of IALs: hallucinated routing, in which the model invents an agent name or routes back to a prior agent, and lack of architectural termination, in which there is no statically enforced acyclicity or loop counter. On web-enabled GAIA tasks, LangGraph’s hallucination rate reached \(69\%\), and the paper notes that many of these corresponded to infinite back-and-forth calls between the same two agents [2605.13848].

The scheduler-theoretic account sharpens the structural point. The classic Agent Loop is modeled as an execution system
$$
E=(S,U,P,O,\delta)
$$
with a single-ready-unit scheduler:
$$
E\ \text{is single-ready-unit}\iff \forall s\in S:\ |U(s)|\le 1.
$$
Observation \(3.4\) states that the classic Agent Loop always has \(|U|\le 1\) and that the policy \(P\) is non-deterministic because it is supplied by LLM inference. When failure returns control to the same context, the ready set can remain \(\{v\}\) indefinitely, allowing a sequence such as
$$
s_0\xrightarrow{v,\mathit{failure}} s_1\xrightarrow{v,\mathit{retry}} s_2\xrightarrow{v,\mathit{failure}}\cdots
$$
with no finite retry budget or strict escalation. In this view, the root cause of IALs is not merely repetition, but unbounded recovery in a scheduler whose control policy is opaque and whose execution history is mutable [2604.11378].

## 4. Static analysis and empirical prevalence

IAL-Scan is a static analysis tool designed to detect IAL failures in real-world LLM-agent repositories. It first abstracts heterogeneous agent code into a framework-independent Agent IR with typed facts \(F_{\mathrm{exec}}, F_{\mathrm{ctrl}}, F_{\mathrm{inv}}, F_{\mathrm{state}}, F_{\mathrm{bound}}, F_{\mathrm{exit}}\), then builds an ALDG
$$
G=(V,E,a)
$$
whose nodes include execution units, controller nodes, high-cost LLM or tool calls, and state-growth operations. Edge kinds include `CONTROL_FLOW`, `CALL`, `WORKFLOW_TRANSITION`, `TOOL_DISPATCH`, `LOOP_BACK`, `FEEDBACK`, `CONDITIONAL_TRUE`, `CONDITIONAL_FALSE`, and `AGENT_REENTRY`. Detection proceeds by extracting the feedback subgraph, computing its strongly connected components, checking entry reachability, identifying the continuation controller, evaluating whether the component contains costly or state-growing operations, and then performing bound-coverage analysis to determine whether any bound dominates all feedback edges in the cycle [2607.01641].

The paper gives several representative examples. In the motivating LangChain wrapper, a loop continues while `finish_reason is None or finish_reason == "tool_calls"`, where `finish_reason` is taken from model output and tool calls append to message history; the inner `break` exits only the `for` loop over tool calls. In Agent IR, the cycle contains an `LLM_CALL` marked `high_cost=true` and a `STATE_APPEND` marked `state_growth=true`, while the exit condition depends on `finish_reason` and no `Bound` fact covers the controller. A second example, drawn from LiteRAG, uses `while not success:` with swallowed parse failures and resets `success` on zero-step plans. A third example, from an NVIDIA AI assistant, iterates with `while True:` over `runnable.invoke(state)`, appending to `state["messages"]` when tool calls are empty or malformed. In each case, the loop guard depends on model or parser behavior and no strong deterministic bound covers the feedback path.

The evaluation scans \(6{,}549\) real-world Python LLM-agent repositories. IAL-Scan builds \(340\) static candidates in \(264\) projects, then—after LLM-assisted pruning and manual review—reports \(74\) alerts, among which \(68\) are confirmed IAL failures across \(47\) projects, for \(91.9\%\) precision. Root causes include missing strong bounds \((100\%)\), tool-controlled retries \((41\%)\), model-controlled termination \((38\%)\), workflow cycles \((31\%)\), state-growth amplifiers \((28\%)\), and agent reentry \((25\%)\). Dominant impacts are API cost exhaustion and model denial of service \((96\%)\), context window exhaustion \((28\%)\), and external tool rate-limit exhaustion \((7\%)\). Static candidate generation is reported as fully repeatable, while the optional LLM-pruning stage varies slightly across runs and models; GPT-5.5 is reported to give the best balance, covering all \(68\) true positives with \(74\) alerts at \(4.2\) K tokens per project and \(31\) s per project [2607.01641].

## 5. Architectural elimination and bounded execution

One line of work addresses IALs by changing the execution model rather than merely detecting failures after the fact. GraphBit defines workflows explicitly and deterministically as a directed acyclic graph \(G=(V,E)\), where \(V=\text{Agent}\cup\text{Tool}\cup\text{Control}\) and \(E\subseteq V\times V\) carries typed data dependencies or control edges. Graph construction rejects any edge that would introduce a cycle; equivalently, the adjacency matrix \(d^+\) must satisfy either
$$
\mathrm{tr}(\exp(d^+))=|V|
$$
or
$$
(d^+)^{|V|}=0.
$$
At runtime, a Rust engine uses a ready-queue dataflow algorithm, with control predicates evaluated over structured state rather than through LLM-decided next-agent selection. The key invariants are that graph construction fails on any cycle, each node executes at most once, and control decisions are pure state-predicate checks. Under this design, every execution trace completes in at most \(|V|\) steps, and the paper reports zero “hang” or “timeout waiting for next agent” incidents across \(68\) tasks and approximately \(5\) k ops/min throughput. On GAIA, GraphBit achieves the highest accuracy \((67.6\ \text{percent})\), zero framework-induced hallucinations, the lowest latency \((11.9\ \text{ms overhead})\), and the highest throughput; its hallucination rate is \(0.0\%\) overall and \(0.0\%\) on web-enabled tasks [2605.13848].

GraphBit couples this execution model with a three-tier memory architecture. Ephemeral scratch is per-node and cleared immediately after execution; structured state is a typed key-value store updated only upon successful node completion and readable only through declared keys; external connectors manage database or web I/O and are never auto-injected into prompts. The stated effect is to prevent cascading context bloat and to ensure that revisiting a node is possible only through an explicit DAG edge. The framework’s main limitation is expressiveness: workflows requiring dynamic `while` loops must be unrolled or encoded as a fixed-depth subgraph, and unbounded iterations are not expressible by default.

The scheduler-theoretic Structured Graph Harness (SGH) reaches a similar conclusion through formal specification. An execution plan is
$$
\Pi=(\mathit{id},\mathit{version},V,E,\sigma,\kappa),
$$
with static DAG edges, per-node configuration, and output contracts. Node states range over
$$
\Sigma=\{pending, ready, running, waiting\_human, blocked, executed, failed\_retryable, failed, cancelled, skipped\},
$$
with terminal states \(\Sigma_{\mathit{term}}=\{executed, failed, cancelled, skipped\}\). Bounded execution requires each node to have finite timeout \(\tau_v\), finite retry budget \(b_v<\infty\), and finite human-wait \(T_{\mathit{human}}\). Recovery is separated into three layers—\(\{\mathit{local\_retry}\}\), \(\{\mathit{local\_patch}\}\), and \(\{\mathit{request\_replan}\}\)—subject to the Escalation Invariant that level \(i\) recovery must be exhausted before level \(i+1\) is allowed. Proposition \(5.3\) gives a progress guarantee, and Theorem \(5.5\) states that under bounded-execution assumptions the SGH main loop always terminates in a finite number of steps, with
$$
\#\text{transitions}\le |V|\times |\Sigma\setminus \Sigma_{\mathit{term}}|<\infty.
$$
The paper is explicit that this is a position paper and design proposal rather than a production implementation or empirical result [2604.11378].

## 6. Applications, controls, and trade-offs

The literature does not treat all iterative loops as pathological. In Tacheny’s framework, contractive prompts such as “rewrite/rephrase/improve fluency while preserving meaning exactly,” especially with low-temperature sampling such as \(T\le 0.5\), reliably yield \(L<1\) behavior and a stable attractor. These convergent loops are reported as useful for iterative refinement tasks including proofreading, paraphrasing, and summary polishing. By contrast, prompts that invert, negate, abstract away meaning, or trigger creative jumps push the loop into \(\mathcal{R}_{\mathrm{exp}}\); divergent or infinite loops may be harnessed for broad creative exploration or adversarial drift, but they also pose risks of runaway semantic drift, hallucination amplification, or denial-of-service through infinite generation. The paper recommends in-loop monitoring of local similarity \(\tilde{s}(x_t,x_{t-1})\), raising an alarm or terminating if \(\tilde{s}<\lambda_{\min}\) such as \(0.7\) for several consecutive steps, enforcing explicit stopping criteria in artifact space through string fingerprinting, and interleaving contractive correction phases to collapse the trajectory back into a bounded region [2512.10350].

At the systems level, the principal recommendation is to make bounds first-class. Framework designers are advised to enforce default bounds such as iteration caps, timeouts, and retry limits at the precise runtime scope where feedback loops form; to propagate and dominate bounds across workflow transitions, tool dispatch, and agent reentry; and to expose state-growth limits such as maximum context size. Agent developers are advised never to rely solely on model outputs or parser successes to terminate loops, always to configure explicit `max_iterations`, `max_turns`, or retry caps, and to validate that every feedback path—model \(\to\) tool \(\to\) state \(\to\) model, or agent \(\to\) agent handoff—is covered by a strong deterministic bound [2607.01641].

The remaining debate is best understood as a trade-off between expressiveness and controllability rather than disagreement over the existence of the failure mode. The scheduler-theoretic analysis states that expressiveness increases with dynamic topology, competitive parallelism, and recursive sub-graph expansion, whereas controllability requires static DAGs, deterministic scheduling, and bounded auditable recovery. Excluding features such as `first_of` removes speculative racing and some dynamic flexibility, but the stated purpose is to guarantee that no unbounded cancellation-orchestration loops can form. This suggests that contemporary research is converging on a common principle: IALs become tractable when feedback paths are explicit, bounds dominate the true runtime cycle, and recovery is structurally separated from unconstrained model-directed continuation [2604.11378].

Source: https://www.emergentmind.com/topics/infinite-agentic-loops-ials