orizu 0.5.19 → 0.5.21

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.
Files changed (378) hide show
  1. package/README.md +23 -0
  2. package/dist/archive-artifacts-cli.d.ts +50 -0
  3. package/dist/archive-artifacts-cli.d.ts.map +1 -0
  4. package/dist/artifact-archive.d.ts +48 -0
  5. package/dist/artifact-archive.d.ts.map +1 -0
  6. package/dist/artifact-pull.d.ts +22 -0
  7. package/dist/artifact-pull.d.ts.map +1 -0
  8. package/dist/banner.d.ts +3 -0
  9. package/dist/banner.d.ts.map +1 -0
  10. package/dist/connectors-cli.d.ts +31 -0
  11. package/dist/connectors-cli.d.ts.map +1 -0
  12. package/dist/credentials.d.ts +46 -0
  13. package/dist/credentials.d.ts.map +1 -0
  14. package/dist/csv.d.ts +49 -0
  15. package/dist/csv.d.ts.map +1 -0
  16. package/dist/dataset-download.d.ts +6 -0
  17. package/dist/dataset-download.d.ts.map +1 -0
  18. package/dist/dataset-edit-rows.d.ts +10 -0
  19. package/dist/dataset-edit-rows.d.ts.map +1 -0
  20. package/dist/dataset-upload-snapshot.d.ts +13 -0
  21. package/dist/dataset-upload-snapshot.d.ts.map +1 -0
  22. package/dist/daytona-slice-rehearsal.d.ts +89 -0
  23. package/dist/daytona-slice-rehearsal.d.ts.map +1 -0
  24. package/dist/daytona-slice.d.ts +106 -0
  25. package/dist/daytona-slice.d.ts.map +1 -0
  26. package/dist/deploy-key-merge-core.d.ts +121 -0
  27. package/dist/deploy-key-merge-core.d.ts.map +1 -0
  28. package/dist/diff-comments-cli.d.ts +12 -0
  29. package/dist/diff-comments-cli.d.ts.map +1 -0
  30. package/dist/diff-comments-cli.js +21 -2
  31. package/dist/egress-allowlist-cli.d.ts +23 -0
  32. package/dist/egress-allowlist-cli.d.ts.map +1 -0
  33. package/dist/egress-policy.d.ts +108 -0
  34. package/dist/egress-policy.d.ts.map +1 -0
  35. package/dist/error-response.d.ts +9 -0
  36. package/dist/error-response.d.ts.map +1 -0
  37. package/dist/file-parser.d.ts +5 -0
  38. package/dist/file-parser.d.ts.map +1 -0
  39. package/dist/gepa-engine-dispatch.d.ts +9 -0
  40. package/dist/gepa-engine-dispatch.d.ts.map +1 -0
  41. package/dist/gepa-engine-dispatch.js +307 -0
  42. package/dist/gepa-python-command.d.ts +6 -0
  43. package/dist/gepa-python-command.d.ts.map +1 -0
  44. package/dist/gepa-python-command.js +26 -0
  45. package/dist/gepa-python-paths.d.ts +6 -0
  46. package/dist/gepa-python-paths.d.ts.map +1 -0
  47. package/dist/gepa-python-paths.js +42 -0
  48. package/dist/git-credential.d.ts +69 -0
  49. package/dist/git-credential.d.ts.map +1 -0
  50. package/dist/git-recovery-environment.d.ts +31 -0
  51. package/dist/git-recovery-environment.d.ts.map +1 -0
  52. package/dist/github-setup.d.ts +122 -0
  53. package/dist/github-setup.d.ts.map +1 -0
  54. package/dist/global-flags.d.ts +12 -0
  55. package/dist/global-flags.d.ts.map +1 -0
  56. package/dist/help.d.ts +46 -0
  57. package/dist/help.d.ts.map +1 -0
  58. package/dist/help.js +93 -25
  59. package/dist/hosted-boot.d.ts +273 -0
  60. package/dist/hosted-boot.d.ts.map +1 -0
  61. package/dist/hosted-bootstrap-rehearsal.d.ts +86 -0
  62. package/dist/hosted-bootstrap-rehearsal.d.ts.map +1 -0
  63. package/dist/hosted-bootstrap.d.ts +188 -0
  64. package/dist/hosted-bootstrap.d.ts.map +1 -0
  65. package/dist/hosted-broker-server.d.ts +50 -0
  66. package/dist/hosted-broker-server.d.ts.map +1 -0
  67. package/dist/hosted-git-http-server.d.ts +36 -0
  68. package/dist/hosted-git-http-server.d.ts.map +1 -0
  69. package/dist/hosted-harness-claude.d.ts +195 -0
  70. package/dist/hosted-harness-claude.d.ts.map +1 -0
  71. package/dist/hosted-harness-opencode.d.ts +227 -0
  72. package/dist/hosted-harness-opencode.d.ts.map +1 -0
  73. package/dist/hosted-harness.d.ts +118 -0
  74. package/dist/hosted-harness.d.ts.map +1 -0
  75. package/dist/hosted-harvest.d.ts +68 -0
  76. package/dist/hosted-harvest.d.ts.map +1 -0
  77. package/dist/hosted-headless.d.ts +72 -0
  78. package/dist/hosted-headless.d.ts.map +1 -0
  79. package/dist/hosted-loop-lifecycle.d.ts +206 -0
  80. package/dist/hosted-loop-lifecycle.d.ts.map +1 -0
  81. package/dist/hosted-loop.d.ts +170 -0
  82. package/dist/hosted-loop.d.ts.map +1 -0
  83. package/dist/hosted-run-event-sink.d.ts +222 -0
  84. package/dist/hosted-run-event-sink.d.ts.map +1 -0
  85. package/dist/hosted-runtime-assets.d.ts +186 -0
  86. package/dist/hosted-runtime-assets.d.ts.map +1 -0
  87. package/dist/hosted-session-cli.d.ts +258 -0
  88. package/dist/hosted-session-cli.d.ts.map +1 -0
  89. package/dist/hosted-skill-staging.d.ts +73 -0
  90. package/dist/hosted-skill-staging.d.ts.map +1 -0
  91. package/dist/http.d.ts +8 -0
  92. package/dist/http.d.ts.map +1 -0
  93. package/dist/index.d.ts +22 -0
  94. package/dist/index.d.ts.map +1 -0
  95. package/dist/index.js +119 -129
  96. package/dist/instruction-set-gepa-launch.d.ts +3 -0
  97. package/dist/instruction-set-gepa-launch.d.ts.map +1 -0
  98. package/dist/instruction-set-gepa-launch.js +15 -0
  99. package/dist/instruction-set-loader.d.ts +6 -0
  100. package/dist/instruction-set-loader.d.ts.map +1 -0
  101. package/dist/instruction-set-loader.js +59 -0
  102. package/dist/instruction-set-manifest.d.ts +14 -0
  103. package/dist/instruction-set-manifest.d.ts.map +1 -0
  104. package/dist/instruction-set-manifest.js +162 -0
  105. package/dist/instruction-sets-cli.d.ts +40 -0
  106. package/dist/instruction-sets-cli.d.ts.map +1 -0
  107. package/dist/instruction-sets-cli.js +361 -0
  108. package/dist/json-response.d.ts +4 -0
  109. package/dist/json-response.d.ts.map +1 -0
  110. package/dist/jsonl-stream.d.ts +8 -0
  111. package/dist/jsonl-stream.d.ts.map +1 -0
  112. package/dist/kill-switch-cli.d.ts +30 -0
  113. package/dist/kill-switch-cli.d.ts.map +1 -0
  114. package/dist/loopback-serve.d.ts +25 -0
  115. package/dist/loopback-serve.d.ts.map +1 -0
  116. package/dist/manifests-cli.d.ts +22 -0
  117. package/dist/manifests-cli.d.ts.map +1 -0
  118. package/dist/markdown-report-input.d.ts +7 -0
  119. package/dist/markdown-report-input.d.ts.map +1 -0
  120. package/dist/markdown-report-input.js +15 -1
  121. package/dist/merge-job.d.ts +155 -0
  122. package/dist/merge-job.d.ts.map +1 -0
  123. package/dist/model-configs-cli.d.ts +19 -0
  124. package/dist/model-configs-cli.d.ts.map +1 -0
  125. package/dist/model-configs-cli.js +104 -0
  126. package/dist/optimization-export-cli.d.ts +19 -0
  127. package/dist/optimization-export-cli.d.ts.map +1 -0
  128. package/dist/optimizations-list-cli.d.ts +20 -0
  129. package/dist/optimizations-list-cli.d.ts.map +1 -0
  130. package/dist/optimizations-promote-cli.d.ts +8 -0
  131. package/dist/optimizations-promote-cli.d.ts.map +1 -0
  132. package/dist/optimizations-promote-cli.js +34 -0
  133. package/dist/option-validation.d.ts +15 -0
  134. package/dist/option-validation.d.ts.map +1 -0
  135. package/dist/preview-runtime.d.ts +63 -0
  136. package/dist/preview-runtime.d.ts.map +1 -0
  137. package/dist/prompt-draft-push.d.ts +60 -0
  138. package/dist/prompt-draft-push.d.ts.map +1 -0
  139. package/dist/prompt-label-cli.d.ts +11 -0
  140. package/dist/prompt-label-cli.d.ts.map +1 -0
  141. package/dist/prompt-label-cli.js +29 -0
  142. package/dist/prompt-length-wire.d.ts +28 -0
  143. package/dist/prompt-length-wire.d.ts.map +1 -0
  144. package/dist/prompt-length-wire.js +2 -2
  145. package/dist/prompt-report-cli.d.ts +10 -0
  146. package/dist/prompt-report-cli.d.ts.map +1 -0
  147. package/dist/prompt-report-cli.js +2 -2
  148. package/dist/prompt-summary-table.d.ts +15 -0
  149. package/dist/prompt-summary-table.d.ts.map +1 -0
  150. package/dist/prompt-summary-table.js +6 -0
  151. package/dist/registration-tag-warning.d.ts +32 -0
  152. package/dist/registration-tag-warning.d.ts.map +1 -0
  153. package/dist/report-comments-cli.d.ts +16 -0
  154. package/dist/report-comments-cli.d.ts.map +1 -0
  155. package/dist/report-markdown-blankness.d.ts +2 -0
  156. package/dist/report-markdown-blankness.d.ts.map +1 -0
  157. package/dist/report-markdown-blankness.js +6 -0
  158. package/dist/report-replacement-warning.d.ts +17 -0
  159. package/dist/report-replacement-warning.d.ts.map +1 -0
  160. package/dist/report-replacement-warning.js +31 -0
  161. package/dist/repository-backup-core.d.ts +225 -0
  162. package/dist/repository-backup-core.d.ts.map +1 -0
  163. package/dist/repository-recovery-manifest.d.ts +83 -0
  164. package/dist/repository-recovery-manifest.d.ts.map +1 -0
  165. package/dist/run-event-digest.d.ts +74 -0
  166. package/dist/run-event-digest.d.ts.map +1 -0
  167. package/dist/runner-dir-verify.d.ts +66 -0
  168. package/dist/runner-dir-verify.d.ts.map +1 -0
  169. package/dist/runner-instruction-set-contract.d.ts +24 -0
  170. package/dist/runner-instruction-set-contract.d.ts.map +1 -0
  171. package/dist/runner-instruction-set-contract.js +50 -0
  172. package/dist/sandbox-hygiene.d.ts +45 -0
  173. package/dist/sandbox-hygiene.d.ts.map +1 -0
  174. package/dist/sandbox-provider.d.ts +193 -0
  175. package/dist/sandbox-provider.d.ts.map +1 -0
  176. package/dist/scorer-draft-push.d.ts +50 -0
  177. package/dist/scorer-draft-push.d.ts.map +1 -0
  178. package/dist/scorers-cli.d.ts +20 -0
  179. package/dist/scorers-cli.d.ts.map +1 -0
  180. package/dist/scorers-cli.js +22 -0
  181. package/dist/scorers-verify-parity-bridge.d.ts +16 -0
  182. package/dist/scorers-verify-parity-bridge.d.ts.map +1 -0
  183. package/dist/scorers-verify-parity-bridge.js +90 -0
  184. package/dist/scorers-verify-parity.d.ts +81 -0
  185. package/dist/scorers-verify-parity.d.ts.map +1 -0
  186. package/dist/scorers-verify-parity.js +502 -0
  187. package/dist/scores-accept-cli.d.ts +21 -0
  188. package/dist/scores-accept-cli.d.ts.map +1 -0
  189. package/dist/secret-redaction.d.ts +47 -0
  190. package/dist/secret-redaction.d.ts.map +1 -0
  191. package/dist/session-timeline.d.ts +54 -0
  192. package/dist/session-timeline.d.ts.map +1 -0
  193. package/dist/setup-prompt.d.ts +5 -0
  194. package/dist/setup-prompt.d.ts.map +1 -0
  195. package/dist/skill-installer.d.ts +68 -0
  196. package/dist/skill-installer.d.ts.map +1 -0
  197. package/dist/skilled-proposer-launch.d.ts +7 -0
  198. package/dist/skilled-proposer-launch.d.ts.map +1 -0
  199. package/dist/skilled-proposer-launch.js +60 -0
  200. package/dist/smoke.d.ts +102 -0
  201. package/dist/smoke.d.ts.map +1 -0
  202. package/dist/start-intent.d.ts +12 -0
  203. package/dist/start-intent.d.ts.map +1 -0
  204. package/dist/task-assignment-manifest.d.ts +15 -0
  205. package/dist/task-assignment-manifest.d.ts.map +1 -0
  206. package/dist/task-create-error.d.ts +18 -0
  207. package/dist/task-create-error.d.ts.map +1 -0
  208. package/dist/team-connectors-cli.d.ts +29 -0
  209. package/dist/team-connectors-cli.d.ts.map +1 -0
  210. package/dist/types.d.ts +39 -0
  211. package/dist/types.d.ts.map +1 -0
  212. package/dist/vercel-sandbox-provider.d.ts +156 -0
  213. package/dist/vercel-sandbox-provider.d.ts.map +1 -0
  214. package/dist/workbench-cli.d.ts +233 -0
  215. package/dist/workbench-cli.d.ts.map +1 -0
  216. package/dist/workspace-sync.d.ts +207 -0
  217. package/dist/workspace-sync.d.ts.map +1 -0
  218. package/dist/workspace.d.ts +92 -0
  219. package/dist/workspace.d.ts.map +1 -0
  220. package/dist/zip-draft-push.d.ts +55 -0
  221. package/dist/zip-draft-push.d.ts.map +1 -0
  222. package/package.json +15 -2
  223. package/requirements/README.md +138 -0
  224. package/requirements/skilled-proposer.in +66 -0
  225. package/requirements/skilled-proposer.lock +265 -0
  226. package/scripts/build-cli-dist.mjs +30 -0
  227. package/scripts/ensure-skilled-proposer-venv.mjs +5 -0
  228. package/scripts/orizu-source-checkout.d.mts +1 -0
  229. package/scripts/orizu-source-checkout.mjs +10 -0
  230. package/scripts/refresh-skilled-proposer-lock.mjs +256 -0
  231. package/scripts/vendor-gepa-python.mjs +187 -4
  232. package/src/diff-comments-cli.ts +41 -3
  233. package/src/gepa-engine-dispatch.ts +340 -0
  234. package/src/gepa-python-command.ts +31 -0
  235. package/src/gepa-python-paths.ts +56 -0
  236. package/src/help.ts +95 -25
  237. package/src/index.ts +131 -166
  238. package/src/instruction-set-gepa-launch.ts +28 -0
  239. package/src/instruction-set-loader.ts +37 -0
  240. package/src/instruction-set-manifest.ts +120 -0
  241. package/src/instruction-sets-cli.ts +306 -0
  242. package/src/markdown-report-input.ts +19 -1
  243. package/src/model-configs-cli.ts +119 -0
  244. package/src/optimizations-promote-cli.ts +41 -0
  245. package/src/prompt-label-cli.ts +55 -0
  246. package/src/prompt-length-wire.ts +1 -1
  247. package/src/prompt-report-cli.ts +2 -2
  248. package/src/prompt-summary-table.ts +12 -0
  249. package/src/report-markdown-blankness.ts +6 -0
  250. package/src/report-replacement-warning.ts +35 -0
  251. package/src/runner-instruction-set-contract.ts +64 -0
  252. package/src/scorers-cli.ts +40 -0
  253. package/src/scorers-verify-parity-bridge.ts +90 -0
  254. package/src/scorers-verify-parity.ts +564 -0
  255. package/src/skilled-proposer-launch.ts +89 -0
  256. package/src/skilled-proposer-venv-manager.mjs +757 -0
  257. package/tsconfig.json +2 -0
  258. package/vendor/gepa-python/LICENSE +7 -0
  259. package/vendor/gepa-python/manifest.json +107 -0
  260. package/vendor/gepa-python/src/gepa/__init__.py +22 -0
  261. package/vendor/gepa-python/src/gepa/adapters/__init__.py +0 -0
  262. package/vendor/gepa-python/src/gepa/adapters/anymaths_adapter/__init__.py +1 -0
  263. package/vendor/gepa-python/src/gepa/adapters/anymaths_adapter/anymaths_adapter.py +174 -0
  264. package/vendor/gepa-python/src/gepa/adapters/confidence_adapter/__init__.py +26 -0
  265. package/vendor/gepa-python/src/gepa/adapters/confidence_adapter/confidence_adapter.py +618 -0
  266. package/vendor/gepa-python/src/gepa/adapters/confidence_adapter/scoring.py +206 -0
  267. package/vendor/gepa-python/src/gepa/adapters/default_adapter/__init__.py +0 -0
  268. package/vendor/gepa-python/src/gepa/adapters/default_adapter/default_adapter.py +206 -0
  269. package/vendor/gepa-python/src/gepa/adapters/dspy_adapter/__init__.py +0 -0
  270. package/vendor/gepa-python/src/gepa/adapters/dspy_adapter/dspy_adapter.py +525 -0
  271. package/vendor/gepa-python/src/gepa/adapters/dspy_adapter/instruction_proposal.py +500 -0
  272. package/vendor/gepa-python/src/gepa/adapters/dspy_full_program_adapter/__init__.py +6 -0
  273. package/vendor/gepa-python/src/gepa/adapters/dspy_full_program_adapter/dspy_program_proposal_signature.py +137 -0
  274. package/vendor/gepa-python/src/gepa/adapters/dspy_full_program_adapter/full_program_adapter.py +269 -0
  275. package/vendor/gepa-python/src/gepa/adapters/generic_rag_adapter/__init__.py +56 -0
  276. package/vendor/gepa-python/src/gepa/adapters/generic_rag_adapter/evaluation_metrics.py +226 -0
  277. package/vendor/gepa-python/src/gepa/adapters/generic_rag_adapter/generic_rag_adapter.py +496 -0
  278. package/vendor/gepa-python/src/gepa/adapters/generic_rag_adapter/rag_pipeline.py +238 -0
  279. package/vendor/gepa-python/src/gepa/adapters/generic_rag_adapter/vector_store_interface.py +212 -0
  280. package/vendor/gepa-python/src/gepa/adapters/generic_rag_adapter/vector_stores/__init__.py +2 -0
  281. package/vendor/gepa-python/src/gepa/adapters/generic_rag_adapter/vector_stores/chroma_store.py +196 -0
  282. package/vendor/gepa-python/src/gepa/adapters/generic_rag_adapter/vector_stores/lancedb_store.py +422 -0
  283. package/vendor/gepa-python/src/gepa/adapters/generic_rag_adapter/vector_stores/milvus_store.py +409 -0
  284. package/vendor/gepa-python/src/gepa/adapters/generic_rag_adapter/vector_stores/qdrant_store.py +368 -0
  285. package/vendor/gepa-python/src/gepa/adapters/generic_rag_adapter/vector_stores/weaviate_store.py +418 -0
  286. package/vendor/gepa-python/src/gepa/adapters/langchain_adapter/__init__.py +11 -0
  287. package/vendor/gepa-python/src/gepa/adapters/langchain_adapter/langchain_adapter.py +261 -0
  288. package/vendor/gepa-python/src/gepa/adapters/mcp_adapter/__init__.py +37 -0
  289. package/vendor/gepa-python/src/gepa/adapters/mcp_adapter/mcp_adapter.py +693 -0
  290. package/vendor/gepa-python/src/gepa/adapters/mcp_adapter/mcp_client.py +364 -0
  291. package/vendor/gepa-python/src/gepa/adapters/optimize_anything_adapter/optimize_anything_adapter.py +879 -0
  292. package/vendor/gepa-python/src/gepa/adapters/terminal_bench_adapter/__init__.py +0 -0
  293. package/vendor/gepa-python/src/gepa/adapters/terminal_bench_adapter/terminal_bench_adapter.py +217 -0
  294. package/vendor/gepa-python/src/gepa/api.py +468 -0
  295. package/vendor/gepa-python/src/gepa/core/__init__.py +0 -0
  296. package/vendor/gepa-python/src/gepa/core/adapter.py +227 -0
  297. package/vendor/gepa-python/src/gepa/core/callbacks.py +551 -0
  298. package/vendor/gepa-python/src/gepa/core/data_loader.py +74 -0
  299. package/vendor/gepa-python/src/gepa/core/engine.py +1025 -0
  300. package/vendor/gepa-python/src/gepa/core/result.py +271 -0
  301. package/vendor/gepa-python/src/gepa/core/state.py +706 -0
  302. package/vendor/gepa-python/src/gepa/examples/__init__.py +0 -0
  303. package/vendor/gepa-python/src/gepa/examples/aime.py +24 -0
  304. package/vendor/gepa-python/src/gepa/examples/anymaths-bench/eval_default.py +111 -0
  305. package/vendor/gepa-python/src/gepa/examples/anymaths-bench/train_anymaths.py +177 -0
  306. package/vendor/gepa-python/src/gepa/examples/mcp_adapter/__init__.py +4 -0
  307. package/vendor/gepa-python/src/gepa/examples/mcp_adapter/mcp_optimization_example.py +456 -0
  308. package/vendor/gepa-python/src/gepa/examples/rag_adapter/__init__.py +9 -0
  309. package/vendor/gepa-python/src/gepa/examples/rag_adapter/rag_optimization.py +824 -0
  310. package/vendor/gepa-python/src/gepa/examples/terminal-bench/train_terminus.py +161 -0
  311. package/vendor/gepa-python/src/gepa/gepa_utils.py +117 -0
  312. package/vendor/gepa-python/src/gepa/gskill/__init__.py +1 -0
  313. package/vendor/gepa-python/src/gepa/gskill/gskill/__init__.py +0 -0
  314. package/vendor/gepa-python/src/gepa/gskill/gskill/cost_tracker.py +194 -0
  315. package/vendor/gepa-python/src/gepa/gskill/gskill/evaluate/__init__.py +0 -0
  316. package/vendor/gepa-python/src/gepa/gskill/gskill/evaluate/claude_code.py +1117 -0
  317. package/vendor/gepa-python/src/gepa/gskill/gskill/evaluate/claude_code_skills.py +613 -0
  318. package/vendor/gepa-python/src/gepa/gskill/gskill/evaluate/mini_swe_agent.py +440 -0
  319. package/vendor/gepa-python/src/gepa/gskill/gskill/experiment_logger.py +367 -0
  320. package/vendor/gepa-python/src/gepa/gskill/gskill/swe_fitness_fn.py +209 -0
  321. package/vendor/gepa-python/src/gepa/gskill/gskill/swe_harness.py +352 -0
  322. package/vendor/gepa-python/src/gepa/gskill/gskill/train_optimize_anything.py +830 -0
  323. package/vendor/gepa-python/src/gepa/image.py +104 -0
  324. package/vendor/gepa-python/src/gepa/lm.py +261 -0
  325. package/vendor/gepa-python/src/gepa/logging/__init__.py +0 -0
  326. package/vendor/gepa-python/src/gepa/logging/experiment_tracker.py +457 -0
  327. package/vendor/gepa-python/src/gepa/logging/logger.py +75 -0
  328. package/vendor/gepa-python/src/gepa/logging/utils.py +130 -0
  329. package/vendor/gepa-python/src/gepa/optimize_anything.py +1701 -0
  330. package/vendor/gepa-python/src/gepa/proposer/__init__.py +0 -0
  331. package/vendor/gepa-python/src/gepa/proposer/base.py +53 -0
  332. package/vendor/gepa-python/src/gepa/proposer/merge.py +403 -0
  333. package/vendor/gepa-python/src/gepa/proposer/reflective_mutation/__init__.py +0 -0
  334. package/vendor/gepa-python/src/gepa/proposer/reflective_mutation/base.py +64 -0
  335. package/vendor/gepa-python/src/gepa/proposer/reflective_mutation/reflection_lm.py +178 -0
  336. package/vendor/gepa-python/src/gepa/proposer/reflective_mutation/reflective_mutation.py +641 -0
  337. package/vendor/gepa-python/src/gepa/py.typed +0 -0
  338. package/vendor/gepa-python/src/gepa/strategies/__init__.py +0 -0
  339. package/vendor/gepa-python/src/gepa/strategies/acceptance.py +66 -0
  340. package/vendor/gepa-python/src/gepa/strategies/batch_sampler.py +103 -0
  341. package/vendor/gepa-python/src/gepa/strategies/candidate_selector.py +82 -0
  342. package/vendor/gepa-python/src/gepa/strategies/component_selector.py +36 -0
  343. package/vendor/gepa-python/src/gepa/strategies/eval_policy.py +64 -0
  344. package/vendor/gepa-python/src/gepa/strategies/instruction_proposal.py +153 -0
  345. package/vendor/gepa-python/src/gepa/strategies/proposal_sampling.py +128 -0
  346. package/vendor/gepa-python/src/gepa/strategies/proposal_selection.py +84 -0
  347. package/vendor/gepa-python/src/gepa/utils/__init__.py +63 -0
  348. package/vendor/gepa-python/src/gepa/utils/code_execution.py +626 -0
  349. package/vendor/gepa-python/src/gepa/utils/stdio_capture.py +145 -0
  350. package/vendor/gepa-python/src/gepa/utils/stop_condition.py +230 -0
  351. package/vendor/gepa-python/src/gepa/visualization.py +359 -0
  352. package/vendor/orizu-gepa/pyproject.toml +18 -0
  353. package/vendor/orizu-gepa/src/orizu_gepa_connector/__init__.py +9 -0
  354. package/vendor/orizu-gepa/src/orizu_gepa_connector/__main__.py +5 -0
  355. package/vendor/orizu-gepa/src/orizu_gepa_connector/adapter.py +138 -0
  356. package/vendor/orizu-gepa/src/orizu_gepa_connector/callbacks.py +666 -0
  357. package/vendor/orizu-gepa/src/orizu_gepa_connector/cli.py +7 -0
  358. package/vendor/orizu-gepa/src/orizu_gepa_connector/engine.py +269 -0
  359. package/vendor/orizu-gepa/src/orizu_gepa_connector/instruction_set_loader.py +52 -0
  360. package/vendor/orizu-gepa/src/orizu_gepa_connector/preflight.py +64 -0
  361. package/vendor/orizu-gepa/src/orizu_gepa_connector/reflection.py +186 -0
  362. package/vendor/orizu-gepa/src/orizu_gepa_connector/runtime.py +721 -0
  363. package/vendor/orizu-gepa/src/orizu_gepa_connector/skilled_proposer_bridge.py +381 -0
  364. package/vendor/orizu-gepa/src/orizu_gepa_connector/stop_conditions.py +55 -0
  365. package/vendor/orizu-gepa/src/orizu_gepa_connector/translator.py +203 -0
  366. package/vendor/orizu-gepa-python/pyproject.toml +1 -1
  367. package/vendor/orizu-gepa-python/src/orizu_gepa/cli.py +1 -0
  368. package/vendor/orizu-gepa-python/src/orizu_gepa/client.py +52 -7
  369. package/vendor/orizu-gepa-python/src/orizu_gepa/local_log.py +52 -0
  370. package/vendor/orizu-gepa-python/src/orizu_gepa/optimizer.py +10 -5
  371. package/vendor/orizu-gepa-python/src/orizu_gepa/reflection.py +323 -68
  372. package/vendor/orizu-gepa-python/src/orizu_gepa/runner.py +207 -13
  373. package/vendor/skills/orizu-cli/SKILL.md +3 -1
  374. package/vendor/skills/orizu-cli/references/cli-reference.md +85 -1
  375. package/vendor/skills/orizu-cli/references/migrate-existing-gepa-setup.md +303 -0
  376. package/vendor/skills/orizu-cli/references/optimization-reports.md +1 -1
  377. package/vendor/skills/orizu-cli/references/optimization-with-gepa.md +26 -1
  378. package/vendor/skills/orizu-cli/references/prompt-control-plane.md +113 -10
