Quick Start

This chapter gets Pi running locally: install dependencies, build, launch the coding agent, and understand the call chain of a minimal run. By the end you will have a working coding agent in your terminal and a clear picture of how a single request travels through Pi's layers. The whole flow is designed to be safe by default — pinned dependencies, disabled install scripts, and a recorded session you can audit after the fact.

Prerequisites

1. Get the source

Clone the repository and step into it. Pi is a single npm-workspaces monorepo, so one clone gives you every package.

git clone https://github.com/earendil-works/pi.git
cd pi

2. Install dependencies safely

Pi uses an npm workspaces monorepo. To avoid lifecycle scripts from untrusted dependencies executing code, the official recommendation is to always pass --ignore-scripts:

# dev install
npm install --ignore-scripts

# CI install
npm ci --ignore-scripts
Supply-chain hardening: dependencies are precisely pinned, package-lock.json is the source of truth; local install, doc install and pi update --self all prefer --ignore-scripts. The build steps run explicitly, not via third-party install hooks.

3. Build & check

Build every package in the workspace, then optionally run the check suite (lint + format + type-check) to confirm your environment is healthy.

npm run build   # build all packages
npm run check   # lint + format + type-check

4. Launch the coding-agent CLI

pi-coding-agent is the interactive coding agent. From inside a repo you can ask it to read code, edit files and run commands like a pair programmer:

# run from source (callable from any directory)
./pi-test.sh

# run tests (auto-skips LLM-dependent cases without an API key)
./test.sh

When the prompt appears, try a small, concrete instruction first — for example, "summarize what this repository does in one sentence" — so you can confirm the model connection before attempting edits.

What you get: a terminal interface where every change the agent proposes is shown as a diff before it is written, every command it runs is visible, and the whole interaction is recorded so you can review or replay it later. Treat it like a very fast junior engineer: give precise instructions, check the diff, and keep the sandbox on.

5. Minimal agent loop

Pi's core is a stable loop: prepare context → call model → handle tool → write back → continue or stop. Here is a sketch of the call chain:

UI→ API→ Session→ AgentLoop→ Model→ Tool
UI      → POST /api/runs
API     → returns runId, opens an SSE event stream
Session → writes the user message, builds context
Loop    → model.complete(messages, tools)
Model   → returns toolCall: read_file
Tool    → executes and returns the result
Loop    → calls the model again, until the final answer
API     → SSE pushes AgentEvent + the full session

Troubleshooting

Tips for daily use

From the CLI to your own agent

The CLI is convenient, but Pi is a toolkit you can embed. The smallest useful agent is just: define a tool, create a model, build an Agent, open a Session, and iterate on the events it emits. The Chinese first-agent tutorial shows the full TypeScript example; the Core packages page lists what each package exports.

Next steps

微信群二维码

扫码加入
Pi Agent 微信交流群

💬