dspy-optimization
Original:🇺🇸 English
Translated
1 scripts
DSPy optimization workflows — teleprompters, metrics, evaluation, and compilation strategies. Use when optimizing DSPy programs with BootstrapFewShot, MIPROv2, or custom metrics.
16installs
Sourceqredence/skills
Added on
NPX Install
npx skill4agent add qredence/skills dspy-optimizationTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →DSPy Optimization
Guidance for optimizing DSPy programs: teleprompter selection, metric definition, evaluation workflows, and save/load patterns.
Environment Setup
This skill requires as the Python package manager.
uvbash
uv venv
source .venv/bin/activate
uv pip install dspyRule: Never use raw. Always usepipfor installs anduv pipfor script execution.uv run
Quick Start
Optimizing with metrics
python
# Use the optimize-dspy script
uv run scripts/optimize-dspy.py --module my_module --metric my_metric --examples examples.jsonlBootstrapFewShot
python
from dspy.teleprompt import BootstrapFewShot
optimizer = BootstrapFewShot(metric=my_metric, max_bootstrapped_demos=4)
compiled = optimizer.compile(program, trainset=trainset)
compiled.save("./compiled/program.json")When to Use This Skill
Use this skill when:
- Running DSPy optimization or compilation with teleprompters
- Defining custom metrics for DSPy evaluation
- Evaluating DSPy programs with dev sets
- Choosing between BootstrapFewShot, MIPROv2, or other optimizers
- Saving and loading compiled programs
Core Concepts
Optimization Reference
See optimization.md for:
- Teleprompter selection guide (BootstrapFewShot, MIPROv2, etc.)
- Metric definition patterns
- Optimization strategies and hyperparameters
- Evaluation and testing workflows
- Save/load best practices (/
.save(), never raw pickle).load()
Scripts
- optimize-dspy.py: Run optimization with custom metrics and teleprompters
Critical Rules
- Always use :
uvfor installs,uv pipfor scriptsuv run - Use /
.save(): Never use raw.load()for DSPy programspickle - Use : Never use deprecated
dspy.LMordspy.OpenAIdspy.settings.configure - Mark inputs on examples: Always call on
.with_inputs()dspy.Example
Related Skills
- dspy-core: Signatures, modules, programs, and compilation fundamentals
- dspy-fleet-rlm: fleet-rlm-specific DSPy patterns and integration
Progressive Disclosure
- SKILL.md (this file): Quick reference and navigation
- references/: Detailed optimization docs loaded as needed
- scripts/: Executable optimization tools