• 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-google-adk-to-pydantic-ai

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

Python用のGoogle Agent Development Kit(ADK)アプリケーションをPydantic AIに移行します。 次のような場合に使用: `LlmAgent`、`Runner`、セッション、状態、メモリ、ツール、コールバック(処理の実行完了時に呼び出す機能)、プラグイン、グラフまたはダイナミックワークフロー(動的な処理フロー)、再開可能性、イベント、成果物、MCP、およびADKのデプロイメント境界。

原文を表示

Migrate Python Google Agent Development Kit (ADK) applications to Pydantic AI. Use for `LlmAgent`, `Runner`, sessions, state, memory, tools, callbacks, plugins, graph or dynamic workflows, resumability, events, artifacts, MCP, and ADK deployment boundaries.

ユースケース
  • Google ADK アプリをPydantic AI に移行するとき
  • LlmAgent やRunner の実装が必要なとき
  • セッション管理や状態保持を行うとき
  • ツールやコールバックを組み込むとき
  • ワークフローの再開可能性が必要なとき
本文(日本語訳)

Google ADKからPydantic AIへの移行

呼び出し側の見える振る舞いを保持する(ADKのクラス構造ではなく)。最小限の完全なリクエスト経路を移行し、製品インフラはアプリケーションに残す。

動作中のアプリケーションから作業を開始する

  1. リポジトリの指示、依存関係、テスト、実行エントリポイントを読む。インストール済みのGoogle ADK、Pydantic AI、オプションのpydantic-ai-harnessのバージョンを記録する。

  2. Runner.run_async()またはデプロイ済みエンドポイントから、ルートエージェント、指示内容、協調モード、モデル呼び出し、ツール、ワークフローノード、コールバック/プラグイン、セッションサービス、出力されたイベント、状態/成果物の差分、最終的な応答を通じて、1つの実際のリクエストをたどる。そのパスが使用する振る舞いのみを記録する。

  3. ターゲットを選択する前に、契約(インターフェース)を分ける:

    • モデルのコンテキストとして使用されるSession.events
    • セッション、ユーザー、アプリケーション、呼び出し単位でのスコープ設定された状態
    • 検索可能な長期メモリ
    • ワークフロー/ノードのチェックポイントと再開ID
    • バージョン管理された成果物と外部への副作用
  4. アクティブなスライス(処理部分)を分類する:

    • 通常のLlmAgent: 通常は1つの再利用可能なAgentで、型指定された依存関係、ツール、出力を持つ。
    • ADKグラフまたは動的ワークフロー: シンプルで確定的な制御フローはプレーンな非同期Pythonで保つ。明示的に型指定されたノード、分岐、またはグラフ検査が価値を持つ場合にpydantic_graphを使用する。
    • マルチエージェント委譲: Python 2.xでADKの協調modeを調べる。1.xのsub_agentsはchatの動作を使用する。chat転送セマンティクス用にマルチエージェント設計パターンを使用する。ハーネスSubAgentsは、隔離されたコンテキスト、戻り値、相互作用、並行性の動作が一致する場合のみtaskまたはsingle_turnに適合できる。
    • 製品ランタイム: 認証、セッション/状態ストア、成果物ストア、キュー、転送、A2A(API間通信)エンドポイント、評価、監視、デプロイメントを保持する(明示的にスコープ内にある場合を除く)。
  5. 決定的な特性評価テストを追加し、既存の呼び出し側の境界の後ろで1つの垂直スライス(関連する層全体)を移行する。

  6. 元のテストと部分的な互換性テストを実行する。実施されていない振る舞いを未検証とマーク;名前の類似性は同等性の証拠ではない。

スライスが使用する機能については概念マッピングを読む。ワークフロー、状態、再開、承認、コールバック/プラグイン、イベントストリーム、スキル、実行環境についてはセマンティックギャップを読む。ADKを削除または本番トラフィックを変更する前に検証とカットオーバーを読む。

高リスク段階

  • ADKのSessionオブジェクトや可変状態の辞書をモデルが選択したツール引数として通さない。認証済みアイデンティティとサービスクライアントを型指定された依存関係に入れ、製品とワークフロー状態をアプリケーション所有のストアを通じて永続化する。

  • message_historyはモデルのコンテキストを継続する。ADKのセッション状態、メモリ、成果物、イベントレコード、ノードチェックポイント、呼び出し再開を置き換えることはない。

  • ADKの再開性は記録されたノード/ツール結果を再度実行でき、ツールを複数回実行できる。永続実行設計を明示的に選択し、再開と副作用の冪等性(何度実行しても同じ結果)を証明する。

  • 対話的な入力、承認、認可を区別して保つ。ツール確認を遅延ツール承認にマップ;アイデンティティとアクセスチェックを信頼できるアプリケーションコードに保つ。

  • コールバック/プラグインの順序と処理の短絡ルール(早期終了の仕組み)を意図的に保存する。Pydantic AIのフックは独自の機能順序と例外ベースのスキップ/復旧セマンティクスを持つ;見た目が似たフックのリストは互換性の証拠ではない。

  • ADKの部分イベントは状態差分を適用せずに配信される。各非部分イベントは追加されるときに差分を適用する。成果物の書き込みは成果物操作中に行われ、現在のイベントが返されたバージョンを記録する前に行われる。呼び出し側がADKイベントフィールドまたは最終イベント検出を使用する場合、境界アダプター(変換層)を保持し、正確なストリームと永続化順序をテストする。

  • ハーネスは観測された再利用可能な機能の場合のみ使用する。通常のエージェントはコアのみが必要で、コマンド許可リストはOS(オペレーティングシステム)のセキュリティ境界ではない。

