← Source on GitHub Saturday, October 3, 2026 3 reports

Agent Anatomy

How production AI agents are really built · read from their source code

Reading: Gemini CLI OpenHands LangGraph Codex
Ask your own: /agent-anatomy:ask <question>

Top story

Four codebases compared · every claim reviewed against the source · analysed October 3, 2026

How agents notice they are stuck in a loop, and what they do about it

Who detects what

Gemini CLIBuilt inThree detectors: repeated tool-call cycles, repeated text, and a model acting as judge, double-checked by a second model when one is available.
OpenHandsBuilt inFour working patterns over recent events, such as four identical action-and-result pairs.
LangGraphLeft to youA step budget only. The default is 10,007 steps.
CodexNot foundNo detector or step cap found in the core turn loop.
Each repository read at one pinned commit. “Not found” means not found in what was searched.

There is no single technique. Gemini CLI hashes every tool call's name and arguments and looks for a cycle of up to five calls repeated five times. That catches the obvious loops. For the subtle ones, where an agent keeps doing slightly different unproductive things, it waits thirty turns and then asks a model whether the conversation is going anywhere.

OpenHands takes the rule-based route. It compares both the action and what came back, so a command that is polled and returns something new each time is not mistaken for a loop.

Both can warn the model before stopping it. Gemini CLI injects a message on the first detection and ends the turn on the second. OpenHands does this for one pattern only: when the same action keeps erroring, it sends a nudge naming the tool and the error before it marks the run as stuck.

LangGraph, a framework, does not look at behaviour at all. It counts steps and leaves the rest to the graph you write.

Read the full report →   Working code →

Deep dive

How Gemini CLI compresses chat history

When the prompt reaches half of the model's token limit, the newest 30% of the conversation is kept and the rest becomes a structured snapshot written by a model.

It then asks the model to critique its own summary. If the new history has more tokens than the old one, it is thrown away, and automatic attempts stop calling the summariser until a new chat starts.

Read the report →   Working code →

Deep dive

How Gemini CLI remembers, without a vector database

Memory is markdown files, each read in full. Three tiers decide where a file enters the prompt: the system instruction, the first user message, or a tool's result when that folder is first touched.

The model saves a memory by editing a file with its ordinary tools. No semantic database was found.

Read the report →   Working code →

How it works

The code on the page cannot be misquoted

The model never writes code into a report. It gives a file, a line range and a string it expects to find there. Every fact carries a citation to the lines behind it.

  1. Each repository is fetched and pinned to one commit.
  2. The implementation is found by search, then read and traced.
  3. A script copies the quoted lines from that commit, and fails the build if anything does not match.
  4. A second agent tries to disprove each claim against the source. Nothing is published until every claim is supported.
  5. Each report ends with working code that follows the original design, with tests that must pass.

The reviewer is a second AI pass, not a proof. Follow a citation before relying on a claim.

Ask your own

One question, one or several codebases

/plugin marketplace add Antriksh29071989/agent-anatomy
/plugin install agent-anatomy@agent-anatomy

Then ask, naming repositories or letting it choose:

  • Context compression
  • Loop detection
  • Memory
  • Tool errors
  • Sub-agents
  • Approvals
  • Prompt assembly
  • Evals
  • Prompt caching
  • Checkpointing