Deep Dive
Pi Agent
|
These 21 chapters take you from the core agent loop to the full engineering picture — based on real source analysis.
Core Agent Loop
Every AI Agent is essentially a loop. pi's core lives in packages/agent/src/agent.ts (577 lines) and agent-loop.ts (792 lines). Click each step to see the corresponding source and implementation details.
User Input
Call Agent.prompt(), push the user message into messages[]
// packages/agent/src/agent.tsconst agent = new Agent({ model, tools, systemPrompt })const sub = agent.subscribe((e) => render(e))await agent.prompt("Fix the bug in auth.ts")// ↑ user message pushed into state.messages
From 30 Lines to 920 Files
A teaching Agent's core loop is just ~30 lines, but how much engineering does production pi stack on top of the same loop?
Five Architecture Layers
pi's ~920 TypeScript files organized into five architecture layers. Click to expand and see core files, design patterns, and corresponding chapters.
8 Distinctive Design Choices in pi
pi's unusual engineering tradeoffs: minimal core + self-extension, Result types, durable session tree, lazy SDKs, supply-chain hardening — each maps to a specific chapter.
Key Source Files
Understanding these key files gives you a grasp of the entire system. File size reflects engineering complexity.
21 Chapters of Source Deep Dive
Each chapter focuses on a core subsystem with source analysis + architecture visualization + runnable demos. Filter by layer, or follow the sequence.