Pydantic AIの規定値

  • instructionをinstructionsにマップ;信頼できるランタイムデータに依存する場合はRunContext指示関数を使用する。

  • 関数ツールを型指定されたPydantic AIツールにマップ。呼び出し側が依存するツール名、説明、検証動作、エラー形式、再試行、確認、並行性のみを保存する。

  • ターミナル出力の契約が構造化されている場合、output_schemaをoutput_typeにマップ。応答形状の変更が移行を拡大する場合は、既存のワイヤーアダプター(変換層)を保持する。

  • ModelMessageの履歴をワークフローと製品状態とは別に永続化する。新しい永続化サブシステムを追加する前に、アプリケーションの現在のストアを再利用する。

  • ローカルのライフサイクル割り込みにはHooksを、ツール、指示内容、設定、イベントも所有する再利用可能なポリシーにはカスタム機能を使用する。

  • 変更が要求されない限り、アクティブなモデル/プロバイダーを保つ。プロバイダー接頭辞付きのPydantic AIモデルIDを使用し、インストール済みAPIに対してプロバイダー固有のツール、設定、ストリーミング、リアルタイム動作を検証する。

完了

スライスが完了するのは、観測されたすべての呼び出し側の契約が実行可能な証拠で保存され、明示的に変更として受け入れられ、または適用外である場合のみ。未検証とブロック済みの契約は完了していないものとして扱う。保持されたランタイム、セッション移行、デプロイメントコマンド、評価、互換性パスが依然としてインポートまたは呼び出す限り、google-adkを削除しない。

原文(English)を表示

Migrate Google ADK to Pydantic AI

Preserve caller-visible behavior, not ADK's class tree. Migrate the smallest complete request path and leave product infrastructure in the application.

Work from the running application

  1. Read repository instructions, dependencies, tests, and runtime entrypoints. Record the installed Google ADK, Pydantic AI, and optional pydantic-ai-harness versions.
  2. Trace one real request from Runner.run_async() or the deployed endpoint through the root agent, instructions, collaboration mode, model calls, tools, workflow nodes, callbacks/plugins, session service, emitted events, state/artifact deltas, and final response. Record only behavior that path uses.
  3. Separate the contracts before choosing targets:
    • Session.events used as model context;
    • session-, user-, app-, and invocation-scoped state;
    • searchable long-term memory;
    • workflow/node checkpoints and resume IDs;
    • versioned artifacts and external side effects.
  4. Classify the active slice:
    • Ordinary LlmAgent: normally one reusable Agent with typed dependencies, tools, and output.
    • ADK graph or dynamic workflow: keep simple deterministic control flow in plain async Python; use pydantic_graph when explicit typed nodes, branching, or graph inspection remain valuable.
    • Multi-agent delegation: inspect ADK's collaboration mode in Python 2.x; 1.x sub_agents use chat behavior. Use core multi-agent patterns for chat transfer semantics. Harness SubAgents can fit task or single_turn only when their isolated context, return, interaction, and concurrency behavior match.
    • Product runtime: retain auth, session/state stores, artifact stores, queues, transport, A2A endpoints, evaluation, observability, and deployment unless they are explicitly in scope.
  5. Add deterministic characterization tests, then migrate one vertical slice behind its existing caller boundary.
  6. Run the original tests and focused parity tests. Mark unexercised behavior unverified; similar names are not equivalence evidence.

Read Concept Mapping for the features the slice uses. Read Semantic Gaps for workflows, state, resume, confirmation, callbacks/plugins, event streams, skills, or execution environments. Read Verification and Cutover before removing ADK or changing production traffic.

High-risk gates

  • Do not pass ADK Session objects or mutable state dictionaries through model-chosen tool arguments. Put authenticated identity and service clients in typed dependencies; persist product and workflow state through application-owned stores.
  • message_history continues model context. It does not replace ADK session state, memory, artifacts, event records, node checkpoints, or invocation resume.
  • ADK resumability replays recorded node/tool results and can execute tools more than once. Choose a durable execution design explicitly and prove restart plus idempotency for side effects.
  • Keep conversational input, approval, and authorization distinct. Map tool confirmation to deferred tool approval; keep identity and access checks in trusted application code.
  • Preserve callback/plugin ordering and short-circuit rules deliberately. Pydantic AI hooks have their own capability ordering and exception-based skip/recovery semantics; a list of lookalike hooks is not parity.
  • ADK partial events are delivered without applying state deltas; each non-partial event applies its delta when appended. Artifact writes happen during the artifact operation, before the current event records the returned version. If callers consume ADK event fields or final-event detection, retain a boundary adapter and test the exact stream and persistence order.
  • Use Harness only for an observed reusable capability. Ordinary agents need core only, and a command allowlist is not an OS security boundary.

Pydantic AI defaults

  • Map instruction to instructions; use a RunContext instructions function when it depends on trusted runtime data.
  • Map function tools to typed Pydantic AI tools. Preserve tool names, descriptions, validation behavior, error shape, retries, confirmation, and concurrency only where callers rely on them.
  • Map output_schema to output_type when the terminal output contract is structured. Preserve an existing wire adapter if changing response shape would widen the migration.
  • Persist ModelMessage histories separately from workflow and product state. Reuse the application's current stores before adding a new persistence subsystem.
  • Use Hooks for local lifecycle interception or a custom capability for reusable policy that also owns tools, instructions, settings, or events.
  • Keep the active model/provider unless changing it is requested. Use provider-prefixed Pydantic AI model IDs and verify provider-specific tools, settings, streaming, and realtime behavior against installed APIs.

Completion

The slice is complete only when every observed caller contract is preserved by executable evidence, explicitly accepted as changed, or not applicable. Treat unverified and blocked contracts as unfinished. Do not remove google-adk while a retained runtime, session migration, deployment command, evaluation, or compatibility path still imports or invokes it.

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