• Projects
  • Service
  • About
  • branding.bz
  • Podcast
  • Tips
  • FAQ
  • Recruit
  • Download
  • Contact
  • branding.bz(ブランド構築SaaS)
  • DESIGN NOW(デザインメディア)
  • X
  • LinkedIn
  • Spotify
  • Facebook

213-0011 神奈川県川崎市高津区久本3-6-7-303

© 2026 ID INC. All rights reserved

claude-skills/スキル
SKILLOfficialdevelopment

migrating-pi-to-pydantic-ai

プラグイン
pydantic-ai
ソース
GitHub で見る ↗
説明

TypeScript版のPi(コーディング支援AI)アプリケーション、拡張機能、またはパッケージをPython版のPydantic AI(Pydantic AIは堅牢なAIアプリケーション開発フレームワーク)およびPydantic AI Harnessを使用した形式に移行します。 次のような場合に使用: - ソースコードが`@earendil-works/pi-*`をインポートしている - `createAgentSession`を呼び出している - Pi拡張機能を登録している - Piのツール、フック(処理の割り込み地点)、スキル(AI機能の個別モジュール)、セッション(作業環境)、圧縮機能(コード最適化)、プロバイダー(外部サービス連携)、TUI(テキスト画面のユーザーインターフェース)、RPC(遠隔手続き呼び出し)、またはパッケージに依存している

原文を表示

Migrate TypeScript Pi coding-agent applications, extensions, or packages to Python with Pydantic AI and Pydantic AI Harness. Use when source code imports `@earendil-works/pi-*`, calls `createAgentSession`, registers Pi extensions, or relies on Pi tools, hooks, skills, sessions, compaction, providers, TUI, RPC, or packages.

ユースケース
  • TypeScript版PiをPydantic AIに移行するとき
  • @earendil-works/pi-*をインポートしているコード
  • createAgentSessionを呼び出している処理
  • Pi拡張機能を登録する場面
  • PiのツールやスキルをPydantic AIに統合するとき
本文(日本語訳)

Piから Pydantic AI へのマイグレーション

観測可能な動作を保存する(Pi の TypeScript API は保存しない)。最小限の完全な呼び出しパスをマイグレーションし、製品・ホストのインフラは既存アプリケーション内に留める。

ターゲット選択の前にソースを追跡する

  1. リポジトリの説明書、package.json、Pi の設定、テスト、拡張機能やパッケージのマニフェスト、実行ポイントを読む。インストール済みの Pi、Pydantic AI、Harness のバージョンを記録する。

  2. Pi CLI、RPC の境界、または createAgentSession().prompt() から出発する実際のリクエストを 1 つ追跡する。リソース検出、システム指示、ツール、拡張機能、モデルリクエスト、メッセージ、圧縮・再試行、イベント、セッションエントリ、UI/RPC 出力、副作用を通じて追跡する。重点的なベースライン、または特性テストを確立する。

  3. すべての有効な拡張機能ファクトリーとパッケージリソースをリスト化する。各 pi.on(...)、registerTool、registerCommand、プロバイダー登録、レンダラー/UI 貢献、スキル(専門知識・機能セット)、プロンプト、保存されたエントリについて、発火ポイント、信頼できる入力、変更、出力、状態の所有者、呼び出し側から見える効果を記録する。

  4. これらの契約(機能仕様)が存在する場合は分離する:

    • モデルメッセージ、追記のみのセッションエントリ・ツリー分岐、圧縮サマリー、拡張機能の状態
    • モデルが選択したツール入力、信頼できるホストコンテキスト、プロジェクト信頼度、承認、認可、OS の分離
    • トークン増減、ツールのライフサイクル、Pi 拡張機能イベント、機能イベント、RPC イベント、ターミナルレンダリング
    • エージェントループの動作、CLI/TUI ホストの動作、プロバイダー転送、パッケージ配布、外部副作用
  5. 観測された各契約、その所有者、意味的な違い、実行可能な証拠を記録する。インストールされても非アクティブな Pi パッケージ機能はマイグレーション対象外である。

検出された機能については「Research and concept mapping」を参照。実装前に「Verification and cutover」も読むこと。

拡張機能を機能候補として扱う

