Generated banner for Migrating Deep Agents To Pydantic AI Harness
Generated logo for Migrating Deep Agents To Pydantic AI Harness

Migrating Deep Agents To Pydantic AI Harness

PydanticOfficialPublished by Pydantic

  • Skill
  • Workflow
  • Software development
  • MIT
  • No issues found

From the author

Migrate Python LangChain Deep Agents applications to Pydantic AI and Pydantic AI Harness. Use when the source uses the upstream `deepagents` package or demonstrably reproduces its middleware, backends, skills, memory, subagents, or sandbox contracts. Use `migrating-langchain-to-pydantic-ai` for plain LangChain, LangGraph, or LCEL migrations and `pydantic-ai-harness` for greenfield Harness usage.
— the description by Pydantic

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured methodology for transitioning existing Deep Agents applications to the Pydantic AI ecosystem. It emphasizes preserving observed application contracts and runtime behavior rather than performing a direct code-to-code translation of framework primitives. The process involves establishing the source contract, mapping features to Pydantic AI and Harness capabilities, and verifying the migration through rigorous parity testing.

What it does

  • Maps Deep Agents middleware, backends, and skills to Pydantic AI primitives and Harness capabilities.
  • Provides a step-by-step procedure for tracing request lifecycles from source to target.
  • Guides the construction of Pydantic AI Agents using typed dependencies and RunContext.
  • Outlines strategies for preserving application-level state, orchestration, and side-effect recovery.
  • Defines validation protocols to ensure parity in request, error, and event shapes.
  • Offers guidance on handling complex features like subagents, sandboxes, and durable execution.

When to use it

  • When migrating an application that uses the upstream deepagents package.
  • When you need to move from Deep Agents to Pydantic AI while maintaining existing business logic and contracts.
  • When you need to verify that the new Pydantic AI implementation matches the original application's behavior.
  • When you need to integrate Harness capabilities into an existing agent-based architecture.

Advantages

  • Ensures functional parity by focusing on contract preservation rather than framework-specific syntax.
  • Reduces regression risks through a structured, slice-based migration approach.
  • Provides clear mapping paths for complex components like sandboxes, skills, and middleware.
  • Maintains application-level control over infrastructure and state management.

Usage examples

“How do I migrate my Deep Agents file-system tools to Pydantic AI Harness?”
The agent will guide you to use the FileSystem capability, mapping Deep Agents file paths to Harness path schemas and ensuring permissions are handled via wrapper toolsets.
“What is the recommended approach for migrating custom middleware from Deep Agents?”
The agent will help you identify whether the middleware should be implemented as a Pydantic AI Hook, a wrapper toolset, or a focused Harness capability based on its specific function.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/pydantic/migrating-deep-agents-to-pydantic-ai-harness/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip migrating-deep-agents-to-pydantic-ai-harness.zip -d .agents/skills

Documentation by Pydantic

Migrate Deep Agents to Pydantic AI Harness

Preserve the application's observed contracts, not the shape of create_deep_agent. Compose Pydantic AI primitives and Harness capabilities; keep infrastructure with the application that already owns it.

Establish the source contract

  1. Resolve the deepagents import origin before applying these mappings. Route a local module or project-owned create_deep_agent to the ordinary LangChain migration only when its implementation has ordinary LangChain or LangGraph semantics; vendored implementations that reproduce Deep Agents contracts remain in scope. Read repository instructions, manifests, lockfiles, tests, runtime entrypoints, and the resolved source. Record exact Deep Agents, LangChain, LangGraph, Pydantic AI, and Harness versions. If the locked source is unavailable, reproduce its environment without changing the target lockfile. If that is not possible, mark affected behavior unverified and do not claim parity.

  2. Trace one representative request through prompt and model profile, tools and integrations, middleware and permissions, backend and execution, skills and memory, delegation, state, checkpoints and approvals, retries and limits, events, side effects, and the public boundary. Inspect every caller of that boundary.

  3. Run the cheapest deterministic baseline. Record evidence separately from the outcome: source-inspected, probe-observed, or regression-tested.

  4. Load only the mapping needed for the detected source features:

    • Core Migration for construction, models and profiles, prompts, tools and MCP, middleware, state, outputs, caching, or tracing.

    • Context and Execution for coding-agent defaults, planning, files, permissions, backends, sandboxes, interpreters, media, skills, memory, retrieval, or context limits.

    • Orchestration and Recovery for synchronous, dynamic, or background subagents; grading loops; approvals; checkpoints; fault tolerance; durable execution; or streaming.

    • Hosts and Protocols only when migrating Deep Agents Code, a frontend, ACP, A2A, or a deployment boundary.

Build the Pydantic AI target

  • Start with one reusable Agent. Pydantic AI owns the model/provider boundary, normalized messages, agent loop, typed dependencies and outputs, tools and toolsets, run APIs, usage limits, and generic hooks.

  • Put authenticated identity, service clients, and configuration in deps_type and RunContext; expose only model-chosen inputs through typed tools. Choose instructions versus system_prompt from the required history behavior, and consume result.output rather than leaking framework messages through the application boundary.

  • Add Harness capabilities one at a time for observed optional behavior. A capability composes instructions, toolsets, hooks, and model settings onto the agent; it does not replace application infrastructure or Pydantic AI runtime semantics.

  • Select run_sync, run, run_stream, run_stream_events, iter, deferred results, and message history from the caller's actual lifecycle. Preserve the old wire shape with a boundary adapter while callers migrate.

  • Before coding, inspect the locked pydantic_ai and pydantic_ai_harness public exports, docs, and source signatures for the selected provider, Agent, tools/toolsets, capabilities, run and deferred APIs, and persistence integration. Import capabilities from their owning public submodules, reject deprecation warnings, and run an import-and-construction smoke test in the exact target environment. Record the interpreter and resolved pydantic_ai and pydantic_ai_harness module paths with the result. Add only the required extras; do not pass LangChain objects through or copy remembered examples.

  • Keep queues, tenancy, artifact storage, remote sandbox lifecycle, durable domain state, deployment, and external side-effect recovery in application services.

  • Classify orchestration as model-controlled delegation, a fixed application workflow, or a background worker before selecting SubAgents or DynamicWorkflow; keep fixed sequencing and worker queues in application code.

  • If public Pydantic AI primitives cannot implement required generic runtime semantics correctly, propose the core primitive instead of recreating the runtime in Harness.

When there is no direct equivalent, do not stop at "unsupported." State the source contract and impact, then recommend either an existing composition, a narrow adapter or application service, a new Harness capability built from public primitives, or a Pydantic AI core change. Recommend one option and name its residual risk; ask before choosing when the options materially change behavior, architecture, public API, or scope.

Migrate and verify

  1. Port one vertical slice behind the existing application boundary: typed dependencies, one tool family, output, and one representative request.

  2. Preserve source request, result, error, event, and continuation shapes with a small adapter while callers migrate.

  3. Run the original suite together with focused characterization, parity, and evaluation checks before expanding to the next capability. Exercise the supported Agent boundary in the same interpreter and installed checkout the target will use; do not accept results from another environment. Read Tested Composition only when a local coding-agent composition is useful.

  4. Read Validation and Cutover before publishing examples or claiming cutover; for a simple slice, use only the applicable checks.

  5. Cut over only when each in-scope contract is regression-tested, intentionally changed with agreement, or explicitly not applicable. Report anything else as unverified.

Match validation to observed contracts. Focused characterization and parity tests are sufficient for a stateless slice; persistence, approvals, concurrency, streaming, and external side effects require the ledger and applicable restart and idempotency checks.

Files

references/CONTEXT-AND-EXECUTION.md

Context and Execution

Read only when the source uses coding-agent defaults, planning, files, backends, sandboxes, skills, memory, or context management. Confirm imports and extras against the locked Harness version.

Use the owning public modules. In particular, import Skills from pydantic_ai_harness.skills and RepoContext from pydantic_ai_harness.repo_context; do not use compatibility modules left behind by a rename.

