85 agentic tools audited for security incidents · Talk to the lab →
MotionticBook a call
Compare

DSPy vs LangChain: optimise the program or orchestrate the agent

DSPy is a framework for programming rather than prompting language models, with optimisers such as GEPA that tune a program's prompts against a metric, while LangChain is an agent layer for wiring models, tools and middleware into a running agent, so DSPy fits teams optimising the quality of specific model calls and LangChain fits teams orchestrating an agent's flow.

Checked

DSPy and LangChain are often compared, but they answer different questions. DSPy asks how to get the highest score from a pipeline of model calls on a metric the team defines, and treats prompts as parameters an optimiser can tune. LangChain asks how to connect a model to tools, guardrails and a runtime so an agent can do work.

That makes them more complementary than competing. A team can optimise a classification or extraction step with DSPy and run it inside an agent built with LangChain, LangGraph or a model vendor's SDK.

What each does

  • DSPy

    Programs are written as modules with declared inputs and outputs. Optimisers such as GEPA search for prompts and instructions that raise a metric on a training set. The README lists agent loops among the programs it can build, and LiteLLM is no longer a runtime dependency.

  • LangChain

    create_agent runs a tool-calling agent on LangGraph, with middleware hooks before and after each model and tool call, structured output in the main loop, and a broad integration surface.

Where each earns its place

  • DSPy

    Steps with a measurable target: extraction, classification, routing, retrieval query rewriting. It needs a labelled set and a metric, which is also what an eval suite needs.

  • LangChain

    Agents whose difficulty is the flow: which tool to call, how to recover from a failed call, where a person approves. Optimising one prompt does not solve those.

How Motiontic approaches it

Prompt optimisation is only as good as the metric behind it. Motiontic's engineers build the eval set from the client's real cases first, then decide per step whether hand-written prompts, an optimiser or a different model clears the bar at the lower cost.

Motiontic's engineers are framework-neutral. They choose per project after a short spike on the client's real task, keep prompts, tool definitions and evals outside the framework so a later switch is a refactor rather than a rewrite, and hand the eval suite to the client's team so the next framework decision can be measured.

DSPy and LangChain, figures retrieved 30 October 2026

DSPy and LangChain, figures retrieved 30 October 2026
DSPyLangChain
JobOptimise prompts and programs against a metricOrchestrate tool-calling agents
Core ideaProgramming, not prompting, language modelscreate_agent on LangGraph, with middleware
Needs to startA metric and a set of examplesA model, tools and instructions
LicenceMITMIT
LanguagesPythonPython, JavaScript / TypeScript
Latest version3.4.1 (12 Oct 2026); 3.0 on 12 Aug 20251.4.7 (21 Oct 2026); 1.0 on 17 Oct 2025
MaintainerRepository under the stanfordnlp GitHub organisationLangChain Inc.
GitHub stars38,856148,719 (Python repo)
PyPI downloads, last week1.32M37.24M

Common questions

Is DSPy a replacement for LangChain?

Not usually. DSPy optimises the prompts inside a pipeline of model calls against a metric, and LangChain orchestrates agents and tools. Many teams could use both: DSPy for a measurable step, LangChain or LangGraph for the agent around it.

What is GEPA in DSPy?

GEPA is one of DSPy's optimisers. The DSPy README cites the paper "GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning".

Can DSPy build agents?

DSPy's README lists agent loops among the programs it can build. It does not ship the persistence, approval and integration features of an agent runtime, so production agents usually pair it with one.

What does DSPy need before it can optimise?

A metric that scores outputs and a set of examples to score against. Without them, an optimiser has nothing to improve towards.

Running agents that have to hold up?

Describe the agent, the systems it touches and what it must never get wrong. The first call is with a lab engineer, who will say plainly whether it is ready for production, and whether Motiontic is the right team.