Pi 拡張機能は Pydantic AI の機能に最も近いソース概念だが、より広い範囲を持つ。拡張機能はエージェント動作とターミナル UI、コマンド、プロバイダー登録、リソース検出、ホストのライフサイクルを組み合わせられる。拡張機能ファイルではなく、責務をポート(移行)する:

  1. 再利用可能なモデル向け動作—ツール、指示、モデル設定、履歴・イベント処理、ガードレール(安全制限)、エージェントループフック—をライフサイクルが一致する既存の Core または Harness 機能にマップする。

  2. 関連する指示とツールをコア Capability にバンドル。AbstractCapability をサブクラス化するのは、ライフサイクルフック、適応的なモデル・設定、ネイティブツール、型付き機能イベントが必要な再利用可能な動作のみとする。

  3. CLI コマンド、フラグ、キーボードショートカット、TUI レンダラー・ダイアログ、セッション選択、プロジェクト信頼度、パッケージインストール、プロバイダー認証情報設定は Python アプリケーションまたはインターフェースアダプター内に留める。Pi 拡張機能が所有しているからといって、これらがエージェント機能ではない。

  4. 混在する拡張機能をその分界線で分割する。権限管理拡張機能は ToolGuardrail または承認機能とアプリケーション所有の承認者 UI になり、コーディングパッケージは Coder とホスト設定になり、プロバイダー拡張機能はモデル・プロバイダー統合のままとなる。

  5. 順序は証拠がそれが重要だと示す場合のみ保存する。Pi ハンドラーの読み込み順と Pydantic AI 機能・フックの順序は異なる契約である。

最小限のターゲットを選ぶ

  • Core: pydantic_ai.Agent をエージェントループ、型付き依存関係、ツール・ツールセット、出力、正規化メッセージ、機能・フック、ストリーミング、承認、使用量制限、計測、MCP、プロバイダー・モデル統合に使用する。

  • Harness: Pi の通常のコーディングツールの構成が厳密に一致する場合のみ Coder を使用する。観測された動作に対してのみ、FileSystem、Shell、Skills、Planning、SubAgents、ガードレール、圧縮、ツール出力制限、ステップ永続性などの重点的な機能を追加する。

  • アプリケーション・インターフェース: CLI/TUI/RPC、認証、プロジェクト信頼度、設定、プロバイダーログイン・カタログ、セッション閲覧、パッケージ管理、デプロイメント、転送は意図的に保持または置き換える。

  • Graph: 決定論的ワークフロー(実行順序が常に同じ処理)には plain async Python または pydantic_graph を使用。プロンプトやサブエージェントで符号化しない。

  • ギャップ: 対応する公開 API がない動作を名付けて、その影響を説明し、限定的なアダプターをテストする。同等性を主張するために Pi の拡張機能バスや JSONL 形式をクローン化しない。

通常の組み込みマイグレーションは、1 つの再利用可能な Agent、Coder、またはより小規模な機能の組み合わせ、型付き依存関係のアプリケーションサービス、アプリケーション所有のメッセージ・セッションストア、既存の RPC または UI 境界の薄いアダプターである。

高リスク関門を適用する

  • ctx(コンテキスト)、プロジェクト信頼度、認証情報、セッションマネージャー、サービスハンドルは信頼できるホストコンテキスト。型付き依存関係またはアプリケーションサービスに相当する機能を配置し、モデル選択ツール引数には決して入れない。

  • Pi セッション JSONL はモデルコンテキスト以上を含む追記のみの分岐ホストログ。result.all_messages() はモデル履歴を保存し、ツリーナビゲーション、ラベル、拡張機能エントリ、圧縮レコード、モデル変更、キュー、放棄された分岐は保存しない。変換、互換性ストア、受け入れられた新規開始のいずれかを選択してテストする。

  • Pi の圧縮、コンテキスト傍受、ステアリング・フォローアップキュー、再試行、分岐サマリーには特定のタイミング。core・Harness シーム(対応ポイント)を独立して選択し、順序をテスト。汎用メッセージ履歴または要約は自動同等ではない。

  • tool_call 権限ゲートを効果でマップ。検証・ブロック・修正にはガードレール、承認待ちのアクションには遅延ツールを使用。ID、認可、UI、監査、永続性、冪等性はアプリケーション内に留める。

  • Pi 拡張機能はホスト権限で任意の TypeScript を実行。Pydantic AI 機能もアプリケーションコードを実行。どちらもサンドボックスではない。信頼できないコマンドやコードには OS・コンテナ・クラウド分離境界を使用する。

  • Harness Skills は設定された SKILL.md 指示をオンデマンド読み込みするが、Pi の検出ルート、リソースファイル、スクリプト、リロード、パッケージインストール、動作フロントマターは再現しない。観測された場合は別途保存する。

  • SubAgents はモデル指示の分離したタスクのみに使用。決定論的オーケストレーションと Pi のサブプロセス・tmux・パッケージ固有のセマンティクスはアプリケーションコード内に留める。

  • 動的ツール有効化を core ToolSearch またはオンデマンド機能にマップするのは、読み込みタイミング、スキーマ、プロンプト・キャッシュ変更、プロバイダー フォールバック動作をテスト後のみ。

  • Pydantic AI 実行イベントと機能イベントは Pi の拡張機能イベントバス、RPC プロトコル、TUI レンダーライフサイクルを再現しない。消費者が使用する安定したフィールドのみ適応させる。

  • Pi プロバイダー拡張機能とペイロードフックは認証、カタログ、ワイヤペイロード、ヘッダー、ストリーミングを変更する可能性。Pydantic AI モデル・プロバイダーまたはアプリケーション転送層で実装し、プロバイダーコントラクトテストを実行。汎用機能に隠さない。

