LLM agent 的结构、包在模型外面的 harness、一个具体 agent loop(Pi)的实现取舍,以及 Agent Skills。分节沿用 index 的三个主题组:LLM Agent 架构与 harness,Agent loop 工程(Pi),Agent Skills。
Core Ideas
What an agent is
- An LLM agent combines planning memory and tool use around a language model core — the language model as the brain, with planning, memory and tool use around it.
- An agent’s short-term memory is its context window and long-term memory is external retrieval — in-context learning is bounded by the window; everything else has to be retrieved.
- Finite context length forces agent design to work within limited communication bandwidth — the window must hold history, instructions, API context and responses at once.
- Tool use is bottlenecked by knowing when and how to call rather than by the tools themselves — the hard part is deciding whether a tool is needed, which one, and with what arguments.
- Keep a tool call only when it improves prediction of future tokens — Toolformer keeps a call only if its result lowers the loss on the following tokens.
- Self-reflection turns trial and error into within-episode learning — Reflexion-style critique and reset turn failed attempts into iteration inside one episode.
- LLMs cannot reliably evaluate their own output in expert domains — in ChemCrow, LLM scoring missed the gap that human experts saw.
The harness around the model
- The harness layer around a model matters as much as its raw intelligence — the system that orchestrates planning, tools, context, artifacts and evaluation around the base model.
- A harness should keep durable state in files rather than in context — logs, diffs and past trajectories outgrow the window, so keep them on disk.
- Context should be maintained as an evolving playbook not an appended log — appending every response grows out of control; curate the context instead.
- Code is the universal language for optimizing agent harnesses — a harness is code, so a model that can edit code can search a far larger design space.
- Harness edits must be falsifiable and the evaluator must stay outside the loop — bound what the program may edit; keep the verifier, tracer and permissions outside it.
- Recursive self-improvement only works above a base-model capability threshold — STOP improved with GPT-4 and degraded with weaker models.
- Repeated agent corrections belong in the codebase rather than the conversation — agents copy what is already in the repo, so fix repeated mistakes in code, lint and CI rather than in chat.
Agent loop engineering (Pi)
Structure and state:
- A stateless loop core plus a stateful wrapper separates orchestration from session state — the loop takes a context snapshot and a config and remembers nothing between calls.
- Inject policy through hooks so the agent loop stays product-agnostic — compaction, permissions, key refresh and shutdown live in config hooks, not in the loop.
- Snapshot boundaries between loop and state owner give crash safety for free — the loop works on a shallow copy of messages and tools on each run.
- Stream partial messages in place so interrupted contexts stay structurally complete — the partial assistant message holds its slot from the start and is replaced as deltas arrive.
Failure handling:
- Agent loops should encode failures as error tool results instead of throwing exceptions — unknown tools, bad arguments and blocked permissions all come back to the model as error results.
- Truncated LLM output should fail all tool calls rather than execute salvaged arguments — arguments salvaged from a length-cut response can validate and still be incomplete.
- Require all tool results to agree before terminating a batch — the loop stops after a batch only when every result sets the terminate flag.
Agent Skills
- Skill descriptions are part of the behavior because they control triggering — the description decides when a skill fires, so tuning it is part of implementation.
- Agent skills should be tested like software rather than trusted like prompts — confidence should come from evals, not from the author’s memory that it worked.
- Agent skill evals are useful but bounded instruments — evals catch regressions on the cases they encode but cannot by themselves prove broad quality.
- Skill evaluations work better in isolated contexts with direct comparisons — clean parallel runs and blinded A/B comparisons give more trustworthy results.
- Agent skills need lifecycle management rather than one-time authoring — create, evaluate, compare, re-evaluate and retire.
- Capability uplift skills can expire as models absorb their behavior — scaffolds for what the model cannot yet do should be rechecked as models improve.
- Encoded preference skills stay valuable when they preserve workflow fidelity — skills that encode a team’s sequence of checks stay useful even with capable models.
Related Sources
- Weng - LLM Powered Autonomous Agents
- Weng - Harness Engineering for Self-Improvement
- Weng - Prompt Engineering
- earendil-works - Pi Agent Loop
- Anthropic - Improving skill-creator Test, measure, and refine Agent Skills
- Lauren Tan - Building a Michelin Kitchen for Agents
Open Threads
- Is Pi’s stateless loop core with a stateful wrapper the same idea as keeping durable state in files, at a smaller scale? (lint X5)
- Reflexion-style self-reflection helps, yet LLMs cannot self-correct without external feedback: how much of reflection’s gain is really environment feedback? (lint C2)
- Lauren Tan ranks Rules and Skills below code and lint as places to put repeated corrections. When is a skill the right home for a correction, and when should it become code? (lint X4)