Pick LangGraph 1.2.24 when the workflow is an explicit graph that must save state every step and pause anywhere: interrupt() works in any node, needs a checkpointer, and on resume the node runs again from its start. Pick Pydantic AI 2.71.0 when the job is a typed agent whose risky tools need sign-off: requires_approval=True ends the run with DeferredToolRequests, you store the Conversation, and the resume skips the model request and executes the approved call directly. LangGraph persists through its checkpointer with durability 'async' by default; Pydantic AI core has no checkpointer, only a Conversation you store, a ConversationStore between runs, Harness StepPersistence snapshots, and three in-package durable engines (Temporal, DBOS, Prefect). pydantic-graph 2.x has had no persistence since 2.0.0b1, so a pydantic-graph workflow that pauses for days needs your own store. Both run against Ollama and vLLM: Pydantic AI through OllamaProvider and VLLMProvider with per-server profiles, LangGraph through ChatOllama 1.2.0 or ChatOpenAI 1.8.5, which drops reasoning_content. Start by gating the one tool that writes to a system of record and killing the process while it waits for approval.
Pydantic AI vs LangGraph, pinned to pydantic-ai-slim 2.71.0 and langgraph 1.2.24: choose LangGraph when the workflow is an explicit graph that must checkpoint its state and pause at any node with interrupt(), accepting that the interrupted node re-runs from its start on resume. Choose Pydantic AI when the job is a typed agent whose output must validate and whose risky tools need approval: requires_approval=True ends the run with DeferredToolRequests, you answer with DeferredToolResults, and the resume executes the approved call without calling the model again. Crash recovery in Pydantic AI comes from Temporal, DBOS or Prefect, not from core. Both run against Ollama or vLLM inside your network.
The pins are the latest finals on PyPI on or before November 23, 2026: pydantic-ai-slim 2.71.0 (uploaded 2026-11-19), langgraph 1.2.24 (2026-11-20) and langchain 1.5.2 (2026-11-18) for create_agent, with langchain-ollama 1.2.0 and langchain-openai 1.8.5 on the model side. Every behaviour below is read from source and docs at those tags; nothing was executed.
The comparison covers three axes: pausing for approval and resuming, surviving a process crash, and running against a local inference server. For the wider landscape, see the comparison of LangGraph, CrewAI and the OpenAI Agents SDK and the AI agents guide.
Pydantic AI vs LangGraph at a glance
Rows three and four carry the core difference: LangGraph owns your paused state and re-executes code to reach the pause point, while Pydantic AI hands you the state as a value and resumes at the tool call.
| Question | Pydantic AI 2.71.0 | LangGraph 1.2.24 (+ langchain 1.5.2) |
|---|---|---|
| Where a pause can happen | At a tool call only | Any node (interrupt()), plus static interrupt_before / interrupt_after |
| What you need to pause | DeferredToolRequests in output_type, or a HandleDeferredToolCalls handler | A checkpointer passed to compile() or create_agent |
| What re-runs on resume | Only the approved calls; no new model request | The interrupted node, from its first line |
| Where paused state lives | A Conversation value you serialize and store | The checkpointer, per thread_id |
| Mid-run crash recovery | A durable engine (Temporal, DBOS, Prefect in core), or Harness StepPersistence snapshots | Checkpointer plus whatever re-invokes the thread |
| Graph persistence | None in pydantic-graph 2.x | Every super-step |
| Local model path | OllamaProvider / OllamaModel, VLLMProvider | ChatOllama (native Ollama API) or ChatOpenAI pointed at vLLM |
| Default structured output | Tool mode, output retries default 1 | AutoStrategy, which falls to ToolStrategy on ChatOllama |
Human in the loop: LangGraph interrupt vs Pydantic AI approval
import uuid
from typing import Optional
from typing_extensions import TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.constants import START
from langgraph.graph import StateGraph
from langgraph.types import interrupt, Command
class State(TypedDict):
foo: str
human_value: Optional[str]
def node(state: State):
# everything above this line runs again on resume
answer = interrupt("what is your age?")
return {"human_value": answer}
builder = StateGraph(State)
builder.add_node("node", node)
builder.add_edge(START, "node")
graph = builder.compile(checkpointer=InMemorySaver())
config = {"configurable": {"thread_id": uuid.uuid4()}}
for chunk in graph.stream({"foo": "abc"}, config):
print(chunk) # {'__interrupt__': (Interrupt(value='what is your age?', ...),)}
for chunk in graph.stream(Command(resume="42"), config):
print(chunk)from langchain.agents import create_agent
from langchain.agents.middleware import HumanInTheLoopMiddleware
from langchain_ollama import ChatOllama
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.types import Command
# delete_file is a tool you define
agent = create_agent(
ChatOllama(model="qwen3", base_url="http://localhost:11434"),
tools=[delete_file],
middleware=[HumanInTheLoopMiddleware(interrupt_on={"delete_file": True})],
checkpointer=InMemorySaver(),
)
config = {"configurable": {"thread_id": "1"}}
result = agent.invoke(
{"messages": [{"role": "user", "content": "Delete the report."}]},
config,
version="v2",
)
agent.invoke(
Command(resume={"decisions": [{"type": "reject", "message": "Keep the report."}]}),
config,
version="v2",
)from pydantic_ai import Agent, ConversationTypeAdapter, DeferredToolRequests
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.vllm import VLLMProvider
model = OpenAIChatModel(
'Qwen/Qwen3.8-27B',
provider=VLLMProvider(base_url='http://localhost:8000/v1'),
)
agent = Agent(model, output_type=[str, DeferredToolRequests])
@agent.tool_plain(requires_approval=True)
def delete_file(path: str) -> str:
return f'File {path!r} deleted'
result = agent.run_sync('Delete `__init__.py`')
stored = ConversationTypeAdapter.dump_json(result.conversation) # put this in your database
# later, possibly in another process
conversation = ConversationTypeAdapter.validate_json(stored)
requests = conversation.deferred_tool_requests
results = requests.build_results(approvals={requests.approvals[0].tool_call_id: False})
result = agent.run_sync(conversation=conversation, deferred_tool_results=results)LangGraph interrupt and resume
Per the interrupt() docstring at 1.2.24, the first interrupt() call in a node raises GraphInterrupt and surfaces its value to the client. The client resumes by invoking the graph again with Command(resume=...) on the same thread. Then line 928: "The graph resumes from the start of the node, re-executing all logic." Line 934: "To use an interrupt, you must enable a checkpointer, as the feature relies on persisting the graph state." Several interrupt() calls in one node are matched to resume values by order. The re-run rule has one consequence that matters for approvals: any side effect above the interrupt() line in the same node happens twice. Put the interrupt in its own node, or make what precedes it idempotent. The LangGraph vs Temporal comparison walks through what that means for write tools. Since at least 1.2.14, interrupt() also takes an optional response_schema. A Pydantic model, TypedDict or dataclass there is converted to JSON Schema and used to validate the resume value; an invalid resume raises pydantic.ValidationError, nothing is saved, and the interrupt can be answered again. A raw JSON Schema dict is passed through as-is and not validated.
LangGraph human in the loop middleware
If you build on create_agent rather than a hand-written StateGraph, the approval layer is HumanInTheLoopMiddleware in langchain.agents.middleware. Its docstring at 1.5.2: each tool in interrupt_on "needs a decision before it runs: approve, edit, reject, or respond. The pause is a LangGraph interrupt, so the agent needs a checkpointer, and the run continues with Command(resume=...)." The default interrupt_mode is "batched": one interrupt per model turn, with the decisions in the HITLResponse matched to the gated calls by position. The alternative, "per_call", raises one interrupt per gated call inside the tool wrapper and is, per the source, planned to become the default in the next major release. Where the batched interrupt sits matters because of the re-run rule. In create_agent the model call is its own graph node named model (factory.py line 1614), and each middleware's after_model hook is a separate node (line 1688). Batched HITL raises its interrupt in after_model, so resuming re-runs that hook node from its start, not the model call. You do not pay for a second generation on approval.
Pydantic AI deferred tool requests
Pydantic AI pauses only at the tool-call boundary. Mark a tool with requires_approval=True (the default is False, tools.py line 410), pass requires_approval=True to a FunctionToolset to gate all its tools, or raise ApprovalRequired from inside a tool when approval depends on the arguments. CallDeferred covers the other case: the result will come from outside the process. Inside the tool, ctx.tool_call_approved is True once the call has been approved. There are two ways to answer. Inline, a HandleDeferredToolCalls capability's handler returns DeferredToolResults and the run continues in the same call. Or stop the world: the run ends with a DeferredToolRequests output (which must be in output_type), you collect a decision, and you start a new run. That second shape is the one a reviewer queue needs. The value of each approval can be True, False, ToolApproved(override_args=...) to approve with edited arguments, or ToolDenied(message=...), whose default message is "The tool call was denied." A denied call reaches the model as a tool return with outcome denied and that message, so the model can explain or try something else. build_results checks that the tool_call_id values you pass exist. Three behaviours at 2.71.0 separate this from LangGraph's model: The follow-up is a separate run with its own run_id; correlate pause and resume through conversation_id. One open bug is worth knowing: pydantic-ai issue #13690 (opened 2026-11-16, still open on November 23) reports that run_stream() builds DeferredToolRequests without validating the deferred calls, and the 2.71.0 docs say run_stream() and run_stream_sync() do not fill validated_args for a call they end on. Pause with run() or run_sync(). Pydantic AI's docs add a limit under the heading "Approval is not an authorization boundary against an untrusted client": behind a UI adapter, the approval is submitted by the client with the request, so a client that can reach the endpoint can approve a call of its own making. Enforce authorization inside the tool function. The same holds for any client-submitted approval in either framework.
- 1. The resume does not call the model.
UserPromptNode.runhands off to_handle_deferred_tool_results, which finds the last model response with tool calls and returns aCallToolsNodedirectly; the source comment on line 1482 reads# Skip ModelRequestNode and go directly to CallToolsNode. - 2. Non-gated calls are not held back. In the docs' worked example, an ungated
update_filecall from the same model response ran during the first run, before the pause. Only the gated calls wait. Supplying a result for a call that already ran raisesUserError: "was already executed and its result cannot be overridden." - 3. Arguments are validated again on resume, hooks included. A validation hook that reads the clock or a database can pass at pause time and fail at resume.
Crash recovery and persistence
LangGraph: the checkpointer is part of compile()
LangGraph saves graph state through the checkpointer per thread. Durability is Literal['sync', 'async', 'exit'] (types.py line 99) and defaults to 'async', which persists while the next step executes (pregel/main.py line 2715); passing durability with no checkpointer only warns that it has no effect. The Postgres checkpointer guide covers the three modes, saver setup and retention, so none of that is repeated here. The shipped savers at the 1.2.24 commit are InMemorySaver (langgraph-checkpoint 4.3.2), SqliteSaver and AsyncSqliteSaver (langgraph-checkpoint-sqlite 3.1.3), and PostgresSaver and AsyncPostgresSaver (langgraph-checkpoint-postgres 3.2.1). put_writes stores intermediate writes linked to a checkpoint per task. Node-level retries come from add_node(..., retry_policy=RetryPolicy(...)), whose defaults are initial_interval=0.5 and max_attempts=3. InMemorySaver, used in both LangGraph blocks above, loses every thread on restart. And a checkpoint makes a run recoverable, not recovered: something has to notice the dead process and invoke the thread again. That is the gap the LangGraph and Temporal comparison covers.
Pydantic AI checkpointer: three layers instead of one
Pydantic AI core has no per-step checkpointer. docs/persistence.md at 2.71.0 maps what it has instead, and the layers do different jobs. Between runs: Conversation and ConversationStore. The paused state in the block above is a Conversation carrying messages, usage, conversation_id and deferred_tool_requests. The docs say the deferred requests "can't be rebuilt from the messages" (which calls need approval and which need an external result, plus their metadata), so store the whole value, not just the message list. ConversationStore automates the load and save around each run with optimistic revision checks that raise ConversationConflict. Only InMemoryConversationStore ships in core, described as for tests and examples; for a real database you subclass ConversationStore. Settled steps: StepPersistence in Pydantic AI Harness 0.71.0. It saves a snapshot of the run's message history at settled node boundaries and on failure, an append-only event trail, and a tool-effect ledger recording started, completed and failed per tool call. A started effect with no terminal record after a crash should be treated as unknown_after_crash. Stores ship for memory, files, SQLite, MongoDB and Postgres. Two limits: a snapshot does not hold capability state outside the messages or workspace files, and it does not resume from the middle of a step. You continue by passing the snapshot's messages to a new Agent.run(message_history=...). Harness is 0.x and its docs say the API may change between minor releases. Mid-step: a durable engine. The durable execution overview at 2.71.0 lists nine engines, but only three ship in pydantic_ai.durable_exec: Temporal (TemporalDurability, extra temporal, temporalio>=1.27.0), DBOS (DBOSDurability, dbos>=3.4.0) and Prefect (PrefectDurability, prefect>=3.9.0). Four more live in Pydantic AI Harness (AWS Lambda, Absurd, pgtask, Azure Durable Task), and Restate and Apache Airflow ship the integration in their own packages. The engine journals model requests and wrapped tool calls; a restarted run replays the completed ones and retries the one in flight. You may attach one engine per agent; a second raises UserError. The retry-in-flight behaviour has the same shape as LangGraph's node re-run. The Restate page warns: "A step interrupted before its result was journaled runs again on retry, even if its external side effect already happened. Make side-effecting tools idempotent." For what to do once retries run out, see tool failure recovery: retry, reroute, replan, and for choosing the engine itself, the durable execution comparison of Temporal, Inngest and Restate.
Pydantic AI graph vs LangGraph
pydantic-graph is a required dependency of pydantic-ai-slim 2.71.0 (pydantic-graph==2.71.0 in requires_dist, not an extra), and the agent loop is itself a pydantic-graph: _agent_graph.py defines UserPromptNode, ModelRequestNode and CallToolsNode on top of it. But the 2.0.0b1 changelog entry (2026-05-20, pull request 5470) removed the pydantic_graph.persistence package and states that "the builder API deliberately does not snapshot graph state, so there is no pydantic_graph replacement for the persistence package", pointing to Harness StepPersistence for agent runs. At 2.71.0, pydantic_graph has no persistence module, and Graph.iter(state=, deps=, inputs=, span=, infer_name=) takes no start node and no snapshot.
So a pydantic-graph workflow that must wait days for a reviewer needs your own state store or a durable engine wrapped around it, while a LangGraph StateGraph gets that from the checkpointer. Pydantic's own graph docs open with "Don't use a nail gun unless you need a nail gun" and suggest trying plain agents and multi-agent patterns before graphs. If your problem is shaped like a graph and must be durable at every edge, that advice points at LangGraph.
| pydantic-graph 2.71.0 | LangGraph StateGraph 1.2.24 | |
|---|---|---|
| State saved between steps | No, by design | Yes, through the checkpointer |
| Pause inside a node | No built-in primitive | interrupt() |
| Resume from a saved point | Your own store or a durable engine | Command(resume=...) on the same thread_id |
| Inspect state after each step | Your own logging | get_state (raises No checkpointer set without one) |
Running on Ollama or vLLM inside your network
Pydantic AI: providers with per-server profiles
Pydantic AI 2.71.0 recognises ollama:<model> and vllm:<model> strings. OllamaProvider reads OLLAMA_BASE_URL (required if you pass no base_url) and OLLAMA_API_KEY; VLLMProvider reads VLLM_BASE_URL and VLLM_API_KEY. Without a key both fall back to a placeholder, which suits unauthenticated local servers. The docs use http://localhost:11434/v1 for self-hosted Ollama and http://localhost:8000/v1 for vLLM, because both go through the OpenAI-compatible chat completions path. Each provider applies a per-server profile: For tool calls the Pydantic AI docs say to start vLLM with --enable-auto-tool-choice and the --tool-call-parser for your model. Whether the server then enforces the schema that NativeOutput sends is a server question, covered in why vLLM structured output is not working; the server-side tool-calling caveats for both Ollama and vLLM are in the OpenAI Agents SDK on Ollama guide.
- Ollama: JSON schema and JSON object output supported, strict tool definitions off (Ollama does not support strict mode), thinking read from the
reasoningfield, and onlymax_tokenssent because Ollama ignoresmax_completion_tokens.OllamaModelswitches JSON schema output off when the base URL is on ollama.com or the model name ends in-cloud, soNativeOutputraisesUserErrorthere; the cloud accepts the schema without enforcing it. - vLLM: JSON schema output supported, with the schema also injected into the instructions (
native_output_requires_schema_in_instructions=True), because guided decoding masks tokens without telling the model what it is producing. Leading system messages are merged into one, document input and tool return schemas are off, and Qwen3-Coder models get forced tool choice and strict tool definitions.
LangGraph: no model layer of its own
langgraph 1.2.24's pyproject.toml depends on langchain-core, langgraph-checkpoint, langgraph-prebuilt and langgraph-sdk, and on no model SDK. A node can call any client you write. The packaged route is a LangChain chat model, and the two local paths behave differently: If your vLLM model is a reasoning model and your audit log needs its reasoning, that ChatOpenAI limitation decides the path. Pydantic AI's OpenAI-compatible model reads reasoning or reasoning_content by default.
ChatOllama(langchain-ollama 1.2.0, uploaded on November 23) uses theollamapackage'sClientand.chat(), which is Ollama's native API, not/v1. Itsbase_urlis the bare host, as in the block above.with_structured_outputdefaults tomethod="json_schema", withfunction_callingandjson_modeas alternatives. It sets no model profile, which matters forcreate_agentbelow.ChatOpenAIpointed at vLLM (langchain-openai 1.8.5) is documented with a vLLM example (base_url='http://localhost:8000/v1',api_key='EMPTY'), but its module docstring says non-standard fields such asreasoning_content"are not extracted or preserved", and says to use the corresponding provider-specific LangChain package instead whenbase_urlpoints at a provider such as vLLM. It also warns that the model name can route requests to the Responses API, so setuse_responses_api=Falsefor OpenAI-compatible servers.
Structured output on each side
Pydantic AI validates output against your output_type. The default mode is tool calling, and neither the Ollama nor the vLLM profile changes it; NativeOutput is opt-in where the server enforces json_schema. Retries come from Agent(retries=...): an int sets both the tools and output budgets, and unset keys default to 1. A dict such as retries={'output': 3} raises only the output budget, and ToolOutput(max_retries=...) overrides it per output tool.
On the LangChain side, create_agent(..., response_format=...) at 1.5.2 accepts ToolStrategy, ProviderStrategy, a bare schema type or a raw dict. A bare schema goes through AutoStrategy, which picks ProviderStrategy only when the model's profile declares structured output support or its name matches a short list of OpenAI models; otherwise it uses ToolStrategy. ChatOllama has no profile, so a local Ollama model gets ToolStrategy unless you pass ProviderStrategy yourself. ToolStrategy retries on validation errors by default (handle_errors=True), but with a raw JSON-schema dict the tool-call arguments are returned as-is without validation, so the retry never triggers. Pass a Pydantic model if you want the check.
| Pydantic AI 2.71.0 | create_agent, langchain 1.5.2 | |
|---|---|---|
| Default mode on local models | Tool calling | ToolStrategy on ChatOllama |
| Server-enforced schema | NativeOutput (off on Ollama Cloud) | ProviderStrategy, passed explicitly |
| Retry on invalid output | Output budget, default 1 | handle_errors=True; inert with a raw dict schema |
On-prem deployment: where the approval record lives
Inside a bank, insurer or hospital, the approval is evidence: who approved which tool call, with which arguments, and when. The two frameworks put that record in different places, and that changes your audit scope.
With LangGraph, the record lives in the checkpointer's tables per thread: the interrupt value and the Command(resume=...) written back. The checkpointer database becomes part of the audit scope, and its retention policy is now a records-retention policy. With Pydantic AI, the paused Conversation (messages, deferred_tool_requests with validated_args and metadata) is a JSON value you write to a table you design, so the schema, tenant column and retention are yours to set. In both cases the authorization check belongs inside the tool, per the Pydantic AI docs' warning quoted above.
Both run entirely against Ollama or vLLM on your own hosts. What differs is the set of packages you mirror into an internal index: pydantic-ai-slim plus one engine extra (temporal, dbos or prefect), or langgraph plus langchain-ollama or langchain-openai plus a checkpoint package. Pin from the registry, not from memory: langchain-ollama 1.2.0 landed on November 23, and its previous final, 1.1.0, dated from April. Check the advisory floors too. GHSA-3fx2-cqw9-xr3c was fixed in langgraph 1.2.14, GHSA-6hmw-9432-67qq in langgraph-checkpoint-postgres 3.1.3 and langgraph-checkpoint-sqlite 3.1.2, and GHSA-5m5q-5qj4-gx9h and GHSA-m4cr-m4qc-9hh3 (both high) in pydantic-ai-harness 0.70.0, published November 18. Every pin in this post sits above those floors.
Pydantic AI or LangGraph: which one to pick
Pick Pydantic AI when:
Conversation between runs and accept that a crash mid-step loses that step;Pick LangGraph when:
compile() argument rather than a layer you assemble.We found no primary source at these versions for a supported integration of one inside the other, so treat them as alternatives; either can be called from plain Python if you need to. If you are building this against your own Ollama or vLLM hosts, that is the work our on-premise AI development team does.
This week, take the one tool in your agent that writes to a system of record and gate it: requires_approval=True in Pydantic AI, or interrupt_on in HumanInTheLoopMiddleware. Swap the in-memory store for a real one, start a run, kill the process while it waits for approval, and confirm the approval still resumes from your store in a fresh process.
FAQ
Quick answers to the questions this post tends to raise.



