Homeโ€บBlogโ€บAgentic AI System Designs
Agentic AI System Designs ยท Harness

Inside the Agent Loop

Every agent harness runs the same cycle: call the model, run the tools it asks for, feed back the results, repeat. What makes Claude Code, Codex, Gemini CLI and Jules, Deep Agents and Hermes Agent different is how they set ten dials on that loop, and whether anything the loop learns survives the task. Here are all five, side by side, with an RSI level for each.

FL
FrontierAGI Team
โš ๏ธ How to read this (as of 7 Nov 2026)Loop details come from each project's public docs and repositories; anything we could not confirm is marked โš ๏ธ, and the station diagrams and RSI placements are our reading. Token and turn figures come from our scripted simulation, not from the products. Disclosure: Claude, made by Anthropic, helps write this site, and this series covers Anthropic, Google and OpenAI products.

1. What a loop is

agent_loop.py ยท not executed: pseudo-code of the shared loop
def agent_loop(task, tools, model, max_turns=50):
    context = [instructions(), task]            # system prompt, memory files, the request
    for turn in range(max_turns):
        reply = model(context)                  # the only "intelligent" step
        if not reply.tool_calls:                # no tool call = the model thinks it is done
            return reply.text
        for call in reply.tool_calls:
            if needs_approval(call) and not human_ok(call):
                result = "denied by user"
            else:
                result = tools[call.name](**call.args)
            context.append(shorten(result))     # observation handling
        if too_long(context):
            context = compact(context)          # context pressure
    return "stopped: turn limit"

2. The ten dials

#DialThe question it answers
1Turn structureOne action per model call, or several in parallel?
2PlanningDoes it write a plan, and does anyone approve it?
3Approval gateWhere does the loop stop and wait for a human?
4Observation handlingWhat happens to a 6,000-line test log?
5Context pressureWhat happens when the context window fills?
6Sub-loopsCan the loop start smaller loops with their own context?
7Error recoveryWhat does it do after a failed step?
8Stop conditionHow does the loop know it is finished?
9Where it runsYour laptop, a sandbox, or a cloud machine you never see?
10Learns after the taskDoes anything from this task change the next one?

3. Five loops, side by side

๐Ÿ” Five loops, one viewer (pick a harness, press play)

Stations are our simplification of each documented loop. Tap a station for what happens there.

4. Each product's loop

Claude Code RSI L1with an L4-style edge

Codex RSI L1

Gemini CLI & Jules RSI L1

Deep Agents RSI L1L4 if you add it

Hermes Agent RSI L4pattern, context-level

5. The dial matrix

DialClaude CodeCodexGemini CLI & JulesDeep AgentsHermes Agent
Turn structureTool calls per turn, parallel when independent โš ๏ธTool calls per turn โš ๏ธReAct stepsGraph step: model node โ†” tool nodeTool calls per turn
PlanningTo-do list tool; plan modeupdate_plan tool โš ๏ธJules: written plan you approvewrite_todos toolTo-do list โš ๏ธ
Approval gateAllow / ask / deny rules, modes, hooksApproval policy + sandbox modeConfirmation prompts; trusted folders โš ๏ธinterrupt_on for chosen toolsCommand approval โš ๏ธ
Observation handlingLong outputs truncated โš ๏ธOutput truncated โš ๏ธBig window holds moreBig results go to virtual filesโš ๏ธ
Context pressureAuto-compact; CLAUDE.md re-readCompaction โš ๏ธCompression command โš ๏ธ; huge windowSummarisation middleware โš ๏ธโš ๏ธ
Sub-loopsSubagents with own contextParallel cloud tasks (not nested) โš ๏ธLimited โš ๏ธtask() subagentsSubagents
Error recoveryReads failure, retries in the next turnRe-runs tests until greenCheckpoints to restore files โš ๏ธYours to add (graph nodes, retries)Retries; learns from failures afterwards
Stop conditionNo tool call, Esc, Stop hook, SDK turn limitNo tool call, or a finished diff (cloud)Answer without tool call; Jules: PRRecursion limit, interrupts, no tool callTask done
Where it runsYour machine; cloud sessionsSandbox locally; cloud containersTerminal; Jules cloud VMInside your Python / JS appTerminal, chat apps, servers โš ๏ธ
Learns after the taskMemory files, skills (context-level)No (AGENTS.md is edited by people)NoOptional long-term storeYes: writes skills and memories
RSI levelL1 with an L4-style edgeL1 L1 L1 L4 if you add itL4 pattern, context-level

