Skip to content

Loop & Graph Engineering

Last updated:

Status: Loop engineering is practitioner vocabulary, not a formal standard. Graph engineering is an emerging research label, not a settled discipline. The underlying mechanisms, such as state machines, workflow graphs, checkpoints, and review gates, are mature engineering techniques.

Use this page for: designing the feedback and topology of an agent system. For runtime-harness components, security controls, and optimizer research, see Agent Harness Engineering. For product classification, see the Agent Harness Landscape.

Explicit contracts make feedback, stopping, routing, and acceptance testable; a longer prompt alone does not define those controls. A loop specifies feedback and stopping. A graph specifies the executable topology. A graph can contain a loop, but neither term establishes that an acceptance decision is correct.

Agent Harness Engineering owns the distinctions between a model, a runtime harness, a repository harness, and an orchestrator. Use it to identify which layer owns context, tools, permissions, verification, recovery, or coordination. This page focuses on the loop and graph contracts that make feedback and routing inspectable.

  1. Choose the smallest control structure
  2. Write a loop contract
  3. Write a graph contract
  4. Static and dynamic graphs
  5. Allocate judgment explicitly
  6. Make execution durable
  7. Observe and evaluate the system
  8. Three implementation cases
  9. Anti-patterns
  10. Selection checklist

Start with the simplest structure that can make the required decision safely.

NeedSmallest suitable loop or graph structureWhat must still be specified
One bounded task with local tool feedbackAgent loopstopping rule, tool policy, local verifier
Known branches, retries, parallel work, or human interruptionExplicit workflow graphstate schema, routes, joins, checkpoint and recovery policy

Yes

No

Yes

No

Yes

Work requirement

Must routing, joins, parallelism, interruption, or durable recovery be explicit?

Workflow graph

Agent loop

Set budget and terminal policy

Repeatable repository behavior?

Repository harness

Multiple runs or queues?

Orchestrator

Yes

No

Yes

No

Yes

Work requirement

Must routing, joins, parallelism, interruption, or durable recovery be explicit?

Workflow graph

Agent loop

Set budget and terminal policy

Repeatable repository behavior?

Repository harness

Multiple runs or queues?

Orchestrator

The diagram selects a control structure; Agent Harness Engineering defines the ownership boundary between a runtime harness, repository harness, and orchestrator.

Do not turn a single bounded task into a multi-agent graph just because a framework makes it easy. Every added component introduces state, overhead, and failure modes. Every verifier, reviewer, or release gate introduces an acceptance boundary to test.

The labels are intentionally narrow. Addy Osmani’s practitioner account is useful experience-based framing for replacing repeated prompting with a system that finds, dispatches, checks, and records work. It is not a standard or a performance study. The two recent preprints, Graph Engineering in the Era of LLM Agents and What Makes Prompts a Graph, propose graph-engineering vocabularies. Treat their definitions as research proposals, not proof that graphs improve every agent system.

A loop contract makes “keep going until it works” testable. It names the unit of work, its permitted actions, the evidence that counts as progress, and every allowed exit.

FieldQuestions the contract must answer
Goal and inputWhat requirement, repository revision, and expected artifact define this run?
StateWhat facts persist outside the context window? Who may update them?
ActionsWhich tools, credentials, files, and external effects are permitted?
ObservationWhich tool outputs, tests, traces, and human feedback enter the next iteration?
VerificationWhich deterministic checks, independent reviews, or human decisions can accept the work?
Stop and escalationWhat ends success, ends failure, consumes budget, times out, or requires a person?
EvidenceWhich commands, outputs, trace IDs, and versions prove the final claim?

Agent Harness Engineering defines the inner, outer, and meta horizons and their owning layers. Apply the loop contract at each boundary: an inner-loop contract records tool evidence and a local stop; an outer-loop contract names the delivery verifier and acceptance authority; a meta-loop contract versions the graph or harness change and evaluates it against held-out evidence. A model statement that it has finished is an observation, not acceptance evidence.

Use an explicit graph when routing itself is material. The LangGraph Graph API is a concrete primary-source example: it represents shared state, nodes, fixed and conditional edges, and parallel execution. Nodes can contain LLM calls or conventional code. This is why a graph is not synonymous with a multi-agent system.