1 つの垂直スライスを実装して証明する

  1. 対応する CLI、RPC、SDK、ジョブ、UI 境界を保存し、エージェント所有の内部のみ置き換える。

  2. core と最小限のコーディング機能から開始。追跡された契約が必要になった後のみ、より広い Harness 動作を追加する。

  3. ソース拡張機能ごとに分割を文書化:機能動作、アプリケーション・インターフェース動作、保持された統合、ギャップ。各側面を実際の境界を通じてテストする。

  4. RPC・イベント、保存レコードに言語中立的なフィクスチャーを使用。ツール引数・結果、エラー、イベント順序、セッション継続、UI 決定、副作用をテスト。オフライン決定論的モデルを使用。プロバイダー動作専用の記録・ライブプロバイダーテストのみ追加。

  5. 保持されたパスが不要になった後のみ、Pi パッケージ、設定、Node ランタイム、拡張機能アダプターを削除する。

意味的に重要な変更を実装する前に説明:Pi 動作、ターゲット動作、呼び出し側への影響、推奨選択肢、残存リスクを述べる。

完了

「Verification and cutover」の完了基準を適用。偽、記録、ライブプロバイダー、ターミナル、再開、サンドボックス証拠に正確にラベル付けする。

原文(English)を表示

Migrate Pi to Pydantic AI

Preserve observable behavior, not Pi's TypeScript API. Migrate the smallest complete caller path and keep product/host infrastructure in the application.

Trace the source before choosing a target

  1. Read repository instructions, package.json, Pi settings, tests, extension/package manifests, and runtime entrypoints. Record the installed Pi, Pydantic AI, and Harness versions.
  2. Trace one real request from the Pi CLI, RPC boundary, or createAgentSession().prompt() through resource discovery, system instructions, tools, extensions, model requests, messages, compaction/retry, events, session entries, UI/RPC output, and side effects. Establish a focused baseline or characterization test.
  3. Inventory every active extension factory and package resource. For each pi.on(...), registerTool, registerCommand, provider registration, renderer/UI contribution, skill, prompt, and persisted entry, record its firing point, trusted inputs, mutations, output, state owner, and caller-visible effect.
  4. Separate these contracts when present:
    • model messages, append-only session entries/tree branches, compaction summaries, and extension state;
    • model-chosen tool input, trusted host context, project trust, approval, authorization, and OS isolation;
    • token deltas, tool lifecycle, Pi extension events, capability events, RPC events, and terminal rendering;
    • agent-loop behavior, CLI/TUI host behavior, provider transport, package distribution, and external side effects.
  5. Record each observed contract, its owner, semantic difference, and executable proof. An installed but inactive Pi package feature is not migration scope.

Read Research and concept mapping for the detected features. Read Verification and cutover before implementation.

Treat extensions as capability candidates

A Pi extension is the closest source concept to a Pydantic AI capability, but it is broader. An extension can combine agent behavior with terminal UI, commands, provider registration, resource discovery, and host lifecycle. Port responsibilities, not the extension file:

  1. Map reusable model-facing behavior—tools, instructions, model settings, history/event processing, guardrails, and agent-loop hooks—to an existing Core or Harness capability when its lifecycle matches.
  2. Bundle related instructions and tools in core Capability; subclass AbstractCapability only for reusable behavior that needs lifecycle hooks, adaptive models/settings, native tools, or typed capability events.
  3. Keep CLI commands, flags, keyboard shortcuts, TUI renderers/dialogs, session selection, project trust, package installation, and provider credential setup in the Python application or interface adapter. They are not agent capabilities merely because a Pi extension owns them.
  4. Split mixed extensions at that seam. A permission extension may become a ToolGuardrail or approval capability plus an application-owned approver UI; a coding package may become Coder plus host configuration; a provider extension remains a model/provider integration.
  5. Preserve order only where evidence shows it matters. Pi handler load order and Pydantic AI capability/hook ordering are different contracts.

