Agent frameworks
DSPy
Treats prompts as parameters to be optimised against a metric instead of hand-tuned strings.
- Category
- Agent frameworks
- Pricing
- Open source
- Runs
- Self-hosted
- Languages
- Python
- Interface
- Library
- Source
- Open source
What DSPy is
DSPy reframes prompting as an optimisation problem. You declare what a step should do and supply a metric and examples; DSPy compiles the prompts, and can re-optimise when you change model. The payoff is that prompt quality stops being craft you redo by hand every time the model changes.
Best for
Tasks with a measurable metric and enough examples to optimise against, where hand-tuned prompts keep drifting.
Consider something else if
The mental model is genuinely different from prompt-writing, and it needs a dataset and a metric before it does anything for you.
DSPy alternatives
The closest options in agent frameworks, on the axes that actually separate them.
| Tool | Best for | Pricing | Runs |
|---|---|---|---|
| DSPyopen source | Tasks with a measurable metric and enough examples to optimise against, where hand-tuned prompts keep drifting. | Open source | Self-hosted |
| Pydantic AIopen source | Python teams already using Pydantic who want type safety and a framework small enough to hold in your head. | Open source | Self-hosted |
| LangChainopen source | Projects that benefit from breadth of integrations, and teams who want explicit stateful graphs via LangGraph. | Open source | Hosted or self-hosted |
| Claude Agent SDKopen source | Filesystem- and shell-shaped agents where the built-in tool set is most of what you need. | Open source | Self-hosted |
| LlamaIndexopen source | Retrieval-heavy applications where document ingestion and indexing are the hard part. | Open source | Hosted or self-hosted |
| Mastraopen source | TypeScript and Node teams who want a framework designed for their stack instead of a translated one. | Open source | Hosted or self-hosted |
Choosing within agent frameworks
Language, honestly
Most of this category is Python-first. If your service is TypeScript, the shortlist is genuinely shorter, and a thin layer over the provider SDK is often better than a half-maintained port.
How much it hides
Some frameworks give you primitives you compose; others give you an agent you configure. The second is faster to a demo and harder to debug at depth. Match this to how much novel behaviour you expect to need.
Questions
What is DSPy?
DSPy reframes prompting as an optimisation problem. You declare what a step should do and supply a metric and examples; DSPy compiles the prompts, and can re-optimise when you change model. The payoff is that prompt quality stops being craft you redo by hand every time the model changes. It is open source and self-hosted.
What are the alternatives to DSPy?
The closest alternatives are Pydantic AI, LangChain, Claude Agent SDK, LlamaIndex, Mastra. They sit in the same category — agent frameworks — and differ mainly on hosting model, pricing shape, and how much they abstract away.
Is DSPy the right choice?
Tasks with a measurable metric and enough examples to optimise against, where hand-tuned prompts keep drifting. The main caveat: The mental model is genuinely different from prompt-writing, and it needs a dataset and a metric before it does anything for you.
Whatever you build on, the model is the line item that scales. See what each one costs per million tokens, or price your own workload.