Files
magnus919_agent-skills/dspy/templates/multi-step.py
Magnus Hedemark 95046675bc feat: add dspy — expert skill for compiled prompt programs
Greenfield SkillOpt: 3 epochs for a Stanford DSPy compiler skill.
DSPy is a fundamentally different paradigm from chain/RAG frameworks.

Epoch 1 — Prominence:
- Hard-gate blockquote: 'DSPy is NOT a chain framework'
- Core Paradigm section with runnable code example early

Epoch 2 — Decision Guidance:
- Framework Routing Guide (DSPy vs LlamaIndex vs LangChain vs LangGraph)
- Where to Start table mapping entry points
- Troubleshooting table with reference links

Epoch 3 — Pattern Expansion:
- Optimizer selection cheat sheet from official docs
- Caching, compilation cost management, save/load
- FAQ covering paradigm confusion, errors, deployment

12 files: SKILL.md, 7 references, 3 templates, 1 script.
v1.0.0 -> v1.0.3 across 3 epochs.

All API surfaces validated against dspy.ai official docs —
optimizer selection guide, caching, core modules, FAQ.
Signed-off-by: Jasper <jasper@montcastle.bitches>
2026-07-09 14:51:32 -04:00

26 lines
937 B
Python

#!/usr/bin/env python3
"""Multi-step reasoning with DSPy — decompose, answer, synthesize."""
import dspy
lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=lm)
class MultiStepQA(dspy.Module):
def __init__(self):
self.decompose = dspy.ChainOfThought("question -> sub_questions")
self.answer = dspy.ChainOfThought("sub_question -> answer")
self.synthesize = dspy.ChainOfThought("answers -> final_answer")
def forward(self, question):
sub_qs = self.decompose(question=question).sub_questions
answers = []
for q in sub_qs:
answers.append(self.answer(sub_question=q).answer)
combined = "\n".join(f"Q: {q}\nA: {a}" for q, a in zip(sub_qs, answers))
return self.synthesize(answers=combined)
program = MultiStepQA()
result = program(question="What are the benefits of using DSPy for prompt optimization?")
print(f"Final Answer: {result.final_answer}")