A graph contract should be reviewable without running the graph.

ElementMinimum contract
Graph identitygraph and policy versions, owner, compatible state schema
Statetyped fields, confidentiality, writer, reducer or conflict rule, retention
Nodepurpose, input and output, idempotency boundary, timeout, side effects
Edgesource, destination, condition, routing evidence, forbidden transitions
Joinexpected inputs, timeout, missing-input behavior, merge rule
Retryretryable failures, cap, backoff, compensation or escalation
Checkpointpersistence boundary, resume semantics, migration compatibility
Completionlegal terminal states and the authority that can mark each one

The graph contract must distinguish a valid route from a correct result. A state machine can reject an illegal transition while still carrying an incorrect requirement or a flawed review verdict forward.

Practical example: a bounded change-review graph

Section titled “Practical example: a bounded change-review graph”

This contract adds state, routing, budget, and terminal policies that a topology-only diagram omits:

graph: change-review
version: 1
state:
requirement: { writer: human, immutable_after: triage }
patch_ref: { writer: implement, validator: commit_exists }
test_evidence: { writer: verify, validator: command_and_exit_status }
remaining_rework_budget:
type: integer
writer: retry_router
initial: 2
minimum: 0
maximum: 2
decrement: { when: verification_failed_and_value_gt_0, by: 1 }
nodes:
triage: { timeout: 10m, output: approved_plan }
implement: { side_effect: git_worktree }
verify: { input: patch_ref, output: test_evidence }
retry_router:
input: [test_evidence, remaining_rework_budget]
behavior: decrement_if_budget_remains_then_route
review: { input: [patch_ref, test_evidence], authority: accept_or_escalate }
terminals:
done: { condition: accepted_with_evidence }
failed: { conditions: [rework_budget_exhausted, policy_violation] }
escalated: { condition: human_escalation }
edges:
- triage -> implement: approved_plan
- triage -> failed: policy_violation
- implement -> verify: patch_ref_exists
- implement -> failed: policy_violation
- verify -> retry_router: verification_failed
- verify -> failed: policy_violation
- retry_router -> implement: rework_budget_decremented
- retry_router -> failed: rework_budget_exhausted
- verify -> review: verification_passed
- review -> done: accepted_with_evidence
- review -> failed: policy_violation
- review -> escalated: ambiguous_or_high_impact

The retry_router is the only writer allowed to decrement the counter. It decrements only while budget remains, then routes to implement; once the budget reaches zero, the next failed verification reaches the failed terminal. The example does not give a reviewer authority to accept an untested patch. In a production design, add the exact test command, budget unit, trace fields, and rules for side effects.

A static graph fixes its topology in reviewed configuration or code. A dynamic graph creates or changes tasks, dependencies, routes, or workers during execution.

AspectStatic graphDynamic graph
Best forstable roles, approved transitions, review gates, known workflowdiscovered tasks, work queues, dependency expansion, adaptive routing
Main benefitinspectable before executioncan respond to new evidence
Main riskbrittleness when the task does not fitunreviewed routes, unbounded work, topology drift
Required controlversion review and route testscreation policy, budget, provenance, validation, audit log, revocation

Dynamic does not mean that an LLM may write arbitrary workflow code and execute it. Keep the control plane static where consequences are high: allowed node types, permissions, transitions, concurrency, budgets, and release authority. Let dynamic execution create only bounded data within that policy.

This distinction is visible in the pinned Liza source evidence. Its pipeline.yaml defines a stable organization graph of roles, transitions, and quorums. Task dependencies evolve at runtime as a work graph. Liza is therefore a domain-specific executable graph and control plane, not evidence of a general-purpose graph runtime. See the Liza evidence record for the exact boundary.

Automation moves judgment. It does not erase it. Write down who owns the quality bar, decomposition, tool permission, exception, acceptance verdict, and release decision. This is judgment allocation.

Removing a person from repetitive execution does not remove human accountability. Treat three loops as separate contracts:

