Tutorial: Self-Optimizing Systems with DSPy
This tutorial demonstrates how to evolve a CNS 2.0 module from a system reliant on brittle, hand-crafted “prompt engineering” to a robust, self-optimizing program using the DSPy framework. We will focus on building a synthesis module that can programmatically learn to generate better prompts by using its own CNS Critic Pipeline as a quality metric.
This approach is a cornerstone of the advanced vision for CNS 2.0, creating a system that can adapt and improve its own reasoning capabilities over time. For more detail, see Chapter 7 of the Developer’s Guide.
Tutorial Path
Follow the steps in order:
- Introduction: From Prompts to Programs: Understanding the limitations of prompt engineering and the paradigm shift offered by DSPy.
- Defining the Task for DSPy: How to set up the core components: the Signature, the Metric, and the training Examples.
- Running the DSPy Optimizer: Using the DSPy compiler to automatically generate and optimize a powerful synthesis prompt.
- Analyzing the Optimized Module: Inspecting the results, comparing the optimized prompt to a naive one, and seeing the performance difference.