# learn-agent

A set of Chinese-language notes that rebuild the internal mechanisms of coding agents such as Claude Code, Codex and OpenCode as small, dependency-free, runnable Node.js programs, one mechanism per chapter.

learn-agent documents mechanisms observed while building a desktop coding agent, reducing each one to a single-file Node.js program with no dependencies that a reader can run directly, rather than only describing the mechanism in prose or inferring it from an API's own documentation. The first twelve chapters build a working agent from nothing: the main agent loop, a tool system, loop-budget correction, tool-output budgeting, streaming output and interruption handling, context compression, prompt caching, session persistence and recovery, subagents and a watchdog, system-prompt assembly, provider compatibility, and putting all of the pieces back into one loop.

Later chapters, numbered thirteen through twenty-three, cover permissions and approval before a destructive command runs, progressive tool disclosure, multi-model consultation, self-review loops, completion gating, the conflict between compaction and prompt-cache reuse, automatic long-term memory across projects, comparing how different agents answer the same question, and handling image input. A companion self-test script runs every chapter's key-free examples in roughly ten seconds, and a separate folder holds source-code research notes on other agents that fed into the write-ups.

Website: https://github.com/7-e1even/learn-agent
