Chapter 2. Introduction to DSPy
You now understand what context engineering is, and why it matters. You’ve seen the failure modes that plague long contexts, and techniques for fixing them. Now it’s time to explore DSPy’s core architecture, and how you can use it to solve context engineering problems. DSPy was designed from the very start to be portable, modular, and self-improving.
Portable: programs can run across different models and providers.
Modular: programs are composable, reusable, and easily modified.
Self-improving: powerful optimizers that evaluate and improve the underlying prompts.
The key to DSPy is understanding the core primitives it offers for building AI programs. DSPy programs are built and optimized with five foundational concepts:
Language Models: Model provider configuration and prompt formatting
Signatures: Task definitions declaring inputs, outputs, and initial instructions
Modules: Reusable components for building program pipelines
Evaluation: Defining metrics and datasets for measuring ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access