@@ -0,0 +1,468 @@
1
+ # Copyright (c) 2025 Lakshya A Agrawal and the GEPA contributors
2
+ # https://github.com/gepa-ai/gepa
3
+
4
+ import os
5
+ import random
6
+ from collections.abc import Sequence
7
+ from typing import TYPE_CHECKING, Any, Literal, cast
8
+
9
+ if TYPE_CHECKING:
10
+ from gepa.core.callbacks import GEPACallback
11
+
12
+ from gepa.adapters.default_adapter.default_adapter import (
13
+ ChatCompletionCallable,
14
+ DefaultAdapter,
15
+ Evaluator,
16
+ )
17
+ from gepa.core.adapter import DataInst, GEPAAdapter, ProposalFn, RolloutOutput, Trajectory
18
+ from gepa.core.data_loader import DataId, DataLoader, ensure_loader
19
+ from gepa.core.engine import GEPAEngine
20
+ from gepa.core.result import GEPAResult
21
+ from gepa.core.state import EvaluationCache, FrontierType
22
+ from gepa.logging.experiment_tracker import create_experiment_tracker
23
+ from gepa.logging.logger import Logger, LoggerProtocol, StdOutLogger
24
+ from gepa.proposer.merge import MergeProposer
25
+ from gepa.proposer.reflective_mutation.base import CandidateSelector, LanguageModel, ReflectionComponentSelector
26
+ from gepa.proposer.reflective_mutation.reflection_lm import ReflectionLM
27
+ from gepa.proposer.reflective_mutation.reflective_mutation import ReflectiveMutationProposer
28
+ from gepa.strategies.acceptance import AcceptanceCriterion, ImprovementOrEqualAcceptance, StrictImprovementAcceptance
29
+ from gepa.strategies.batch_sampler import BatchSampler, EpochShuffledBatchSampler
30
+ from gepa.strategies.candidate_selector import (
31
+ CurrentBestCandidateSelector,
32
+ EpsilonGreedyCandidateSelector,
33
+ ParetoCandidateSelector,
34
+ TopKParetoCandidateSelector,
35
+ )
36
+ from gepa.strategies.component_selector import (
37
+ AllReflectionComponentSelector,
38
+ RoundRobinReflectionComponentSelector,
39
+ )
40
+ from gepa.strategies.eval_policy import EvaluationPolicy, FullEvaluationPolicy
41
+ from gepa.strategies.proposal_sampling import SamplingStrategy
42
+ from gepa.strategies.proposal_selection import SelectionStrategy
43
+ from gepa.utils import FileStopper, StopperProtocol
44
+
45
+
46
+ def optimize(
47
+ seed_candidate: dict[str, str],
48
+ trainset: list[DataInst] | DataLoader[DataId, DataInst],
49
+ valset: list[DataInst] | DataLoader[DataId, DataInst] | None = None,
50
+ adapter: GEPAAdapter[DataInst, Trajectory, RolloutOutput] | None = None,
51
+ task_lm: str | ChatCompletionCallable | None = None,
52
+ evaluator: Evaluator | None = None,
53
+ # Reflection-based configuration
54
+ reflection_lm: LanguageModel | str | None = None,
55
+ reflection_lm_kwargs: dict[str, Any] | None = None,
56
+ candidate_selection_strategy: CandidateSelector
57
+ | Literal["pareto", "current_best", "epsilon_greedy", "top_k_pareto"] = "pareto",
58
+ frontier_type: FrontierType = "instance",
59
+ skip_perfect_score: bool = True,
60
+ batch_sampler: BatchSampler | Literal["epoch_shuffled"] = "epoch_shuffled",
61
+ reflection_minibatch_size: int | None = None,
62
+ perfect_score: float = 1.0,
63
+ reflection_prompt_template: str | dict[str, str] | None = None,
64
+ custom_candidate_proposer: ProposalFn | None = None,
65
+ # Component selection configuration
66
+ module_selector: ReflectionComponentSelector | str = "round_robin",
67
+ # Merge-based configuration
68
+ use_merge: bool = False,
69
+ max_merge_invocations: int = 5,
70
+ merge_val_overlap_floor: int = 5,
71
+ # Budget and Stop Condition
72
+ max_metric_calls: int | None = None,
73
+ max_reflection_cost: float | None = None,
74
+ stop_callbacks: StopperProtocol | Sequence[StopperProtocol] | None = None,
75
+ # Logging and Callbacks
76
+ logger: LoggerProtocol | None = None,
77
+ run_dir: str | None = None,
78
+ callbacks: "list[GEPACallback] | None" = None,
79
+ use_wandb: bool = False,
80
+ wandb_api_key: str | None = None,
81
+ wandb_init_kwargs: dict[str, Any] | None = None,
82
+ wandb_attach_existing: bool = False,
83
+ use_mlflow: bool = False,
84
+ mlflow_tracking_uri: str | None = None,
85
+ mlflow_experiment_name: str | None = None,
86
+ mlflow_attach_existing: bool = False,
87
+ tracking_key_prefix: str = "",
88
+ track_best_outputs: bool = True,
89
+ display_progress_bar: bool = False,
90
+ use_cloudpickle: bool = False,
91
+ # Evaluation caching
92
+ cache_evaluation: bool = False,
93
+ # Reproducibility
94
+ seed: int = 0,
95
+ raise_on_exception: bool = True,
96
+ val_evaluation_policy: EvaluationPolicy[DataId, DataInst] | Literal["full_eval"] | None = None,
97
+ acceptance_criterion: AcceptanceCriterion
98
+ | Literal["strict_improvement", "improvement_or_equal"] = "strict_improvement",
99
+ # Proposal strategies (default: 1 parent, 1 mutation per iteration)
100
+ sampling_strategy: SamplingStrategy | None = None,
101
+ selection_strategy: SelectionStrategy | None = None,
102
+ reflection_strategy: ReflectionLM | None = None,
103
+ ) -> GEPAResult[RolloutOutput, DataId]:
104
+ """
105
+ GEPA is an evolutionary optimizer that evolves (multiple) text components of a complex system to optimize them towards a given metric.
106
+ GEPA can also leverage rich textual feedback obtained from the system's execution environment, evaluation,
107
+ and the system's own execution traces to iteratively improve the system's performance.
108
+
109
+ Concepts:
110
+ - System: A harness that uses text components to perform a task. Each text component of the system to be optimized is a named component of the system.
111
+ - Candidate: A mapping from component names to component text. A concrete instantiation of the system is realized by setting the text of each system component
112
+ to the text provided by the candidate mapping.
113
+ - `DataInst`: An (uninterpreted) data type over which the system operates.
114
+ - `RolloutOutput`: The output of the system on a `DataInst`.
115
+
116
+ Each execution of the system produces a `RolloutOutput`, which can be evaluated to produce a score. The execution of the system also produces a trajectory,
117
+ which consists of the operations performed by different components of the system, including the text of the components that were executed.
118
+
119
+ GEPA can be applied to optimize any system that uses text components (e.g., prompts in a AI system, code snippets/code files/functions/classes in a codebase, etc.).
120
+ In order for GEPA to plug into your system's environment, GEPA requires an adapter, `GEPAAdapter` to be implemented. The adapter is responsible for:
121
+ 1. Evaluating a proposed candidate on a batch of inputs.
122
+ - The adapter receives a candidate proposed by GEPA, along with a batch of inputs selected from the training/validation set.
123
+ - The adapter instantiates the system with the texts proposed in the candidate.
124
+ - The adapter then evaluates the candidate on the batch of inputs, and returns the scores.
125
+ - The adapter should also capture relevant information from the execution of the candidate, like system and evaluation traces.
126
+ 2. Identifying textual information relevant to a component of the candidate
127
+ - Given the trajectories captured during the execution of the candidate, GEPA selects a component of the candidate to update.
128
+ - The adapter receives the candidate, the batch of inputs, and the trajectories captured during the execution of the candidate.
129
+ - The adapter is responsible for identifying the textual information relevant to the component to update.
130
+ - This information is used by GEPA to reflect on the performnace of the component, and propose new component texts.
131
+
132
+ At each iteration, GEPA proposes a new candidate using one of the following strategies:
133
+ 1. Reflective mutation: GEPA proposes a new candidate by mutating the current candidate, leveraging rich textual feedback.
134
+ 2. Merge: GEPA proposes a new candidate by merging 2 candidates that are on the Pareto frontier.
135
+
136
+ GEPA also tracks the Pareto frontier of performance achieved by different candidates on the validation set. This way, it can leverage candidates that
137
+ work well on a subset of inputs to improve the system's performance on the entire validation set, by evolving from the Pareto frontier.
138
+
139
+ Parameters:
140
+ - seed_candidate: The initial candidate to start with.
141
+ - trainset: Training data supplied as an in-memory sequence or a `DataLoader` yielding batches for reflective updates.
142
+ - valset: Validation data source (sequence or `DataLoader`) used for tracking Pareto scores. If not provided, GEPA reuses the trainset.
143
+ - adapter: A `GEPAAdapter` instance that implements the adapter interface. This allows GEPA to plug into your system's environment. If not provided, GEPA will use a default adapter: `gepa.adapters.default_adapter.default_adapter.DefaultAdapter`, with model defined by `task_lm`.
144
+ - task_lm: Optional. The model to use for the task. This is only used if `adapter` is not provided, and is used to initialize the default adapter.
145
+ - evaluator: Optional. A custom evaluator to use for evaluating the candidate program. If not provided, GEPA will use the default evaluator: `gepa.adapters.default_adapter.default_adapter.ContainsAnswerEvaluator`. Only used if `adapter` is not provided.
146
+
147
+ # Reflection-based configuration
148
+ - reflection_lm: A `LanguageModel` instance that is used to reflect on the performance of the candidate program.
149
+ - sampling_strategy: Controls how many (parent, minibatch) proposal tasks are sampled per iteration. One of `SingleMutationSampling` (default; 1 parent, 1 mutation — identical to classic GEPA), `SameParentSampling(n)`, `IndependentSampling(n)`, or `PxNSampling(p, n)`, or any custom `SamplingStrategy`.
150
+ - selection_strategy: Controls which of an iteration's improving proposals enter the candidate pool. One of `AllImprovements` (default), `BestImprovement`, or `TopKImprovements(k)`, or any custom `SelectionStrategy`.
151
+ - reflection_strategy: Advanced: a `ReflectionLM` implementation that owns how reflective mutation calls the reflection model (e.g. stateful sessions or aggregating reflectors). Defaults to the stateless single-call reflector built from `reflection_lm`. Implementations may provide `reflect_many` for batched reflection; otherwise `reflect` is called once per task.
152
+ - candidate_selection_strategy: The strategy to use for selecting the candidate to update. Supported strategies: 'pareto', 'current_best', 'epsilon_greedy'. Defaults to 'pareto'.
153
+ - frontier_type: Strategy for tracking Pareto frontiers. 'instance' tracks per validation example, 'objective' tracks per objective metric, 'hybrid' combines both, 'cartesian' tracks per (example, objective) pair. Defaults to 'instance'.
154
+ - skip_perfect_score: Whether to skip updating the candidate if it achieves a perfect score on the minibatch.
155
+ - batch_sampler: Strategy for selecting training examples. Can be a [BatchSampler](src/gepa/strategies/batch_sampler.py) instance or a string for a predefined strategy from ['epoch_shuffled']. Defaults to 'epoch_shuffled', which creates an [EpochShuffledBatchSampler](src/gepa/strategies/batch_sampler.py).
156
+ - reflection_minibatch_size: The number of examples to use for reflection in each proposal step. Defaults to 3. Only valid when batch_sampler='epoch_shuffled' (default), and is ignored otherwise.
157
+ - perfect_score: The perfect score to achieve.
158
+ - reflection_prompt_template: The prompt template to use for reflection. Can be either a string (applied to all components) or a dict mapping component names to their specific templates. If not provided, GEPA will use the default prompt template (see [InstructionProposalSignature](src/gepa/strategies/instruction_proposal.py)). Each prompt template must contain the following placeholders, which will be replaced with actual values: `<curr_param>` (will be replaced by the instructions/component to evolve) and `<side_info>` (replaced with the inputs, outputs, and feedback generated with current instruction). When using a dict, components without a specified template will use the default template. This will be ignored if the adapter provides its own `propose_new_texts` method.
159
+ - custom_candidate_proposer: Optional custom function for proposing new candidates. If provided, this will be used instead of the default LLM-based reflection approach. Cannot be used if adapter provides `propose_new_texts`. Signature: `(candidate, reflective_dataset, components_to_update) -> dict[str, str]`.
160
+
161
+ # Component selection configuration
162
+ - module_selector: Component selection strategy. Can be a ReflectionComponentSelector instance or a string ('round_robin', 'all'). Defaults to 'round_robin'. The 'round_robin' strategy cycles through components in order. The 'all' strategy selects all components for modification in every GEPA iteration.
163
+
164
+ # Merge-based configuration
165
+ - use_merge: Whether to use the merge strategy.
166
+ - max_merge_invocations: The maximum number of merge invocations to perform.
167
+ - merge_val_overlap_floor: Minimum number of shared validation ids required between parents before attempting a merge subsample. Only relevant when using `val_evaluation_policy` other than `full_eval`.
168
+
169
+ # Budget and Stop Condition
170
+ - max_metric_calls: Optional maximum number of metric calls to perform. If not provided, stop_callbacks must be provided.
171
+ - stop_callbacks: Optional stopper(s) that return True when optimization should stop. Can be a single StopperProtocol or a list or tuple of StopperProtocol instances. Examples: FileStopper, TimeoutStopCondition, SignalStopper, NoImprovementStopper, or custom stopping logic. If not provided, max_metric_calls must be provided.
172
+
173
+ # Logging and Callbacks
174
+ - logger: A `LoggerProtocol` instance that is used to log the progress of the optimization.
175
+ - callbacks: Optional list of callback objects for observing optimization progress. Callbacks receive events like on_optimization_start, on_iteration_start, on_candidate_accepted, etc. See `gepa.core.callbacks.GEPACallback` for the full protocol.
176
+ - run_dir: The directory to save the results to. Optimization state and results will be saved to this directory. If the directory already exists, GEPA will read the state from this directory and resume the optimization from the last saved state. If provided, a FileStopper is automatically created which checks for the presence of "gepa.stop" in this directory, allowing graceful stopping of the optimization process upon its presence.
177
+ - use_wandb: Whether to use Weights and Biases to log the progress of the optimization.
178
+ - wandb_api_key: The API key to use for Weights and Biases.
179
+ - wandb_init_kwargs: Additional keyword arguments to pass to the Weights and Biases initialization.
180
+ - wandb_attach_existing: When True, log into the already-active W&B run without calling wandb.init() or wandb.finish(). Use when GEPA is embedded in a training loop that owns the run.
181
+ - mlflow_attach_existing: When True, log into the already-active MLflow run without calling mlflow.start_run() or mlflow.end_run(). Use when GEPA is embedded in a training loop that owns the run.
182
+ - use_mlflow: Whether to use MLflow to log the progress of the optimization.
183
+ Both wandb and mlflow can be used simultaneously if desired.
184
+ - mlflow_tracking_uri: The tracking URI to use for MLflow.
185
+ - mlflow_experiment_name: The experiment name to use for MLflow.
186
+ - track_best_outputs: Whether to track the best outputs on the validation set. If True, GEPAResult will contain the best outputs obtained for each task in the validation set.
187
+ - display_progress_bar: Show a tqdm progress bar over metric calls when enabled.
188
+ - use_cloudpickle: Use cloudpickle instead of pickle. This can be helpful when the serialized state contains dynamically generated DSPy signatures.
189
+
190
+ # Evaluation caching
191
+ - cache_evaluation: Whether to cache the (score, output, objective_scores) of (candidate, example) pairs. If True and a cache entry exists, GEPA will skip the fitness evaluation and use the cached results. This helps avoid redundant evaluations and saves metric calls. Defaults to False.
192
+
193
+ # Reproducibility
194
+ - seed: The seed to use for the random number generator.
195
+ - val_evaluation_policy: Strategy controlling which validation ids to score each iteration and which candidate is currently best. Supported strings: "full_eval" (evaluate every id each time) Passing None defaults to "full_eval".
196
+ - raise_on_exception: Whether to propagate proposer/evaluator exceptions instead of stopping gracefully.
197
+ """
198
+ # Validate seed_candidate is not None or empty
199
+ if seed_candidate is None or not seed_candidate:
200
+ raise ValueError("seed_candidate must contain at least one component text.")
201
+
202
+ active_adapter: GEPAAdapter[DataInst, Trajectory, RolloutOutput] | None = None
203
+ if adapter is None:
204
+ assert task_lm is not None, (
205
+ "Since no adapter is provided, GEPA requires a task LM to be provided. Please set the `task_lm` parameter."
206
+ )
207
+ active_adapter = cast(
208
+ GEPAAdapter[DataInst, Trajectory, RolloutOutput], DefaultAdapter(model=task_lm, evaluator=evaluator)
209
+ )
210
+ else:
211
+ assert task_lm is None, (
212
+ "Since an adapter is provided, GEPA does not require a task LM to be provided. Please set the `task_lm` parameter to None."
213
+ )
214
+ assert evaluator is None, (
215
+ "Since an adapter is provided, GEPA does not require an evaluator to be provided. Please set the `evaluator` parameter to None."
216
+ )
217
+ active_adapter = adapter
218
+
219
+ # Normalize datasets to DataLoader instances
220
+ train_loader = ensure_loader(trainset)
221
+ val_loader = ensure_loader(valset) if valset is not None else train_loader
222
+
223
+ # Validate that only one custom proposal method is provided
224
+ adapter_has_propose = hasattr(active_adapter, "propose_new_texts") and active_adapter.propose_new_texts is not None
225
+ if adapter_has_propose and custom_candidate_proposer is not None:
226
+ raise ValueError(
227
+ "Cannot provide both adapter.propose_new_texts and custom_candidate_proposer. "
228
+ "Please use only one custom proposal method."
229
+ )
230
+
231
+ if not adapter_has_propose and custom_candidate_proposer is None:
232
+ assert reflection_lm is not None or reflection_strategy is not None, (
233
+ f"reflection_lm was not provided. The adapter used '{active_adapter!s}' does not provide a propose_new_texts method, "
234
+ + "and custom_candidate_proposer was not provided. "
235
+ + "GEPA will use the default proposer, which requires a reflection_lm (or a "
236
+ + "reflection_strategy) to be specified."
237
+ )
238
+
239
+ # Resolve reflection LM before building stoppers so cost stopper can reference it
240
+ reflection_lm_callable: LanguageModel | None = None
241
+ if isinstance(reflection_lm, str):
242
+ from gepa.lm import LM
243
+
244
+ reflection_lm_callable = LM(reflection_lm, **(reflection_lm_kwargs or {}))
245
+ elif reflection_lm is not None:
246
+ from gepa.lm import TrackingLM
247
+
248
+ reflection_lm_callable = TrackingLM(reflection_lm) if not hasattr(reflection_lm, "total_cost") else reflection_lm
249
+ else:
250
+ reflection_lm_callable = None
251
+
252
+ # --- Build stoppers (all in one place, after LM conversion) ---
253
+ stop_callbacks_list: list[StopperProtocol] = []
254
+ if stop_callbacks is not None:
255
+ if isinstance(stop_callbacks, Sequence):
256
+ stop_callbacks_list.extend(stop_callbacks)
257
+ else:
258
+ stop_callbacks_list.append(stop_callbacks)
259
+
260
+ if run_dir is not None:
261
+ stop_callbacks_list.append(FileStopper(os.path.join(run_dir, "gepa.stop")))
262
+
263
+ if max_metric_calls is not None:
264
+ from gepa.utils import MaxMetricCallsStopper
265
+
266
+ stop_callbacks_list.append(MaxMetricCallsStopper(max_metric_calls))
267
+
268
+ if max_reflection_cost is not None:
269
+ from gepa.utils import MaxReflectionCostStopper
270
+
271
+ if reflection_strategy is not None:
272
+ if not hasattr(reflection_strategy, "total_cost"):
273
+ raise ValueError(
274
+ "max_reflection_cost is set but reflection_strategy does not expose total_cost — "
275
+ "the cost stopper would silently never fire (unbounded reflection spend). Expose a "
276
+ "total_cost property on the strategy, or remove max_reflection_cost."
277
+ )
278
+ stop_callbacks_list.append(MaxReflectionCostStopper(max_reflection_cost, reflection_lm=reflection_strategy))
279
+ else:
280
+ stop_callbacks_list.append(
281
+ MaxReflectionCostStopper(max_reflection_cost, reflection_lm=reflection_lm_callable)
282
+ )
283
+
284
+ if not stop_callbacks_list:
285
+ raise ValueError(
286
+ "The user must provide at least one of stop_callbacks, max_metric_calls, or max_reflection_cost to specify a stopping condition."
287
+ )
288
+
289
+ stop_callback: StopperProtocol
290
+ if len(stop_callbacks_list) == 1:
291
+ stop_callback = stop_callbacks_list[0]
292
+ else:
293
+ from gepa.utils import CompositeStopper
294
+
295
+ stop_callback = CompositeStopper(*stop_callbacks_list)
296
+
297
+ if logger is None:
298
+ if run_dir is not None:
299
+ os.makedirs(run_dir, exist_ok=True)
300
+ logger = Logger(os.path.join(run_dir, "run_log.txt"))
301
+ else:
302
+ logger = StdOutLogger()
303
+
304
+ rng = random.Random(seed)
305
+
306
+ candidate_selector: CandidateSelector
307
+ if isinstance(candidate_selection_strategy, str):
308
+ factories = {
309
+ "pareto": lambda: ParetoCandidateSelector(rng=rng),
310
+ "current_best": lambda: CurrentBestCandidateSelector(),
311
+ "epsilon_greedy": lambda: EpsilonGreedyCandidateSelector(epsilon=0.1, rng=rng),
312
+ "top_k_pareto": lambda: TopKParetoCandidateSelector(k=5, rng=rng),
313
+ }
314
+
315
+ try:
316
+ candidate_selector = factories[candidate_selection_strategy]()
317
+ except KeyError as exc:
318
+ raise ValueError(
319
+ f"Unknown candidate_selector strategy: {candidate_selection_strategy}. "
320
+ "Supported strategies: 'pareto', 'current_best', 'epsilon_greedy', 'top_k_pareto'"
321
+ ) from exc
322
+ elif isinstance(candidate_selection_strategy, CandidateSelector):
323
+ candidate_selector = candidate_selection_strategy
324
+ else:
325
+ raise TypeError(
326
+ "candidate_selection_strategy must be a supported string strategy or an instance of CandidateSelector."
327
+ )
328
+
329
+ if val_evaluation_policy is None or val_evaluation_policy == "full_eval":
330
+ val_evaluation_policy = FullEvaluationPolicy()
331
+ elif not isinstance(val_evaluation_policy, EvaluationPolicy):
332
+ raise ValueError(
333
+ f"val_evaluation_policy should be one of 'full_eval' or an instance of EvaluationPolicy, but got {type(val_evaluation_policy)}"
334
+ )
335
+
336
+ if isinstance(module_selector, str):
337
+ module_selector_cls = {
338
+ "round_robin": RoundRobinReflectionComponentSelector,
339
+ "all": AllReflectionComponentSelector,
340
+ }.get(module_selector)
341
+
342
+ assert module_selector_cls is not None, (
343
+ f"Unknown module_selector strategy: {module_selector}. Supported strategies: 'round_robin', 'all'"
344
+ )
345
+
346
+ module_selector_instance: ReflectionComponentSelector = module_selector_cls()
347
+ else:
348
+ module_selector_instance = module_selector
349
+
350
+ if batch_sampler == "epoch_shuffled":
351
+ batch_sampler = EpochShuffledBatchSampler(minibatch_size=reflection_minibatch_size or 3, rng=rng)
352
+ else:
353
+ assert reflection_minibatch_size is None, (
354
+ "reflection_minibatch_size only accepted if batch_sampler is 'epoch_shuffled'"
355
+ )
356
+
357
+ acceptance_criterion_instance: AcceptanceCriterion
358
+ if isinstance(acceptance_criterion, str):
359
+ acceptance_factories: dict[str, type[AcceptanceCriterion]] = {
360
+ "strict_improvement": StrictImprovementAcceptance,
361
+ "improvement_or_equal": ImprovementOrEqualAcceptance,
362
+ }
363
+ try:
364
+ acceptance_criterion_instance = acceptance_factories[acceptance_criterion]()
365
+ except KeyError as exc:
366
+ raise ValueError(
367
+ f"Unknown acceptance_criterion: {acceptance_criterion}. "
368
+ "Supported strategies: 'strict_improvement', 'improvement_or_equal'"
369
+ ) from exc
370
+ elif isinstance(acceptance_criterion, AcceptanceCriterion):
371
+ acceptance_criterion_instance = acceptance_criterion
372
+ else:
373
+ raise TypeError(
374
+ "acceptance_criterion must be a supported string strategy or an instance of AcceptanceCriterion."
375
+ )
376
+
377
+ experiment_tracker = create_experiment_tracker(
378
+ use_wandb=use_wandb,
379
+ wandb_api_key=wandb_api_key,
380
+ wandb_init_kwargs=wandb_init_kwargs,
381
+ wandb_attach_existing=wandb_attach_existing,
382
+ use_mlflow=use_mlflow,
383
+ mlflow_tracking_uri=mlflow_tracking_uri,
384
+ mlflow_experiment_name=mlflow_experiment_name,
385
+ mlflow_attach_existing=mlflow_attach_existing,
386
+ key_prefix=tracking_key_prefix,
387
+ )
388
+
389
+ if reflection_prompt_template is not None:
390
+ assert not (adapter is not None and getattr(adapter, "propose_new_texts", None) is not None), (
391
+ f"Adapter {adapter!s} provides its own propose_new_texts method; reflection_prompt_template will be ignored. "
392
+ "Set reflection_prompt_template to None."
393
+ )
394
+
395
+ # Create evaluation cache if enabled
396
+ evaluation_cache: EvaluationCache[RolloutOutput, DataId] | None = None
397
+ if cache_evaluation:
398
+ evaluation_cache = EvaluationCache[RolloutOutput, DataId]()
399
+
400
+ reflective_proposer = ReflectiveMutationProposer(
401
+ logger=logger,
402
+ trainset=train_loader,
403
+ adapter=active_adapter,
404
+ candidate_selector=candidate_selector,
405
+ module_selector=module_selector_instance,
406
+ batch_sampler=batch_sampler,
407
+ perfect_score=perfect_score,
408
+ skip_perfect_score=skip_perfect_score,
409
+ experiment_tracker=experiment_tracker,
410
+ reflection_lm=reflection_lm_callable,
411
+ reflection_prompt_template=reflection_prompt_template,
412
+ custom_candidate_proposer=custom_candidate_proposer,
413
+ callbacks=callbacks,
414
+ sampling_strategy=sampling_strategy,
415
+ reflection_strategy=reflection_strategy,
416
+ )
417
+
418
+ def evaluator_fn(
419
+ inputs: list[DataInst], prog: dict[str, str]
420
+ ) -> tuple[list[RolloutOutput], list[float], Sequence[dict[str, float]] | None]:
421
+ eval_out = active_adapter.evaluate(inputs, prog, capture_traces=False)
422
+ return eval_out.outputs, eval_out.scores, eval_out.objective_scores
423
+
424
+ merge_proposer: MergeProposer | None = None
425
+ if use_merge:
426
+ merge_proposer = MergeProposer(
427
+ logger=logger,
428
+ valset=val_loader,
429
+ evaluator=evaluator_fn,
430
+ use_merge=use_merge,
431
+ max_merge_invocations=max_merge_invocations,
432
+ rng=rng,
433
+ val_overlap_floor=merge_val_overlap_floor,
434
+ callbacks=callbacks,
435
+ )
436
+
437
+ engine = GEPAEngine(
438
+ adapter=active_adapter,
439
+ run_dir=run_dir,
440
+ valset=val_loader,
441
+ seed_candidate=seed_candidate,
442
+ perfect_score=perfect_score,
443
+ seed=seed,
444
+ reflective_proposer=reflective_proposer,
445
+ merge_proposer=merge_proposer,
446
+ frontier_type=frontier_type,
447
+ logger=logger,
448
+ experiment_tracker=experiment_tracker,
449
+ callbacks=callbacks,
450
+ track_best_outputs=track_best_outputs,
451
+ display_progress_bar=display_progress_bar,
452
+ raise_on_exception=raise_on_exception,
453
+ stop_callback=stop_callback,
454
+ val_evaluation_policy=val_evaluation_policy,
455
+ acceptance_criterion=acceptance_criterion_instance,
456
+ selection_strategy=selection_strategy,
457
+ use_cloudpickle=use_cloudpickle,
458
+ evaluation_cache=evaluation_cache,
459
+ )
460
+
461
+ with experiment_tracker:
462
+ if isinstance(logger, Logger):
463
+ with logger:
464
+ state = engine.run()
465
+ else:
466
+ state = engine.run()
467
+
468
+ return GEPAResult.from_state(state, run_dir=run_dir, seed=seed)
File without changes