Four isolated coding agents, one integration failure, and a graph that retries only the branch that owns it.
By Youssef Hosni
Published: 2026-09-05
URL: https://todatabeyond.substack.com/p/loops-vs-graphs-for-ai-coding-agents
Imagine a release that needs four small code fixes. One function converts titles into URL slugs, another parses timeout values, a third normalizes HTTP headers, and a fourth removes duplicate items. Each fix is small enough for one coding agent, and the four fixes appear independent when viewed separately.
A coding agent can read one task, inspect the relevant source, edit it, run tests, and use the test result to decide what to do next. This repeated sequence is the loop. It explains how one agent improves one patch after its first answer is incomplete or incorrect.
The release introduces a wider coordination problem. Something must decide that four tasks exist, determine whether they may run at the same time, wait for their results, test the combined system, and choose what to repeat if integration fails. That wider control structure is the graph.
This distinction becomes easier once the vocabulary is introduced in layers. We will begin with one agent and one task, add the loop around its actions, add the graph around several agents, and only then run a sequence of Codex prompts that demonstrates both control levels.
Get All My 9 Books With 60% Off
Table of Contents:
-
Begin With One AI Coding Agent
-
What the Loop Controls
-
What a Graph Adds
-
Run the Demo in Four Codex Prompts
4.1. Prompt 1 — Create a failing baseline
4.2. Prompt 2 — Fan out the repair work
4.3. Prompt 3 — Apply the wider gate
4.4. Prompt 4 — Correct only the rejected unit
-
Retry Only What the Failure Invalidates
Get all my 10 AI Courses with 60% off
My new live cohort: Claude Agent Engineering. Six 3-hour live sessions, six office hours, and one agent system you build layer by layer.
Only 20 seats, starting 1 November. Founding rate: $320 instead of $400 until Sunday, 27 September, 23:59 Helsinki time. Use code CLAUDECOURSE20
Claude Agent Engineering Live Course
1. Begin With One AI Coding Agent
A language model receives input and produces a response. A coding agent places that model inside an operating environment where it can inspect files, edit code, run commands, and observe the results.
The OpenAI Agents SDK definition similarly describes an agent as a model configured with instructions, tools, and optional control features such as guardrails and structured outputs.
The environment around the model is often called the harness or runner. It decides which tools are available, which directory the agent may change, how command output is returned, and when execution must stop. The model supplies judgment about the next action, while the harness turns an allowed action into a real file edit or test process.
An agent works best when it receives a bounded unit of work. A useful unit has one objective, the context needed for that objective, an artifact to produce, and an acceptance check. Here, an artifact is a saved result such as a patch, generated file, or test report. “Repair the slug-normalization function and pass its unit tests” is a bounded unit; “improve the whole application” leaves ownership, dependencies, and completion too ambiguous.
During one unit, the agent alternates between actions and observations. It may inspect a function, edit its implementation, run a test, read the error, and inspect a related function before editing again. The files and command results become the working state for the next decision, so the agent can revise the same patch instead of producing a disconnected answer.
Get all my 10 AI Courses with 60% off
Figure 1. A coding-agent loop keeps actions and feedback inside one bounded task. A failed test returns evidence to the same agent so it can revise the current patch.
The accepted box in Figure 1 represents a precise condition rather than the agent’s confidence. In a coding workflow, acceptance normally comes from executable evidence such as tests, type checks, lint rules, or a schema validator. A model may explain why it believes the task is complete, but the harness should still run the declared check and record the result.
A coding agent is a model operating inside a controlled workspace; its loop turns observations into another action on the same task.
Get All My 9 Books With 60% Off
2. What the Loop Controls
A loop is a repeated control cycle with state and a stopping condition. At the beginning of a cycle, the agent sees the current task, files, and previous tool results; it chooses an action; the harness executes that action; and the resulting observation is added to the next cycle. The loop ends when the completion condition is satisfied, or a safety limit interrupts it.
The OpenAI Agents SDK runner documents this pattern directly. A model can return a final answer, hand control to another agent, or request tool calls; tool results are appended to the conversation before the model runs again. A maximum-turn setting bounds the cycle when a final result never arrives.
For a coding agent, the familiar form is inspect → edit → test → inspect again when necessary. “Test” is feedback, not merely a final ceremony: a failure supplies a stack trace, assertion difference, or compiler message that changes the next decision. The loop therefore improves the current artifact by repeatedly comparing it with a local acceptance rule.
A useful analogy is a developer debugging one ticket at one desk. The developer may open several files and run the test many times, yet every action serves the same ticket and produces one patch. The loop describes that focused debugging process; it does not schedule the other tickets waiting elsewhere in the release.
Every practical loop needs failure limits as well as a success condition. Maximum turns, elapsed time, tool-call budgets, repeated-error detection, and human escalation prevent an agent from editing forever. These controls belong to the harness because they must remain effective even when the model continues requesting another attempt.
The loop’s knowledge is limited to the context made available to it. If the agent sees one task and one test suite, a green test result establishes that local contract. It cannot establish compatibility with a hidden deployment rule, a sibling patch, or an integration test that the harness never exposed.
The sequence Prompts → Context → Harness → Loops → Graphs describes progressively wider control boundaries. The prompt states the objective; context supplies the visible evidence; the harness grants tools and enforces permissions; the loop decides whether the current unit needs another cycle; and the graph determines which units are active and how they relate.
Get all my 10 AI Courses with 60% off
Figure 2. Prompt, context, and harness shape one agent’s operating conditions. Loops add repeated correction within a unit, while graphs add coordination across units.
This layering also explains why a stronger model does not remove the need for orchestration. A highly capable agent can execute a poorly chosen task perfectly, wait on a dependency that should have run first, or repeat work whose result was already accepted. Those are decisions about the set and order of work, which sit outside the local correction cycle.
A local pass establishes exactly the contract examined by the local gate; it says nothing about checks that were outside the agent’s context.
Get All My 9 Books With 60% Off
