裸のPiでミニマルAgentを自作する
完全なOpenClawスタックを使わず、内核エンジンであるPiだけで完全に制御できるミニマルAgentを構築します。インストール、モデル設定、最初の拡張作成、プロジェクトレベルのSkills、セッションツリーの使い方まで。
前提条件
- Node.js 22.19+ (required by Pi)
- One LLM API key (OpenAI / Anthropic / Google, etc.)
- Terminal and CLI basics
- A clear idea of what your agent should do
ステップ
pi-coding-agentをインストール
Piの対話型coding agentはnpmパッケージとして提供されます。Nodeバージョンを確認してからグローバルインストールします。
コマンド
node -v && npm install -g @earendil-works/pi-coding-agent ヒント
- Pi's supply-chain discipline (pinned deps + shrinkwrap, --ignore-scripts installs) is part of why it has a reliability reputation.
初回起動とモデル設定
任意のディレクトリでpiを実行し、案内に従ってAPIキーを入力します。pi-aiレイヤーがOpenAI / Anthropic / Google等を統一しており、モデル切替でコードは変わりません。
コマンド
pi ヒント
- You can switch models mid-session; messages from different providers coexist in one session by design.
公式サンプル拡張から始める
リポジトリのpackages/coding-agent/examples/に公式サンプル拡張があります。Piに見せて「これに似たものを作って」と頼むのが、ゼロから書くよりずっと速いです。
コマンド
https://github.com/earendil-works/pi/tree/main/packages/coding-agent/examples/ ヒント
- Pi's philosophy is self-extension: instead of downloading community extensions, point the agent at an example and have it remix it for you.
「最小限の拡張」原則を実践
r/PiCodingAgentのコミュニティコンセンサス:拡張は少ないほどPiは良く動く。導入のたびに「本当に良いか?」を問い、違えば削除。
ヒント
- Throw away skills you no longer need too — Armin Ronacher prunes hand-crafted skills regularly.
高頻操作をプロジェクトレベルのSkillsに
リポジトリ内でプロジェクトレベルのSkillsを管理すると、そのプロジェクトでは常に自分の規約に従います。チームメンバーもcloneだけで同じ挙動を得られます。
コマンド
https://www.reddit.com/r/PiCodingAgent/comments/1ttv8fu/project_level_skillsextensions_are_op/ ヒント
- The community calls project-level skills 'OP': commit-message style, changelog generation, forcing uv over pip — all great skill or interception-extension material.
セッションツリーと自己拡張ループ
Piのセッションはツリーです。壊れた拡張を直すために分岐し、完了後にメインセッションへ戻れば文脈を汚しません。Agentに拡張を書かせ→ホットリロード→テストを繰り返します。
ヒント
- Pi can even render custom TUI components (progress bars, file pickers, preview panes) — the author ran Doom in the TUI.