ReadingResearchRadarInvestment framework
Sign in / Sign up
← Back to reading
News3 min read·2026-10-14

Pydantic Founder: Graph Libraries Fail on Type Safety, Parallelism, and Snapshots; Code Is the Architecture

Pydantic founder Samuel Colvin argues that existing graph libraries face an irreconcilable conflict between type safety, parallel execution, and state snapshots. He advocates defining agent workflows in native Python code, executed securely via the sandboxed interpreter Monty, to resolve fundamental flaws in traditional graph architectures.

ImportanceStructuralEvidenceE3 inspectableWrite-upQuick

2026-10-13 17:00 GMT+8

In AI agent development, the debate over whether to use explicit graphs or loops/prompts as the core architecture is intensifying. In his article "The code is the graph," Pydantic founder Samuel Colvin presents a counterintuitive view: traditional graph libraries are a mistake, and the only graph that works is code itself. He argues that while humans writing specific business code is diminishing, developers must shift to higher-level tasks—defining problems, setting metrics and constraints, and making it easy for agents to iterate.

Colvin points out that most popular graph libraries (such as LangGraph or early pydantic-graph) attempt to abstract control flow through nodes and edges, leading to fundamental technical conflicts. He calls this the "CAP theorem for graphs": any developer building a graph agent wants three properties—type safety (ensuring correct data passing between nodes), parallel execution (supporting fan-out and join), and state snapshots (allowing resumption from a breakpoint after a crash). However, existing graph APIs cannot provide all three simultaneously.

The mechanism lies in the fact that when parallel execution is introduced, the "current run location" is no longer a simple node pointer but a set of in-flight nodes and half-filled joins. If multiple nodes modify shared state concurrently, the moment for writing a snapshot becomes ambiguous: some updates may have occurred, others not. To achieve serializable snapshots under parallelism, nodes must stop mutating state directly and instead return change descriptions, which the runtime applies at commit points via merge rules. This breaks type safety because merge rules (like reducers) are typically declared outside node code, and type checkers cannot verify their semantic correctness or cross-field invariants.

Sign in / Sign up
ReadingResearchRadarInvestment framework

Native code, by contrast, naturally solves this problem. In Python, if is a branch, for is a loop, and await asyncio.gather(...) is a fan-out and join. The call stack records execution state, and debuggers and type checkers work directly. For example, after two asynchronous functions execute in parallel, developers can explicitly write a line of code to combine the results; this line is both type-safe and order-deterministic. Durability can be achieved by replaying the code via an external engine (like Temporal) or by saving the entire interpreter state in a sandbox environment.

To address the secure execution of agent-generated code, Pydantic developed Monty, a sandboxed Python interpreter designed specifically for agents. Monty holds no operating system resources (such as sockets or file descriptors); all external interactions must go through host-registered functions. This makes the interpreter's heap and call stack a coherent value that can be snapshotted and resumed at any point where it waits for an external call. This design allows agents to write pure Python code to orchestrate subtasks, retaining the language's expressiveness and safety while achieving the persistence and parallel capabilities that graph libraries struggle to provide.

Sources

  • 原始出处pydantic.dev↗
Continue researching →