Deep Agents featureHarness candidateImportant difference
coding-agent defaultsCoder() plus a workspace capability (LocalWorkspace('.') or a sandbox)Compare its documented composition first. Coder fails at run start without a workspace. It is an opinionated local coding harness, not a semantic guarantee of Deep Agents parity. Use individual capabilities when a component must change.
todo planningPlanningDeep Agents before 0.7, or an explicitly configured TodoListMiddleware, exposes write_todos; current 0.7.x defaults do not. Add Planning only when that behavior exists or is an accepted addition. Harness has its own schema, tools, reminder injection, events, and stores.
local workspace filesFileSystemIt works in the run's workspace, bounded by root_dir (the working directory by default); it is not Deep Agents' virtual BackendProtocol. Compare the installed tool schemas and source limits: for example, Deep Agents file tools use file_path, while Harness uses path, and backend file-size limits need a separate guard.
filesystem permissionsa wrapper toolset or capability, deferred approval, and backing-service authorizationPreserve operation classes, first-match rule order, unmatched-call behavior, allow/deny/interrupt results, route-relative paths, and child overrides. Deep Agents interrupt rules require a checkpointer; persist and restore the target approval continuation too. The rules cover built-in file tools, not arbitrary tools, direct backend access, or sandbox commands.
host or local shell executionShellIt runs commands in the run's workspace: host subprocesses with LocalWorkspace. Its command filtering cannot preserve a sandbox backend's OS isolation; use a sandbox workspace for that.
remote isolated executionModalSandbox or another sandbox capabilityMatch lease, filesystem, network, credential, reconnect, timeout, and cleanup contracts.
interpreter and programmatic tool callingCodeMode, DynamicWorkflow, or an application interpreterDeep Agents QuickJS eval defaults to thread persistence; the other modes are turn and call. task() is enabled with subagents, while tools.* requires an allowlist. Harness uses Monty and different tool schemas. Match state lifetime, structured results, resource limits, and authority; interpreter bridges can bypass ordinary tool-approval paths unless guarded explicitly.
multimodal input, file reads, or tool resultsPydantic AI user-content and ToolReturn; pydantic_ai_harness.media stores and walkers for persistence offloadKeep model-facing content in Pydantic AI types. With StepPersistence, configure media_store on its FileStepStore, SqliteStepStore, MongoStepStore, or PostgresStepStore; for another serializer, use externalize_media and restore_media directly. Preserve order, MIME support, provider filtering, references, serialization, and restoration.
Agent SkillsSkillsPass the parent skill-library directory, whose immediate children are <name>/SKILL.md packages. Harness reads it from the run's workspace (or workspace=) at each run start, and offers each skill as a deferred capability the model loads with load_capability. For a static slice, normalize flat catalogs into this shape and use Skills; do not replace it with eager prompt concatenation. Preserve writable catalogs, tool names and results, bundled files, scripts, standard-root discovery, and behavioral frontmatter with a focused service only when those contracts matter.
repository instructions and asset inventoryRepoContextIt starts at the workspace's working directory. Configure home_dir, filenames, autoload_instructions, expose_inventory_tool, inventory_tool_name, asset_roots, nested_traversal, and nested_inject from observed discovery and injection behavior. Compose it with FileSystem when file traversal should inject nested context. It does not replace skill activation or writable memory.
writable long-term memoryMemoryCheck namespace, store, injection role and bound, search, concurrency, retention, and deletion. Deep Agents memory=[...] injects backend-relative files; use explicit instructions for static content, RepoContext only for repository-owned context, or an adapter/application store for arbitrary files. If callers use file tools at paths such as /memory/..., preserve those names and paths with a filesystem/tool adapter, or intentionally change callers and prompts. Memory has different tools and namespace semantics.
retrieval or RAGexisting retrieval services exposed as typed tools; a focused Harness search capability only when it matchesRetrieval is application data access, not Deep Agents memory or a filesystem backend. Preserve ingestion, chunking, filters, tenancy, ranking, metadata, citations, result bounds, latency, and failure shapes.
context summarizationcompaction capabilities, often TieredCompactionHarness rewrites Pydantic AI message history. Match thresholds, summary prompt and role, tool-pair validity, receipts, usage, and recovery.
oversized tool-result offloadToolOutputLimits with matching bands/store, or the retained backend artifact pathUse ToolOutputLimits(store=...) only when its overflow-store contract matches. Otherwise retain or adapt the backend artifact path. Deep Agents human-message eviction needs separate handling. Verify thresholds, lossless versus lossy behavior, receipts, read-back, failure fallback, store lifetime, and serialization.

For pluggable or composite backends, expose the existing storage or sandbox service through a focused toolset or capability. Preserve runtime-injected backend factories, route prefixes, path, tenancy, transaction, sandbox ownership, and lifecycle contracts instead of forcing them through local FileSystem. Preserve each route's storage lifetime and ownership; do not replace an ephemeral StateBackend route with persistent filesystem or store state.

Enforce authorization and isolation at the backing service. Treat prompt instructions, globs, path checks, and shell allowlists as defense in depth.

Primary sources: Deep Agents changelog, backends, permissions, sandboxes, interpreters, multimodality, skills, memory, and Pydantic AI Harness.

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Published by
Pydantic
Publisher
Pydantic (Official)
Source
pydantic/skills · skills/migrating-deep-agents-to-pydantic-ai-harness · commit 98f591c
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Also distributed in
pydantic/skills

AutoGineer is not affiliated with or endorsed by Pydantic.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download migrating-deep-agents-to-pydantic-ai-harness.zip