写好一个 Agent,70% 的难点不在 LLM,在系统工程;20% 在设计哲学,10% 才在 prompt 与模型。
基于 Claude Code (TypeScript) 和 Codex CLI (Rust) 的真实源码,系统化整理的 Agent 构建知识体系。
docs/
├── layer1/ OS 与沙箱(6 篇)
├── layer2/ 并发与异步(5 篇)
├── layer3/ 状态机与类型驱动(5 篇)
├── layer4/ LLM 工程(8 篇)
├── layer5/ Agent 系统设计(7 篇)
├── learning/ 学习路径(3 篇)
├── reference/ 参考对照(2 篇)
└── strategy/ 策略文档(3 篇)
缺这一层,你的 Agent 就只能靠 prompt 自律。
| 文档 | 核心内容 |
|---|---|
| 进程线程信号 | wait/waitpid、SIGTERM/SIGKILL、process group |
| macOS Seatbelt 沙箱 | sandbox-exec、profile DSL |
| Linux Landlock 与 seccomp 沙箱 | ruleset、syscall filter |
| Windows Job Object 沙箱 | nested jobs、kill-on-close |
| WASI WASM 沙箱 | capability token、resource limits |
| 文件锁 原子写 fsync | flock、rename(2) 原子性 |
缺这一层,你的 lifecycle 会有难以复现的 bug。
| 文档 | 核心内容 |
|---|---|
| Structured Concurrency | Trio、Kotlin、Rust 1.75+ |
| Actor CSP | Erlang/Akka 思路、tokio channels |
| Backpressure | bounded channel、drop strategy |
| Cancellation Propagation | ctx cancel、cooperative vs preemptive |
| Race Conditions in Lifecycle | happens-before、CAS、memory ordering |
缺这一层,你的 Agent 会出"理论上不可能发生"的状态。
| 文档 | 核心内容 |
|---|---|
| 有限状态机正式建模 | sealed enum、exhaustive match |
| Make Illegal States Unrepresentable | sum types、phantom types、newtype |
| Property Based Testing | quickcheck、proptest |
| Invariant 驱动设计 | DbC(design by contract) |
| Event Sourcing | append-only log、snapshot |
缺这一层,你只是"调 API",不是"做 Agent"。
| 文档 | 核心内容 |
|---|---|
| Token 经济学 | tokenizer、BPE、context window 拆分 |
| Streaming 协议 | SSE、chunk boundary、partial JSON |
| Tool Calling 格式 | OpenAI tools、Anthropic tool_use、Gemini parts |
| Structured Output | JSON Schema、Pydantic、Zod |
| Context Engineering | sliding window、summarization、RAG 何时不用 |
| Prompt Injection 防御 | system instruction 与 user data 分离 |
| 模型差异性 | sampling、temperature、top_p、seed |
| 失败模式分类 | timeout / refusal / hallucination / loop |
缺这一层,你只能写出 demo,做不出产品。
| 文档 | 核心内容 |
|---|---|
| Capability-based Security | object capabilities、不可伪造的句柄 |
| Replay and Audit | deterministic replay、audit log schema |
| Subagent 多Agent协调 | 五种架构模式、委派模型、snapshot 继承 |
| Agent Team 协调 | Leader/Worker、Mailbox 消息协议、Team Memory |
| Memory 分级 | trusted / diagnostic / skipped、provenance tag |
| Compact and Handoff | summary contract、anchor 引用 |
| Hook 系统 | fail-closed、紧急绕过 |
| 文档 | 内容 |
|---|---|
| 写一个 Agent 需要补足的知识体系 | 五层必修 + 进阶专题 + 思维方式 + 反模式 |
| 12 个月 Agent 学习路径 | 每月核心书/章节 → 必看 talk → 必读代码 → 必做练习 |
| 12 个月骨架之外,还该补的知识 | Evals、安全攻防、产品 UX、运维 SLO、成本工程 |
| 文档 | 内容 |
|---|---|
| 源码实现对照:Claude Code vs Codex | 11 个核心主题的逐项实现对比 |
| Agent 测评:方法论与基准 | pass@k vs pass^k、LLM-as-Judge、Golden Set |
| 文档 | 内容 |
|---|---|
| 如何架构一个 Agent | 六条第一性原理、顶层骨架、关键抽象、反向决策 |
| 写一个 Agent 需要多大团队 | 反规模特性、按产品形态配置、必备角色 |
| 让 AI 来写 Agent 的优劣与红线 | 红利、陷阱、绝对红线、协作模式 |