A bilingual tutorial and source-code walkthrough of the Pi-Agent SDK, with a companion code set and an AI-assistant skill for building agents.
hahhforest/pi-textbook
A Chinese-language textbook that teaches you to build a Pi-style coding agent step by step across 15 runnable Git checkpoints in TypeScript.
- Stars
- 1,407
- Forks
- 83
- Open issues
- 1
- Last commit
- 3 months ago
What is it?
This is a course for building a Pi-style coding agent from scratch in TypeScript. It starts from an offline agent trajectory and adds one layer per checkpoint: message and model protocols, streaming, provider adapters, tools, the agent loop, session trees, context compaction, extensions, and a standalone evaluation harness.
Each chapter combines textbook text, a real commit in the companion course repository, focused tests, and fault-injection experiments. The course code is a Git history that can be checked out, run, and verified at each step rather than pseudocode. The project is available as an online book and as a local dev server built with npm.
The course is unofficial and community-written. It is licensed under MIT for code and CC BY 4.0 for textbook content, and it ships a helper CLI that sets up checkpoints and practice directories for use with a learning agent.
Key features
- 01Fifteen checkpoints, each a real commit that can be checked out and run.
- 02Covers the full path from message types and streaming to provider adapters, tools, and the agent loop.
- 03Includes session tree persistence and context compaction for long conversations.
- 04Ends with an extension system and a standalone evaluation for the finished agent.
- 05Provides a CLI to jump to a checkpoint or generate an exercise directory without answers.
Use cases
- Learning how a coding agent works internals by building one yourself.
- Studying TypeScript patterns such as discriminated unions, event streams, and runtime validation in a realistic project.
- Using the checkpoints as a guided practice path alongside an AI tutor agent.
Quick start
- 1
Clone the textbook repository
git clone https://github.com/hahhforest/pi-textbook.git - 2
Enter the project directory
cd pi-textbook - 3
Install dependencies
npm install - 4
Start the local dev server
npm run dev
Things to know
- The textbook is written in Chinese, so English readers may find the main content hard to follow.
- The course code lives in a separate fork branch, so you must clone that branch to run the checkpoints.
Topics
FAQ
- What is pi-textbook?
- A Chinese-language textbook that teaches you to build a Pi-style coding agent step by step across 15 runnable Git checkpoints in TypeScript. This is a course for building a Pi-style coding agent from scratch in TypeScript. It starts from an offline agent trajectory and adds one layer per checkpoint: message and model protocols, streaming, provider adapters, tools, the agent loop, session trees, context compaction, extensions, and a standalone evaluation harness.
- Is pi-textbook free to use? What license does it have?
- pi-textbook is open source under the MIT license. Check the license terms before using it in commercial products.
- Is pi-textbook still maintained?
- Updated within 6 months. The last commit to pi-textbook was on Jul 23, 2026.
- What can I use pi-textbook for?
- Learning how a coding agent works internals by building one yourself. Studying TypeScript patterns such as discriminated unions, event streams, and runtime validation in a realistic project. Using the checkpoints as a guided practice path alongside an AI tutor agent.
- How do I install pi-textbook?
- Clone the textbook repository: git clone https://github.com/hahhforest/pi-textbook.git Enter the project directory: cd pi-textbook Install dependencies: npm install Start the local dev server: npm run dev
- Where can I get pi-textbook?
- The source code and installation instructions are on GitHub: https://github.com/hahhforest/pi-textbook
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A 17-lesson Python tutorial that builds a Claude Code-like agent harness from scratch, starting with a single loop and bash.
A step-by-step Go workshop that teaches you to build a coding agent on the Claude API, adding file, shell and search tools one at a time.
A non-official Chinese learning handbook for the Pi Coding Agent terminal harness, covering setup through Skills, Extensions, Subagents and long-running workflows.
Open source autonomous coding agent that runs as an IDE extension, terminal CLI, desktop app, or SDK.
A terminal coding agent with built-in LSP, debugger, browser and subagent tools, supporting 60+ model providers.