prompt-moose 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- prompt_moose-0.1.0/.gitignore +66 -0
- prompt_moose-0.1.0/LICENSE +21 -0
- prompt_moose-0.1.0/PKG-INFO +189 -0
- prompt_moose-0.1.0/README.md +151 -0
- prompt_moose-0.1.0/pyproject.toml +89 -0
- prompt_moose-0.1.0/src/prompt_moose/__init__.py +120 -0
- prompt_moose-0.1.0/src/prompt_moose/__main__.py +5 -0
- prompt_moose-0.1.0/src/prompt_moose/algo_builder.py +721 -0
- prompt_moose-0.1.0/src/prompt_moose/algorithm/__init__.py +47 -0
- prompt_moose-0.1.0/src/prompt_moose/algorithm/cople.py +2295 -0
- prompt_moose-0.1.0/src/prompt_moose/algorithm/emoprompt.py +3568 -0
- prompt_moose-0.1.0/src/prompt_moose/algorithm/evo_prompt.py +2017 -0
- prompt_moose-0.1.0/src/prompt_moose/algorithm/gepa.py +2446 -0
- prompt_moose-0.1.0/src/prompt_moose/algorithm/gpo.py +1314 -0
- prompt_moose-0.1.0/src/prompt_moose/algorithm/opro.py +752 -0
- prompt_moose-0.1.0/src/prompt_moose/algorithm/pe2.py +796 -0
- prompt_moose-0.1.0/src/prompt_moose/algorithm/textgrad.py +1963 -0
- prompt_moose-0.1.0/src/prompt_moose/analysis.py +363 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/COMMANDS.md +656 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/__init__.py +109 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/_command.py +42 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/_generation.py +33 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/_help.py +143 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/_prompt_selection.py +70 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/common.py +324 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/eval.py +375 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/infer.py +246 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/init_agents.py +211 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/init_dataset.py +41 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/init_expt.py +25 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/init_prompt.py +24 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/train.py +83 -0
- prompt_moose-0.1.0/src/prompt_moose/cli/train_eval.py +5 -0
- prompt_moose-0.1.0/src/prompt_moose/config.py +256 -0
- prompt_moose-0.1.0/src/prompt_moose/config_generator.py +2683 -0
- prompt_moose-0.1.0/src/prompt_moose/context_manager.py +414 -0
- prompt_moose-0.1.0/src/prompt_moose/data_input.py +273 -0
- prompt_moose-0.1.0/src/prompt_moose/data_structures.py +463 -0
- prompt_moose-0.1.0/src/prompt_moose/exceptions.py +25 -0
- prompt_moose-0.1.0/src/prompt_moose/gradient_computer.py +271 -0
- prompt_moose-0.1.0/src/prompt_moose/instruction_schema.py +211 -0
- prompt_moose-0.1.0/src/prompt_moose/llm_utils.py +27 -0
- prompt_moose-0.1.0/src/prompt_moose/loss_computer.py +452 -0
- prompt_moose-0.1.0/src/prompt_moose/metrics.py +722 -0
- prompt_moose-0.1.0/src/prompt_moose/observability.py +803 -0
- prompt_moose-0.1.0/src/prompt_moose/pareto_sampling.py +224 -0
- prompt_moose-0.1.0/src/prompt_moose/prompt_algorithm.py +1572 -0
- prompt_moose-0.1.0/src/prompt_moose/prompt_artifacts.py +139 -0
- prompt_moose-0.1.0/src/prompt_moose/prompt_optimizer.py +358 -0
- prompt_moose-0.1.0/src/prompt_moose/prompt_presets.py +280 -0
- prompt_moose-0.1.0/src/prompt_moose/prompt_template.py +317 -0
- prompt_moose-0.1.0/src/prompt_moose/prompt_trajectory.py +408 -0
- prompt_moose-0.1.0/src/prompt_moose/resume.py +191 -0
- prompt_moose-0.1.0/src/prompt_moose/runtime_config.py +296 -0
- prompt_moose-0.1.0/src/prompt_moose/task_output_spec.py +525 -0
- prompt_moose-0.1.0/src/prompt_moose/task_predictor.py +749 -0
- prompt_moose-0.1.0/src/prompt_moose/types.py +341 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
.env
|
|
2
|
+
_env
|
|
3
|
+
.idea/
|
|
4
|
+
.venv/
|
|
5
|
+
morphic/
|
|
6
|
+
__pycache__/*
|
|
7
|
+
**/__pycache__/*
|
|
8
|
+
.ipynb_checkpoints/*
|
|
9
|
+
**/.ipynb_checkpoints/*
|
|
10
|
+
expt/outputs/*
|
|
11
|
+
expt/outputs_old/*
|
|
12
|
+
outputs/
|
|
13
|
+
tests/e2e_outputs/*
|
|
14
|
+
JEV_INTEGRATION.md
|
|
15
|
+
Transcripts/
|
|
16
|
+
*.egg-info/
|
|
17
|
+
build/
|
|
18
|
+
dist/
|
|
19
|
+
|
|
20
|
+
# Local working material, not part of the published package.
|
|
21
|
+
drafts/
|
|
22
|
+
paper_audits/
|
|
23
|
+
.agent/
|
|
24
|
+
.cursor/commands/
|
|
25
|
+
.cursor/rules/
|
|
26
|
+
Parth 03Oct2025.md
|
|
27
|
+
To_Do_Final.md
|
|
28
|
+
HANDOFF.md
|
|
29
|
+
docs_commit_ledger.md
|
|
30
|
+
QUICKSTART.md
|
|
31
|
+
CLI_LOGIC.md
|
|
32
|
+
EVAL_REDESIGN.md
|
|
33
|
+
CLI_DESIGN.md
|
|
34
|
+
.DS_Store
|
|
35
|
+
**/.DS_Store
|
|
36
|
+
expt/AAFAQ/AAFAQ.csv
|
|
37
|
+
expt/data/AAFAQ/AAFAQ.csv
|
|
38
|
+
expt/data/SummEval/cleaned_df.csv
|
|
39
|
+
expt/data/WildGuard/wildguard_train.parquet
|
|
40
|
+
expt/data/WildGuard/wildguard_test.parquet
|
|
41
|
+
tests/demo_legend_approaches.py
|
|
42
|
+
tests/demo_legend_v2.py
|
|
43
|
+
tests/demo_legend_v3.py
|
|
44
|
+
tests/demo_legend_v3_fixed.py
|
|
45
|
+
tests/demo_legend_v3_styled.py
|
|
46
|
+
tests/eval_feedback_adherence.py
|
|
47
|
+
tests/eval_gradient_specificity.py
|
|
48
|
+
tests/generate_summeval_textgrad_mode_report.py
|
|
49
|
+
tests/opro_hparam_analysis.py
|
|
50
|
+
tests/opro_hparam_runner.py
|
|
51
|
+
tests/run_12x2_parallel.py
|
|
52
|
+
tests/run_3_parallel.py
|
|
53
|
+
tests/run_8_parallel_brighter.py
|
|
54
|
+
tests/run_8_parallel_modes.py
|
|
55
|
+
tests/run_cherrypick_summeval.py
|
|
56
|
+
tests/plot_gradient_specificity.py
|
|
57
|
+
tests/plot_hparam_metrics.py
|
|
58
|
+
tests/plot_textgrad_hparam_metrics.py
|
|
59
|
+
tests/plot_textgrad_mode_metrics.py
|
|
60
|
+
tests/run_brighter_ssc_mae.py
|
|
61
|
+
tests/run_evo_prompt_runs.py
|
|
62
|
+
tests/run_mae_runs_1_2.py
|
|
63
|
+
tests/run_mae_runs_2_3.py
|
|
64
|
+
tests/run_nogate_and_singletask.py
|
|
65
|
+
tests/run_nogate_runs_2_3.py
|
|
66
|
+
tests/smoke_emoprompt_components.py
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Abhishek Divekar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: prompt-moose
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Multi-objective prompt optimization for decision models and LLM judges
|
|
5
|
+
Project-URL: Repository, https://github.com/adivekar-utexas/MOOSe
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: <3.14,>=3.11
|
|
9
|
+
Requires-Dist: concurry>=0.13.2
|
|
10
|
+
Requires-Dist: datasets==4.0.0
|
|
11
|
+
Requires-Dist: litellm<2,>=1.109.1
|
|
12
|
+
Requires-Dist: morphic<0.3,>=0.2.4
|
|
13
|
+
Requires-Dist: numpy==2.3.4
|
|
14
|
+
Requires-Dist: openai>=2.20.0
|
|
15
|
+
Requires-Dist: pandas==2.3.3
|
|
16
|
+
Requires-Dist: pyarrow<21,>=15
|
|
17
|
+
Requires-Dist: pydantic-settings
|
|
18
|
+
Requires-Dist: pydantic==2.12.3
|
|
19
|
+
Requires-Dist: pymoo
|
|
20
|
+
Requires-Dist: pyyaml<7,>=6.0
|
|
21
|
+
Requires-Dist: scikit-learn==1.7.0
|
|
22
|
+
Requires-Dist: scipy
|
|
23
|
+
Requires-Dist: sentence-transformers>=3
|
|
24
|
+
Requires-Dist: slowburn>=0.7.0
|
|
25
|
+
Provides-Extra: analysis
|
|
26
|
+
Requires-Dist: bokeh; extra == 'analysis'
|
|
27
|
+
Requires-Dist: holoviews; extra == 'analysis'
|
|
28
|
+
Requires-Dist: hvplot; extra == 'analysis'
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: bokeh; extra == 'dev'
|
|
31
|
+
Requires-Dist: holoviews; extra == 'dev'
|
|
32
|
+
Requires-Dist: hvplot; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-timeout; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest==8.4.2; extra == 'dev'
|
|
35
|
+
Requires-Dist: python-dotenv>=1.2.2; extra == 'dev'
|
|
36
|
+
Requires-Dist: transformers>=4.45.0; extra == 'dev'
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
|
|
39
|
+
# MOOSe
|
|
40
|
+
|
|
41
|
+
**Multi-Objective Tuning of Decision Model Questions and Label Definitions for Rubric-Based Judging**
|
|
42
|
+
|
|
43
|
+
[](https://pypi.org/project/prompt-moose/)
|
|
44
|
+
[](LICENSE)
|
|
45
|
+
|
|
46
|
+
## Overview
|
|
47
|
+
|
|
48
|
+
MOOSe tunes the questions and label definitions that a judge uses to score responses. Give it labeled examples and an initial rubric, and it searches for a prompt that better matches your labels across multiple criteria. You can run the same workflow with a coding agent or directly from the command line.
|
|
49
|
+
|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
### Cite MOOSe
|
|
53
|
+
|
|
54
|
+
```bibtex
|
|
55
|
+
@software{moose2026,
|
|
56
|
+
title={MOOSe: Multi-Objective Tuning of Decision Model Questions and Label Definitions for Rubric-Based Judging},
|
|
57
|
+
author={Divekar, Abhishek and Darshan, Parth},
|
|
58
|
+
year={2026},
|
|
59
|
+
url={https://github.com/adivekar-utexas/MOOSe}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
Requires Python 3.11–3.13.
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
python -m pip install prompt-moose # CLI
|
|
69
|
+
python -m pip install 'prompt-moose[analysis]' # optional plotting dependencies
|
|
70
|
+
python -m pip install 'prompt-moose[dev]' # development and test dependencies
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
Both examples use [NVIDIA HelpSteer2](https://huggingface.co/datasets/nvidia/HelpSteer2) to tune a TextGrad judge for five ratings: helpfulness, correctness, coherence, complexity, and verbosity. Set `OPENROUTER_API_KEY` in your environment before running the example. Training and evaluation make billable model calls.
|
|
76
|
+
|
|
77
|
+
### Agent UX
|
|
78
|
+
|
|
79
|
+
From your project directory, run `moose agents init`. It writes `AGENTS.md` at the project root, `.agents/skills/prompt-moose/SKILL.md`, and the bundled reference at `.agents/skills/prompt-moose/references/COMMANDS.md`. The setup itself is offline and does not launch an agent.
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
moose agents init
|
|
83
|
+
claude -p "Read AGENTS.md and the MOOSe skill. Use moose to optimize a judge prompt for nvidia/HelpSteer2 with TextGrad. Predict helpfulness, correctness, coherence, complexity, and verbosity. For each model role use openrouter/deepseek/deepseek-v4.1-flash with api_base null and api_key_name OPENROUTER_API_KEY. Run three training steps, evaluate the saved selection on held-out data, plot per-task MAE, and stop. If blocked, report the error without starting a server or changing permissions."
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Give the same prompt to Codex or OpenCode from that directory. The agent can create the YAML files, run `moose`, and plot results from the saved evaluation data. You can also do those steps yourself below.
|
|
87
|
+
|
|
88
|
+
### CLI usage
|
|
89
|
+
|
|
90
|
+
Generate the three files offline. Here `--path` is the **output** file to create.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
moose init dataset --hf --path expt/configs/data/dataset.yaml
|
|
94
|
+
moose init prompt --path expt/configs/rubric/prompts.yaml
|
|
95
|
+
moose init expt --textgrad --path expt/configs/algo/main.yaml \
|
|
96
|
+
--dataset-path ../data/dataset.yaml --initial-prompt-path ../rubric/prompts.yaml
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Dataset (`expt/configs/data/dataset.yaml`).** Use the [complete HelpSteer2 dataset YAML](expt/configs/data/help2steer_dataset.yaml) in place of the generated template. It declares `prompt` and `response` as inputs and all five ratings as ordinal integers from 0 to 4. Its source block reads:
|
|
100
|
+
|
|
101
|
+
```yaml
|
|
102
|
+
# Excerpt from dataset.yaml
|
|
103
|
+
dataset:
|
|
104
|
+
mode: huggingface
|
|
105
|
+
name: HelpSteer2
|
|
106
|
+
input_cols: [prompt, response]
|
|
107
|
+
setup:
|
|
108
|
+
hf_id: nvidia/HelpSteer2
|
|
109
|
+
hf_config: default
|
|
110
|
+
split_map: {train: train, test: validation}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
MOOSe holds out part of the Hub training split for prompt selection. The Hub `validation` split serves as the separate test set here.
|
|
114
|
+
|
|
115
|
+
**Prompt (`expt/configs/rubric/prompts.yaml`).** Use the [complete HelpSteer2 rubric](expt/configs/rubric/help2steer_prompts.yaml). Each seed contains an instruction and optional label descriptions for every task. Here is the helpfulness entry:
|
|
116
|
+
|
|
117
|
+
```yaml
|
|
118
|
+
# Excerpt from prompts.yaml
|
|
119
|
+
prompt:
|
|
120
|
+
input_col_labels: {prompt: User Prompt, response: Assistant Response}
|
|
121
|
+
initial_instruction:
|
|
122
|
+
0:
|
|
123
|
+
helpfulness:
|
|
124
|
+
instructions: Rate how well the response helps the user with the prompt.
|
|
125
|
+
criteria:
|
|
126
|
+
"0": Does not help address the prompt.
|
|
127
|
+
"4": Provides excellent help and fully addresses the relevant needs.
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Experiment (`expt/configs/algo/main.yaml`).** Replace the generated main file with the example below. The `dataset` and `prompt` paths are relative to `main.yaml`, so other experiments can reuse either file. `run.output_dir` is relative to where you run `moose`.
|
|
131
|
+
|
|
132
|
+
```yaml
|
|
133
|
+
name: textgrad
|
|
134
|
+
dataset: data/dataset.yaml
|
|
135
|
+
prompt: prompts/prompts.yaml
|
|
136
|
+
train:
|
|
137
|
+
steps: 3
|
|
138
|
+
batch_size: 4
|
|
139
|
+
val_size: 16
|
|
140
|
+
validation_metric: mae
|
|
141
|
+
task_llm: &model
|
|
142
|
+
name: openrouter/deepseek/deepseek-v4.1-flash
|
|
143
|
+
api_key_name: OPENROUTER_API_KEY
|
|
144
|
+
loss_llm: *model
|
|
145
|
+
gradient_llm: *model
|
|
146
|
+
optimizer_llm: *model
|
|
147
|
+
eval: {metrics: [mae], size: 25}
|
|
148
|
+
run: {output_dir: outputs/helpsteer2}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
moose train expt/configs/algo/main.yaml
|
|
153
|
+
moose eval expt/configs/algo/main.yaml --eval.prompts best_macro
|
|
154
|
+
moose infer expt/configs/algo/main.yaml --id a5defc --data inputs.parquet
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`train` writes the run summary, prompt library, and step logs. `eval` measures the selected prompt on labeled test rows. For `infer`, replace `a5defc` with the six-character ID in `run_summary.json` and provide a CSV or Parquet file with `prompt` and `response`; no labels are needed.
|
|
158
|
+
|
|
159
|
+
To reuse the selected TextGrad rubric, set `prompt: ../outputs/helpsteer2/best_macro.yaml` in a new experiment YAML under `expt/configs/algo/`. Set a new `run.output_dir` before training again.
|
|
160
|
+
|
|
161
|
+
**Paper experiments.** The [experiment settings](expt/configs/algo/), [dataset definitions](expt/configs/data/), and [starting rubrics](expt/configs/rubric/) are already separate. The [experiment runners](expt/scripts/) show how to pair them; start with the [family runner](expt/scripts/run_family.sh). Check model IDs and credentials before running those configurations. For flags and artifact details, see the [command reference](src/prompt_moose/cli/COMMANDS.md).
|
|
162
|
+
|
|
163
|
+
## Algorithm Catalog
|
|
164
|
+
|
|
165
|
+
| Algorithm | How it proposes edits | What to evaluate |
|
|
166
|
+
|---|---|---|
|
|
167
|
+
| OPRO (`opro`) | Uses a history of prompts and numeric scores to propose candidates. | `best_macro`: the highest-scoring prompt in the validation-ranked history. |
|
|
168
|
+
| GPO (`gpo`) | Uses a scored prompt history and an edit budget. Textual feedback is optional. | `best_macro`: the highest-scoring prompt in the validation-ranked history. |
|
|
169
|
+
| TextGrad (`textgrad`) | By default, writes critiques and edit suggestions per task, then updates the rubric jointly. | `best_macro`: the final accepted prompt. The default validation gate uses MAE. |
|
|
170
|
+
| EmoPrompt (`emoprompt`) | Crosses over and mutates prompts, keeping a population rather than a single winner. | `final_front`: the saved non-dominated prompts evaluated as an ensemble. |
|
|
171
|
+
|
|
172
|
+
Each task declares its label column and output type, such as binary, categorical, ordinal integer, ordered string labels, or a bounded numeric score. Tasks can use different output types and loss metrics in the same rubric. For example, pair a binary safety judgment with a 0–4 helpfulness rating.
|
|
173
|
+
|
|
174
|
+
## Design Principles
|
|
175
|
+
|
|
176
|
+
- **Keep the rubric portable.** Reuse the same dataset and starting rubric across experiments, or take a saved rubric into another run without an export step.
|
|
177
|
+
- **Separate selection from reporting.** Use validation data to compare prompts; reserve test data for reporting. Pareto group evaluation follows the same separation.
|
|
178
|
+
- **Keep the evidence.** Run artifacts show what the judge predicted, what feedback the optimizer saw, and how the rubric changed.
|
|
179
|
+
- **Use the same workflow with or without an agent.** Agents call the same CLI and produce the same artifacts you get from running it directly.
|
|
180
|
+
|
|
181
|
+
## Contributing
|
|
182
|
+
|
|
183
|
+
Open an [issue](https://github.com/adivekar-utexas/MOOSe/issues) with a minimal reproduction, or submit a pull request with tests for the changed behavior. Never include API keys or private data in configs or logs you share.
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
MOOSe is free forever under the [MIT License](LICENSE). Hosted model providers may charge for API calls.
|
|
188
|
+
|
|
189
|
+
If you use MOOSe in your research, please [cite it](#cite-moose).
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# MOOSe
|
|
2
|
+
|
|
3
|
+
**Multi-Objective Tuning of Decision Model Questions and Label Definitions for Rubric-Based Judging**
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/prompt-moose/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
MOOSe tunes the questions and label definitions that a judge uses to score responses. Give it labeled examples and an initial rubric, and it searches for a prompt that better matches your labels across multiple criteria. You can run the same workflow with a coding agent or directly from the command line.
|
|
11
|
+
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
### Cite MOOSe
|
|
15
|
+
|
|
16
|
+
```bibtex
|
|
17
|
+
@software{moose2026,
|
|
18
|
+
title={MOOSe: Multi-Objective Tuning of Decision Model Questions and Label Definitions for Rubric-Based Judging},
|
|
19
|
+
author={Divekar, Abhishek and Darshan, Parth},
|
|
20
|
+
year={2026},
|
|
21
|
+
url={https://github.com/adivekar-utexas/MOOSe}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
Requires Python 3.11–3.13.
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
python -m pip install prompt-moose # CLI
|
|
31
|
+
python -m pip install 'prompt-moose[analysis]' # optional plotting dependencies
|
|
32
|
+
python -m pip install 'prompt-moose[dev]' # development and test dependencies
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
Both examples use [NVIDIA HelpSteer2](https://huggingface.co/datasets/nvidia/HelpSteer2) to tune a TextGrad judge for five ratings: helpfulness, correctness, coherence, complexity, and verbosity. Set `OPENROUTER_API_KEY` in your environment before running the example. Training and evaluation make billable model calls.
|
|
38
|
+
|
|
39
|
+
### Agent UX
|
|
40
|
+
|
|
41
|
+
From your project directory, run `moose agents init`. It writes `AGENTS.md` at the project root, `.agents/skills/prompt-moose/SKILL.md`, and the bundled reference at `.agents/skills/prompt-moose/references/COMMANDS.md`. The setup itself is offline and does not launch an agent.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
moose agents init
|
|
45
|
+
claude -p "Read AGENTS.md and the MOOSe skill. Use moose to optimize a judge prompt for nvidia/HelpSteer2 with TextGrad. Predict helpfulness, correctness, coherence, complexity, and verbosity. For each model role use openrouter/deepseek/deepseek-v4.1-flash with api_base null and api_key_name OPENROUTER_API_KEY. Run three training steps, evaluate the saved selection on held-out data, plot per-task MAE, and stop. If blocked, report the error without starting a server or changing permissions."
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Give the same prompt to Codex or OpenCode from that directory. The agent can create the YAML files, run `moose`, and plot results from the saved evaluation data. You can also do those steps yourself below.
|
|
49
|
+
|
|
50
|
+
### CLI usage
|
|
51
|
+
|
|
52
|
+
Generate the three files offline. Here `--path` is the **output** file to create.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
moose init dataset --hf --path expt/configs/data/dataset.yaml
|
|
56
|
+
moose init prompt --path expt/configs/rubric/prompts.yaml
|
|
57
|
+
moose init expt --textgrad --path expt/configs/algo/main.yaml \
|
|
58
|
+
--dataset-path ../data/dataset.yaml --initial-prompt-path ../rubric/prompts.yaml
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Dataset (`expt/configs/data/dataset.yaml`).** Use the [complete HelpSteer2 dataset YAML](expt/configs/data/help2steer_dataset.yaml) in place of the generated template. It declares `prompt` and `response` as inputs and all five ratings as ordinal integers from 0 to 4. Its source block reads:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
# Excerpt from dataset.yaml
|
|
65
|
+
dataset:
|
|
66
|
+
mode: huggingface
|
|
67
|
+
name: HelpSteer2
|
|
68
|
+
input_cols: [prompt, response]
|
|
69
|
+
setup:
|
|
70
|
+
hf_id: nvidia/HelpSteer2
|
|
71
|
+
hf_config: default
|
|
72
|
+
split_map: {train: train, test: validation}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
MOOSe holds out part of the Hub training split for prompt selection. The Hub `validation` split serves as the separate test set here.
|
|
76
|
+
|
|
77
|
+
**Prompt (`expt/configs/rubric/prompts.yaml`).** Use the [complete HelpSteer2 rubric](expt/configs/rubric/help2steer_prompts.yaml). Each seed contains an instruction and optional label descriptions for every task. Here is the helpfulness entry:
|
|
78
|
+
|
|
79
|
+
```yaml
|
|
80
|
+
# Excerpt from prompts.yaml
|
|
81
|
+
prompt:
|
|
82
|
+
input_col_labels: {prompt: User Prompt, response: Assistant Response}
|
|
83
|
+
initial_instruction:
|
|
84
|
+
0:
|
|
85
|
+
helpfulness:
|
|
86
|
+
instructions: Rate how well the response helps the user with the prompt.
|
|
87
|
+
criteria:
|
|
88
|
+
"0": Does not help address the prompt.
|
|
89
|
+
"4": Provides excellent help and fully addresses the relevant needs.
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Experiment (`expt/configs/algo/main.yaml`).** Replace the generated main file with the example below. The `dataset` and `prompt` paths are relative to `main.yaml`, so other experiments can reuse either file. `run.output_dir` is relative to where you run `moose`.
|
|
93
|
+
|
|
94
|
+
```yaml
|
|
95
|
+
name: textgrad
|
|
96
|
+
dataset: data/dataset.yaml
|
|
97
|
+
prompt: prompts/prompts.yaml
|
|
98
|
+
train:
|
|
99
|
+
steps: 3
|
|
100
|
+
batch_size: 4
|
|
101
|
+
val_size: 16
|
|
102
|
+
validation_metric: mae
|
|
103
|
+
task_llm: &model
|
|
104
|
+
name: openrouter/deepseek/deepseek-v4.1-flash
|
|
105
|
+
api_key_name: OPENROUTER_API_KEY
|
|
106
|
+
loss_llm: *model
|
|
107
|
+
gradient_llm: *model
|
|
108
|
+
optimizer_llm: *model
|
|
109
|
+
eval: {metrics: [mae], size: 25}
|
|
110
|
+
run: {output_dir: outputs/helpsteer2}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
moose train expt/configs/algo/main.yaml
|
|
115
|
+
moose eval expt/configs/algo/main.yaml --eval.prompts best_macro
|
|
116
|
+
moose infer expt/configs/algo/main.yaml --id a5defc --data inputs.parquet
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`train` writes the run summary, prompt library, and step logs. `eval` measures the selected prompt on labeled test rows. For `infer`, replace `a5defc` with the six-character ID in `run_summary.json` and provide a CSV or Parquet file with `prompt` and `response`; no labels are needed.
|
|
120
|
+
|
|
121
|
+
To reuse the selected TextGrad rubric, set `prompt: ../outputs/helpsteer2/best_macro.yaml` in a new experiment YAML under `expt/configs/algo/`. Set a new `run.output_dir` before training again.
|
|
122
|
+
|
|
123
|
+
**Paper experiments.** The [experiment settings](expt/configs/algo/), [dataset definitions](expt/configs/data/), and [starting rubrics](expt/configs/rubric/) are already separate. The [experiment runners](expt/scripts/) show how to pair them; start with the [family runner](expt/scripts/run_family.sh). Check model IDs and credentials before running those configurations. For flags and artifact details, see the [command reference](src/prompt_moose/cli/COMMANDS.md).
|
|
124
|
+
|
|
125
|
+
## Algorithm Catalog
|
|
126
|
+
|
|
127
|
+
| Algorithm | How it proposes edits | What to evaluate |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| OPRO (`opro`) | Uses a history of prompts and numeric scores to propose candidates. | `best_macro`: the highest-scoring prompt in the validation-ranked history. |
|
|
130
|
+
| GPO (`gpo`) | Uses a scored prompt history and an edit budget. Textual feedback is optional. | `best_macro`: the highest-scoring prompt in the validation-ranked history. |
|
|
131
|
+
| TextGrad (`textgrad`) | By default, writes critiques and edit suggestions per task, then updates the rubric jointly. | `best_macro`: the final accepted prompt. The default validation gate uses MAE. |
|
|
132
|
+
| EmoPrompt (`emoprompt`) | Crosses over and mutates prompts, keeping a population rather than a single winner. | `final_front`: the saved non-dominated prompts evaluated as an ensemble. |
|
|
133
|
+
|
|
134
|
+
Each task declares its label column and output type, such as binary, categorical, ordinal integer, ordered string labels, or a bounded numeric score. Tasks can use different output types and loss metrics in the same rubric. For example, pair a binary safety judgment with a 0–4 helpfulness rating.
|
|
135
|
+
|
|
136
|
+
## Design Principles
|
|
137
|
+
|
|
138
|
+
- **Keep the rubric portable.** Reuse the same dataset and starting rubric across experiments, or take a saved rubric into another run without an export step.
|
|
139
|
+
- **Separate selection from reporting.** Use validation data to compare prompts; reserve test data for reporting. Pareto group evaluation follows the same separation.
|
|
140
|
+
- **Keep the evidence.** Run artifacts show what the judge predicted, what feedback the optimizer saw, and how the rubric changed.
|
|
141
|
+
- **Use the same workflow with or without an agent.** Agents call the same CLI and produce the same artifacts you get from running it directly.
|
|
142
|
+
|
|
143
|
+
## Contributing
|
|
144
|
+
|
|
145
|
+
Open an [issue](https://github.com/adivekar-utexas/MOOSe/issues) with a minimal reproduction, or submit a pull request with tests for the changed behavior. Never include API keys or private data in configs or logs you share.
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
MOOSe is free forever under the [MIT License](LICENSE). Hosted model providers may charge for API calls.
|
|
150
|
+
|
|
151
|
+
If you use MOOSe in your research, please [cite it](#cite-moose).
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "prompt-moose"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Multi-objective prompt optimization for decision models and LLM judges"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.11,<3.14"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"concurry>=0.13.2",
|
|
15
|
+
"datasets==4.0.0",
|
|
16
|
+
"litellm>=1.109.1,<2",
|
|
17
|
+
"morphic>=0.2.4,<0.3",
|
|
18
|
+
"numpy==2.3.4",
|
|
19
|
+
"openai>=2.20.0",
|
|
20
|
+
"pandas==2.3.3",
|
|
21
|
+
"pyarrow>=15,<21",
|
|
22
|
+
"pydantic==2.12.3",
|
|
23
|
+
"pydantic-settings",
|
|
24
|
+
"pymoo",
|
|
25
|
+
"PyYAML>=6.0,<7",
|
|
26
|
+
"scikit-learn==1.7.0",
|
|
27
|
+
"scipy",
|
|
28
|
+
"sentence-transformers>=3",
|
|
29
|
+
"slowburn>=0.7.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = [
|
|
34
|
+
"prompt-moose[analysis]",
|
|
35
|
+
"pytest==8.4.2",
|
|
36
|
+
"pytest-timeout",
|
|
37
|
+
"python-dotenv>=1.2.2",
|
|
38
|
+
"transformers>=4.45.0",
|
|
39
|
+
]
|
|
40
|
+
analysis = [
|
|
41
|
+
"bokeh",
|
|
42
|
+
"holoviews",
|
|
43
|
+
"hvplot",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[project.urls]
|
|
47
|
+
Repository = "https://github.com/adivekar-utexas/MOOSe"
|
|
48
|
+
|
|
49
|
+
[project.scripts]
|
|
50
|
+
moose = "prompt_moose.cli:main"
|
|
51
|
+
|
|
52
|
+
[tool.hatch.build.targets.wheel]
|
|
53
|
+
packages = ["src/prompt_moose"]
|
|
54
|
+
|
|
55
|
+
# Ship only the package and its release metadata. Without this, hatchling's
|
|
56
|
+
# default sdist includes the whole working tree (datasets, notebooks, media),
|
|
57
|
+
# which exceeds PyPI's per-file size limit.
|
|
58
|
+
[tool.hatch.build.targets.sdist]
|
|
59
|
+
include = [
|
|
60
|
+
"/src/prompt_moose",
|
|
61
|
+
"/README.md",
|
|
62
|
+
"/LICENSE",
|
|
63
|
+
"/pyproject.toml",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
[tool.pytest.ini_options]
|
|
67
|
+
pythonpath = ["src"]
|
|
68
|
+
testpaths = ["tests"]
|
|
69
|
+
markers = [
|
|
70
|
+
"integration: marks tests requiring real API calls (may cost $)",
|
|
71
|
+
"unit: marks pure unit tests (no network)",
|
|
72
|
+
]
|
|
73
|
+
timeout = 120
|
|
74
|
+
timeout_method = "thread"
|
|
75
|
+
|
|
76
|
+
[tool.ruff]
|
|
77
|
+
line-length = 110
|
|
78
|
+
# gepa.py is tab-indented and its prompt strings contain tabs, so a mechanical
|
|
79
|
+
# re-indent would change prompt text. It is not reachable from the CLI.
|
|
80
|
+
extend-exclude = ["src/prompt_moose/algorithm/gepa.py"]
|
|
81
|
+
|
|
82
|
+
[tool.ruff.lint]
|
|
83
|
+
# Correctness checks only: undefined names, unused imports/variables, syntax
|
|
84
|
+
# errors and whitespace. Line length and formatting are not gated yet.
|
|
85
|
+
select = ["E9", "E101", "F", "W"]
|
|
86
|
+
ignore = ["E731", "E741"]
|
|
87
|
+
|
|
88
|
+
[tool.ruff.lint.isort]
|
|
89
|
+
known-first-party = ["prompt_moose"]
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PromptMOO: Multi-Objective Prompt Optimization Framework
|
|
3
|
+
|
|
4
|
+
This package provides a modular framework for optimizing prompts across multiple objectives
|
|
5
|
+
using algorithms like OPRO, GPO, and TextGrad.
|
|
6
|
+
|
|
7
|
+
Key Components:
|
|
8
|
+
- algorithm: Core optimization algorithms (OPRO, GPO, TextGrad)
|
|
9
|
+
- config: Centralized configuration system (moose_config)
|
|
10
|
+
- data_structures: Immutable data classes (Task, Batch, PredictionResult, etc.)
|
|
11
|
+
- task_predictor: Generate predictions using task LLM
|
|
12
|
+
- loss_computer: Compute numeric and textual feedback
|
|
13
|
+
- gradient_computer: Generate textual gradients from feedback
|
|
14
|
+
- prompt_optimizer: Update prompts based on gradients
|
|
15
|
+
- observability: Structured logging and output management
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from importlib import import_module
|
|
19
|
+
from typing import Dict, Tuple
|
|
20
|
+
|
|
21
|
+
# Keep initialization and CLI help independent of the network-capable model stack.
|
|
22
|
+
_EXPORT_GROUPS: Dict[str, Tuple[str, ...]] = {
|
|
23
|
+
"algorithm": (
|
|
24
|
+
"OPRO", "GPO", "PE2", "TextGrad", "EmoPromptSingleRunContext",
|
|
25
|
+
"GPOSingleRunContext", "OPROSingleRunContext", "TextGradSingleRunContext",
|
|
26
|
+
),
|
|
27
|
+
"config": ("LLM_CONFIGS", "MOOSeConfig", "MOOSeDefaults", "moose_config", "temp_config"),
|
|
28
|
+
"algo_builder": ("AlgorithmBuilder",),
|
|
29
|
+
"context_manager": ("SingleRunContext",),
|
|
30
|
+
"data_input": ("Dataset",),
|
|
31
|
+
|
|
32
|
+
"data_structures": (
|
|
33
|
+
"AlgoMetricSeries", "Batch", "CombinedFeedback", "DatasetSample", "NumericFeedback",
|
|
34
|
+
"OptimizerResult", "PredictionResult", "StepMetricResult", "Task", "TextGradient", "TextualFeedback",
|
|
35
|
+
),
|
|
36
|
+
"gradient_computer": ("GradientComputer", "StandardGradientComputer"),
|
|
37
|
+
"loss_computer": ("LossComputer", "TaskLevelLossComputer"),
|
|
38
|
+
"metrics": ("F1", "LCE", "Accuracy", "Metric", "Precision", "Recall"),
|
|
39
|
+
"observability": ("ObservabilityManager",),
|
|
40
|
+
"prompt_algorithm": ("PromptAlgorithm",),
|
|
41
|
+
"prompt_optimizer": ("LLMBasedOptimizer", "PromptOptimizer"),
|
|
42
|
+
"prompt_template": ("PromptTemplate",),
|
|
43
|
+
"prompt_trajectory": ("PromptTrajectory", "TrajectoryElement"),
|
|
44
|
+
"task_output_spec": ("TaskOutputSpec",),
|
|
45
|
+
"task_predictor": ("DecisionTaskPredictor", "StandardTaskPredictor", "TaskPredictor"),
|
|
46
|
+
}
|
|
47
|
+
_EXPORT_MODULES: Dict[str, str] = {
|
|
48
|
+
name: module for module, names in _EXPORT_GROUPS.items() for name in names
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
__all__ = [
|
|
52
|
+
# Algorithms
|
|
53
|
+
"PromptAlgorithm",
|
|
54
|
+
"OPRO",
|
|
55
|
+
"GPO",
|
|
56
|
+
"TextGrad",
|
|
57
|
+
"PE2",
|
|
58
|
+
# "COPLE",
|
|
59
|
+
# "Cople",
|
|
60
|
+
# "CopleInfluentialTokens",
|
|
61
|
+
# "CopleOptimizer",
|
|
62
|
+
# "CopleGradientComputer",
|
|
63
|
+
# Configuration
|
|
64
|
+
"moose_config",
|
|
65
|
+
"temp_config",
|
|
66
|
+
"MOOSeConfig",
|
|
67
|
+
"MOOSeDefaults",
|
|
68
|
+
"LLMBuilder",
|
|
69
|
+
"AlgorithmBuilder",
|
|
70
|
+
# Data structures
|
|
71
|
+
"Task",
|
|
72
|
+
"DatasetSample",
|
|
73
|
+
"Batch",
|
|
74
|
+
"PredictionResult",
|
|
75
|
+
"NumericFeedback",
|
|
76
|
+
"TextualFeedback",
|
|
77
|
+
"CombinedFeedback",
|
|
78
|
+
"TextGradient",
|
|
79
|
+
"OptimizerResult",
|
|
80
|
+
# Pipeline components (base + shared)
|
|
81
|
+
"TaskPredictor",
|
|
82
|
+
"StandardTaskPredictor",
|
|
83
|
+
"DecisionTaskPredictor",
|
|
84
|
+
"LossComputer",
|
|
85
|
+
"TaskLevelLossComputer",
|
|
86
|
+
"GradientComputer",
|
|
87
|
+
"StandardGradientComputer",
|
|
88
|
+
"PromptOptimizer",
|
|
89
|
+
"LLMBasedOptimizer",
|
|
90
|
+
# Supporting
|
|
91
|
+
"Dataset",
|
|
92
|
+
"Metric",
|
|
93
|
+
"Accuracy",
|
|
94
|
+
"F1",
|
|
95
|
+
"Precision",
|
|
96
|
+
"Recall",
|
|
97
|
+
"LCE",
|
|
98
|
+
"PromptTemplate",
|
|
99
|
+
"ObservabilityManager",
|
|
100
|
+
"PromptTrajectory",
|
|
101
|
+
"TrajectoryElement",
|
|
102
|
+
"TaskOutputSpec",
|
|
103
|
+
# Run contexts
|
|
104
|
+
"SingleRunContext",
|
|
105
|
+
"GPOSingleRunContext",
|
|
106
|
+
"OPROSingleRunContext",
|
|
107
|
+
"TextGradSingleRunContext",
|
|
108
|
+
"EmoPromptSingleRunContext",
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
def __getattr__(name: str) -> object:
|
|
112
|
+
if name == "LLMBuilder":
|
|
113
|
+
return __getattr__("AlgorithmBuilder")
|
|
114
|
+
if name not in _EXPORT_MODULES:
|
|
115
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
116
|
+
if name == "OptimizerResult":
|
|
117
|
+
import_module(".prompt_template", __name__)
|
|
118
|
+
exported: object = getattr(import_module(f".{_EXPORT_MODULES[name]}", __name__), name)
|
|
119
|
+
globals()[name] = exported
|
|
120
|
+
return exported
|