pi-textbook

作者 hahhforest

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

1,213
Stars
72
Forks
TypeScript
语言
2026/8/23
添加时间

⚠️ 第三方软件声明

本 Skill 为第三方开源软件,独立托管于 GitHub。SkillTip 仅为信息目录,不控制或维护底层仓库。所显示的安全检查为自动化且范围有限,安装前请自行审查源码。

阅读服务条款

安装

添加到你的 Claude Code skills 目录:

# Add to your Claude Code skills
git clone https://github.com/hahhforest/pi-textbook

快速入门

使用 pi-textbook 等 Skills 的指南。

安全报告

已验证

上次扫描:—

{
  "status": "PASSED",
  "issues": []
}

README.md

简体中文 · English

动手学 Pi Logo

动手学 Pi

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

在线阅读 · 课程代码

动手学 Pi 在线教材首页

这是什么

沿 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 · 状态与历史10从一棵会话树恢复当前对话把完成消息追加为带父指针的 JSONL 记录,再从指定叶子恢复当前对话路径。打开
III · 状态与历史11历史不动,上下文按预算重建按完整工具交互切分历史,在 token 预算内保留后缀,并用结构化摘要补回早期事实。打开
IV · 扩展与验证12知识按需进入上下文,代码先过信任门发现项目规则、Skill 与模板,按需送入上下文,并让可信扩展原子注册工具与 hooks。打开
IV · 扩展与验证13把已有能力接成一个能提交历史的 Runtime把 Agent、Session Store、上下文、资源与扩展接成 Runtime,让 prompt 在新消息被接受后完成。打开
IV · 扩展与验证14给完整的 Pi 建一套独立评测用全新 fixture 运行 Runtime,核对活动路径与文件结果,再输出稳定的分类和计数。打开

开始阅读

直接打开在线教材,或在本地运行:

git clone https://github.com/hahhforest/pi-textbook.git
cd pi-textbook
npm install
npm run dev

教材与课程代码

仓库作用
pi-textbook你正在看的 HTML 教材与网站
pi 的课程分支15 个 checkpoint 的可运行代码;课程源码位于仓库内的 packages/pi-course/

课程分支从固定上游 commit 8479bd84 出发,以 course(00)course(14) 组织完整历史;pi-course-v1course-v1/00course-v1/14 tags 固定第一版课程。

和 Agent 一起练习

git clone --branch course/build-your-own-pi https://github.com/hahhforest/pi.git
cd pi
npm install
npm run checkpoint -w @pi/course -- 05
npm run practice -w @pi/course -- 05 ../pi-practice-05

checkpoint 定位本章的 parent、target 与聚焦测试;practice 创建一个不含答案和 Git 历史的练习目录。把本章网页、命令输出与练习目录中的 LEARNING.md 一起交给陪学 Agent 即可。

项目说明

这是社区原创的非官方课程,不隶属于或代表 Pi / Earendil Works。应用与原创代码采用 MIT License;教材正文与原创媒体采用 CC BY 4.0;Pi 上游代码沿用其原许可证和作者归属。详见 LICENSELICENSE-CONTENT

构建、测试和跨仓库历史校验见 CONTRIBUTING.md

感谢 LINUX DO 提供中文技术交流空间。

常见问题

What is pi-textbook?

pi-textbook is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by hahhforest. 《动手学 Pi》:沿 15 个真实 checkpoint 从零构建 Pi-style Agent. It has 1,213 GitHub stars.

Is pi-textbook safe to use?

pi-textbook returned warnings in SkillsLLM's automated security scan. It has no critical vulnerabilities, but review the flagged issues in the Security Report section before adding it to your workflow.

How do I install pi-textbook?

Clone the repository with "git clone https://github.com/hahhforest/pi-textbook" and add it to your Claude Code skills directory (see the Installation section above).

What programming language is pi-textbook written in?

pi-textbook is primarily written in TypeScript. It is open-source under hahhforest on GitHub, so you can review or fork the full source.

Are there alternatives to pi-textbook?

Yes. SkillsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh pi-textbook against similar tools.

评论 (0)

暂无评论,成为第一个分享想法的人!

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情

claude-code

by anthropics

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

120,03119,897Shell
AI 智能体
查看详情

开发者还喜欢

基于喜欢此 Skill 的开发者投票和收藏

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

n8n

by n8n-io

12

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

201,88160,308TypeScript
MCP 服务器apisai-tools
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情