Migrating Deep Agents To Pydantic AI Harness
PydanticOfficialPublished by Pydantic
- Skill
- Workflow
- Software development
- MIT
- No issues found
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
Download the skill as a ZIP:
https://autogineer.com/agent-skills/pydantic/migrating-deep-agents-to-pydantic-ai-harness/downloadUnzip 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
Resolve the
deepagentsimport origin before applying these mappings. Route a local module or project-ownedcreate_deep_agentto 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.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.
Run the cheapest deterministic baseline. Record evidence separately from the outcome:
source-inspected,probe-observed, orregression-tested.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_typeandRunContext; expose only model-chosen inputs through typed tools. Chooseinstructionsversussystem_promptfrom the required history behavior, and consumeresult.outputrather 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_aiandpydantic_ai_harnesspublic 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 resolvedpydantic_aiandpydantic_ai_harnessmodule 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
SubAgentsorDynamicWorkflow; 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
Port one vertical slice behind the existing application boundary: typed dependencies, one tool family, output, and one representative request.
Preserve source request, result, error, event, and continuation shapes with a small adapter while callers migrate.
Run the original suite together with focused characterization, parity, and evaluation checks before expanding to the next capability. Exercise the supported
Agentboundary 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.Read Validation and Cutover before publishing examples or claiming cutover; for a simple slice, use only the applicable checks.
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
- ATTRIBUTION.mdAdded by AutoGineer905 B
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md6.5 KiB
- agents/openai.yaml258 B
- references/CONTEXT-AND-EXECUTION.md7.3 KiB
- references/CORE-MIGRATION.md4.1 KiB
- references/HOSTS-AND-PROTOCOLS.md2.4 KiB
- references/ORCHESTRATION-AND-RECOVERY.md6.0 KiB
- references/TESTED-COMPOSITION.md2.3 KiB
- references/VALIDATION.md4.9 KiB
references/VALIDATION.md
Validation and Cutover
Use this reference when the source has state, streaming, approvals, sandboxed execution, subagents, persistence, or external side effects.
Contract ledger
For each observed source contract, record:
source owner and locked version;
source behavior and evidence;
target owner: core, Harness, adapter, application service, or retained source;
outcome:
verified-equivalent,verified-adapter,intentional-change,external-owner,not-applicable,unverified, orblocked;focused test and residual risk.
Do not mark a mapping equivalent from documentation or a matching class name alone.
Focused checks
Prompt and tools: compare effective instructions, ordering, tool names, descriptions, JSON schemas, hidden context, retries, errors, timeouts, approvals, and provider-native tools.
MCP: test authentication, filtering, structured content, connection and session lifetime, elicitation, sampling, retries, and trace correlation against the selected transport.
State and memory: restart the process and test namespace isolation, retention, concurrent writes, deletion, corrupt data, and whether the next run observes a write.
Subagents: test context isolation, explicit state transfer, model and tool selection, parent and child budgets, timeout, cancellation, partial failure, result shape, and streamed identity.
Plans: test create or replace semantics, status transitions, persistence, concurrent writers, visibility on the next request, and UI events.
Files and sandboxes: test traversal, absolute paths, symlinks, media and binary data, output bounds, environment leakage, timeout, reconnect, egress, and cleanup failure. For permissions, test operation classes, first-match order, unmatched calls, allow, deny, interrupt, route-relative paths, and child overrides.
Interpreters: test generated-code limits, state and reset scope, tool and subagent bridges, schema conversion, approval enforcement, OS access, timeouts, and resource-limit failures.
Skills and repository context: test discovery layout, precedence, catalog names and descriptions, deferred loading, snapshot or rescan behavior, runtime writes, bundled resources and scripts, walk-up boundaries, instruction precedence, and nested traversal.
Retrieval: test ingestion, chunking, filters, tenancy, ranking, metadata, citations, bounds, latency, and failure shapes.
Context offload: test thresholds, lossy versus lossless paths, backend/store failure, model-visible receipts, read-back bounds, store lifetime, serialization, and restoration of text and media.
Approvals: test approve, deny, changed arguments, stale decisions, authorization changes, crash before and after execution, replay, and side-effect idempotency.
Persistence: test continuation from every promised stop point. Determine whether the source retains complete tool-call history or only selected user and final messages before choosing Pydantic AI
message_history. Separate message snapshots from graph state, pending work, files, plans, and tool effects.Streaming: compare event types, lineage, order, redaction, backpressure, child and tool events, error termination, and when the final result becomes visible.
Observability: capture spans or callbacks and verify conversation, run, child, tool-call, and external-job correlation plus redaction and error attributes.
Use TestModel(call_tools=[]) for construction-only checks. When a test claims tool behavior, use TestModel(call_tools=[...]) for simple coverage or a FunctionModel that returns scripted ModelResponse tool calls. FunctionModel(function=...) covers only non-streamed requests. Event-aware capabilities such as RepoContext can make Agent.run() use the streamed model path; provide stream_function (or both callbacks) and yield the documented text or tool-call deltas. Execute the complete composition once so that path is not guessed from the model stub alone. Exercise public Agent(..., capabilities=[...]) paths where possible, and probe the locked external runtime for contracts that deterministic models cannot establish.
Example policy
Every example added during the migration must be executable in the target repository or name the exact executable test that backs it. Linting alone proves only syntax. Do not publish model output, network calls, sandbox code, shell commands, or partial fragments as examples unless a focused test exercises the claimed behavior. Prefer fewer complete examples over a catalog of unverified snippets.
Cutover
Keep the old path reversible until representative contract tests and evaluations pass. Remove Deep Agents, LangChain, or LangGraph dependencies only after no retained path, adapter, deployment tool, or test needs them. Report which behavior was exercised against a real backend or runtime, which used a deterministic substitute, and every remaining unverified contract.
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 or 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