optimize_anything¶
gepa.optimize_anything.optimize_anything(seed_candidate: str | Candidate | None = None, *, evaluator: Callable[..., Any] | None = None, batch_evaluator: Callable[..., Any] | None = None, dataset: list[Any] | None = None, valset: list[Any] | None = None, objective: str | None = None, background: str | None = None, test_set: list[Any] | None = None, config: OptimizeAnythingConfig | None = None) -> GEPAResult
¶
Optimize a text candidate (prompt, code, instructions, ...) against a score.
The signature mirrors :func:gepa.gepa_launcher.optimize_anything
(seed_candidate / evaluator / batch_evaluator / dataset /
valset / objective / background) so the two entry points share
one shape; the new API swaps config for an
:class:OptimizeAnythingConfig and adds test_set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed_candidate
|
str | Candidate | None
|
The seed to evolve from — either a single text string
or, for multi-component optimization, a |
None
|
evaluator
|
Callable[..., Any] | None
|
Scoring function returning |
None
|
batch_evaluator
|
Callable[..., Any] | None
|
Grouped scoring hook (launcher parity): receives ALL
|
None
|
dataset
|
list[Any] | None
|
Optional training examples used during optimization. Items
are opaque — any object |
None
|
valset
|
list[Any] | None
|
Optional validation examples used for candidate selection. |
None
|
objective
|
str | None
|
Short goal statement (e.g. "Maximize sum of circle radii"). Surfaced verbatim by every engine as the optimization goal. |
None
|
background
|
str | None
|
Long-form context — problem statement, evaluation rules, domain notes. Surfaced verbatim by every engine. |
None
|
test_set
|
list[Any] | None
|
Optional held-out test examples. When provided, the seed and
optimized candidates are each scored on it outside the budget — the
test set never enters the eval server, so engines and agents cannot
see it. When omitted, test scoring is skipped entirely. Reported
under |
None
|
config
|
OptimizeAnythingConfig | None
|
Engine selection, run |
None
|
Returns:
| Type | Description |
|---|---|
GEPAResult
|
A single :class: |
GEPAResult
|
universal core is always populated — |
GEPAResult
|
|
GEPAResult
|
the |
GEPAResult
|
|
GEPAResult
|
pool and Pareto data; other engines return a single-candidate snapshot |
GEPAResult
|
with the gepa-only fields ( |
GEPAResult
|
|
GEPAResult
|
|
GEPAResult
|
|
GEPAResult
|
|
GEPAResult
|
( |
GEPAResult
|
|
GEPAResult
|
and GEPA-core fields. |
Source code in gepa/optimize_anything.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |