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

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

Pydantic AI および Pydantic AI Harness(必要に応じて)へ、Python の LangChain、LangGraph、Deep Agents アプリケーションを移行させます。 **次のような場合に使用:** - LangChain エージェント、チェーン、LCEL(LangChain の構成フレームワーク)の移行 - LangGraph グラフの直接的な移行 - 永続化(データ保存)、割り込み、ストリーミング機能が必要なプロジェクト - `create_deep_agent` で構築されたプロジェクト(計画機能、ファイルシステム、サンドボックス(実行環境の隔離)バックエンドを含む) - スキル、メモリ、サブエージェント、権限管理、承認フロー、Deep Agents Code hosts を備えたプロジェクト

原文を表示

Migrate Python LangChain, LangGraph, or Deep Agents applications to Pydantic AI and, when the source uses harness features, Pydantic AI Harness. Use for LangChain agents, chains, LCEL, direct LangGraph graphs, persistence, interrupts, streaming, and `create_deep_agent` projects with planning, filesystem or sandbox backends, skills, memory, subagents, permissions, approvals, or Deep Agents Code hosts.

ユースケース
  • LangChain エージェント・チェーンを移行するとき
  • LangGraph グラフを移行するとき
  • 永続化やストリーミング機能が必要なとき
  • Deep Agents で構築したプロジェクト移行時
本文(日本語訳)

LangChain、LangGraph、Deep Agents から Pydantic AI への移行

動作を保持する。フレームワークの形ではなく。動作的に完全な最小単位のスライスを移行し、そのスライスの外側のアプリケーション基盤は変更しないままにする。LangChain、LangGraph、Deep Agents は一つのソースエコシステム(出発元となる関連フレームワークの集合); Pydantic AI、pydantic_graph、Pydantic AI Harness は対応するターゲットエコシステムであり、このスキルはこれら全体にわたってマッピングする。

実行中のアプリケーションから着手する

  1. リポジトリの説明、依存関係ファイル、テスト、実際の実行ポイント(エントリポイント)を読む。インストールされている LangChain、LangGraph、Deep Agents、Pydantic AI、Harness のバージョンを特定する。

  2. 代表的な一つのリクエストをプロンプト、検索、モデル呼び出し、ツール呼び出し、状態、永続化、割り込み、出力イベント、トレース・メトリクスのコールバック、公開結果を通して追跡する。移行対象のコンポーネントを呼び出すすべての上位呼び出し元と兄弟エンドポイント(同じレベルの他の機能)を検査する; スライスが狭くても複数の公開インターフェイス(契約)を持つことができる。呼び出し元が実際に使用する同期・非同期・コールバック・ストリーミング形式とキーワード引数の名前を含める。それらのパスが実際に使う契約だけを記録する。

  3. 最も低コストな有用なベースラインを実行する。移行対象の範囲が広いか不明確な場合、依存関係ファイルとソースコードで langchain、langgraph、langsmith、deepagents を検索し、インポート、ファクトリ(生成関数)、呼び出し箇所に照らして確認する。create_deep_agent がどこから来るかを解決する: アップストリームパッケージと、その契約を複製した内部コピーの両方が Deep Agents としてカウントされる。

  4. ターゲットを選択する前にスライスを分類する:

    • チェーン(Chain)または LCEL パイプライン: 決定論的な検索と変換は素の Python に保つ; モデル・ツールループが価値を加える場所でのみ Pydantic AI エージェント(AIエージェント)を使用する。
    • LangChain エージェント: 通常、型付きの依存関係、ツール、出力を持つ再利用可能な pydantic_ai.Agent を使用する。
    • 直接的な LangGraph ワークフロー: 単純で固定的な制御フローには素の非同期 Python を使用するか、型付きノードと分岐が有用なままの場合は pydantic_graph を使用する。永続化(データの保存)は別の設計判断として扱う。
    • Deep Agents ハーネス: create_deep_agent はファイルツール、シェル実行、サブエージェント委譲、要約、スキル、メモリ、権限、プロンプトキャッシング、承認ミドルウェア(承認処理)を LangChain エージェントループの上にまとめ、ハーネスプロフィール(設定)はさらに多くの機能を追加または非表示にできる。LangChain マッピングでループを移行し、スライスが実際に使用する各種バンドル機能を Harness 機能、コアプリミティブ(基本要素)、またはアプリケーションサービスにマッピングする(Deep Agents Mapping 参照)。アプリケーションコードが決して言及しない暗黙のデフォルトを把握する。
    • 製品ランタイム: ユーザーがスコープ内に配置した場合を除き、キュー、設定されたデータベースバックエンド、サンドボックス、認証、スケジューラ、ウェブフック、トレース、トランスポートアダプタを保持する。 並列な永続化またはプロバイダサブシステムを作成する前に、既存のアプリケーション接続点(シーム)を拡張する。
  5. 決定論的な特性化テスト(動作確認テスト)を追加または保存し、既存の公開境界の後ろで一つの垂直スライスを移行する。

  6. 元のテストと焦点を当てた同等性テスト(パリティテスト)を実行する。 観察された各契約を根拠で分類する; ハッピーパスやトレース形状が似ているというだけの理由で、移行を一対一だと説明してはならない。

検出されたソース機能については Concept Mapping を読む。スライスに deepagents が含まれている場合は常に Deep Agents Mapping を読む。Semantic Gaps は、状態、ミドルウェア、リトライ(再試行)、承認、並行処理、ストリーミング、または同じように見える API が異なる可能性がある他の動作についてのみ読む。具体的なギャップが特定された後に Workaround Recipes を使用する; 必須チェックリストではない。観測可能性を追加するとき、ソースとターゲットの実行を比較するとき、またはセマンティックな違いをデバッグするときは Logfire Verification を読む。本番環境への切り替え前に Verification and Cutover を読む。

セマンティックな違いを説明する

観察されたソース契約に直接相当するものがない場合、重要な設計判断を下す前にそれをユーザーに説明する。ソースの動作、提案される Pydantic AI 設計がどのように異なるか、ユーザーに見える、または運用上の影響、利用可能な選択肢を述べる。一つのオプションを推奨し、その残存リスク(残った問題)に名前を付ける。これを比例配分する: 通常のインポートや命名の変更をセマンティック警告に変えてはならない。

「非サポート」で止まってはならない。何も直接マッピングしない場合、既存のコアまたは Harness コンポジション、狭いアダプタまたはアプリケーションサービス、公開プリミティブから構築された新機能、またはコア変更を、その優先順でお勧めする。オプションが動作、アーキテクチャ、公開 API、またはスコープを本質的に変更する場合のみ質問する。

リスクに厳密さを合わせる

  • ステートレス(状態を持たない)チェーンまたは通常のエージェント移行では、焦点を当てた特性化テストと短い残存リスク注記で十分である。ソースが持たない動作について、セマンティックギャップレジスタ(記録)や耐久性演習を要求してはならない。
  • ミドルウェア、構造化出力トランスポート、検索、ツールリトライ、ストリーミングの場合、インストール済みバージョンに対して影響を受ける契約を調査する。
  • チェックポイント付きグラフ(保存ポイント付きワークフロー)、割り込み、承認、耐久的実行、並行ファンアウト(分散処理)、または外部サイドエフェクト(副作用)の場合、移行台帳(記録簿)を作成する。依存関係、メッセージ、ワークフロー状態、チェックポイント状態、長期メモリを分離する。リポジトリの既存のバックエンド選択とサービスインターフェイスにそれらのオーナーを適合させる。ソースがそれらを約束する範囲でのみ再開、リプレイ、相関、認可、べき等性(何度実行しても結果が同じ)をテストする。
  • deepagents 依存関係だけでは何も変わらない。アクティブなスライスが create_deep_agent を呼び出すか、その計画、ファイルシステム、サンドボックス、スキル、メモリ、サブエージェント、権限、デプロイメント契約に依存する場合、それらはスコープ内の機能であり、Harness またはアプリケーションのオーナーであり、停止する理由ではない。ファイル、サンドボックス、権限、サブエージェント、バックグラウンド作業はチェックポイント付きグラフと同じ台帳および再開義務を持つ。

Pydantic AI のデフォルト

  • 認証済みアイデンティティ、サービスクライアント、設定を型付き依存関係に置く; モデルが選択したツール引数には決して置かない。
  • アプリケーション全体ではなく、観察された不安定な接続点を強化する: エージェントの依存関係と出力型をパラメータ化し、ターミナル選択、永続化されたワークフローレコード、フレームワークアダプタを検証する。安定した公開ワイア形状(通信形式)を保存し、移行対象スライスの外側のパスに型を発明してはならない。
  • 小さなアダプタで公開リクエスト、レスポンス、エラー、イベント形状を保存し、呼び出し元が移行する間にそれをサポートする。
  • 要求されたスライスの外側にある場合、検索、ストレージ、プロバイダ、トランスポート統合を配置したままにする。遷移中の LangChain 統合は、命名され、制限された場合に受け入れられる。
  • ターミナル構造化出力に Pydantic モデルを使用してその契約を保存するとき; ワイア契約を変更することが移行を拡張するとき既存パーサを保持する。
  • すべての Agent を決定論的 LCEL または pydantic_graph をすべての StateGraph に強制してはならない。
  • モデルクラス、プロバイダトランスポート、フック、ストリーミング方法、または耐久的統合を選択する前に、インストール済み Pydantic AI API を検査する。
  • 観察されたハーネス動作に対してのみ pydantic-ai-harness を追加する: 計画、ワークスペースファイル、シェルまたはサンドボックス実行、Agent Skills、メモリノートブック、リポジトリコンテキスト、モデル指向サブエージェント、モデル非依存圧縮、ツール出力制限、ガードレール(制限)、支出制限、またはステップ永続化。機能を一度に一つ追加し、各機能をそのオーナー公開サブモジュールからインポートし、pydantic_ai_harness.experimental.* をバージョン依存として扱い、ターゲット環境でインポートおよび構築スモークテスト(基本動作確認)を実行する。Harness はコアエージェントループに構成される; それは第二のランタイムではなく、アプリケーション基盤を置き換えない。
  • Pydantic AI を追加するとき、現在サポートされている安定版リリースを優先する。無関連なメジャー・ランタイムアップグレードで移行を拡張しない限り、最新の互換性のあるリリースを使用する; 例外を説明してピン留めする。クリーン環境から全体プロジェクトを解決し、既存環境は互換性のない推移的バージョンを隠す可能性があるため、インポートプローブを実行する。依存関係サーフェスが制限されている場合、必要なプロバイダと統合エキストラのみを持つ pydantic-ai-slim を優先し、その広い統合が実際に必要なときは完全な配布を使用する。覚えている例に合わせるだけの理由で古いリリースをピン留めしてはならない。
  • ソースが既に LangSmith、Langfuse、または別の観測可能性システム(トレースシステム)を使用している場合、黙ってそれを置き換えてはならない。Logfire が Pydantic AI の第一方統合であり、通常は最も直接的なエージェント、モデル、ツール、リトライ、エラー、使用量、タイミング体験を提供することを説明する。現在のシステム継続の対比を含め、そのダッシュボード、アラート、評価、保持、エクスポートパイプラインを含む; 選択を推奨し、スイッチングの前に同意を得る。トレースシステムが存在しない、またはユーザーがそれを選択したときアプリケーション起動時に Logfire を提供し、コンテンツキャプチャを明示的なプライバシー判断にし、実行可能な契約テストをパ
原文(English)を表示

Migrate LangChain, LangGraph, and Deep Agents to Pydantic AI

Preserve behavior, not framework shape. Migrate the smallest behaviorally complete slice and leave application infrastructure outside that slice unchanged. LangChain, LangGraph, and Deep Agents are one source ecosystem; Pydantic AI, pydantic_graph, and Pydantic AI Harness are the matching target ecosystem, and this skill maps across all of it.

Work from the running application

  1. Read repository instructions, dependency files, tests, and the actual runtime entrypoints. Identify the installed LangChain, LangGraph, Deep Agents, Pydantic AI, and Harness versions.
  2. Trace one representative request through prompts, retrieval, model and tool calls, state, persistence, interrupts, emitted events, tracing/metrics callbacks, and the public result. Inspect every caller and sibling endpoint that consumes the migrated component; a narrow implementation slice can still have several public contracts. Include keyword parameter names and the sync, async, callback, and streaming forms callers actually use. Record only contracts those paths actually use.
  3. Run the cheapest useful baseline. When the migration surface is broad or unclear, search dependency files and source for langchain, langgraph, langsmith, and deepagents, then confirm findings against imports, factories, and call sites. Resolve where create_deep_agent comes from: the upstream package and a vendored copy that reproduces its contracts both count as Deep Agents.
  4. Classify the slice before choosing a target:
    • Chain or LCEL pipeline: keep deterministic retrieval and transformation in plain Python; use a Pydantic AI agent only where a model/tool loop adds value.
    • LangChain agent: normally use one reusable pydantic_ai.Agent with typed dependencies, tools, and outputs.
    • Direct LangGraph workflow: use plain async Python for simple fixed control flow, or pydantic_graph when explicit typed nodes and branching remain useful. Treat persistence as a separate design decision.
    • Deep Agents harness: create_deep_agent bundles file tools, shell execution, subagent delegation, summarization, skills, memory, permissions, prompt caching, and approval middleware on top of the LangChain agent loop, and a harness profile can add or hide more. Migrate the loop with the LangChain mappings, then map each bundled feature the slice actually uses to a Harness capability, a core primitive, or an application service with Deep Agents Mapping. Inventory implicit defaults the application code never mentions.
    • Product runtime: retain queues, configured database backends, sandboxes, auth, schedulers, webhooks, tracing, and transport adapters unless the user placed them in scope. Extend an existing application seam before creating a parallel persistence or provider subsystem.
  5. Add or preserve deterministic characterization tests, then migrate one vertical slice behind the existing public boundary.
  6. Run the original tests and focused parity tests. Classify each observed contract by its evidence; never describe the migration as one-to-one merely because the happy path or trace shape looks similar.

Read Concept Mapping for the detected source features. Read Deep Agents Mapping whenever deepagents is in the slice. Read Semantic Gaps only for state, middleware, retries, approval, concurrency, streaming, or other behavior where similar-looking APIs may differ. Use Workaround Recipes after a concrete gap is identified, not as a mandatory checklist. Read Logfire Verification when adding observability, comparing source and target runs, or debugging a semantic difference. Read Verification and Cutover before a production cutover.

Explain semantic differences

When an observed source contract has no direct equivalent, explain it to the user before making a consequential design choice. State the source behavior, how the proposed Pydantic AI design differs, the user-visible or operational impact, and the available choices. Recommend one option and name its residual risk. Keep this proportional: do not turn ordinary import or naming changes into semantic warnings.

Do not stop at "unsupported." When nothing maps directly, recommend an existing core or Harness composition, a narrow adapter or application service, a new capability built from public primitives, or a core change, in that order of preference. Ask before choosing only when the options materially change behavior, architecture, public API, or scope.

Match rigor to risk

  • For a stateless chain or ordinary agent port, focused characterization tests and a short residual-risk note are enough. Do not require a semantic-gap register or durability exercise for behavior the source does not have.
  • For middleware, structured output transport, retrieval, tool retries, or streaming, probe the affected contract against the installed versions.
  • For checkpointed graphs, interrupts, approvals, durable execution, concurrent fan-out, or external side effects, create a migration ledger. Separate dependencies, messages, workflow state, checkpoint state, and long-term memory. Fit those owners into the repository's existing backend-selection and service interfaces where possible. Test restart, replay, correlation, authorization, and idempotency only to the extent the source promises them.
  • A deepagents dependency alone changes nothing. When the active slice calls create_deep_agent or depends on its planning, filesystem, sandbox, skills, memory, subagent, permission, or deployment contracts, those are in-scope features with Harness or application owners, not a reason to stop. Files, sandboxes, permissions, subagents, and background work carry the same ledger and restart obligations as checkpointed graphs.

Pydantic AI defaults

  • Put authenticated identity, service clients, and configuration in typed dependencies, never model-chosen tool arguments.
  • Strengthen observed unstable seams, not the whole application: parameterize the agent's dependency and output types, and validate terminal choices, persisted workflow records, and framework adapters. Preserve stable public wire shapes and do not invent types for paths outside the migrated slice.
  • Preserve public request, response, error, and event shapes with a small adapter while callers migrate.
  • Keep retrieval, storage, provider, and transport integrations in place when they are outside the requested slice. Transitional LangChain integrations are acceptable when named and bounded.
  • Use Pydantic models for terminal structured output when that preserves the contract; retain an existing parser when changing the wire contract would expand the migration.
  • Do not force an Agent onto deterministic LCEL or pydantic_graph onto every StateGraph.
  • Inspect the installed Pydantic AI API before choosing model classes, provider transports, hooks, streaming methods, or durable integrations.
  • Add pydantic-ai-harness only for observed harness behavior: planning, workspace files, shell or sandboxed execution, Agent Skills, memory notebooks, repository context, model-directed subagents, model-agnostic compaction, tool-output limits, guardrails, spend limits, or step persistence. Add capabilities one at a time, import each from its owning public submodule, treat pydantic_ai_harness.experimental.* as version-sensitive, and run an import-and-construction smoke test in the target environment. Harness composes onto the core agent loop; it is not a second runtime and does not replace application infrastructure.
  • When adding Pydantic AI, prefer a currently supported stable release. Use the newest compatible release unless that would expand the migration through an unrelated major/runtime upgrade; explain and pin any exception. Resolve the whole project from a clean environment and run an import probe because an existing environment can hide incompatible transitive versions. Prefer pydantic-ai-slim with only the required provider and integration extras when the dependency surface is bounded, and use the full distribution when its broader integrations are actually needed. Do not pin an older release merely to match a remembered example.
  • If the source already uses LangSmith, Langfuse, or another observability system, do not replace it silently. Explain that Logfire is the first-party Pydantic AI integration and normally provides the most direct agent, model, tool, retry, error, usage, and timing experience. Contrast that with the continuity of retaining the current system, including its dashboards, alerts, evaluations, retention, and export pipeline; recommend a choice and obtain agreement before switching. Offer Logfire at application startup when no tracing system exists or the user chooses it, make content capture an explicit privacy decision, and keep executable contract tests as the authority for parity.

Completion

The slice is complete when every observed contract is either preserved by an executable check, intentionally changed by an accepted decision, or explicitly not applicable. An untested contract is unverified, not equivalent; an unresolved requested contract is unfinished work, not completion evidence. Constrain the slice or ask the user to accept the deferral. Remove LangChain, LangGraph, or Deep Agents dependencies only after no retained path needs them.

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