dspy-modules
Installation
SKILL.md
Build Composable AI Programs with dspy.Module
Guide the user through structuring DSPy programs as reusable, composable modules. A dspy.Module is the building block for all DSPy programs -- like PyTorch's nn.Module but for language model pipelines.
Step 1 — Gather context
Ask before writing any code:
- What kind of pipeline? (RAG, classify-then-route, iterative refinement, simple extraction?)
- How many sub-modules / steps? (Single-step can skip the Module wrapper; 2+ steps benefit from it)
- Will you optimize this with a DSPy optimizer? (If yes, sub-module layout as
self.attributes is critical) - Do you need async support? (Requires
async def forward()andacall— impacts design from the start)
Then build or explain the pattern that fits.
What is dspy.Module
dspy.Module is the building block for multi-step DSPy programs. Declare sub-modules in __init__ as self. attributes, wire them together with Python logic in forward(). DSPy optimizers automatically discover and tune all sub-modules in the tree.