Donggua's AI Learning Notes: In-depth Pi-Agent SDK Tutorial
A systematic source-code breakdown of the production-grade Agent SDK Pi-Agent, with TypeScript and Python dual-language comparison, helping developers understand internal Agent architecture.
- Source repo
- buchidonggua/dg-ai-notes
- Stars
- ★ 3.8k
- Last updated
- 3mo ago v1.0
- FARS reviewed
- Nov 08, 2026
- License
- MIT
- Primary language
- MDX
- FA score
- 49/100 · Major gaps
At a glance
- How it runs
- Works with
- Universal · cross-platform
- Cost
- Free, no paid service needed
- Setup effort
- Low · running in minutes
- Typical use
- Developers planning to build an AI Agent from scratch using the pi-agent SDK can quickly grasp core concepts and source implementation through this tutorial.
- Not a fit if
- Hands-on learners: companion lab code L00-L31 is not public
- Python-only readers: source analysis is TypeScript-centric
- Teams needing closed-source reuse: docs are CC-BY-SA-4.0
- Website
- dg-ai-notes.pages.dev ↗ set on GitHub
- Maintenance
- Commits in the last 6 monthslast commit 2026-08-23latest release v1.0 (2026-07-05)+9.9 ★/day over 7 days
- Source review
- 49/100 · Major gaps
What does this agent do, and when should you use it?
This repository is a collection of learning notes for deeply analyzing the source code of Pi-Agent, an open-source Agent SDK by earendil-works. The tutorial consists of 10 chapters that systematically dissect Pi's core design, including three-layer architecture, Agent Loop, tool system, message system, event-driven model, context engineering and compression, and session management. Each chapter provides both TypeScript (matching Pi's original language) and Python versions. The content is stored as Markdown docs under pi-agent/docs, with a web version (three-column layout, figure linking, theme switching) and a PDF version (v1.0 Release). Additionally, an executable Jupyter Notebook serves as an experimental playground for Chapter 3 (Agent Loop). The tutorial is suitable for developers wanting to build agents with the Pi SDK, engineers who want to understand the internals of production-grade agents, and curiosity-driven folks who aren't satisfied with just using tools like Claude Code. Code is licensed under MIT, documentation under CC-BY-SA-4.0.
The repository provides a systematic tutorial on the Pi-Agent SDK, centered on source-code analysis. It covers Pi's Agent Loop (model loop invocation, stop conditions, error guardrails), tool system (five-step pipeline: define/register/intercept/execute/reclaim), message system (7 internal free expressions translated to 3 standard Messages), event-driven architecture (synchronous barriers + pub/sub), session management (Session Tree), and extension mechanism (factory functions + throwing stubs + event bus). Readers can follow the chapters sequentially (ch01 to ch10) or directly access Markdown docs under pi-agent/docs (TypeScript and Python folders). The web version and PDF version offer alternative reading modes. The Notebook (notebooks/agent-loop.ipynb) allows step-by-step execution and parameter adjustments for the Agent Loop. Three reading methods are provided: web (recommended), Markdown download, and PDF. The repository also includes a content map and contribution guidelines.
- Developers planning to build an AI Agent from scratch using the pi-agent SDK can quickly grasp core concepts and source implementation through this tutorial.
- Engineers who want to deeply understand the internal architecture of production-grade agents (e.g., Claude Code, Cursor, Cline) can learn by comparing with Pi's source code.
- Python-centric developers can use the Python documentation (pi-agent/docs/python) to learn Agent SDK design without TypeScript hurdles.
- Learners preferring an immersive reading experience can access the web version (dg-ai-notes.pages.dev) with a three-column layout, figures, and theme switching.
- Those needing offline or archival reading can download the PDF version (v1.0 Release).
- Researchers interested in Agent Loop mechanics can use the Notebook playground (notebooks/agent-loop.ipynb) for interactive exploration and debugging.
How do you install or deploy this agent?
This is a learning notes repository; no installation is required for runtime. For online reading, visit https://dg-ai-notes.pages.dev. To read locally, clone the repo: git clone https://github.com/buchidonggua/dg-ai-notes.git, then open the Markdown files under pi-agent/docs in a Markdown reader. The PDF can be downloaded from the GitHub Releases (v1.0).
How do you use this agent?
Choose a reading method: 1) Access the web version (recommended) for an immersive three-column experience; 2) Clone the repo and read Markdown files under pi-agent/docs (TypeScript: pi-agent/docs/typescript/, Python: pi-agent/docs/python/); 3) Download the PDF for offline reading. It's suggested to read chapters sequentially (ch01 to ch10). You can also run the Notebook (requires Jupyter Notebook or JupyterLab) notebooks/agent-loop.ipynb to experiment with Agent Loop, adjusting parameters and observing loop state.
What are this agent's strengths and limitations?
- In-depth analysis of a production-grade Agent SDK (Pi-Agent), covering core modules like Agent Loop, tool system, and message system, with clear explanations of design tradeoffs.
- Offers both TypeScript and Python versions, catering to readers with different language backgrounds.
- Multiple reading modes (web, Markdown, PDF) plus an interactive Agent Loop Notebook, enhancing learning.
- Systematic 10-chapter structure, each chapter answering what, how, and why.
- The tutorial is read-focused; companion experiment code (L00-L31) is not public, limiting hands-on practice.
- The content is tied to Pi-Agent source; readers unfamiliar with TypeScript or Agent basics may face a steep learning curve.
- Documentation is CC-BY-SA-4.0, requiring derivative works to be open-sourced, which may restrict commercial use.
- No direct installation/run instructions; relies on external web service (pages.dev) for best experience, and full hands-on requires manual source inspection.
How does this agent compare with similar options?
Key facts side by side with the most closely related agents.
| Agent | Source review | Form / cost | Stars | Updated | Language | Full support on |
|---|---|---|---|---|---|---|
| Donggua's AI Learning Notes: In-depth Pi-Agent SDK Tutorial This agent | 49 · Major gaps | Web appFree | ★ 3.8k | 3mo ago | MDX | — |
| Claude Code From Scratch | 62 · Some gaps | CLIFree + model costs | ★ 2.9k | 3d ago | HTML | OpenAI API · Claude API |
| PI from Scratch | 56 · Major gaps | CLIFree + model costs | ★ 1.3k | 1mo ago | TypeScript | OpenAI API |
| Learn Claude Code: Harness Engineering for Real Agents | 57 · Major gaps | CLIFree + model costs | ★ 81k | 18d ago | Python | Claude API |
How does FollowAgents rate this agent?
Why each dimension lost points
The material explicitly flags the default bash tool as a security opening in multi-user settings and the default session path as unsuitable for multi-user web use, recommending in-memory session management and application-owned persistence. This gives partial least-privilege and sensitive-data guidance. Upgrade instructions require checking releases and leaving the upgrade decision to the user; the advice to queue slow extension I/O shows awareness of side effects. Event dispatch, persistence and blocking behavior are described, but general retention, credential handling and recovery controls are absent. The skill pins an install version but provides no dependency vulnerability review. The README credits Pi's team and cited projects, making sources traceable; author attribution is clear, while ongoing maintenance responsibility is less explicit.
The skill claims alignment with v0.83.0 and gives a pinned install command, event guidance and code example. The supplied README and skill serve different purposes and do not independently corroborate the API details; the README's claim that seven code groups run with npm install cannot be verified from this packet. Version and upgrade guidance are relatively clear, but failure handling appears as scattered issue-specific advice rather than a systematic approach.
The material targets pi-agent SDK developers and covers agents, tools, extensions, sessions, models and enterprise internal-model integration, with trigger terms and an intent index. This makes common scenarios fairly clear. The skill limits its subject to pi-agent work, but phrases such as “any task” involving SDK APIs make triggering broad, and supported environments and out-of-scope cases are not well defined.
The README and skill use a layered directory structure, scenario identifiers, an intent index and installation instructions, with quick-start examples and a contribution path. A fixed version baseline is paired with upgrade review and a maintenance procedure. The MIT license file is clear, while the README separately assigns CC-BY-SA-4.0 to documentation, so asset-specific licensing must be observed. The author and contribution channel are identified, but ownership of ongoing maintenance, release cadence and long-term support are not established.
The materials focus on Pi SDK development and provide scenario guides, bilingual source explanations, event pitfalls and a copyable minimal example that could reduce integration and lookup work. The skill also claims to help produce configurations, implement features and search community extensions, but those outcome claims lack demonstrated results or evaluation. The effort required to read the large documentation set and keep it aligned with SDK versions is not quantified.
The README and skill provide specific product, installation and version-baseline statements that can be traced to supplied files. A separate implementation, test evidence or second source does not corroborate API or tutorial correctness. Claims such as “production-grade,” “one step” completion and superiority to scattered documentation are not clearly separated from demonstrated evidence or substantiated.
- This is a static review of the supplied README, skill excerpt and license; examples were not run and the full repository was not checked, so confidence is low.
- Before using the skill for a multi-user web service, independently restrict tool permissions, design session isolation and persistence, and handle credentials and data retention for the application.
- The README assigns CC-BY-SA-4.0 to documentation and MIT to code; identify the applicable license for each asset when distributing or adapting it.
Recent releases
Latest entries from the project's GitHub Releases. Notes are quoted from upstream as written, not rewritten or tested by FollowAgents.
-
v1.0 v1.0 · Pi-Agent 教程首发(TS + Python 双版本 PDF)
Release notes excerpt
📚 Pi-Agent 教程首发 10 章深度拆解 [pi-agent](https://github.com/earendil-works/pi) SDK 的设计与实现,提供 TypeScript 与 Python 双版本。 📥 下载 | 文件 | 适用读者 | 大小 | |------|---------|------| | \pi-agent-book-ts.pdf\ | TypeScript / 前端 / 全栈 | 14 MB | | \pi-agent-book-python.pdf\ | Python / AI 工程师 | 16 MB | 🌐 在线版本 - Web 版(推荐 PC 阅读):https://dg-ai-notes.pages.dev/ - Markdown 版(边读边问 AI):见仓库 \pi-agent/docs/{typescript,python}/\ 📋 覆盖内容(10 章) ch01 开篇总览 → ch02 三层架构 → ch03 Agent Loop → ch04 模型调用 → ch05 工具系统 → ch06 消息系统 → ch07 事件驱动 → ch08 上下文工程 → ch09 上下文压缩 → ch10 会话管理 ⚠️ 关于版本 …View on GitHub ↗
FAQ
Is this tutorial suitable for complete beginners to Agent development?
Does the tutorial include runnable code?
Are the Python and TypeScript versions identical in content?
Can I build a production-grade Agent based on these tutorials?
Thanks — we use this to improve the page.
Subscribe to the FollowAgents RSS feed, or save this agent to your browser shortlist to compare on your next visit.