CoachDiscoverMapCompareSavedAI LearningAI WeeklyAbout
← Back to Library
03 · Advanced

Agent Infrastructure Deep Dive

The 11 areas of the engineering layer that turns a capable model into a reliable agent — memory, skills, sandboxes, the harness, loop control, inference optimization, post-training, long-horizon execution, evaluation, and model-native orchestration.

01 · CORE

Master the core five first

Memory, Skills, Harness, frameworks & long-horizon execution underpin everything else. Master these first.

02 · HANDS-ON

Build a coding agent yourself

It's the fastest way to internalize these ideas. Getting hands-on with sandboxes gives you the deepest intuition.

03 · MODEL SIDE

Know the model side, but go shallow

You don't need to go very deep — understanding how post-training shapes model behavior inside the harness is enough.

Memory — the persistent state system

One line: Memory is the agent's "sustainable state system" — what lets it carry knowledge across turns and sessions beyond the context window.

Think of the agent as a person with a small desk and a big filing cabinet. The desk is the context window — what it can see right now, but it's tiny and gets wiped at the end of each session. The filing cabinet is long-term memory: a database it can write notes into and pull from later. Memory has three jobs — write (save a note), read/retrieve (find the right note and lay it on the desk), and manage (tidy the cabinet: merge duplicates, toss stale notes, fix contradictions). Reading is mostly solved; the hard parts are deciding what's worth writing down and keeping the cabinet clean — which is why many teams do the tidying overnight in a batch ("dreaming") rather than scribbling notes mid-conversation.

Key concepts to understand

Retrieval and update have decent patterns now; writing is the unsolved part — give a model a memory tool and it over-writes everything, unsure what matters. Strong approach: avoid real-time writes; do scheduled next-day ("T+1") nightly "dreaming" consolidation so the problem degrades into a single global fold-and-merge update. Scope it too: a personal long-term memory writes very differently from a per-workspace working memory.

Skill System — loadable capabilities

One line: Skills are packaged, on-demand capabilities (instructions + optional scripts/resources) the agent discovers and pulls into context when relevant.

Picture a shelf of how-to binders. The agent doesn't read every binder up front — that would bury its tiny desk (context window) before any work starts. At startup it only reads the table of contents: each binder's title + one-line description (~60 tokens each). When a task matches, it pulls just that one binder off the shelf and reads it fully; deeper appendices load only if needed. This staged reveal is called progressive disclosure — and the savings are huge: ~8 skills cost about 500 tokens at startup instead of 70,000 if you'd dumped them all in.

Key concepts to understand

Unloading mid-conversation invalidates the key-value cache (see topic 7) — a real cache-miss cost. In controlled experiments, loading with no unload is roughly equivalent in quality. Don't over-engineer it. Nuance: unloading is mostly a passive process governed by the harness. If the harness compresses context frequently, inject a short note recording the loaded skill's identifier into the post-compression summary, so the agent remembers it already used that skill.

Sandbox & Virtualization — safe execution environments

One line: The isolated environment where the agent runs tools/code without endangering the host — the biggest skill-builder if you've actually constructed one.

It's a disposable, sealed playroom — a little throwaway computer where the agent can run code, install things, and even break stuff without touching the real system. The lifecycle is about speed versus cost: cold start = building the playroom from scratch (slow); snapshot = taking a photo of a fully set-up room so you can recreate it instantly; resume = reopening a paused room; idle = a room sitting empty, which you pause to stop paying for it. A MicroVM is a playroom with bank-vault walls (genuine isolation) that still opens in well under a second.

Key concepts to understand

The tension is between cold-start latency and isolation strength. The practical answer: pre-warmed pools plus snapshot-and-restore to get fast resume without giving up full virtual-machine isolation.

Framework Comparison — Claude Code vs. Codex vs. OpenClaw

One line: Know each framework's design philosophy and where it's strong/weak — and the deeper axis: model-driven versus role-driven orchestration.

