agentsclimarketplace

Dspy better together

Skill OmidZamani/dspy-skills/skills/dspy-better-together

Use for BetterTogether, prompt plus weight optimization, fine-tuning sequences, and strategy chains like p -> w -> p.From its SKILL.md

Install
npx -y skills add OmidZamani/dspy-skills --skill dspy-better-together

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

3.0 KB, 681 tokens by cl100k_base, as published. Nobody here has run it

DSPy BetterTogether

Goal

Sequence prompt and weight optimizers, evaluate intermediate programs, and return the best candidate.

Prerequisites

  • Use DSPy 3.2.1 or later in the stable 3.2.x series.
  • Assign an LM directly to every predictor with student.set_lm(lm).
  • Keep a validation set, or allow BetterTogether to hold out part of the trainset.
  • Confirm the LM provider supports fine-tuning before including BootstrapFinetune.

Basic Pattern

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 Choices

StrategyUse 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 chainsComparing prompt optimizers or conducting controlled experiments

Optimizer names come from constructor keyword arguments. For example, mipro=... and gepa=... make "mipro -> gepa" valid.

Per-Optimizer Compile Arguments

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.

Inspect Results

The returned program exposes:

  • candidate_programs: evaluated candidates with score and strategy
  • flag_compilation_error_occurred: whether a step failed before completion

Related Skills

Official Documentation

What ships with it: 1 file

879 B alongside SKILL.md, 1 of them executable

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.