From each project's documentation as of 7โ€“11 Nov 2026. โš ๏ธ = we could not confirm the detail in official docs from our sandbox, or it is inferred from documented behaviour.

6. RSI levels: how far each loop improves itself

L1runs a loop a human designedClaude CodeCodexGemini CLI & JulesDeep Agents
L2chooses how to improveno harness here by default
L3sets its own curriculumno harness here by default
L4improves in deploymentHermes AgentClaude Code (memory, skills)Deep Agents (if a store is added)
L5improves the improverno harness here by default

7. The same task through every loop

loop_lab.py ยท Python 3, standard library only; scripted stub model
"""loop_lab.py โ€” one agent loop, five "dial settings" in the style of five harnesses (illustrative).

The same task (a failing date test -> fix -> open a PR) runs through one loop whose dials
are set the way each harness documents its behaviour: planning, approvals, sub-loops,
compaction, and whether it writes something reusable after the task. The "model" is a
scripted stub, so the run is repeatable; token counts are our rough model (4 chars/token).
Standard library only.
"""
PROFILES = {   # plan, approve edits?, subagent explore?, compact at (tokens), learn after task?, async?
    "Claude Code":  dict(plan="todo list", ask_edit=True,  sub=True,  compact=1200, learn="memory note", run="interactive"),
    "Codex":        dict(plan="plan step", ask_edit=False, sub=False, compact=1200, learn=None,          run="sandboxed"),
    "Gemini/Jules": dict(plan="plan approval", ask_edit=False, sub=False, compact=9000, learn=None,       run="async VM"),
    "Deep Agents":  dict(plan="write_todos", ask_edit=True, sub=True,  compact=1200, learn=None,          run="in your app"),
    "Hermes Agent": dict(plan="todo list", ask_edit=False, sub=True,  compact=1200, learn="new skill",   run="interactive"),
}
BIG_LOG = "x" * 6000                      # a noisy test log: observation handling matters

def tok(lines): return sum(len(l) for l in lines) // 4

def run(name, p, truncate=True, known=False):
    ctx = ["system: repo rules", "user: date test fails; fix it and open a PR"]
    turns = calls = approvals = compactions = 0
    steps = [("plan", p["plan"])]
    if not known:
        steps += [("explore", "subagent summary: parse() in dates.py")] if p["sub"] else [("search", "dates.py"), ("read", "dates.py, test_dates.py")]
    steps += [("bash", "FAIL ValueError\n" + BIG_LOG), ("edit", "dates.py"), ("bash", "PASS"), ("git", "PR opened")]
    for act, out in steps:
        turns += 1; calls += 1
        if act == "edit" and p["ask_edit"]: approvals += 1
        if act == "plan" and p["plan"] == "plan approval": approvals += 1
        if truncate and act == "bash" and len(out) > 2000: out = out[:200] + " ...[truncated, full log saved to file]"
        ctx.append(f"{act}: {out}")
        if tok(ctx) > p["compact"]: ctx = ctx[:2] + ["summary of earlier turns"] + ctx[-1:]; compactions += 1
    learned = p["learn"] or "-"
    return turns, calls, approvals, compactions, tok(ctx), learned

print(f"{'harness':13} {'turns':>5} {'calls':>5} {'asks':>4} {'compact':>7} {'ctx tok':>7}  after task")
for name, p in PROFILES.items():
    t, c, a, k, x, l = run(name, p)
    print(f"{name:13} {t:5} {c:5} {a:4} {k:7} {x:7}  {l}")
