skills/dspy-better-together/SKILL.md
This skill should be used when the user asks to "use BetterTogether", "combine prompt optimization and fine-tuning", "sequence DSPy optimizers", "run prompt then weight optimization", mentions `dspy.BetterTogether`, strategy strings such as "p -> w -> p", or needs to compose multiple DSPy teleprompters into an evaluated optimization sequence.
npx skillsauth add omidzamani/dspy-skills dspy-better-togetherInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Sequence prompt and weight optimizers, evaluate intermediate programs, and return the best candidate.
3.2.1 or later in the stable 3.2.x series.student.set_lm(lm).BetterTogether to hold out part of the trainset.BootstrapFinetune.import dspy
lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=lm)
student = dspy.ChainOfThought("question -> answer")
student.set_lm(lm)
def metric(example, pred, trace=None):
return float(example.answer.lower() == pred.answer.lower())
optimizer = dspy.BetterTogether(
metric=metric,
p=dspy.GEPA(
metric=lambda gold, pred, trace=None, pred_name=None, pred_trace=None:
dspy.Prediction(score=metric(gold, pred), feedback="Check answer correctness."),
reflection_lm=dspy.LM("openai/gpt-4o"),
auto="light",
),
w=dspy.BootstrapFinetune(metric=metric),
)
compiled = optimizer.compile(
student,
trainset=trainset,
valset=valset,
strategy="p -> w -> p",
)
| Strategy | Use it when |
|----------|-------------|
| "p -> w" | Start with a simple prompt-then-weight pass |
| "p -> w -> p" | Re-optimize prompts after fine-tuning |
| "w -> p" | Fine-tuning data is already strong |
| Custom chains | Comparing prompt optimizers or conducting controlled experiments |
Optimizer names come from constructor keyword arguments. For example, mipro=... and gepa=... make "mipro -> gepa" valid.
Pass optimizer-specific arguments through optimizer_compile_args:
compiled = optimizer.compile(
student,
trainset=trainset,
valset=valset,
strategy="p -> w",
optimizer_compile_args={
"p": {"max_metric_calls": 150},
},
)
Do not pass student inside optimizer_compile_args; BetterTogether manages the current program.
The returned program exposes:
candidate_programs: evaluated candidates with score and strategyflag_compilation_error_occurred: whether a step failed before completiontools
This skill should be used when the user asks to "optimize with SIMBA", "use mini-batch introspective optimization", "generate self-reflective rules", mentions "SIMBA optimizer", "stochastic mini-batch ascent", "output variability", or needs an alternative to MIPROv2/GEPA that evolves rules and demonstrations from numeric metrics.
data-ai
This skill should be used when the user asks to "create a DSPy signature", "define inputs and outputs", "design a signature", "use InputField or OutputField", "add type hints to DSPy", mentions "signature class", "type-safe DSPy", "Pydantic models in DSPy", or needs to define what a DSPy module should do with structured inputs and outputs.
development
This skill should be used when the user asks to "use DSPy RLM", "process a very long context", "use ProgramOfThought", "use CodeAct", "run DSPy modules in parallel", mentions Recursive Language Models, sandboxed Python execution, Deno, `dspy.RLM`, `dspy.ProgramOfThought`, `dspy.CodeAct`, or `dspy.Parallel`, or needs to choose a DSPy reasoning module beyond Predict, ChainOfThought, and ReAct.
tools
This skill should be used when the user asks to "create a ReAct agent", "build an agent with tools", "implement tool-calling agent", "use dspy.ReAct", mentions "agent with tools", "reasoning and acting", "multi-step agent", "agent optimization with GEPA", or needs to build production agents that use tools to solve complex tasks.