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.

Stars
★ 3.8k
Last updated
3mo ago v1.0
FARS reviewed
Nov 08, 2026
License
MIT
Primary language
MDX

At a glance

How it runs
Web appLibrary / SDK
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

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.

  1. 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.
  2. 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.
  3. Python-centric developers can use the Python documentation (pi-agent/docs/python) to learn Agent SDK design without TypeScript hurdles.
  4. 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.
  5. Those needing offline or archival reading can download the PDF version (v1.0 Release).
  6. 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?

Pros
  • 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.
Limitations
  • 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?

FollowAgents source review · FARS-2.1
Major gaps
49/ 100 5-point scale 2.5 / 5
Trust 14/29
Reliability 5/14
Adaptability 9/18
Convention 10/18
Effectiveness 7/13
Verifiability 4/8
Why each dimension lost points
Trust14 / 29 · 2.4/5

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.

Reliability5 / 14 · 1.8/5

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.

Adaptability9 / 18 · 2.5/5

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.

Convention10 / 18 · 2.8/5

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.

Effectiveness7 / 13 · 2.7/5

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.

Verifiability4 / 8 · 2.5/5

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.

Risks and how to mitigate them
  • 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.
Evidence confidence: Low Reviewed Nov 08, 2026 Reviewed revision 5f4abd34d3d4
See the full review method →
Maintain this project? Add the FARS badge to your README

The badge shows the current review score and verdict and links back to this page. It refreshes about once an hour after a re-review.

FARS

[![FARS review](https://followagents.com/badge/dg-ai-notes.svg)](https://followagents.com/en/agents/dg-ai-notes)
<a href="https://followagents.com/en/agents/dg-ai-notes"><img src="https://followagents.com/badge/dg-ai-notes.svg" alt="FARS review"></a>

Recent releases

Latest entries from the project's GitHub Releases. Notes are quoted from upstream as written, not rewritten or tested by FollowAgents.

  1. 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?
The tutorial assumes some basic familiarity with Agent concepts but progresses from concepts to implementation to design choices. Beginners are advised to first understand LLM and Agent basics before reading sequentially.
Does the tutorial include runnable code?
The main body is read-focused; it does not provide a fully runnable Agent. Only the Agent Loop chapter includes a Jupyter Notebook playground. Companion experiment code (L00-L31) is not public.
Are the Python and TypeScript versions identical in content?
Both versions cover the same chapters and design topics, but implementation languages differ, so code examples vary. Content is equivalent, though details may differ due to language features.
Can I build a production-grade Agent based on these tutorials?
The tutorial provides source analysis and design insights from Pi-Agent, serving as a reference for building agents. However, production-grade agents also involve deployment, operations, security, and other aspects that require consideration in real scenarios.
Was this page helpful?
View on GitHub ↗ Install ↓

Compare agents like this one

The same FARS review applied across the shortlist this agent qualifies for.

Related concepts