MECHANISM · LOOP · CORE

Agent Loop

Own the repeated transition from user intent to model response, tool effects, updated context, and an explicit stop reason.

3 lessons6 agent snapshots0 experiments
01Intentuser.message
02Modelrequest / response
03Policyvalidate / authorize
04Tooleffect / result
05Contextappend / prune
HARNESSowns the loop
L0Intuitioncomplete
L1Buildcomplete
L2Engineeringpartial
L3Architecturepartial
L4Researchpartial
DEPENDENCY GRAPH · READER PATH

What feeds it, and what does it unlock?

Arrows show learning and design dependencies, not runtime data flow. Follow any node to continue through the Atlas.

Agent Loop

L0 · Intuition

A model is not an agent. The model answers “what next”; the harness turns that answer into effects, adds results to context, and decides whether to continue or stop.

User intent → Model response → Tool request → Policy → Tool result
     ↑                                             │
     └────────── Update context and continue ──────┘

A trustworthy loop can answer three questions: what state it is in, why it continues, and why it stops.

L1 · Runnable reference

Run python3 -m curriculum.lessons.s03_tool_dispatch.demo. The fake model requests echo, the registry validates and executes it, and the result becomes a tool message for the second model call. The run prints Trace 0.1 JSONL.

L2 · Engineering constraints

  • Bound turns, wall time, tokens, and tool calls independently.
  • Separate validation, authorization, execution, and result normalization.
  • Give stream failures, model failures, and tool failures different recovery paths.
  • Treat cancellation and steering as loop state, not UI exceptions.
  • Put the stop reason in the trace, not only in an incidental log string.

L3 · Agent mapping

Official documentation observed on 2026-08-10 presents Codex CLI as one terminal loop for exploration, planning, editing, local tools, steering, and same-session follow-up. The current claim supports product-surface behavior only; source mapping, request protocol, retry behavior, and termination logic remain unknown.

L4 · Research entry

The synthetic controlled trace proves this project's event and tool round-trip contract runs, but it cannot substitute for a native Agent trace. The next experiment must pin Agent version, model, permissions, sandbox, fixture, and visibility gaps.

AGENT MAPPING · EVIDENCE ONLY

Snapshot implementations

An implementation enters the map only when both a snapshot and claims exist; unknowns remain visible.

UNKNOWN · EVIDENCE GAPClaude Code

No implementation currently clears the Snapshot + Claim threshold; this is not a claim that the product lacks the capability.

Inspect coverage boundary
PARTIALCodex

Official-documentation mapping only. A pinned source map and native trace are still required for Tier A.

codex-2026-08-10-cli
UNKNOWN · EVIDENCE GAPReference Harness

No implementation currently clears the Snapshot + Claim threshold; this is not a claim that the product lacks the capability.

Inspect coverage boundary
CLAIMS · EVIDENCE LEDGER6 RECORDS
source + sourcereviewed

codex-source-agent-loop

At the pinned Codex source revision, run_turn repeatedly samples the model, executes requested function calls, feeds results into later samples, accepts steering input, and stops when follow-up work is no longer required or a stop/error path wins.

Agent
Codex
Snapshot
codex-2026-08-10-source
Reviewed
2026-08-10
sourcereviewed

grok-build-source-agent-loop

Grok Build's pinned session actor multiplexes commands and asynchronous events, explicitly starts turns, streams sampler output, dispatches tool calls, and emits lifecycle updates through completion, failure, or cancellation.

Agent
Grok Build
Snapshot
grok-build-2026-08-10-source
Reviewed
2026-08-10
sourcereviewed

reasonix-source-agent-loop

The pinned Reasonix engine runs a bounded tool-round loop that captures a cache prefix shape, streams a provider turn, commits only a clean terminal attempt, then either finalizes or dispatches the committed tool calls before the next round.

Agent
Reasonix
Snapshot
reasonix-2026-08-10-source
Reviewed
2026-08-10
EXPERIMENTS · EXERCISES

What has actually been tested?

Formal experiments are separate from course exercises. Exercises can validate the reference implementation but cannot replace Native evidence from a real agent.

Formal experiment · not registered

No experiment record means untested, not passed. The course checks below cover only the deterministic reference harness.

s01-agent-loopobserve
Verify the Golden Trace

The committed JSONL exactly matches a real demo run and passes the trace schema.

python3 -m curriculum.golden verify s01-agent-loop
s01-agent-loopmodify
Preserve loop invariants

A completed run keeps contiguous sequence numbers and ends with session.stop.

python3 -m unittest curriculum.tests.test_vertical_slice.VerticalSliceTests.test_s01_minimal_loop -v
s02-events-streamingobserve
Verify the streaming trace

Three deltas produce three ordered events and the last is explicitly final.

python3 -m curriculum.golden verify s02-events-streaming
s02-events-streamingmodify
Test the streaming message contract

Deltas remain replayable without polluting the next-turn message history.

python3 -m unittest curriculum.tests.test_vertical_slice.VerticalSliceTests.test_s02_streaming_becomes_events -v
s03-tool-dispatchobserve
Verify the tool roundtrip

The request, result, and second model request appear in causal order.

python3 -m curriculum.golden verify s03-tool-dispatch
s03-tool-dispatchmodify
Test the dispatch contract

The tool result returns to the next turn as a tool message bound to tool_call_id.

python3 -m unittest curriculum.tests.test_vertical_slice.VerticalSliceTests.test_s03_tool_roundtrip -v
OPEN QUESTIONS · L4
01

Which termination reasons should be portable across provider and Agent adapters?

02

How should streaming tool-call arguments appear without leaking provider-specific wire formats?

03

Which retry decisions belong inside the loop versus a provider adapter?