These are the "operating systems" for coding agents — each one is a different opinion on how to run an agent. Claude Code is fast and highly controllable (lots of knobs: hooks, sub-agents, skills). Codex is prized for a disciplined run-loop and clean code structure. OpenClaw is a personal Swiss-army-knife that plugs into all your chat apps via one gateway — flexible, but the sprawling plugin ecosystem gets messy and risky to maintain. The deeper question: who decides how to split up the work? Fixed, human-designed roles (Claude Code, Codex) or the model itself deciding on the fly (Kimi Swarm, #11).

FrameworkStrong atWatch-outs
Claude CodeAgentic control plane + iteration speedOpinionated; hooks/subagents/skills give fine control
CodexAgent Loop + code architectureLoop discipline is the headline strength
OpenClawPersonal use, extensions, gatewayPoor maintainability — sprawling plugin/channel ecosystem, security surface
Claude Code & Codex use predefined roles for orchestration; Kimi's Swarm pushes orchestration into the model (see #11). That model-versus-role contrast is the discriminating idea.

The Harness — THE central concept

One line: The engineering shell around the model that makes an agent reliably finish tasks — everything that is not the model weights.

The model is a brilliant but forgetful contractor; the harness is the entire job site that makes them productive. The schedule that orders the work, the toolbox with safety locks, the checklist, the supervisor who re-checks the output, and the system for handing off across shifts — that's the harness. Drop a genius contractor onto a site with none of that and they wander off, repeat mistakes, or blow the budget. The key insight: as models get smarter, the job site is increasingly what decides whether the project actually ships — reliably, cheaply, and safely.

The seven things a harness owns

Model = the brain; harness = the nervous system, body, and environment. As models get stronger, the harness is what decides reliability, cost, latency and safety.

Loop Controllability — steering the agent loop

One line: How precisely you can steer, intercept and recover within the run-loop — the practical craft of a good harness.

An agent runs in a cycle: think → use a tool → read the result → think again. "Loop controllability" is how tightly you can supervise that cycle. The levers: build the prompt the same way every time (predictability); catch and retry when a tool returns garbage; drop in checkpoints (hooks) before/after each step; trim the conversation without confusing the model; pause for a human's OK on risky actions; and even start the model's answer for it to nudge direction (prefill).

The levers to understand

"How do you compress while keeping the cache?" → keep a stable prefix and only mutate the tail; never rewrite earlier tokens, or you invalidate the whole prefix cache and pay for a full recompute.

Inference Optimization — prefill, decode & caching

One line: Understand the two phases and how the harness exploits them — this is why prefix stability matters so much.

Answering happens in two stages. Prefill is the model "reading" the whole prompt — fast, done in parallel, like skimming a page at a glance. Decode is "writing" the answer one word at a time — slower. The big money-saver is prompt caching: if the start of the prompt is identical to last time, the system reuses its earlier "reading" instead of re-doing it (a cache hit) — which is exactly why a good harness keeps the beginning of the prompt stable. Continuous batching squeezes many users together word-by-word to keep the GPU busy. Takeaway: stable prompt prefixes turn directly into lower cost and faster responses.

Key concepts to understand

This is exactly why the harness keeps a stable prefix and compresses only the tail (#6): every prefix change is a cache miss = real money + real latency.

Post-training — fitting the model to the agent environment

One line: Making a base model fit the agentic environment — not deep model research, just enough to understand the mechanism.

A base model is a brilliant new-grad who's read the whole internet but never held this specific job. Post-training is the on-the-job training: first show it thousands of worked examples of doing the task the right way (supervised fine-tuning), then let it practice in a realistic setup and reward good outcomes (reinforcement learning) — for example, "did the code it wrote actually pass the tests?" The goal isn't to redesign the model; it's to make it fluent in your tools, your loop, and your conventions, and good at recovering when a tool fails.

Key concepts to understand

You don't need the math — what matters is understanding why post-training shapes how the model behaves inside your harness. The model's habits as an agent are shaped here: its tool-call conventions, error-recovery patterns, and loop discipline.

Long-horizon Tasks — keeping coherence over many steps

One line: Keeping an agent coherent over many steps / hours / days — the failure modes plus the compression playbook.

It's project management for a job that runs for days, not minutes. Four ways it derails: the agent forgets the original goal (goal drift), its notes pile up until the desk overflows (context explosion), nobody double-checks the work (weak verification), and small early mistakes snowball (error accumulation). The main fix is smart note-condensing (compaction): when the desk fills, summarize the old stuff into a tight recap and carry on. Real systems do this in tiers — light cleanup → full summary → a pre-saved notes file — and time it carefully, ideally at a natural task boundary.

The four failure modes

The compression playbook

Coding Agent Evaluation — benchmarks & eval pipelines

One line: Know the benchmarks and the eval pipeline that runs them — and why the harness is part of what's being measured.

It's a standardized exam for coding agents. SWE-bench hands the agent a real GitHub bug report and checks whether its fix makes the project's existing tests pass — graded automatically. The eval pipeline is the exam hall: spin up a fresh sandbox per question, apply the agent's patch, run the tests, tally the score (often "pass@k" — did it succeed on any of N tries). A critical insight: the same model can score very differently depending on the harness wrapped around it — so a benchmark number reflects the scaffolding as much as the model itself.

Key concepts to understand

Harness sensitivity — the same model scores very differently under different harnesses. Also watch for benchmark contamination (training data including test cases). A score without knowing the harness tells you only half the story.

Kimi Swarm — model-native orchestration

One line: Moonshot's Agent Swarm bakes multi-agent orchestration into the model — a concrete example of model-driven versus role-driven orchestration.

Instead of one worker grinding through a big job step-by-step, the model acts like a team lead that instantly "hires" a swarm of temp workers, hands each a slice of the task, lets them work in parallel, then stitches their results back together — and crucially, the model itself decides the split, not a fixed org chart. Kimi scaled this from ~100 parallel workers (K2.5) to ~300 (K2.6). Claw Groups lets workers on different devices and even different underlying models — plus humans — join the same job.

Key concepts to understand

✦ Quiz — check your understanding (8 questions)

Pick an answer and hit "Check" to see if you've got it. These questions cover the most important concepts across all 11 topics.

Question 1 of 8

What are the seven things a harness owns?

Question 2 of 8

What is "progressive disclosure" in the context of the Skill System?

Question 3 of 8

What is the difference between Prefill and Decode in model inference?

Question 4 of 8

What are the four failure modes of long-horizon tasks?

Question 5 of 8

What is "dreaming" in the context of agent memory management?

Question 6 of 8

What is a MicroVM (like Firecracker), and why is it used for agent sandboxes?

Question 7 of 8

Why do prefix-stable prompts matter for inference cost and speed?

Question 8 of 8

What is the key difference between how Claude Code/Codex and Kimi Swarm handle multi-agent orchestration?

🃏 Flashcards — tap any card to reveal the definition

14 key terms from this guide. Tap to flip.

Harness
tap to reveal →
The engineering shell around the model — tools, context management, sandbox, loop control — everything that is not the model weights. Makes an agent reliable.
← tap to flip back
KV cache (key-value cache)
tap to reveal →
Cached attention data for an unchanged prompt prefix. A cache hit avoids expensive recomputation. Prefix stability = cache hits = lower cost and latency.
← tap to flip back
Prefill / Decode
tap to reveal →
Prefill = parallel prompt processing (compute-bound, fast). Decode = token-by-token answer generation (memory-bandwidth-bound, slower). Long answers are the bottleneck.
← tap to flip back
Continuous batching
tap to reveal →
Token-level dynamic batching of concurrent users' requests to maximize GPU throughput. Standard practice in production LLM serving.
← tap to flip back
MicroVM
tap to reveal →
Lightweight virtual machine (Firecracker-style) — full VM isolation with near-container startup speed. Used for agent sandboxes to safely run arbitrary code.
← tap to flip back
Snapshot / Resume
tap to reveal →
Snapshot = save full machine state. Resume = restore instantly. Together they hide cold-start latency for sandboxes without sacrificing isolation.
← tap to flip back
Human-in-the-loop (HITL)
tap to reveal →
A gate where the loop pauses for human approval or input before continuing — used for risky or irreversible actions.
← tap to flip back
Stop reason
tap to reveal →
Why generation halted: turn finished, model wants a tool call, or hit max tokens. The harness branches on this signal to decide what to do next.
← tap to flip back
Prefill intervention
tap to reveal →
Steering output by pre-writing the opening tokens of the model's response — strongly nudges the direction or format of what comes next.
← tap to flip back
Progressive disclosure
tap to reveal →
Only keep a skill's name and description in context at startup (~60 tokens); load the full body on-demand when triggered. Saves tens of thousands of tokens.
← tap to flip back
Dreaming / nightly tide
tap to reveal →
Offline batch consolidation of memory — scheduled nightly (T+1) instead of real-time writes. Avoids the hard problem of deciding what to write mid-conversation.
← tap to flip back
Process reward model (PRM)
tap to reveal →
A model that gives step-by-step reward signals during RL training — much denser feedback for long agentic tasks than a final-outcome reward alone.
← tap to flip back
SWE-bench
tap to reveal →
Benchmark of real GitHub issues. The agent must produce a patch that passes the repository's existing tests. Score reflects both model and harness quality.
← tap to flip back
Goal drift
tap to reveal →
Long-horizon failure where the agent gradually loses or mutates its original objective — often subtle, compounding over many steps.
← tap to flip back