Deep agents built with pydantic-ai
Project description
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:
- Discovery — at startup, only skill names + descriptions go into the system prompt
- Activation — the agent calls
read_skill("skill-name")to load full instructions on demand - 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
- langchain-ai/deepagents — the original Deep Agents implementation
- Claude Code — the architecture that inspired it all
- Pydantic AI — the agent framework used here
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_ai_deepagents-0.0.2.tar.gz.
File metadata
- Download URL: pydantic_ai_deepagents-0.0.2.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91643fd05253f4c16b4065a2fe09eb8101b5ed1808d97d577b13d9882b81c8cf
|
|
| MD5 |
932f67f514d13018b23ed45ecdbd8885
|
|
| BLAKE2b-256 |
a2d94d11d2bb61806941b0471f69f44cc9cc9025c16a15f4f207e1a94438edf6
|
Provenance
The following attestation bundles were made for pydantic_ai_deepagents-0.0.2.tar.gz:
Publisher:
publish.yml on WillemDeGroef/pydantic-ai-deepagents
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_ai_deepagents-0.0.2.tar.gz -
Subject digest:
91643fd05253f4c16b4065a2fe09eb8101b5ed1808d97d577b13d9882b81c8cf - Sigstore transparency entry: 1134258218
- Sigstore integration time:
-
Permalink:
WillemDeGroef/pydantic-ai-deepagents@171b5f092a1e1dca068b1405cdf0b5e7281279b3 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/WillemDeGroef
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@171b5f092a1e1dca068b1405cdf0b5e7281279b3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pydantic_ai_deepagents-0.0.2-py3-none-any.whl.
File metadata
- Download URL: pydantic_ai_deepagents-0.0.2-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b2f2d6b5fafcbc894433483260dec0f17fb524ea89fda445b2633247ae80745
|
|
| MD5 |
f79968c9aa38eb5a362a5d77cdac2075
|
|
| BLAKE2b-256 |
74d4d995d4093a24369d92b680eaf4f19e21f1e969b2bcc220bd22ec3b114a20
|
Provenance
The following attestation bundles were made for pydantic_ai_deepagents-0.0.2-py3-none-any.whl:
Publisher:
publish.yml on WillemDeGroef/pydantic-ai-deepagents
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_ai_deepagents-0.0.2-py3-none-any.whl -
Subject digest:
7b2f2d6b5fafcbc894433483260dec0f17fb524ea89fda445b2633247ae80745 - Sigstore transparency entry: 1134258276
- Sigstore integration time:
-
Permalink:
WillemDeGroef/pydantic-ai-deepagents@171b5f092a1e1dca068b1405cdf0b5e7281279b3 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/WillemDeGroef
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@171b5f092a1e1dca068b1405cdf0b5e7281279b3 -
Trigger Event:
release
-
Statement type: