# How Pi Agent Works: Building an AI Agent from Scratch

A Chinese-language tutorial site that breaks down the Pi coding agent's source code into core concepts, then walks through building a teaching version of an agent in TypeScript, React and Node.js.

how-pi-agent-works is a runnable, Chinese-language VitePress tutorial that explains how the Pi coding agent works from an engineering perspective, based on the earendil-works/pi source and its official documentation, rather than translating the source file by file. It covers core concepts such as the agent loop, messages, streaming events, tool calls, the session tree and context compression, and walks through the layering of the pi-ai, pi-agent-core and pi-coding-agent packages.

Four progressive TypeScript demos build from a minimal loop up to one with tools, sessions and compression, with an optional fifth demo against a real model over an OpenAI-compatible endpoint. The final project implements a runnable teaching version of an agent using React, Node.js and TypeScript, with its own Express API and test, typecheck and build commands, deployed as a static documentation site to Vercel.

Website: https://how-pi-agent-works.vercel.app
