dspy-better-together
Skill124 starsChanged 11 months agoMITView on GitHub
Use for BetterTogether, prompt plus weight optimization, fine-tuning sequences, and strategy chains like p -> w -> p.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- lebsral/DSPy-Programming-not-prompting-LMs-skillstheir own version, first seen Jun 27, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- lebsral/DSPy-Programming-not-prompting-LMs-skills★ 11same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository24 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skill-perfectionSkill
- skill-perfectionSkill
- dspy-adapters-multimodalSkill
- dspy-advanced-module-compositionSkill
- dspy-bootstrap-fewshotSkill
- dspy-custom-module-designSkill
- dspy-debugging-observabilitySkill
- dspy-embedding-retrievalSkill
- dspy-evaluation-suiteSkill
- dspy-finetune-bootstrapSkill
- dspy-gepa-reflectiveSkill
- dspy-haystack-integrationSkill
- dspy-mcp-tool-integrationSkill
- dspy-miprov2-optimizerSkill
- dspy-optimize-anythingSkill
- dspy-optimizer-selectionSkill
- dspy-output-refinement-constraintsSkill
- dspy-production-deploymentSkill
- dspy-rag-pipelineSkill
- dspy-react-agent-builderSkill
- dspy-reasoning-modulesSkill
- dspy-signature-designerSkill
- dspy-simba-optimizerSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 23
Use DSPy 3.2.1 or later in the stable 3.2.x series.
- Very specific: line 25
Keep a validation set, or allow BetterTogether to hold out part of the trainset.
- Very specific: line 88
Do not pass student inside optimizer_compile_args.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
DSPy BetterTogether
Goal
Sequence prompt and weight optimizers, evaluate intermediate programs, and return the best candidate.
Prerequisites
- Use DSPy
3.2.1or later in the stable3.2.xseries. - Assign an LM directly to every predictor with
student.set_lm(lm). - Keep a validation set, or allow
BetterTogetherto 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 strategyflag_compilation_error_occurred: whether a step failed before completion
Related Skills
- Pick optimizers: dspy-optimizer-selection
- Fine-tune weights: dspy-finetune-bootstrap
- Reflect with GEPA: dspy-gepa-reflective
Official Documentation
- BetterTogether API: https://dspy.ai/api/optimizers/BetterTogether/
- Optimizer guide: https://dspy.ai/learn/optimization/optimizers/
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

