Learn Claude Code
从 0 到 1 构建 nano Claude Code-like agent,每次只加一个机制
核心模式
所有 AI 编程 Agent 共享同一个循环:调用模型、执行工具、回传结果。生产级系统会在其上叠加策略、权限和生命周期层。
while True:
response = client.messages.create(messages=messages, tools=tools)
if response.stop_reason != "tool_use":
break
for tool_call in response.content:
result = execute_tool(tool_call.name, tool_call.input)
messages.append(result)消息增长
观察 Agent 循环执行时消息数组的增长
学习路径
20 个渐进式课程,从简单循环到完整多 Agent Harness
The Agent Loop
The smallest useful agent is a loop that calls the model, runs tools, and feeds results back.
Tool Use
The loop stays stable while capabilities register into a dispatch table.
Permission
Dangerous actions need a harness decision point before the shell runs.
Hooks
Cross-cutting behavior belongs around the loop, not tangled inside it.
TodoWrite
Explicit plans keep long-running work visible and correctable.
Subagent
Subagents give each subtask a clean message history while preserving the main thread.
Skill Loading
Inject specialized knowledge only when the task actually needs it.
Context Compact
Compression keeps the conversation usable when the context window gets crowded.
Memory
Some facts should survive summarization and future sessions.
System Prompt
The system prompt is a generated product of policy, tools, skills, and context.
Error Recovery
A robust harness classifies failures and decides what kind of retry is worthwhile.
Task System
A task graph turns vague goals into ordered, observable work.
Background Tasks
The agent can keep reasoning while slow work completes elsewhere.
Cron Scheduler
Recurring work should be created by the harness, not remembered by the model.
Agent Teams
Persistent teammates let work continue in parallel without stuffing every thought into one context.
Team Protocols
Multi-agent systems need explicit message contracts, not vibes.
Autonomous Agents
Teammates become useful when they can discover and claim work themselves.
Worktree Isolation
Parallel agents need isolated filesystems as much as isolated conversations.
MCP Tools
External services can become agent tools through a standard discovery and call protocol.
Comprehensive Agent
The final harness is still one loop, now surrounded by the systems that make it production-shaped.
架构层次
五个正交关注点组合成完整的 Agent