LoopPrimary responsibilityHuman role
Execution loopplan, act, observe, verify, retry within a budgethandle exceptions and escalations that exceed policy
Governance loopdefine goals, permissions, budgets, acceptance policy, and release authorityremain accountable for risk and irreversible effects
Improvement loopinspect traces and failures, propose a changed prompt, graph, policy, or harnessapprove the versioned change against held-out evidence

This resolves an ambiguity in practitioner discussions of loop engineering. Pavan Belagatti describes removing the operator who repeatedly prompts the agent, then describes software-factory workflows that retain human gates for sensitive transitions. The coherent interpretation is that the person leaves the repetitive execution loop while remaining in the governance loop. See Loop Engineering Explained and the human review gate in Build Your Own Software Factory. These videos are practitioner and vendor-oriented demonstrations, not comparative reliability studies.

OpenAI’s Harness Engineering account uses the related framing “Humans steer. Agents execute.” Its reported throughput and time savings describe one internal greenfield experiment. They do not establish a universal autonomy level or productivity baseline.

DecisionPreferWhy
schema, required command, prohibited transitiondeterministic validator or policy engineexact, repeatable, auditable
ambiguous requirement, risk trade-off, business priorityaccountable humanrequires authority and context outside the run
exploratory analysis or qualitative rankingagent or LLM judge, with sampled adjudicationuseful signal, not a sole production gate
release or irreversible external effectnamed human or pre-authorized policyestablishes accountability and exception handling

Creator-verifier separation is a treatment to test, not proof of independence. A reviewer can have a fresh context yet still share the same flawed specification, model, provider, tools, or incentives. Compare self-review, fresh-context review, different-model review, deterministic checks, and human adjudication against the same sampled defects. Record false accepts, false rejects, rescues, misses, disagreements, and the evidence each verdict used.

For Liza specifically, its deterministic supervisor can reject illegal workflow states, stale leases, and unmet quorums. The pinned source and its own issues ledger do not establish semantic correctness of a legal verdict. The third-party practitioner REX from Ippon is explicitly bounded to one small project and reports continued human checkpoints. It is a useful operational account, not a comparative benchmark.

Durable execution means that an interruption does not silently lose, duplicate, or invent work. It is not merely saving chat history.

RequirementDesign question
Persisted stateCan another process reconstruct the run from a durable record?
IdempotencyWhat happens if a node or tool call runs again after a resume?
CheckpointingAt which safe boundaries can the system resume?
External effectsWhich idempotency key, receipt, compensation, or read-before-write rule protects each effect?
RecoveryWho retries, who resolves conflicts, and when does recovery escalate?
VersioningCan an old checkpoint be resumed under a changed graph or policy?

The LangGraph persistence documentation classifies InMemorySaver as an experimentation implementation and lists persistent checkpointers for production; use a durable backend when state must survive a process restart. With a dynamic interrupt(), resuming restarts the containing node from its beginning, so code before the interrupt can run again. Replay and incomplete attempts have their own re-execution semantics. Make side effects idempotent at each applicable boundary instead of assuming every resumed node behaves identically. Temporal’s workflow documentation is a second primary-source reference for durable workflow execution, replay, and event history.

Do not claim crash recovery unless it has been exercised. Interrupt a run at a defined point, resume it in a clean process, and inspect the state transition, external effect, evidence record, and duplicate-work behavior.

An agent trace needs enough evidence to answer four questions: what ran, why it routed, what state changed, and who accepted the result. Capture data at the layer that made the decision.

LayerMinimum evidence
Runtime loopmodel and harness version, tool calls, permissions, context policy, retry, stop reason
Graphgraph and policy version, node, edge, route reason, state before and after, join wait, checkpoint, resume
Repository harnesssetup command, changed artifact, verifier command, output, exit status
Orchestratordispatch, ownership, queue wait, handoff, lease, escalation, human checkpoint
Judgmentevaluator identity and provenance, evidence references, verdict, overturn, exception authority

