Advanced Intermediate 30-60 min

裸のPiでミニマルAgentを自作する

完全なOpenClawスタックを使わず、内核エンジンであるPiだけで完全に制御できるミニマルAgentを構築します。インストール、モデル設定、最初の拡張作成、プロジェクトレベルのSkills、セッションツリーの使い方まで。

#Pi#Agent開発#TypeScript

前提条件

  • 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

ステップ

1

pi-coding-agentをインストール

Piの対話型coding agentはnpmパッケージとして提供されます。Nodeバージョンを確認してからグローバルインストールします。

コマンド

All
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.
2

初回起動とモデル設定

任意のディレクトリでpiを実行し、案内に従ってAPIキーを入力します。pi-aiレイヤーがOpenAI / Anthropic / Google等を統一しており、モデル切替でコードは変わりません。

コマンド

All
pi

ヒント

  • You can switch models mid-session; messages from different providers coexist in one session by design.
3

公式サンプル拡張から始める

リポジトリのpackages/coding-agent/examples/に公式サンプル拡張があります。Piに見せて「これに似たものを作って」と頼むのが、ゼロから書くよりずっと速いです。

コマンド

Reference
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.
4

「最小限の拡張」原則を実践

r/PiCodingAgentのコミュニティコンセンサス:拡張は少ないほどPiは良く動く。導入のたびに「本当に良いか?」を問い、違えば削除。

ヒント

  • Throw away skills you no longer need too — Armin Ronacher prunes hand-crafted skills regularly.
5

高頻操作をプロジェクトレベルのSkillsに

リポジトリ内でプロジェクトレベルのSkillsを管理すると、そのプロジェクトでは常に自分の規約に従います。チームメンバーもcloneだけで同じ挙動を得られます。

コマンド

Reference
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.
6

セッションツリーと自己拡張ループ

Piのセッションはツリーです。壊れた拡張を直すために分岐し、完了後にメインセッションへ戻れば文脈を汚しません。Agentに拡張を書かせ→ホットリロード→テストを繰り返します。

ヒント

  • Pi can even render custom TUI components (progress bars, file pickers, preview panes) — the author ran Doom in the TUI.

よくある問題

PiとOpenClawの関係は?
Piはミニマルなエージェントエンジン(内核)で、OpenClawは同じ哲学の上に築かれた完全形態(チャネル統合+24時間自律稼働)です。完成品の執事ならOpenClaw、完全制御や自作なら裸のPiを。
PiにMCPがないが、既存のMCPツールは?
2つの道:mcporterでMCP呼び出しをCLI/TypeScriptバインディングとして公開する(OpenClawと同じ方法)、またはAgentに直接对接skill/拡張を書かせる。自己拡張こそPiの設計思想です。
Piの権限管理は?
Piには権限システムが組み込まれておらず、起動ユーザーの権限で動きます。強い境界が必要な場合、公式はコンテナ化/サンドボックス(Gondolin拡張、Docker、OpenShell)を推奨しています。