Skip to main content

Deep Agent — Pydantic AI

A Pydantic AI re-implementation of the LangChain Deep Agents pattern, which itself was reverse-engineered from Claude Code's architecture.

What is this?

LangChain's Deep Agents project identified four architectural pillars that make Claude Code effective at complex, multi-step tasks. This project recreates those pillars using Pydantic AI instead of LangChain/LangGraph:

Pillar Deep Agents (LangChain) This Project (Pydantic AI)
Planning TodoListMiddleware — no-op tool for context engineering write_todos / read_todos — same pattern, injected via RunContext
Filesystem FilesystemMiddleware with BackendProtocol read_file, write_file, edit_file, list_files, grep_files — in-memory or disk-backed
Sub-agents SubAgentMiddleware + task tool task tool that spawns fresh pydantic_ai.Agent with shared filesystem
Skills SkillsMiddleware — scans directories, injects names into prompt, lazy-loads discover_skills() + read_skill / read_skill_resource tools — same progressive disclosure
System Prompt Claude Code–inspired prompt with tool usage guidelines Same approach — detailed instructions on planning, filesystem usage, delegation, skills
Context Mgmt SummarizationMiddleware with auto-compaction Filesystem-as-memory pattern + output truncation

Installation

pip install pydantic-ai-deepagents

Quickstart

import asyncio
from pydantic_ai_deepagents import create_deep_agent

async def main():
    agent, deps = create_deep_agent(
        system_prompt="You are a research assistant.",
    )

    result = await agent.run(
        "Research X and write your findings to notes.md",
        deps=deps,
    )

    print(result.output)

    # Check what files the agent created
    for path, entry in deps.files.items():
        print(f"{path}: {len(entry.content)} chars")

asyncio.run(main())

Customisation

Custom model

agent, deps = create_deep_agent(
    model="openai:gpt-4o",  # or any pydantic-ai model string
)

Custom tools

from pydantic_ai import RunContext
from pydantic_ai_deepagents import DeepAgentDeps

async def search_web(ctx: RunContext[DeepAgentDeps], query: str) -> str:
    """Search the web for information."""
    # your implementation
    return "results..."

agent, deps = create_deep_agent(tools=[search_web])

Disk-backed workspace with shell

from pathlib import Path

agent, deps = create_deep_agent(
    workspace=Path("./my_workspace"),
    enable_shell=True,
)

Sub-agent depth control

agent, deps = create_deep_agent(
    max_sub_agent_depth=3,  # allow 3 levels of nesting
    enable_subagents=True,
)

Skills

Skills follow the open Agent Skills specification with progressive disclosure:

  1. Discovery — at startup, only skill names + descriptions go into the system prompt
  2. Activation — the agent calls read_skill("skill-name") to load full instructions on demand
  3. Execution — the agent follows the instructions, optionally loading resource files

Loading skills

# From directories
agent, deps = create_deep_agent(skills=["./skills/"])

# Inline
from pydantic_ai_deepagents import Skill
agent, deps = create_deep_agent(inline_skills=[Skill(
    name="my-skill", description="...", instructions="...", source_path="<inline>",
)])

# From raw SKILL.md text
from pydantic_ai_deepagents import load_skill_from_text
skill = load_skill_from_text("my-skill", open("SKILL.md").read())
agent, deps = create_deep_agent(inline_skills=[skill])

Example skills included

The example_skills/ directory contains three ready-to-use skills:

  • web-research — structured research workflow with synthesis
  • code-review — multi-pass review (correctness, security, maintainability, performance)
  • data-analysis — data profiling, cleaning, analysis, and reporting

Credits

Metadata

Release files for pydantic-ai-deepagents 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-ai-deepagents 0.0.2
File Size Uploaded Provenance
pydantic_ai_deepagents-0.0.2.tar.gz 15.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-ai-deepagents 0.0.2
File Interpreter ABI Platform
pydantic_ai_deepagents-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 30.5 kB

Release files / pydantic_ai_deepagents-0.0.2.tar.gz

Download URL pydantic_ai_deepagents-0.0.2.tar.gz
Size 15.0 kB
Tags Source
SHA-256 checksum
How to use checksums
91643fd05253f4c16b4065a2fe09eb8101b5ed1808d97d577b13d9882b81c8cf
BLAKE2b-256 checksum
How to use checksums
a2d94d11d2bb61806941b0471f69f44cc9cc9025c16a15f4f207e1a94438edf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 19, 2026.

Transparency log

Release files / pydantic_ai_deepagents-0.0.2-py3-none-any.whl

Download URL pydantic_ai_deepagents-0.0.2-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b2f2d6b5fafcbc894433483260dec0f17fb524ea89fda445b2633247ae80745
BLAKE2b-256 checksum
How to use checksums
74d4d995d4093a24369d92b680eaf4f19e21f1e969b2bcc220bd22ec3b114a20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 19, 2026.

Transparency log

Security for pydantic-ai-deepagents 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydantic_ai_deepagents-0.0.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page