Skip to content
Development
Skill

/dspy-better-together

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

From plugin
dspy-skills
12423 skills

Claude Code

$ npx -y skills add OmidZamani/dspy-skills --skill dspy-better-together --agent claude-code

SKILL.md

dspy-better-together.SKILL.md
name: dspy-better-together
version: "1.0.0"
dspy-compatibility: "3.2.1"
tags: ["optimizer"]
requires-extras: []
description: Use for BetterTogether, prompt plus weight optimization, fine-tuning sequences, and strategy chains like p -> w -> p.
allowed-tools:
  - Read
  - Write
  - Glob
  - Grep

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

| 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.

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

  • Pick optimizers: [dspy-optimizer-selection](../dspy-optimizer-selection/SKILL.md)
  • Fine-tune weights: [dspy-finetune-bootstrap](../dspy-finetune-bootstrap/SKILL.md)
  • Reflect with GEPA: [dspy-gepa-reflective](../dspy-gepa-reflective/SKILL.md)

Official Documentation

  • **BetterTogether API**: https://dspy.ai/api/optimizers/BetterTogether/
  • **Optimizer guide**: https://dspy.ai/learn/optimization/optimizers/
Read more
@omidzamani
Ships withdspy-skills

A Claude Code plugin containing 22 focused skills for programming, optimizing, evaluating, and deploying LLM applications with DSPy. Stable DSPy baseline: 3.2.1, released May 5, 2026.

Stars on GitHub

Momentum

stars in total
124
Star history of OmidZamani/dspy-skills on GitHub, a chart by star-history.com

Other skills on dspy-skills.

skill-perfection

skill-perfection

Use this skill when you need to QA audit and fix a plugin skill file. Provides a methodology for verifying skill content against…

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills10d309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc12d293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react1d252k
@facebook@facebookInstall Skill

Questions about dspy-better-together.

Which coding agents can use dspy-better-together?
dspy-better-together installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.