---
title: 'Agent loop'
description: 'The repeated cycle in which an agent observes state, selects an action, invokes a tool or model, receives feedback, updates state, and decides whether to continue.'
canonical_url: 'https://darkfactory.dev/glossary/agent-loop'
markdown_url: 'https://darkfactory.dev/glossary/agent-loop.md'
collection: glossary
date_published: '2026-08-03T00:00:00-04:00'
date_modified: '2026-08-26T00:00:00-04:00'
---

# Agent loop


## Definition

An agent loop is the repeated control cycle in which an agent observes its state, selects an action, invokes a model or tool, receives a result, updates state, and decides what to do next. A useful loop also has explicit outcomes for completion, handoff, pause, timeout, budget exhaustion, and failure.

The loop can be only a few lines of code. Its operational behavior still depends on the surrounding harness: which observations enter context, how tool errors are represented, what state persists, who can approve an action, and how the system detects that it is no longer making progress.

Without bounded retries and a termination policy, a loop can turn one plausible mistake into repeated cost or damage. Durable loops record attempts, distinguish transient failures from semantic failures, and escalate when another iteration is unlikely to help.

## Distinguish it from nearby terms

The loop is the local cycle of observe, act, and update. A workflow defines a larger sequence of work. Orchestration coordinates tasks, runs, agents, and lifecycle around one or more loops. A control graph may contain loops as cycles.

## Check your understanding

An agent retries the same failing API call with slightly different wording until its budget is gone. It has a loop, but no useful progress test or failure policy.

## Also called

tool loop, reason-act-observe loop, core agent loop

## Related terms

- [Graph engineering](https://darkfactory.dev/glossary/graph-engineering)
- [Loop engineering](https://darkfactory.dev/glossary/loop-engineering)
- [Verification loop](https://darkfactory.dev/glossary/verification-loop)
- [Control graph](https://darkfactory.dev/glossary/control-graph)
- [Directed acyclic graph (DAG)](https://darkfactory.dev/glossary/directed-acyclic-graph)

## Related factory areas

- [Orchestration, state, concurrency & recovery](https://darkfactory.dev/factory/orchestration-state)

## Evidence and further reading

- [The Anatomy of an Agent Harness](https://www.langchain.com/blog/the-anatomy-of-an-agent-harness)
- [Long-Running Agents](https://addyosmani.com/blog/long-running-agents/)
- [LangChain: 3 Years of Graph Engineering with LangGraph](https://www.langchain.com/blog/3-years-of-graph-engineering-with-langgraph)
- [The Art of Loop Engineering: How to Build Agents That Improve Over Time](https://www.youtube.com/watch?v=jPPiZ22DY3g)
