Docs
Python: Pydantic AI & LangGraph

Python: Pydantic AI & LangGraph

Recommended libraries and frameworks for integrating AI into Python applications, with LangSmith for observability.


The Python ecosystem is the most mature in AI. Options range from low-level SDKs to full orchestration frameworks:

Pydantic AILangGraph
Best forTyped agents, FastAPI/Pydantic integrationStateful workflows, complex graphs, multi-agent
PhilosophyType-safety first, clean APIExplicit state graph, full control
Learning curveLow (if you know Pydantic)Medium-high
StreamingYesYes
Structured outputNative (Pydantic models)Yes
TestingExcellent (built-in test mode)Good

Pydantic AI

Agent framework from the Pydantic team. Its premise: agents should be as easy to type, test, and maintain as any other Python code. If your stack uses FastAPI + Pydantic, the same data models are reused in the agent without duplication.

Covers the following cases well:

  • Agents with tool use and native structured output via Pydantic models
  • Typed dependency injection in tools (repositories, services)
  • Streaming with direct FastAPI integration
  • Testing without complex mocks thanks to the built-in TestModel
  • Multi-provider support (OpenAI, Anthropic, Google, Ollama)

Official docs: ai.pydantic.dev


LangGraph

State graph-based orchestration framework for building complex agents and multi-agent systems. Models flow as a directed graph where nodes are functions and edges are state transitions, giving full control over agent behaviour.

Covers the following cases well:

  • Multi-step workflows with branches and persistent state
  • Human-in-the-loop with pause and resume execution
  • Multi-agent systems with supervisor/worker pattern
  • Checkpointing for multi-turn conversations (PostgreSQL, SQLite)
  • Native LangSmith integration for observability

Official docs: langchain-ai.github.io/langgraph

LangChain vs LangGraph

LangChain (the original chains framework) turned out to be too abstract for production. LangGraph is its successor: more explicit and controllable. If you’re starting from scratch, use LangGraph directly.


LangSmith β€” cross-cutting observability

LangSmith is the observability, testing, and evaluation platform for LLM applications. It’s not an agent framework but the traceability layer you add on top of any code calling LLMs β€” compatible with LangGraph, Pydantic AI, or directly the Anthropic/OpenAI SDKs.

Covers the following cases well:

  • Automatic tracing of LLM calls (inputs, outputs, tokens, latency, cost)
  • Manual tracing of arbitrary functions via the @traceable decorator
  • Test case datasets and automated evals
  • Prompt management and versioning
  • Production monitoring

Official docs: docs.smith.langchain.com

When to use each

Use Pydantic AI for typed agents in FastAPI environments or when testing is a priority. Use LangGraph for workflows with complex state, branches, human-in-the-loop, or multi-agent systems. Add LangSmith in either case to have visibility into what the LLM is doing in production.