---
published: true
id: agent-loop
title: Agent Loop
description: Knowledge captured in João Lopes' learning graph.
tags:
- ai-engineering
- agent-design
locale: en
resource: https://joaolopes.dev.br/knowledge/concepts/en/agent-loop/
created: '2026-04-06'
---

# Agent Loop
The cycle where a model produces a response, the harness executes tool calls, results feed back as context, and the loop repeats until no tool calls remain.

## Definition
The agent loop is the core execution pattern of every agentic harness. The model receives context and produces a response. If the response contains tool calls, the harness executes them and appends the results to the context. The model sees the updated context and responds again. This continues until the model produces a response with no tool calls, which the harness treats as the final answer. The loop is the same regardless of the agent or task. What varies is the context fed in, the tools available, and the policies that gate execution.

## Source
- [How Claude Code works](https://code.claude.com/docs/en/how-claude-code-works)
- [Unrolling the Codex agent loop](https://openai.com/index/unrolling-the-codex-agent-loop/)

## Related
- [AI Agent](/concepts/en/ai-agent.md)
- [Tool Call](/concepts/en/tool-call.md)
- [Context](/concepts/en/context.md)
- [Turn](/concepts/en/turn.md)
- [Agentic Harness](/concepts/en/agentic-harness.md)