A collection of notes on building coding agents, derived from the production development of the desktop agent Reina, with each mechanism simplified into a zero-dependency, single-file Node.js demo.

Stars

218

7-day growth

No data

Forks

13

Open issues

0

License

MIT

Last updated

2026-07-27

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

Every implementation is validated in a real product (Reina) rather than inferred from API docs; all 23+ mechanisms come with runnable, minimal demos that require no dependencies beyond Node 18.

Who it is for

  • Developers building or extending coding agents
  • Engineers optimizing agent toolchains and context management
  • Students and researchers studying practical agent architectures
  • Interview candidates preparing for agent-specialized roles

Use cases

  • Learning how to build a complete agent loop from scratch (s01–s12)
  • Implementing specific mechanisms like tool system, compaction, or prompt caching
  • Comparing design decisions across agents (pi, Kimi CLI) via agent_analysis/
  • Practicing for agent-related technical interviews with curated questions

Strengths

  • Zero-dependency, single-file demos that run on Node 18+ with no setup
  • Derived from real production code in Reina, not hypothetical design
  • Covers a wide range of mechanisms (23 topics) from basic loops to advanced issues like cache-compaction conflicts
  • Includes source-code analysis of other popular agents for cross-validation

Considerations

  • Requires Node 18+ and a compatible OpenAI API key for most demos (some parts work without key)
  • Focuses primarily on coding agents and may not generalize to other agent types
  • Still a work in progress—some sections (interview series) are ongoing

README quick start

learn-agent · AI Agent 开发笔记

简体中文 · English

开发桌面 agent Reina 过程中记下的笔记,讲 coding agent(Claude Code、Codex、opencode 这类工具)的内部实现机制。每篇讲一个机制,把 Reina 里的生产实现简化成零依赖、单文件、可直接运行的 Node 程序——所以这些做法不是照 API 文档推想的,是实际产品里验证过的。

仓库分三块:notes/ 是正篇笔记(s01–s23,每篇一个机制,配可运行 demo);agent_analysis/ 是其他 agent(pi、Kimi CLI)的源码调研档案,笔记从这里取材;interview/ 是从笔记整理的面试题(连载中)。

运行

Node 18+,零依赖:

git clone https://github.com/7-e1even/learn-agent && cd learn-agent
AGENT_API_KEY=sk-xxx node notes/s01_agent_loop/agent.mjs

任何 OpenAI 兼容的 API key(DeepSeek / Kimi / GLM / OpenRouter / 本地 Ollama)都行;没有 key 的话,多数章节的 demo.mjss12 的自测模式不需要 key。

clone 之后可以一键验证所有免 key 的示例:node selftest.mjs——20 个章末 demo 加 s12 的整合自测,十几秒跑完。

目录

s01–s12 从零搭出一个完整可用的 agent,按顺序读;s13 之后是开发 Reina 时陆续踩到、记下来的边界问题,挑感兴趣的读。每篇结尾附 Reina 中对应生产实现的位置。

#主题要解决的问题
s01Agent 主循环最小可用的 agent 长什么样
s02工具系统工具越加越多,怎么不用每次都改循环
s03循环预算与纠偏模型原地打转、反复报错,怎么发现并拉回来
s04工具输出预算与溢出一条 cat 的输出就能撑爆上下文,怎么办
s05流式输出与中断用户按下 Ctrl+C,断在一半的消息记录怎么修
s06上下文压缩上下文满了要压缩,怎么不忘掉最初的任务
s07Prompt 缓存同样的对话,为什么有人的账单贵 10 倍
s08会话持久化与恢复进程崩了,跑了半小时的会话怎么接着跑
s09子代理与看门狗子任务卡死了,怎么发现它并保住已完成的部分
s10System prompt 组装system prompt 越写越长,怎么按需拼装
s11多 agent 协作几个 agent 同时干活,怎么分工不重复不冲突
s12完整 agent 整合前面所有机制装回一个循环里是什么样
s13权限与审批模型要执行 rm -rf,怎么在动手前拦住
s14Provider 兼容层换个模

Description

从零写一个能活下来的 AI Agent:机制从真实产品 Reina 移植 | Build a coding agent from scratch — how Claude Code / Codex / Cursor actually work under the hood. 15 runnable lessons, zero deps.

Related repositories

Similar projects matched by category, topics, and programming language.

deerwork-ai
Featured
deerwork-ai GitHub avatar

deer-workflow

An open-source Dynamic Workflow runtime that combines deterministic TypeScript orchestration with replaceable Agent runtimes.

AI & Machine LearningLarge Language Models
312
makecindy
Featured
makecindy GitHub avatar

cindy

Cindy is an open-source AI agent that runs locally on your machine, integrates multiple AI harnesses and models, and provides memory, skills, and automation to perform real work in your projects and apps.

AI & Machine LearningLarge Language Models
958
0xwilliamortiz
Featured
0xwilliamortiz GitHub avatar

openclaude-improved

OpenClaude is an open-source CLI coding agent that runs on any platform and supports a wide range of LLM providers, offering the same tools and workflows as Claude Code.

AI & Machine LearningLarge Language Models
577