Overview
DSPy (Declarative Self-improving Python) is a framework that treats programming—not prompting—as the primary interface to foundation models. It provides composable Python primitives to build model calls, retrieval, evaluation, and self-improvement loops, making it suitable for classifiers, RAG pipelines, and multi-step agent systems.
Key Features
- Programming-first API: Compose model interactions and pipelines in Python to reduce brittle prompt engineering.
- Self-improvement algorithms: Tools to iteratively optimize instructions and examples across multi-stage pipelines.
- Reusable components: Built-in support for retrieval, evaluation, assertions, and training helpers to accelerate development.
- Strong docs and community: Official docs at dspy.ai and an active contributor base.
Use Cases
- Knowledge-intensive QA and information extraction via robust RAG setups.
- Multi-step decision-making and agent loops with stateful improvement.
- Model evaluation and iterative optimization to refine task performance.
Technical Notes
- Python-centric: Developer-friendly declarative APIs that integrate with the Python ecosystem.
- Modular & composable: Component-based design for flexible assembly of inference and data flows.
- Model & tool agnostic: Works with local models, cloud LLMs, and retrieval systems.
- Open-source (MIT) on GitHub, suitable for research and production use.