A hands-on course that walks through building a Pi-style coding agent from scratch across 15 checkpoints, starting from an offline agent trajectory.

Stars

625

7-day growth

+484

Forks

39

Open issues

0

License

MIT

Last updated

2026-07-23

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

It provides a real, checkoutable Git history with incremental commits, focused tests, and failure experiments, making the learning process concrete and verifiable.

Who it is for

  • Developers wanting to learn how to build an AI coding agent
  • TypeScript enthusiasts interested in agent architectures
  • Self-learners who prefer hands-on, git-based tutorials

Use cases

  • Self-study of agent loop, tool invocation, and session management
  • Reference for implementing coding agents in TypeScript
  • Teaching material for workshops or university courses on AI agents

Strengths

  • 15 sequential checkpoints with clear learning path
  • Each chapter includes real commits, tests, and failure experiments
  • Online textbook with readable content and downloadable code

Considerations

  • Requires prior knowledge of TypeScript and basic async programming
  • Course depends on a specific upstream Pi commit, may become outdated
  • Limited to one specific agent architecture (Pi-style); not a general survey

README quick start

简体中文 · English

动手学 Pi

沿 15 个 checkpoint,从一条离线轨迹开始,亲手实现一个 Pi-style coding agent。

在线阅读 · 课程代码

这是什么

沿 15 个可运行 checkpoint,从一条离线 Agent 轨迹出发,逐步实现:

TypeScript 协议 → 流式模型 → Provider → 工具 → Agent Loop → 会话树 → Context Compaction → 扩展 → Eval

每章由四部分闭环:教材正文 + 真实 commit + 聚焦测试 + 故障实验。课程代码不是伪代码演示,而是一条可以 checkout、运行和验证的 Git 历史。

内容速览(Checkpoint 00–14)

15 个 checkpoint 沿同一条 Agent 执行链逐层推进:先建立消息与模型协议,再接入工具和循环,随后保存状态与历史,最后组合 Runtime 并用独立评测验收。

部分Checkpoint章节这一章完成什么阅读
序章00一次 README 读取请求怎样走完 Agent 闭环跟随一次 README 请求,把用户消息、两次模型调用、工具调用与结果、最终回答连成完整闭环。打开
I · 模型与协议01TypeScript 生存集:四个 DemoEvent 怎样进入测试用四个 DemoEvent 串起联合类型、运行时校验、Promise 与 ESM 测试。打开
I · 模型与协议02EventStream:同一个对象怎样交付下一项和最终结果实现 EventStream,让事件先到与消费者先等两种时序都能交付过程项和最终结果。打开
I · 模型与协议03保存一次完整的工具往返把文本、工具调用和配对结果保存为统一消息,并从模型事件收束出完整 assistant message。打开
I · 模型与协议04ScriptedModel:同一个实例怎样依次播放两个回合实现可重复播放预设回合的 ScriptedModel,保存请求快照并投影稳定事件流。打开
I · 模型与协议05模型调用:在课程协议和 Provider API 之间转换把课程消息写成 Provider 请求,再将 SSE 响应还原为统一模型事件。打开
II · 工具与循环06工具调用:一条 echo 请求怎样变成配对结果让 echo 调用经过 schema、Registry 和 executor,返回沿用原 call id 的工具结果。打开
II · 工具与循环07Agent Loop:一次 README 往返怎样调用模型两次实现两轮 Agent Loop:模型提出 read,工具结果写回后再生成最终回答。打开
II · 工具与循环08四个工具怎样在同一个 workspace 里完成文件任务让 read、write、edit、bash 在同一 workspace 内完成受控的文件与进程操作。打开
III · 状态与历史09从单次循环到有状态 Agent让同一个 Agent 保存跨运行消息,并管理订阅、取消、运行中指令、follow-up 与重入。打开
III · 状态

Description

《动手学 Pi》:沿 15 个真实 checkpoint 从零构建 Pi-style Agent

Related repositories

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

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
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
uzairansaruzi
Featured
uzairansaruzi GitHub avatar

hermex

Hermex is a native SwiftUI iPhone app that lets you control a self-hosted Hermes AI agent directly from your phone, with no subscriptions, tracking, or third-party relay.

AI & Machine LearningLarge Language Models
941