Metadata-Version: 2.5
Name: peachtrees
Version: 1.0.0
Summary: An optimizer-agnostic, never-worse inference layer on top of an optimized DSPy program (GEPA, MIPROv2, SIMBA, ...).
Author: Daglar Dragomirov
License-Expression: MIT
License-File: LICENSE
Keywords: agents,dspy,gepa,llm,prompt optimization,react,selection
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: dspy>=3.0
Requires-Dist: litellm>=1.60
Provides-Extra: test
Requires-Dist: pytest>=8; extra == 'test'
Description-Content-Type: text/markdown

# PeachTrees

**An optimizer-agnostic, never-worse inference layer on top of an optimized [DSPy](https://dspy.ai) program.**

Prompt optimizers (GEPA, MIPROv2, SIMBA, ...) return one fixed program. PeachTrees keeps that program and adds two
universal ReAct forms around it, then picks one output per input with a label-free rule:

| form | what it is |
|---|---|
| `rigid` | the optimized program itself |
| `assembled` | the program's draft, then a ReAct reviewer that checks it and fixes it only if it finds a defect |
| `liquid` | a ReAct agent that solves the task from scratch |

Both agents get the same task-agnostic instructions: the program's own predictor instructions (the task's purpose and
the guidance the optimizer learned), a few correct outputs of labeled examples if you pass them, and one fixed template
per form. They have `run_python` plus any task tools you give them.

**Item rule** (no labels): drop forms without a usable output; if you pass a deterministic task checker, drop forms that
fail it; if two forms give the same answer, return it; otherwise return the reviewer's answer (then the program's, then
the agent's). In `full` mode the agent runs only when the program and the reviewer disagree.

**Task rule** (once per task, on labeled selection data): the layer is used only if its score minus the program's is
not below zero by more than one standard error; otherwise the wrapped object is exactly the program. So the layer
cannot make a task worse on that data.

## Install

```bash
pip install peachtrees
```

## Use

```python
import dspy
from peachtrees import PeachTrees

dspy.configure(lm=dspy.LM("openrouter/z-ai/glm-5.3-flash"))
program = optimizer.compile(student, trainset=train, valset=val)   # GEPA, MIPROv2, SIMBA, ...

pt = PeachTrees(program, mode="full", examples=train)   # mode="lite": the reviewer only, ~2.6x the program's cost
pt.fit(train + val, metric)                              # the task decision; see pt.report
prediction = pt(question="...")
```

Options: `tools=[...]` (task tools for both agents), `answer_key=callable(prediction) -> hashable` (how answers are
compared, e.g. a math normaliser or the result set of a SQL query; default: normalised text), `checker=callable(inputs,
prediction) -> bool | None` (a deterministic, label-free check such as public unit tests), `input_fields` /
`output_field` (inferred from the program's first and last predictors), `z` (the non-inferiority margin in standard
errors, default 1.0), `max_iters` (agent steps, default 8), `retries` (re-runs of a form whose output cannot be parsed).

## Results (research evaluation)

GLM 5.3 Flash, 13 benchmarks (AIME, GPQA, LiveBench, LiveCodeBench, HotpotQA, HoVer, IFBench, PUPA, BFCL, tau2-bench,
NATURAL PLAN, BIRD, ToolHop) x 3 optimizers (GEPA, MIPROv2, SIMBA), 36 cells, development split, mean gain of
PeachTrees 1.0 over the optimizer's own program:

| | full | lite |
|---|---|---|
| over GEPA | +10.2 pp | +9.4 pp |
| over MIPROv2 | +8.7 pp | +8.4 pp |
| over SIMBA | +9.2 pp | +8.7 pp |
| all 36 cells | **+9.4 pp** | **+8.8 pp** |

No cell below the program; 24 of 36 significantly above. These numbers use per-task answer keys and checkers where a
task has one (without them: about +9.2 pp). Inference cost: about 2.6x (lite) to 4.6x (full) the program's.

**Sealed test** (opened once, after the rule and every per-task decision were frozen): PeachTrees 1.0-lite on the five
benchmarks with a held-out test set, gain over the optimizer's program in percentage points:

| benchmark (test items) | over GEPA | over MIPROv2 | over SIMBA |
|---|---|---|---|
| NATURAL PLAN (200) | +13.5 | +17.0 | +10.5 |
| LiveCodeBench (82) | +11.0 | +14.6 | +13.4 |
| BIRD (200) | +2.5 | +9.0 | +3.5 |
| GPQA (80) | +3.8 | 0.0 | +3.8 |
| ToolHop (200) | +2.5 | +2.0 | -0.5 |
| mean | +6.7 | +8.5 | +6.1 |

Mean +7.1 pp over the 15 cells; 7 cells significantly above the program, none significantly below.

## Notes

- `run_python` runs code in a subprocess with a 10 s limit; it is **not** a security sandbox. Run untrusted workloads in
  an isolated environment.
- PeachTrees calls your LM several times per input; set DSPy's caching and rate limits accordingly.

## License

MIT