Use stable event names and redact sensitive prompt text, tool arguments, tool results, paths, and identifiers before exporting telemetry. The OpenTelemetry GenAI semantic-conventions repository defines agent, model, request, response, token, and tool telemetry, but its status is Development. Keep an adapter between those conventions and your telemetry backend, and version local graph and judgment fields such as graph.version and verdict.overturned, because the upstream vocabulary can change.

Evaluate the exact model-harness pair, repository revision, permission set, graph version, tool set, budget, and task distribution. A green graph test shows that the control flow followed its contract. It does not prove that the delivered patch meets the requirement. Pair workflow tests with requirement-level verification, recovery drills, and repeated representative tasks. Agent Evaluation defines useful graph-level and reviewer-independence measures.

Claude Code: inner loop plus repository harness

Section titled “Claude Code: inner loop plus repository harness”

Claude Code owns the interactive model-and-tool loop. The repository harness provides the project contract through CLAUDE.md, optionally importing or symlinking an existing AGENTS.md, plus setup, task state, tests, hooks, and delivery gates. A practical Claude Code design should make the stop rule explicit: for example, a targeted test passes, the change is reviewed against the requirement, and no policy or budget exit has fired. Do not infer a general explicit graph runtime from subagents, teams, or hooks alone. See Agent Harness Engineering for the runtime boundary, the official explanation of the Claude Code agentic loop for product behavior, and the AGENTS.md compatibility section for the supported instruction-file pattern.

LangGraph is appropriate when state, routing, conditional branches, parallel work, interrupts, or persistence must be first-class artifacts. Its official graph API represents state, nodes, and edges explicitly, and its persistence API supplies checkpoints and stores. The engineering work remains in the contracts: state reducers, route conditions, side-effect idempotency, checkpoint selection, and observability.

Liza: repository harness plus control plane

Section titled “Liza: repository harness plus control plane”

Liza coordinates external coding-agent CLIs through a persistent task state, worktrees, leases, doer/reviewer roles, recovery, and merge gates. The selected CLI retains its inner tool loop. Its stable pipeline configuration and changing task dependencies make it a useful case for separating organization and work graphs. Its worktree isolation is not a substitute for filesystem, credential, or network sandboxing. The Liza evaluation records the pinned commit and the security boundary.

Anti-patternWhy it failsCorrective action
”Keep trying until done”no termination, cost, or escalation boundarywrite explicit success, failure, budget, timeout, and human exits
A diagram without executable semanticsreviewers cannot test routing, joins, or recoverydefine state, node contracts, edge conditions, and checkpoint behavior
Dynamic topology without policyan LLM can create hidden loops or unapproved effectsconstrain allowed mutations, budget them, log provenance, and validate every route
One agent both creates and acceptsself-review can mistake confidence for evidenceseparate deterministic checks and sample independent or human review
Checkpoints without idempotencyresume can duplicate writes or corrupt stateuse effect receipts, idempotency keys, upserts, or compensation
Token-only observabilitycost cannot explain a bad route, stale state, or incorrect verdicttrace topology, state transitions, evidence, and judgment
Calling a scheduler a runtime harnessobscures who owns tool policy and recoveryidentify the owner of the actual model-tool-observation loop
Treating an REX as a benchmarkone project cannot establish general performancelabel REX scope, retain artifacts, and avoid comparative claims

Before adding a loop, graph, or orchestrator, answer yes to each relevant question.

  • The selected structure is the smallest one that meets the routing, durability, and authority requirements.
  • The loop has explicit success, failure, timeout, budget, and escalation exits.
  • State, side effects, evidence, and retention are defined outside the model context.
  • Every graph node, edge, join, retry, and checkpoint has a reviewed contract.
  • Static policy constrains dynamic task and route creation.
  • Deterministic checks own what they can decide deterministically.
  • Human authority is named for ambiguity, exceptions, release, and irreversible effects.
  • Reviewer independence is measured rather than assumed from role names.
  • Resume behavior and side-effect idempotency have been tested under interruption.
  • Traces reconstruct routing, state changes, evidence, and verdicts without exporting sensitive payloads.
  • Evaluation records the exact model-harness pair, graph version, budget, task set, and failure modes.

Resolve every applicable unchecked contract before increasing the system’s routing scope, side effects, or release authority.