Choose the smallest target

  • Core: use pydantic_ai.Agent for the agent loop, typed dependencies, tools/toolsets, outputs, normalized messages, capabilities/hooks, streaming, approvals, usage limits, instrumentation, MCP, and provider/model integration.
  • Harness: use Coder for Pi's ordinary coding tools only when its exact composition fits. Add focused capabilities such as FileSystem, Shell, Skills, Planning, SubAgents, guardrails, compaction, tool-output limits, or step persistence only for observed behavior.
  • Application/interface: retain or replace CLI/TUI/RPC, auth, project trust, settings, provider login/catalogs, session browsing, package management, deployment, and transport deliberately.
  • Graph: use plain async Python or pydantic_graph for deterministic workflows; do not encode them in prompts or subagents.
  • Gap: name behavior with no supported public seam, explain its impact, and test a bounded adapter. Do not clone Pi's extension bus or JSONL format just to claim parity.

The normal embedded migration is one reusable Agent, Coder or a smaller capability composition, application services in typed dependencies, an application-owned message/session store, and a thin adapter at the existing RPC or UI boundary.

Apply high-risk gates

  • ctx, project trust, credentials, session managers, and service handles are trusted host context. Put equivalents in typed dependencies or application services, never model-chosen tool arguments.
  • Pi session JSONL is an append-only branching host log containing more than model context. result.all_messages() preserves model history, not tree navigation, labels, extension entries, compaction records, model changes, queues, or abandoned branches. Choose and test conversion, a compatibility store, or an accepted fresh start.
  • Pi compaction, context interception, steering/follow-up queues, retries, and branch summaries have specific timing. Select matching core/Harness seams independently and test ordering; generic message history or summarization is not automatic parity.
  • Map tool_call permission gates by effect. Use guardrails for validation/block/redaction and deferred tools for an action that must await approval. Keep identity, authorization, UI, audit, persistence, and idempotency in the application.
  • Pi extensions run arbitrary TypeScript with host permissions. A Pydantic AI capability also runs application code; neither is a sandbox. Use an OS/container/cloud isolation boundary for untrusted commands or code.
  • Harness Skills loads configured SKILL.md instructions on demand but does not reproduce Pi's discovery roots, resource files, scripts, reload, package installation, or behavioral frontmatter. Preserve those separately when observed.
  • Use SubAgents only for model-directed isolated tasks. Keep deterministic orchestration and Pi subprocess/tmux/package-specific semantics in application code.
  • Map dynamic tool activation to core ToolSearch or on-demand capabilities only after testing load timing, schemas, prompt/cache changes, and provider fallback behavior.
  • Pydantic AI run events and capability events do not reproduce Pi's extension event bus, RPC protocol, or TUI render lifecycle. Adapt only stable fields consumers use.
  • Pi provider extensions and payload hooks may alter authentication, catalogs, wire payloads, headers, and streaming. Implement them at the Pydantic AI model/provider or application transport layer and run provider contract tests; do not hide them in a generic capability.

Implement and prove one vertical slice

  1. Preserve the supported CLI, RPC, SDK, job, or UI boundary and replace only agent-owned internals.
  2. Start with core plus the smallest coding capabilities. Add broader Harness behavior only after a traced contract requires it.
  3. For each source extension, document the split: capability behavior, application/interface behavior, retained integration, and gap. Test each side through its real boundary.
  4. Use language-neutral fixtures for RPC/events and persisted records. Test tool arguments/results, errors, event order, session continuation, UI decisions, and side effects. Use deterministic models offline; add focused recorded/live provider tests only for provider behavior.
  5. Remove Pi packages, settings, Node runtime, or extension adapters only after no retained path needs them.

Explain consequential semantic changes before implementing them: state the Pi behavior, target behavior, caller impact, recommended choice, and remaining risk.

Completion

Apply the completion criterion in Verification and cutover. Label fake, recording, live-provider, terminal, restart, and sandbox evidence accurately.

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。