print()
t, c, a, k, x, l = run("Claude Code", PROFILES["Claude Code"], truncate=False)
print(f"without truncating the test log: ctx {x} tokens after {k} compaction(s)")
for name in ("Claude Code", "Hermes Agent"):
    t2 = run(name, PROFILES[name], known=True)[0]
    print(f"{name}: rerun of a similar task with what it kept: {t2} turns instead of {run(name, PROFILES[name])[0]}")
print("same task, same model stub: the dials change approvals, context and what is kept afterwards")
$ python3 loop_lab.py harness turns calls asks compact ctx tok after task Claude Code 6 6 1 0 101 memory note Codex 7 7 0 0 101 - Gemini/Jules 7 7 1 0 102 - Deep Agents 6 6 1 0 101 - Hermes Agent 6 6 0 0 101 new skill without truncating the test log: ctx 30 tokens after 2 compaction(s) Claude Code: rerun of a similar task with what it kept: 5 turns instead of 6 Hermes Agent: rerun of a similar task with what it kept: 5 turns instead of 6 same task, same model stub: the dials change approvals, context and what is kept afterwards

8. Loop lab

๐ŸŽ›๏ธ Loop lab: set the dials, run the same task

โ€“turns
โ€“human asks
โ€“tokens (k, est.)
โ€“RSI level

Simulated with our own rough model of a 6-step fix-and-PR task (the same logic as loop_lab.py, plus a cost estimate at 30k tokens per turn without truncation). Not a benchmark of any product.

9. Where loops break

FailureWhat you seeHow harnesses defend
Edit-test spiralIt edits, tests, fails and repeats the same fix.Turn limits, a plan to re-read, a human interrupt; you saying "step back and explain the bug".
Context rotLate in a long session it forgets rules from the start.Instruction files re-read every session, compaction that keeps rules, subagents for noisy work.
Observation floodOne command prints 50,000 lines and pushes everything else out.Truncating outputs, saving them to files (Deep Agents' virtual files), reading only the tail.
Runaway sub-loopsSubagents spawn work that costs more than the task.Subagents return summaries only; budgets and turn limits; no nested spawning by default โš ๏ธ.
Premature "done"It stops because the model stopped calling tools, but the tests were never run.Instructions to verify, Stop hooks that check (Claude Code), cloud tasks that show test results with the diff (Codex).
Injected instructionsA web page or file says "ignore your rules and push to main".Approval gates on risky tools, sandboxes without secrets, treating tool output as data, not orders.
Learning the wrong lessonA saved skill encodes a mistake and is reused.Only relevant to L4-style loops (Hermes, memory features): human review of saved skills, or a gate that tests them first.

10. What to copy if you build one

11. The series

Agentic AI System Designs: four kinds of agent system, one article each

Start here๐Ÿงญ Four ways to build an agentHarness๐Ÿงฐ Claude CodeHarness๐Ÿงฐ CodexHarness๐Ÿงฐ Gemini CLI, Antigravity & JulesHarness๐Ÿงฐ Deep AgentsHarness๐Ÿงฐ Hermes AgentFramework๐Ÿงฑ OpenAI Agents SDK ยท comingFramework๐Ÿงฑ Google ADK ยท comingFramework๐Ÿงฑ LangChain / LangGraph ยท comingFramework๐Ÿงฑ CrewAI ยท comingFramework๐Ÿงฑ Claude Agent SDK & Microsoft Agent Framework ยท comingRuntimeโš™๏ธ Amazon Bedrock AgentCore ยท comingRuntimeโš™๏ธ LangSmith Deployment ยท comingRuntimeโš™๏ธ Temporal ยท comingRuntimeโš™๏ธ Vertex AI Agent Engine & Azure AI Foundry ยท comingBuilder๐Ÿงฉ n8n ยท comingBuilder๐Ÿงฉ Zapier Agents ยท comingBuilder๐Ÿงฉ Microsoft Copilot Studio ยท comingBuilder๐Ÿงฉ Make ยท coming

See them all on one page: Agentic Systems at a Glance.

12. Sources