agentevolve-optimizer 0.5.0__py3-none-any.whl

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 (414) hide show
  1. agent_evolve/__init__.py +722 -0
  2. agent_evolve/agentic.py +2800 -0
  3. agent_evolve/api.py +767 -0
  4. agent_evolve/application/__init__.py +1580 -0
  5. agent_evolve/application/action_allocation.py +744 -0
  6. agent_evolve/application/action_allocation_frame.py +347 -0
  7. agent_evolve/application/action_allocation_frame_commit.py +185 -0
  8. agent_evolve/application/action_allocation_frame_commit_v3.py +184 -0
  9. agent_evolve/application/action_allocation_frame_v3.py +338 -0
  10. agent_evolve/application/action_archive_value.py +497 -0
  11. agent_evolve/application/action_evidence_consistency.py +455 -0
  12. agent_evolve/application/action_forecast_partitioning.py +1471 -0
  13. agent_evolve/application/action_metric_projection.py +211 -0
  14. agent_evolve/application/action_role_value.py +680 -0
  15. agent_evolve/application/action_score_authorities.py +363 -0
  16. agent_evolve/application/action_structural_signature.py +116 -0
  17. agent_evolve/application/action_target_realization.py +402 -0
  18. agent_evolve/application/agentic_evolution.py +7734 -0
  19. agent_evolve/application/agentic_portfolio_residual_expert.py +835 -0
  20. agent_evolve/application/anchor_residual_identification.py +463 -0
  21. agent_evolve/application/archive_conditioned_action_target.py +208 -0
  22. agent_evolve/application/artifact_journal.py +246 -0
  23. agent_evolve/application/artifact_replay.py +347 -0
  24. agent_evolve/application/budgeted_optimizer.py +1828 -0
  25. agent_evolve/application/calibrated_campaign.py +485 -0
  26. agent_evolve/application/calibrated_current_prefix_forecast_opportunity.py +322 -0
  27. agent_evolve/application/calibrated_positive_gain_opportunity.py +1581 -0
  28. agent_evolve/application/campaign_capacity_recourse.py +254 -0
  29. agent_evolve/application/campaign_contextual_outcomes.py +119 -0
  30. agent_evolve/application/campaign_diagnostic_blocks.py +930 -0
  31. agent_evolve/application/campaign_evidence_registry.py +262 -0
  32. agent_evolve/application/campaign_execution.py +2537 -0
  33. agent_evolve/application/campaign_generation_audit.py +942 -0
  34. agent_evolve/application/campaign_learning.py +1812 -0
  35. agent_evolve/application/campaign_learning_runtime.py +1977 -0
  36. agent_evolve/application/campaign_search_phase.py +227 -0
  37. agent_evolve/application/campaign_selector_context_extension.py +220 -0
  38. agent_evolve/application/campaign_variation_envelope.py +649 -0
  39. agent_evolve/application/campaign_variation_trace.py +451 -0
  40. agent_evolve/application/candidate_archive_consequence.py +128 -0
  41. agent_evolve/application/causal_opportunity_portfolio_gate.py +385 -0
  42. agent_evolve/application/composite_outcome_updater.py +145 -0
  43. agent_evolve/application/composition_portfolio_selection.py +363 -0
  44. agent_evolve/application/concurrent_stage.py +144 -0
  45. agent_evolve/application/contextual_action_allocation.py +181 -0
  46. agent_evolve/application/contextual_campaign_outcomes.py +267 -0
  47. agent_evolve/application/contextual_campaign_planning.py +1366 -0
  48. agent_evolve/application/contextual_delayed_credit.py +651 -0
  49. agent_evolve/application/contextual_search_controller.py +2374 -0
  50. agent_evolve/application/current_prefix_forecast_opportunity.py +714 -0
  51. agent_evolve/application/decision_metric_projection.py +112 -0
  52. agent_evolve/application/derived_action_semantics.py +129 -0
  53. agent_evolve/application/detailed_evaluation.py +449 -0
  54. agent_evolve/application/earned_lineage.py +1011 -0
  55. agent_evolve/application/effective_choice_audit.py +484 -0
  56. agent_evolve/application/empirical_consequence_calibration.py +908 -0
  57. agent_evolve/application/evaluation_accounting.py +325 -0
  58. agent_evolve/application/evaluation_cache.py +199 -0
  59. agent_evolve/application/evaluation_escrow.py +547 -0
  60. agent_evolve/application/evaluation_recourse.py +253 -0
  61. agent_evolve/application/event_recorder.py +151 -0
  62. agent_evolve/application/evolution_campaign.py +1840 -0
  63. agent_evolve/application/executable_hypothesis.py +323 -0
  64. agent_evolve/application/factorial_branch_pilot.py +772 -0
  65. agent_evolve/application/finite_acquisition_capacity_recourse.py +672 -0
  66. agent_evolve/application/finite_acquisition_residual_expert.py +373 -0
  67. agent_evolve/application/finite_acquisition_variation_envelope.py +802 -0
  68. agent_evolve/application/finite_action_hypothesis_semantics.py +446 -0
  69. agent_evolve/application/finite_action_selection.py +188 -0
  70. agent_evolve/application/finite_action_set.py +306 -0
  71. agent_evolve/application/finite_action_transition.py +537 -0
  72. agent_evolve/application/finite_variation_eligibility.py +296 -0
  73. agent_evolve/application/forecast_geometry_portfolio.py +799 -0
  74. agent_evolve/application/forecast_opportunity_shadow_calibration.py +316 -0
  75. agent_evolve/application/front_proximity_admission.py +311 -0
  76. agent_evolve/application/front_proximity_parent_basis.py +458 -0
  77. agent_evolve/application/frozen_hurdle_score.py +659 -0
  78. agent_evolve/application/g3_causal_screen.py +2257 -0
  79. agent_evolve/application/g3_causal_validation.py +1046 -0
  80. agent_evolve/application/g3_postseal_curation.py +818 -0
  81. agent_evolve/application/gated_agentic_generator.py +205 -0
  82. agent_evolve/application/generation_feedback.py +293 -0
  83. agent_evolve/application/generative_proposal_journal.py +185 -0
  84. agent_evolve/application/geometry_conditional_elasticity.py +453 -0
  85. agent_evolve/application/global_wave_action_allocation.py +1151 -0
  86. agent_evolve/application/head_mass_conditional_seat.py +268 -0
  87. agent_evolve/application/identifiable_reflection_evidence.py +1147 -0
  88. agent_evolve/application/identifiable_reflection_learning.py +395 -0
  89. agent_evolve/application/identifiable_reflection_request.py +364 -0
  90. agent_evolve/application/in_memory_residual_archive.py +341 -0
  91. agent_evolve/application/insight_memory.py +1804 -0
  92. agent_evolve/application/live_runtime_manifest.py +758 -0
  93. agent_evolve/application/llm_task_queue.py +769 -0
  94. agent_evolve/application/matched_finite_action_block.py +409 -0
  95. agent_evolve/application/materialized_action_broker.py +2328 -0
  96. agent_evolve/application/materialized_action_constraints.py +83 -0
  97. agent_evolve/application/materialized_variation.py +211 -0
  98. agent_evolve/application/multi_option_evolution.py +1536 -0
  99. agent_evolve/application/outcome_adaptive_action_racing.py +2827 -0
  100. agent_evolve/application/outcome_adaptive_residual_campaign_runtime.py +580 -0
  101. agent_evolve/application/outcome_adaptive_residual_portfolio_evolution.py +3671 -0
  102. agent_evolve/application/outcome_conditioned_portfolio_selection.py +1374 -0
  103. agent_evolve/application/outcome_relation.py +193 -0
  104. agent_evolve/application/paired_allocation_comparison.py +241 -0
  105. agent_evolve/application/paired_block_schedule.py +127 -0
  106. agent_evolve/application/parent_measurement.py +226 -0
  107. agent_evolve/application/pareto_archive.py +811 -0
  108. agent_evolve/application/portfolio_campaign_runtime.py +4739 -0
  109. agent_evolve/application/portfolio_evolution.py +2950 -0
  110. agent_evolve/application/portfolio_hypothesis_observations.py +814 -0
  111. agent_evolve/application/portfolio_memory_attribution.py +581 -0
  112. agent_evolve/application/portfolio_memory_dose.py +788 -0
  113. agent_evolve/application/portfolio_memory_matched_control.py +938 -0
  114. agent_evolve/application/portfolio_memory_transfer.py +297 -0
  115. agent_evolve/application/portfolio_optimization_memory.py +363 -0
  116. agent_evolve/application/portfolio_outcome_feedback.py +1613 -0
  117. agent_evolve/application/portfolio_projection.py +335 -0
  118. agent_evolve/application/portfolio_recombination.py +2032 -0
  119. agent_evolve/application/post_evolution_reflection.py +834 -0
  120. agent_evolve/application/postcommit_rank_authority.py +245 -0
  121. agent_evolve/application/precommitted_portfolio_racing.py +2762 -0
  122. agent_evolve/application/prequential_archive_opportunity_calibration.py +1154 -0
  123. agent_evolve/application/prequential_residual_exploration.py +343 -0
  124. agent_evolve/application/prequential_score_portfolio.py +954 -0
  125. agent_evolve/application/projections.py +292 -0
  126. agent_evolve/application/protected_action_committee.py +1027 -0
  127. agent_evolve/application/protected_branch_pilot.py +376 -0
  128. agent_evolve/application/protected_current_prefix_forecast_opportunity.py +552 -0
  129. agent_evolve/application/provider_replay.py +910 -0
  130. agent_evolve/application/rank_balanced_causal_pilot.py +1372 -0
  131. agent_evolve/application/recombination_residual_expert.py +403 -0
  132. agent_evolve/application/reflection_workflow.py +571 -0
  133. agent_evolve/application/region_conditional_credit.py +911 -0
  134. agent_evolve/application/residual_campaign_runtime.py +531 -0
  135. agent_evolve/application/residual_headroom_campaign_runtime.py +459 -0
  136. agent_evolve/application/residual_headroom_ledger.py +1544 -0
  137. agent_evolve/application/residual_learning_transaction.py +396 -0
  138. agent_evolve/application/residual_portfolio_evolution.py +1228 -0
  139. agent_evolve/application/residual_reachability.py +749 -0
  140. agent_evolve/application/residual_stage_credit.py +499 -0
  141. agent_evolve/application/same_prefix_paired_audit.py +1580 -0
  142. agent_evolve/application/semantic_coverage_score_portfolio.py +838 -0
  143. agent_evolve/application/sequential_lineage_allocation.py +1017 -0
  144. agent_evolve/application/sequential_market_replay.py +1395 -0
  145. agent_evolve/application/sequential_residual_campaign_runtime.py +305 -0
  146. agent_evolve/application/sequential_residual_portfolio_evolution.py +940 -0
  147. agent_evolve/application/single_score_action_allocation.py +299 -0
  148. agent_evolve/application/source_exposure_allocation.py +906 -0
  149. agent_evolve/application/staged_memory.py +210 -0
  150. agent_evolve/application/stratified_cold_start_allocation.py +732 -0
  151. agent_evolve/application/support_guarded_hurdle_score.py +549 -0
  152. agent_evolve/application/target_conditioned_action_forecast.py +595 -0
  153. agent_evolve/application/target_conditioned_campaign.py +566 -0
  154. agent_evolve/application/treatment_assignment.py +201 -0
  155. agent_evolve/application/trusted_objective_evidence.py +217 -0
  156. agent_evolve/application/two_stage_action_evolution.py +1131 -0
  157. agent_evolve/application/v8lite_allocation_policy.py +1083 -0
  158. agent_evolve/application/v9_candidate_policy.py +1303 -0
  159. agent_evolve/bootstrap.py +108 -0
  160. agent_evolve/campaign_presets.py +517 -0
  161. agent_evolve/campaign_profiles.py +452 -0
  162. agent_evolve/campaign_variation_topology.py +288 -0
  163. agent_evolve/campaign_workload.py +950 -0
  164. agent_evolve/cli.py +797 -0
  165. agent_evolve/contract.py +241 -0
  166. agent_evolve/core/__init__.py +91 -0
  167. agent_evolve/core/action_semantics.py +411 -0
  168. agent_evolve/core/authored.py +105 -0
  169. agent_evolve/core/formatting.py +286 -0
  170. agent_evolve/core/optimization_semantics.py +324 -0
  171. agent_evolve/core/problem.py +167 -0
  172. agent_evolve/core/results.py +323 -0
  173. agent_evolve/core/stats.py +70 -0
  174. agent_evolve/core/telemetry.py +100 -0
  175. agent_evolve/domain/__init__.py +89 -0
  176. agent_evolve/domain/artifact.py +162 -0
  177. agent_evolve/domain/durable_text.py +68 -0
  178. agent_evolve/domain/event.py +1454 -0
  179. agent_evolve/domain/finite_action_set.py +426 -0
  180. agent_evolve/domain/finite_variation.py +526 -0
  181. agent_evolve/domain/generative_emission.py +559 -0
  182. agent_evolve/domain/ids.py +163 -0
  183. agent_evolve/domain/inline_text.py +106 -0
  184. agent_evolve/domain/insight.py +27 -0
  185. agent_evolve/domain/lineage.py +737 -0
  186. agent_evolve/domain/llm_task_queue.py +960 -0
  187. agent_evolve/domain/outcome.py +96 -0
  188. agent_evolve/domain/patch.py +854 -0
  189. agent_evolve/domain/typed_json.py +542 -0
  190. agent_evolve/domain/variation_space.py +158 -0
  191. agent_evolve/driver.py +1014 -0
  192. agent_evolve/harness/__init__.py +29 -0
  193. agent_evolve/harness/base.py +242 -0
  194. agent_evolve/harness/directives.py +163 -0
  195. agent_evolve/harness/generative_seal.py +479 -0
  196. agent_evolve/harness/registry.py +41 -0
  197. agent_evolve/infrastructure/__init__.py +39 -0
  198. agent_evolve/infrastructure/artifacts/__init__.py +6 -0
  199. agent_evolve/infrastructure/artifacts/_verification.py +67 -0
  200. agent_evolve/infrastructure/artifacts/filesystem.py +343 -0
  201. agent_evolve/infrastructure/artifacts/in_memory.py +73 -0
  202. agent_evolve/infrastructure/asyncio_runtime.py +109 -0
  203. agent_evolve/infrastructure/authored_runtime.py +188 -0
  204. agent_evolve/infrastructure/authored_worker.py +171 -0
  205. agent_evolve/infrastructure/clock.py +53 -0
  206. agent_evolve/infrastructure/events/__init__.py +6 -0
  207. agent_evolve/infrastructure/events/_validation.py +89 -0
  208. agent_evolve/infrastructure/events/in_memory.py +56 -0
  209. agent_evolve/infrastructure/events/jsonl.py +193 -0
  210. agent_evolve/infrastructure/exception_provenance.py +215 -0
  211. agent_evolve/infrastructure/ids.py +118 -0
  212. agent_evolve/infrastructure/lineage_codec.py +1836 -0
  213. agent_evolve/infrastructure/outcome_adaptive_phase_journal.py +170 -0
  214. agent_evolve/infrastructure/residual_headroom_journal.py +221 -0
  215. agent_evolve/infrastructure/resource_lease.py +370 -0
  216. agent_evolve/infrastructure/sanitization/__init__.py +8 -0
  217. agent_evolve/infrastructure/sanitization/strict_json.py +484 -0
  218. agent_evolve/infrastructure/sequential_phase_journal.py +170 -0
  219. agent_evolve/infrastructure/stream_liveness.py +383 -0
  220. agent_evolve/infrastructure/subprocess_boundary.py +136 -0
  221. agent_evolve/integrations/__init__.py +1 -0
  222. agent_evolve/integrations/botorch/__init__.py +28 -0
  223. agent_evolve/integrations/botorch/finite_qlognehvi.py +190 -0
  224. agent_evolve/integrations/botorch/finite_qlognehvi_batch.py +155 -0
  225. agent_evolve/integrations/botorch/finite_qlognehvi_batch_identity.py +20 -0
  226. agent_evolve/integrations/botorch/finite_qlognehvi_batch_worker.py +55 -0
  227. agent_evolve/integrations/botorch/finite_qlognehvi_identity.py +22 -0
  228. agent_evolve/integrations/botorch/finite_qlognehvi_worker.py +55 -0
  229. agent_evolve/integrations/botorch/subprocess_qlognehvi.py +261 -0
  230. agent_evolve/integrations/botorch/subprocess_qlognehvi_batch.py +273 -0
  231. agent_evolve/integrations/completion.py +242 -0
  232. agent_evolve/integrations/pydantic_ai/__init__.py +441 -0
  233. agent_evolve/integrations/pydantic_ai/action_forecast.py +1068 -0
  234. agent_evolve/integrations/pydantic_ai/agentic_generator.py +2308 -0
  235. agent_evolve/integrations/pydantic_ai/async_generator.py +1604 -0
  236. agent_evolve/integrations/pydantic_ai/boundary_codec.py +1526 -0
  237. agent_evolve/integrations/pydantic_ai/calibrated_portfolio_campaign.py +756 -0
  238. agent_evolve/integrations/pydantic_ai/calibrated_portfolio_selection.py +7537 -0
  239. agent_evolve/integrations/pydantic_ai/campaign_acquisition.py +609 -0
  240. agent_evolve/integrations/pydantic_ai/execution_binding.py +138 -0
  241. agent_evolve/integrations/pydantic_ai/forecast_geometry_action_committee.py +217 -0
  242. agent_evolve/integrations/pydantic_ai/harness.py +159 -0
  243. agent_evolve/integrations/pydantic_ai/heterogeneous_model_execution.py +306 -0
  244. agent_evolve/integrations/pydantic_ai/hierarchical_residual_adaptive_semantic_view.py +179 -0
  245. agent_evolve/integrations/pydantic_ai/json_schema_dialect.py +108 -0
  246. agent_evolve/integrations/pydantic_ai/materialized_hierarchical_residual_expert.py +952 -0
  247. agent_evolve/integrations/pydantic_ai/materialized_portfolio_judge.py +520 -0
  248. agent_evolve/integrations/pydantic_ai/model_execution_profile.py +659 -0
  249. agent_evolve/integrations/pydantic_ai/outbound_request_manifest.py +1170 -0
  250. agent_evolve/integrations/pydantic_ai/portable_residual_consequence_features.py +575 -0
  251. agent_evolve/integrations/pydantic_ai/portfolio_selection.py +422 -0
  252. agent_evolve/integrations/pydantic_ai/progress_aware_openrouter.py +416 -0
  253. agent_evolve/integrations/pydantic_ai/provider_attempt_join.py +1523 -0
  254. agent_evolve/integrations/pydantic_ai/provider_free_calibrated_runner.py +607 -0
  255. agent_evolve/integrations/pydantic_ai/queued_runner.py +2634 -0
  256. agent_evolve/integrations/pydantic_ai/reconciled_residual_reachability.py +1417 -0
  257. agent_evolve/integrations/pydantic_ai/residual_forecast_geometry.py +445 -0
  258. agent_evolve/integrations/pydantic_ai/residual_reachability.py +674 -0
  259. agent_evolve/integrations/pydantic_ai/residual_semantic_cells.py +239 -0
  260. agent_evolve/integrations/pydantic_ai/sealed_output_replay.py +1068 -0
  261. agent_evolve/integrations/pydantic_ai/semantic_coverage_residual_portfolio.py +770 -0
  262. agent_evolve/integrations/pydantic_ai/semantic_decision_replay.py +383 -0
  263. agent_evolve/integrations/pydantic_ai/support_adaptive_residual_portfolio.py +135 -0
  264. agent_evolve/integrations/pydantic_ai/trusted_residual_prompt_context.py +143 -0
  265. agent_evolve/integrations/pydantic_ai/validated_openrouter_model.py +107 -0
  266. agent_evolve/integrations/pymoo_adapter.py +242 -0
  267. agent_evolve/policies/__init__.py +17 -0
  268. agent_evolve/policies/check.py +469 -0
  269. agent_evolve/policies/emit_scaffold.py +451 -0
  270. agent_evolve/policies/feedback/__init__.py +37 -0
  271. agent_evolve/policies/feedback/held_out_asn.py +1325 -0
  272. agent_evolve/policies/genetic.py +607 -0
  273. agent_evolve/policies/llm_backoff.py +183 -0
  274. agent_evolve/policies/llm_chooser.py +226 -0
  275. agent_evolve/policies/llm_generator.py +1760 -0
  276. agent_evolve/policies/llm_init.py +267 -0
  277. agent_evolve/policies/llm_operator.py +109 -0
  278. agent_evolve/policies/llm_prior.py +194 -0
  279. agent_evolve/policies/llm_surrogate.py +334 -0
  280. agent_evolve/policies/measurement_evidence.py +704 -0
  281. agent_evolve/policies/memory/__init__.py +223 -0
  282. agent_evolve/policies/memory/balanced_subset_blocks.py +707 -0
  283. agent_evolve/policies/memory/compatibility_matching.py +593 -0
  284. agent_evolve/policies/memory/global_falsification.py +1841 -0
  285. agent_evolve/policies/memory/prompt_shape.py +503 -0
  286. agent_evolve/policies/memory/randomized_subset.py +714 -0
  287. agent_evolve/policies/memory/staged_causal.py +1270 -0
  288. agent_evolve/policies/memory/treatment_compliance.py +759 -0
  289. agent_evolve/policies/objective_resolution/__init__.py +17 -0
  290. agent_evolve/policies/objective_resolution/fixed_grid.py +364 -0
  291. agent_evolve/policies/operator_portfolio.py +407 -0
  292. agent_evolve/policies/reguidance.py +1133 -0
  293. agent_evolve/policies/reward/__init__.py +83 -0
  294. agent_evolve/policies/reward/affine_candidate_consequence.py +156 -0
  295. agent_evolve/policies/reward/affine_candidate_consequence_3d.py +159 -0
  296. agent_evolve/policies/reward/affine_hypervolume.py +490 -0
  297. agent_evolve/policies/reward/affine_hypervolume_3d.py +567 -0
  298. agent_evolve/policies/reward/contextual_marginal_utility.py +318 -0
  299. agent_evolve/policies/reward/frozen_archive.py +360 -0
  300. agent_evolve/policies/reward/frozen_wave_archive.py +368 -0
  301. agent_evolve/policies/search_state.py +208 -0
  302. agent_evolve/policies/selection/__init__.py +345 -0
  303. agent_evolve/policies/selection/acquisition_certified_slate.py +684 -0
  304. agent_evolve/policies/selection/affine_frontier_context.py +330 -0
  305. agent_evolve/policies/selection/affine_frontier_target.py +473 -0
  306. agent_evolve/policies/selection/archive_elite.py +1346 -0
  307. agent_evolve/policies/selection/calibrated_portfolio_binding.py +640 -0
  308. agent_evolve/policies/selection/calibrated_slate.py +1394 -0
  309. agent_evolve/policies/selection/calibrated_slate_codec.py +579 -0
  310. agent_evolve/policies/selection/common_candidate_pool.py +685 -0
  311. agent_evolve/policies/selection/diagnostic_sampling.py +319 -0
  312. agent_evolve/policies/selection/disjoint_pairs.py +479 -0
  313. agent_evolve/policies/selection/elite_explorer.py +719 -0
  314. agent_evolve/policies/selection/finite_action.py +187 -0
  315. agent_evolve/policies/selection/finite_option_prompt_projection.py +377 -0
  316. agent_evolve/policies/selection/finite_palette_evidence.py +247 -0
  317. agent_evolve/policies/selection/forecast_calibration.py +922 -0
  318. agent_evolve/policies/selection/frontier_probe_slate.py +814 -0
  319. agent_evolve/policies/selection/frozen_archive_pairs.py +762 -0
  320. agent_evolve/policies/selection/full_support_slate.py +91 -0
  321. agent_evolve/policies/selection/meaningful_direction.py +240 -0
  322. agent_evolve/policies/selection/memory_dose_feasibility.py +259 -0
  323. agent_evolve/policies/selection/model_anchored_slate.py +826 -0
  324. agent_evolve/policies/selection/phenotype_recourse.py +979 -0
  325. agent_evolve/policies/selection/proposal_support.py +368 -0
  326. agent_evolve/policies/selection/random_portfolio.py +254 -0
  327. agent_evolve/policies/selection/regret_bounded_slate.py +1084 -0
  328. agent_evolve/policies/selection/residual_frontier.py +463 -0
  329. agent_evolve/policies/selection/residual_frontier_target.py +605 -0
  330. agent_evolve/policies/selection/structural_posterior_slate.py +1571 -0
  331. agent_evolve/policies/selection/target_conditioned_allocator.py +648 -0
  332. agent_evolve/policies/selection/target_conditioned_features.py +812 -0
  333. agent_evolve/policies/selection/target_conditioned_prequential.py +1527 -0
  334. agent_evolve/policies/selection/task_keyed_palette.py +906 -0
  335. agent_evolve/policies/semantics.py +147 -0
  336. agent_evolve/policies/structure.py +362 -0
  337. agent_evolve/policies/structured_output_budget.py +62 -0
  338. agent_evolve/policies/surrogate.py +696 -0
  339. agent_evolve/policies/variation/__init__.py +1 -0
  340. agent_evolve/policies/variation/compositional_finite_catalog.py +426 -0
  341. agent_evolve/policies/variation/crossover_inheritance.py +575 -0
  342. agent_evolve/policies/variation/disjoint_recombination.py +611 -0
  343. agent_evolve/policies/variation/exact_composition_capacity.py +214 -0
  344. agent_evolve/policies/variation/exact_parent_crossover.py +950 -0
  345. agent_evolve/policies/variation/multiscale_restart_catalog.py +372 -0
  346. agent_evolve/policies/variation/source_union_finite_catalog.py +403 -0
  347. agent_evolve/policies/variation/typed_patch.py +1981 -0
  348. agent_evolve/policies/weighted_prior.py +394 -0
  349. agent_evolve/ports/__init__.py +383 -0
  350. agent_evolve/ports/action_allocation.py +733 -0
  351. agent_evolve/ports/action_allocation_frame.py +1153 -0
  352. agent_evolve/ports/action_allocation_frame_commit.py +294 -0
  353. agent_evolve/ports/action_allocation_frame_commit_v3.py +432 -0
  354. agent_evolve/ports/action_allocation_frame_v3.py +995 -0
  355. agent_evolve/ports/action_forecast.py +1568 -0
  356. agent_evolve/ports/action_metric_projection.py +165 -0
  357. agent_evolve/ports/agentic_generator.py +1561 -0
  358. agent_evolve/ports/archive_context.py +136 -0
  359. agent_evolve/ports/artifact_sanitizer.py +44 -0
  360. agent_evolve/ports/artifact_store.py +225 -0
  361. agent_evolve/ports/clock.py +13 -0
  362. agent_evolve/ports/contextual_search_allocation.py +827 -0
  363. agent_evolve/ports/decision_metric_projection.py +258 -0
  364. agent_evolve/ports/event_store.py +55 -0
  365. agent_evolve/ports/executable_hypothesis.py +557 -0
  366. agent_evolve/ports/finite_acquisition.py +377 -0
  367. agent_evolve/ports/finite_acquisition_batch.py +296 -0
  368. agent_evolve/ports/finite_acquisition_batch_json.py +164 -0
  369. agent_evolve/ports/finite_acquisition_json.py +247 -0
  370. agent_evolve/ports/finite_acquisition_space.py +168 -0
  371. agent_evolve/ports/finite_action_selection.py +348 -0
  372. agent_evolve/ports/finite_action_set.py +256 -0
  373. agent_evolve/ports/frontier_target.py +396 -0
  374. agent_evolve/ports/generation_failure.py +43 -0
  375. agent_evolve/ports/hard_feasibility.py +233 -0
  376. agent_evolve/ports/id_factory.py +34 -0
  377. agent_evolve/ports/llm_task_queue.py +93 -0
  378. agent_evolve/ports/objective_resolution.py +419 -0
  379. agent_evolve/ports/paired_allocation_comparison.py +401 -0
  380. agent_evolve/ports/paired_block_schedule.py +475 -0
  381. agent_evolve/ports/parent_measurement.py +336 -0
  382. agent_evolve/ports/portfolio_memory_dose.py +643 -0
  383. agent_evolve/ports/portfolio_selection.py +3169 -0
  384. agent_evolve/ports/postcommit_rank_authority.py +467 -0
  385. agent_evolve/ports/presented_action_evidence.py +794 -0
  386. agent_evolve/ports/resource_lease.py +162 -0
  387. agent_evolve/ports/structured_generator.py +734 -0
  388. agent_evolve/ports/structured_output_budget.py +120 -0
  389. agent_evolve/ports/subprocess_boundary.py +138 -0
  390. agent_evolve/ports/treatment_assignment.py +466 -0
  391. agent_evolve/ports/variation_catalog.py +76 -0
  392. agent_evolve/ports/variation_source.py +226 -0
  393. agent_evolve/proposal_mode.py +157 -0
  394. agent_evolve/proposers/__init__.py +10 -0
  395. agent_evolve/proposers/random_proposer.py +188 -0
  396. agent_evolve/provider_accounting.py +163 -0
  397. agent_evolve/py.typed +0 -0
  398. agent_evolve/reference_method.py +1570 -0
  399. agent_evolve/session/__init__.py +11 -0
  400. agent_evolve/session/authorship.py +864 -0
  401. agent_evolve/session/evaluate.py +236 -0
  402. agent_evolve/session/fidelity.py +237 -0
  403. agent_evolve/session/genetic_loop.py +742 -0
  404. agent_evolve/session/loop.py +803 -0
  405. agent_evolve/session/screening.py +671 -0
  406. agent_evolve/settings.py +376 -0
  407. agent_evolve/workload_kit.py +368 -0
  408. agent_evolve/workload_prompt.py +398 -0
  409. agentevolve_optimizer-0.5.0.dist-info/METADATA +599 -0
  410. agentevolve_optimizer-0.5.0.dist-info/RECORD +414 -0
  411. agentevolve_optimizer-0.5.0.dist-info/WHEEL +5 -0
  412. agentevolve_optimizer-0.5.0.dist-info/entry_points.txt +2 -0
  413. agentevolve_optimizer-0.5.0.dist-info/licenses/LICENSE +21 -0
  414. agentevolve_optimizer-0.5.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1570 @@
1
+ """One authenticated AgentEvolve successor method across workloads and models.
2
+
3
+ Workload adapters provide evaluators, finite catalogs, objective semantics, and
4
+ optional semantic prompt extensions. They must not silently choose different
5
+ optimizer policies. This module owns the public identities of the reference
6
+ parent-selection, memory, acquisition, recombination, and reflection policies,
7
+ then binds workload-local runtime objects behind those identities.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import hashlib
13
+ import json
14
+ from dataclasses import dataclass, replace
15
+ from enum import Enum
16
+
17
+ from agent_evolve.application.evolution_campaign import (
18
+ CampaignPolicyBinding,
19
+ CampaignReflectionSupervisionPolicy,
20
+ ReflectionFailureMode,
21
+ )
22
+ from agent_evolve.application.portfolio_campaign_runtime import (
23
+ ResidualHypervolumeCampaignParentSelector,
24
+ StagnationAwareDiverseCampaignParentSelector,
25
+ )
26
+ from agent_evolve.application.contextual_search_controller import (
27
+ CONTEXTUAL_SEARCH_CONTROLLER_DEFINITION_SHA256,
28
+ )
29
+ from agent_evolve.application.contextual_delayed_credit import (
30
+ CONTEXTUAL_DELAYED_CREDIT_DEFINITION_SHA256,
31
+ )
32
+ from agent_evolve.campaign_presets import (
33
+ REFERENCE_36_OFFSPRING_SCALE_SHAPE,
34
+ PortfolioScaleShape,
35
+ )
36
+ from agent_evolve.campaign_profiles import CampaignExperimentProfile
37
+ from agent_evolve.integrations.pydantic_ai.model_execution_profile import (
38
+ OpenRouterModelExecutionProfile,
39
+ )
40
+ from agent_evolve.integrations.pydantic_ai.calibrated_portfolio_selection import (
41
+ CONTEXTUAL_SEARCH_ALLOCATION_PORTFOLIO_SELECTION_POLICY_DEFINITION_SHA256,
42
+ )
43
+ from agent_evolve.policies.selection.structural_posterior_slate import (
44
+ HorizonBoundedStructuralPosteriorSlatePolicy,
45
+ OperatorStratifiedStructuralPosteriorSlatePolicy,
46
+ )
47
+ from agent_evolve.policies.selection.target_conditioned_allocator import (
48
+ TargetConditionedSlateAllocatorAdapter,
49
+ )
50
+ from agent_evolve.policies.selection.affine_frontier_target import (
51
+ ALLOCATOR_DEFINITION_SHA256 as AFFINE_FRONTIER_TARGET_DEFINITION_SHA256,
52
+ DIRECTION_COVERED_ALLOCATOR_DEFINITION_SHA256,
53
+ )
54
+ from agent_evolve.policies.selection.residual_frontier_target import (
55
+ RESIDUAL_TARGET_ALLOCATOR_DEFINITION_SHA256,
56
+ )
57
+ from agent_evolve.ports.archive_context import (
58
+ CampaignPortfolioArchiveContextProjector,
59
+ )
60
+ from agent_evolve.workload_prompt import WorkloadPromptArm
61
+
62
+
63
+ REFERENCE_AGENT_EVOLVE_METHOD_ID = "agent_evolve_reference_successor"
64
+ REFERENCE_AGENT_EVOLVE_METHOD_VERSION = 2
65
+ HIERARCHICAL_AGENT_EVOLVE_METHOD_ID = "agent_evolve_hierarchical_successor"
66
+ HIERARCHICAL_AGENT_EVOLVE_METHOD_VERSION = 3
67
+ FRONTIER_AGENT_EVOLVE_METHOD_ID = "agent_evolve_frontier_successor"
68
+ FRONTIER_AGENT_EVOLVE_METHOD_VERSION = 3
69
+ FRONTIER_HIERARCHICAL_AGENT_EVOLVE_METHOD_ID = (
70
+ "agent_evolve_frontier_hierarchical_successor"
71
+ )
72
+ FRONTIER_HIERARCHICAL_AGENT_EVOLVE_METHOD_VERSION = 4
73
+ CONTEXT_LOCAL_AGENT_EVOLVE_METHOD_ID = "agent_evolve_context_local_successor"
74
+ CONTEXT_LOCAL_AGENT_EVOLVE_METHOD_VERSION = 5
75
+ OPERATOR_STRATIFIED_AGENT_EVOLVE_METHOD_ID = (
76
+ "agent_evolve_operator_stratified_successor"
77
+ )
78
+ OPERATOR_STRATIFIED_AGENT_EVOLVE_METHOD_VERSION = 6
79
+ HORIZON_BOUNDED_AGENT_EVOLVE_METHOD_ID = "agent_evolve_horizon_bounded_successor"
80
+ HORIZON_BOUNDED_AGENT_EVOLVE_METHOD_VERSION = 7
81
+ STAGNATION_AWARE_AGENT_EVOLVE_METHOD_ID = "agent_evolve_stagnation_aware_successor"
82
+ STAGNATION_AWARE_AGENT_EVOLVE_METHOD_VERSION = 8
83
+ CONSTRAINT_DECOUPLED_AGENT_EVOLVE_METHOD_ID = (
84
+ "agent_evolve_constraint_decoupled_successor"
85
+ )
86
+ CONSTRAINT_DECOUPLED_AGENT_EVOLVE_METHOD_VERSION = 9
87
+ MINIMUM_INTERVENTION_AGENT_EVOLVE_METHOD_ID = (
88
+ "agent_evolve_minimum_intervention_successor"
89
+ )
90
+ MINIMUM_INTERVENTION_AGENT_EVOLVE_METHOD_VERSION = 10
91
+ EVIDENCE_CALIBRATED_SOURCE_MIX_AGENT_EVOLVE_METHOD_ID = (
92
+ "agent_evolve_evidence_calibrated_source_mix_successor"
93
+ )
94
+ EVIDENCE_CALIBRATED_SOURCE_MIX_AGENT_EVOLVE_METHOD_VERSION = 11
95
+ CONTEXTUAL_SEARCH_AGENT_EVOLVE_METHOD_ID = "agent_evolve_contextual_search_successor"
96
+ CONTEXTUAL_SEARCH_AGENT_EVOLVE_METHOD_VERSION = 21
97
+ RESIDUAL_FRONTIER_AGENT_EVOLVE_METHOD_ID = (
98
+ "agent_evolve_residual_frontier_successor"
99
+ )
100
+ RESIDUAL_FRONTIER_AGENT_EVOLVE_METHOD_VERSION = 23
101
+ TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_ID = (
102
+ "agent_evolve_target_conditioned_successor"
103
+ )
104
+ TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_VERSION = 17
105
+ CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_ID = (
106
+ "agent_evolve_constraint_decoupled_target_conditioned_successor"
107
+ )
108
+ CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_VERSION = 19
109
+
110
+
111
+ class ReferenceCampaignPolicyRole(str, Enum):
112
+ """Closed optimizer-policy roles shared by every reference workload."""
113
+
114
+ PARENT_SELECTION = "parent_selection"
115
+ MEMORY_ASSIGNMENT = "memory_assignment"
116
+ PORTFOLIO_SELECTION = "portfolio_selection"
117
+ RECOMBINATION = "recombination"
118
+ REFLECTION = "reflection"
119
+ ARCHIVE_CONTEXT = "archive_context"
120
+ VARIATION_TOPOLOGY = "variation_topology"
121
+ CONTEXTUAL_OUTCOMES = "contextual_outcomes"
122
+
123
+
124
+ _POLICY_IDS = {
125
+ ReferenceCampaignPolicyRole.PARENT_SELECTION: (
126
+ "archive_elite_explorer_common",
127
+ b"agent-evolve:reference-parent-selection:v1;archive-elite-explorer",
128
+ ),
129
+ ReferenceCampaignPolicyRole.MEMORY_ASSIGNMENT: (
130
+ "parent_conditioned_predictive_memory",
131
+ b"agent-evolve:reference-memory:v2;authenticated-local-transition;"
132
+ b"quarantine;matched-active-neutral-diagnostics;no-unidentified-credit",
133
+ ),
134
+ ReferenceCampaignPolicyRole.PORTFOLIO_SELECTION: (
135
+ "complete_contract_model_k8_engine_k4",
136
+ b"agent-evolve:reference-acquisition:v2;task-keyed-complete-finite-contract;"
137
+ b"model-ranked-k8;engine-allocated-k4;hidden-feasibility-certificate",
138
+ ),
139
+ ReferenceCampaignPolicyRole.RECOMBINATION: (
140
+ "typed_disjoint_patch_union",
141
+ b"agent-evolve:reference-recombination:v1;archive-aware;typed-disjoint-union;"
142
+ b"infeasibility-recourse",
143
+ ),
144
+ ReferenceCampaignPolicyRole.REFLECTION: (
145
+ "delayed_identifiable_mutation_reflection",
146
+ b"agent-evolve:reference-reflection:v2;sealed-direct-single-mutation;"
147
+ b"delayed-quarantine;parent-conditioned-executable-semantics",
148
+ ),
149
+ }
150
+
151
+ _HIERARCHICAL_PORTFOLIO_POLICY = (
152
+ "hierarchical_support_structural_k8_engine_k4",
153
+ b"agent-evolve:reference-acquisition:v3;task-keyed-complete-finite-contract;"
154
+ b"model-ranked-k8;proposal-reservations=archive-novelty,structural-coverage;"
155
+ b"reservations-force-evaluator-slots=false;"
156
+ b"engine-allocator=calibrated-frontier-four-role-v2;"
157
+ b"hidden-feasibility-certificate=true",
158
+ )
159
+
160
+ _OPERATOR_STRATIFIED_PORTFOLIO_POLICY = (
161
+ "operator_stratified_hierarchical_k8_engine_k4",
162
+ b"agent-evolve:reference-acquisition:v4;task-keyed-complete-finite-contract;"
163
+ b"model-ranked-k8;hierarchical-r2-proposal-minimum=authenticated;"
164
+ b"engine-k4-composite-family-minimum=1;"
165
+ b"minimum-is-assay-exposure-not-quality-prior;"
166
+ b"remaining-slots=calibrated-frontier-four-role-v2;"
167
+ b"joint-feasibility-and-role-optimization=true;outcome-blind=true;"
168
+ b"hidden-feasibility-certificate=true;workload-specific-parameters=none",
169
+ )
170
+
171
+ _HORIZON_BOUNDED_PORTFOLIO_POLICY = (
172
+ "horizon_bounded_hierarchical_k8_engine_k4",
173
+ b"agent-evolve:reference-acquisition:v5;task-keyed-complete-finite-contract;"
174
+ b"model-ranked-k8;hierarchical-r2-proposal-minimum=authenticated;"
175
+ b"engine-k4-family-exposure-phases=authenticated;"
176
+ b"lower-and-upper-bounds=true;phase-index=sealed-wave-index;"
177
+ b"bounds-are-assay-exposure-not-quality-priors;"
178
+ b"infeasible-bounds=minimum-l1-structural-recourse;"
179
+ b"remaining-slots=calibrated-frontier-four-role-v2;"
180
+ b"joint-feasibility-and-role-optimization=true;outcome-blind=true;"
181
+ b"hidden-feasibility-certificate=true;workload-specific-parameters=none",
182
+ )
183
+
184
+ _CONSTRAINT_DECOUPLED_HORIZON_PORTFOLIO_POLICY = (
185
+ "constraint_decoupled_horizon_k8_engine_k4",
186
+ b"agent-evolve:reference-acquisition:v6;"
187
+ b"model-authority=local-finite-semantic-preferences;"
188
+ b"engine-authority=dedupe-support-composition-dose-feasibility-refill;"
189
+ b"original-and-reconciled-proposals-authenticated=true;"
190
+ b"engine-inserted-forecast=unknown;"
191
+ b"engine-k4-family-exposure-phases=authenticated;"
192
+ b"objective-values-consulted-by-reconciliation=false;"
193
+ b"workload-specific-parameters=none",
194
+ )
195
+
196
+ _TARGET_CONDITIONED_PORTFOLIO_POLICY = (
197
+ "target_conditioned_realizable_k8_engine_k4",
198
+ b"agent-evolve:reference-acquisition:v12;"
199
+ b"model-authority=finite-semantic-hypotheses;"
200
+ b"engine-authority=target-conditioned-prequential-realizable-allocation;"
201
+ b"context=append-only-authenticated-precall-branch;"
202
+ b"features=portable-typed-configuration-transitions;"
203
+ b"state=selected-only-generation-barrier;"
204
+ b"workload-model-provider-current-outcome-fields=false",
205
+ )
206
+
207
+ _CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_PORTFOLIO_POLICY = (
208
+ "constraint_decoupled_target_conditioned_k8_engine_k4",
209
+ b"agent-evolve:reference-acquisition:v14;"
210
+ b"model-authority=local-finite-semantic-hypotheses;"
211
+ b"engine-authority=dedupe-support-composition-dose-feasibility-refill;"
212
+ b"allocation=target-conditioned-prequential-realizable-portfolio-v1;"
213
+ b"evaluation-source-floor=sealed-contract-task-keyed;"
214
+ b"independent-evaluation-does-not-require-disjoint-parent-patches=true;"
215
+ b"original-and-reconciled-proposals-authenticated=true;"
216
+ b"engine-inserted-forecast=unknown;"
217
+ b"objective-values-consulted-by-reconciliation=false;"
218
+ b"workload-model-provider-specific-parameters=none;"
219
+ b"frontier-target="
220
+ + DIRECTION_COVERED_ALLOCATOR_DEFINITION_SHA256.encode("ascii"),
221
+ )
222
+
223
+ _MINIMUM_INTERVENTION_HORIZON_PORTFOLIO_POLICY = (
224
+ "minimum_intervention_horizon_k8_engine_k4",
225
+ b"agent-evolve:reference-acquisition:v7;"
226
+ b"model-authority=local-finite-semantic-hypotheses;"
227
+ b"engine-authority=dedupe-support-composition-dose-feasibility-refill;"
228
+ b"projection=max-retained-model-count-then-model-rank;"
229
+ b"canonical-order=final-tie-break-only;"
230
+ b"original-reconciled-and-intervention-receipts-authenticated=true;"
231
+ b"engine-inserted-forecast=unknown;"
232
+ b"engine-k4-family-exposure-phases=authenticated;"
233
+ b"objective-values-consulted-by-reconciliation=false;"
234
+ b"workload-specific-parameters=none",
235
+ )
236
+
237
+ _EVIDENCE_CALIBRATED_SOURCE_MIX_PORTFOLIO_POLICY = (
238
+ "evidence_calibrated_source_mix_horizon_k8_engine_k4",
239
+ b"agent-evolve:reference-acquisition:v8;"
240
+ b"model-authority=local-finite-semantic-hypotheses;"
241
+ b"engine-authority=feasibility-soft-support-source-floor-allocation;"
242
+ b"protected-source=task-keyed-global-feasibility-member;"
243
+ b"protected-source-count=one;protected-source-phase=wave-one;"
244
+ b"remaining-projection=max-retained-model-count-then-model-rank;"
245
+ b"proposal-support-conflicts=deterministically-deferred;"
246
+ b"required-allocation-membership-authenticated=true;"
247
+ b"engine-k4-family-exposure-phases=authenticated;"
248
+ b"objective-values-consulted-by-source-mix=false;"
249
+ b"workload-specific-parameters=none",
250
+ )
251
+
252
+ _CONTEXTUAL_SEARCH_PORTFOLIO_POLICY = (
253
+ "contextual_source_operator_horizon_k8_engine_k4",
254
+ b"agent-evolve:reference-acquisition:v12;"
255
+ b"model-authority=local-finite-semantic-hypotheses;"
256
+ b"engine-authority=feasibility-and-authenticated-contextual-allocation;"
257
+ b"allocation-marginals=sealed-finite-variation-source,atomic-vs-composite;"
258
+ b"semantic-model-vs-engine-origin=separate-provenance;"
259
+ b"allocation-evidence=prior-only-normalized-marginal-utility;"
260
+ b"allocation-phase=finite-horizon-generic;"
261
+ b"operator-envelope=full-k4-structurally-feasible-range;"
262
+ b"requested-allocation-exact-when-feasible=true;"
263
+ b"structural-recourse=authenticated-minimum-l1-projection;"
264
+ b"requested-and-realized-allocation-authenticated=true;"
265
+ b"allocation-capability=prior-realized-workload-blind-count-witnesses;"
266
+ b"frontier-target=coordinated-affine-opportunity-directions;"
267
+ b"realized-allocation-membership-authenticated=true;"
268
+ b"objective-values-consulted-by-reconciliation=false;"
269
+ b"workload-model-provider-specific-parameters=none;"
270
+ + CONTEXTUAL_SEARCH_CONTROLLER_DEFINITION_SHA256.encode("ascii")
271
+ + b";frontier-target="
272
+ + AFFINE_FRONTIER_TARGET_DEFINITION_SHA256.encode("ascii")
273
+ + b";selector="
274
+ + CONTEXTUAL_SEARCH_ALLOCATION_PORTFOLIO_SELECTION_POLICY_DEFINITION_SHA256.encode(
275
+ "ascii"
276
+ ),
277
+ )
278
+
279
+ _RESIDUAL_FRONTIER_CONTEXTUAL_SEARCH_PORTFOLIO_POLICY = (
280
+ "residual_frontier_contextual_source_operator_horizon_k8_engine_k4",
281
+ b"agent-evolve:reference-acquisition:v13;"
282
+ b"base=contextual-source-operator-horizon-k8-engine-k4;"
283
+ b"parent-and-target=joint-largest-positive-residual-hypervolume-cell;"
284
+ b"lane-directions=canonical-needed-improvement-axes;"
285
+ b"fallback=prior-stagnation-aware-plus-global-direction-coverage;"
286
+ b"objective-values=authenticated-prior-affine-archive-only;"
287
+ b"workload-model-provider-specific-parameters=none;"
288
+ + CONTEXTUAL_SEARCH_CONTROLLER_DEFINITION_SHA256.encode("ascii")
289
+ + b";frontier-target="
290
+ + RESIDUAL_TARGET_ALLOCATOR_DEFINITION_SHA256.encode("ascii")
291
+ + b";selector="
292
+ + CONTEXTUAL_SEARCH_ALLOCATION_PORTFOLIO_SELECTION_POLICY_DEFINITION_SHA256.encode(
293
+ "ascii"
294
+ ),
295
+ )
296
+
297
+ _CONTEXT_LOCAL_MEMORY_POLICY = (
298
+ "exact_context_predictive_memory",
299
+ b"agent-evolve:reference-memory:v3;authenticated-local-transition;"
300
+ b"exact-source-parent-forced-replay-only;nonexact-transfer-advisory;"
301
+ b"quarantine;no-unidentified-credit",
302
+ )
303
+ _ATOMIC_VARIATION_TOPOLOGY_POLICY = (
304
+ "parent_bound_atomic_finite_variation",
305
+ b"agent-evolve:reference-variation-topology:v1;complete-parent-bound-finite-"
306
+ b"atomic-support;engine-materialized;provider-cannot-invent-actions",
307
+ )
308
+ _HIERARCHICAL_R2_VARIATION_TOPOLOGY_POLICY_ID = (
309
+ "bounded_hierarchical_r2_finite_variation"
310
+ )
311
+ _HIERARCHICAL_R2_VARIATION_TOPOLOGY_DOMAIN = (
312
+ b"agent-evolve:reference-variation-topology:hierarchical-r2:v2\x00"
313
+ )
314
+ _CONTEXTUAL_OUTCOMES_POLICY = (
315
+ "parent_local_prior_outcome_history",
316
+ b"agent-evolve:reference-contextual-outcomes:v1;max-actions=24;prior-only;"
317
+ b"same-parent-first;direct-lineage-second;cross-lineage-excluded;"
318
+ b"observational-predictive-history-not-causal-credit",
319
+ )
320
+ _MULTI_HORIZON_CONTEXTUAL_OUTCOMES_POLICY = (
321
+ "multi_horizon_parent_local_outcomes",
322
+ b"agent-evolve:reference-contextual-outcomes:v2;max-actions=24;prior-only;"
323
+ b"same-parent-first;direct-lineage-second;cross-lineage-excluded;"
324
+ b"immediate=observational-predictive-history-not-causal-credit;"
325
+ b"post-recombination=stage-front-survival-and-selection-conditioned-"
326
+ b"descendant-yield;terminal=successful-final-front-membership;"
327
+ + CONTEXTUAL_DELAYED_CREDIT_DEFINITION_SHA256.encode("ascii"),
328
+ )
329
+
330
+
331
+ def _binding(
332
+ role: ReferenceCampaignPolicyRole,
333
+ implementation: object,
334
+ *,
335
+ hierarchical_proposal_support: bool = False,
336
+ context_local_memory: bool = False,
337
+ operator_stratified_acquisition: bool = False,
338
+ horizon_bounded_acquisition: bool = False,
339
+ target_conditioned_acquisition: bool = False,
340
+ constraint_decoupled_acquisition: bool = False,
341
+ minimum_intervention_projection: bool = False,
342
+ evidence_calibrated_source_mix: bool = False,
343
+ contextual_search_allocation: bool = False,
344
+ residual_frontier_planning: bool = False,
345
+ ) -> CampaignPolicyBinding:
346
+ if type(role) is not ReferenceCampaignPolicyRole:
347
+ raise TypeError("role must be an exact ReferenceCampaignPolicyRole")
348
+ if implementation is None:
349
+ raise ValueError("reference policy implementation cannot be None")
350
+ if sum(
351
+ (
352
+ operator_stratified_acquisition,
353
+ horizon_bounded_acquisition,
354
+ target_conditioned_acquisition,
355
+ )
356
+ ) > 1:
357
+ raise ValueError("acquisition treatments are mutually exclusive")
358
+ if constraint_decoupled_acquisition and not (
359
+ horizon_bounded_acquisition or target_conditioned_acquisition
360
+ ):
361
+ raise ValueError(
362
+ "constraint-decoupled acquisition requires horizon-bounded or "
363
+ "target-conditioned acquisition"
364
+ )
365
+ if minimum_intervention_projection and not constraint_decoupled_acquisition:
366
+ raise ValueError(
367
+ "minimum intervention requires constraint-decoupled acquisition"
368
+ )
369
+ if evidence_calibrated_source_mix and not minimum_intervention_projection:
370
+ raise ValueError("evidence-calibrated source mix requires minimum intervention")
371
+ if contextual_search_allocation and not evidence_calibrated_source_mix:
372
+ raise ValueError(
373
+ "contextual search allocation requires evidence-calibrated source mix"
374
+ )
375
+ if residual_frontier_planning and not contextual_search_allocation:
376
+ raise ValueError(
377
+ "residual frontier planning requires contextual search allocation"
378
+ )
379
+ if (
380
+ role is ReferenceCampaignPolicyRole.PARENT_SELECTION
381
+ and type(implementation)
382
+ in {
383
+ StagnationAwareDiverseCampaignParentSelector,
384
+ ResidualHypervolumeCampaignParentSelector,
385
+ }
386
+ ):
387
+ return CampaignPolicyBinding(
388
+ implementation=implementation,
389
+ policy_id=implementation.policy_id,
390
+ policy_version=implementation.policy_version,
391
+ definition_sha256=implementation.definition_sha256,
392
+ )
393
+ if role is ReferenceCampaignPolicyRole.MEMORY_ASSIGNMENT and context_local_memory:
394
+ policy_id, definition = _CONTEXT_LOCAL_MEMORY_POLICY
395
+ elif (
396
+ role is ReferenceCampaignPolicyRole.PORTFOLIO_SELECTION
397
+ and contextual_search_allocation
398
+ ):
399
+ policy_id, definition = (
400
+ _RESIDUAL_FRONTIER_CONTEXTUAL_SEARCH_PORTFOLIO_POLICY
401
+ if residual_frontier_planning
402
+ else _CONTEXTUAL_SEARCH_PORTFOLIO_POLICY
403
+ )
404
+ if type(implementation) is not HorizonBoundedStructuralPosteriorSlatePolicy:
405
+ raise TypeError("contextual-search method requires its exact allocator")
406
+ definition += b"\x00" + json.dumps(
407
+ implementation.to_record(),
408
+ allow_nan=False,
409
+ ensure_ascii=True,
410
+ separators=(",", ":"),
411
+ sort_keys=True,
412
+ ).encode("ascii")
413
+ elif (
414
+ role is ReferenceCampaignPolicyRole.PORTFOLIO_SELECTION
415
+ and evidence_calibrated_source_mix
416
+ ):
417
+ policy_id, definition = _EVIDENCE_CALIBRATED_SOURCE_MIX_PORTFOLIO_POLICY
418
+ if type(implementation) is not HorizonBoundedStructuralPosteriorSlatePolicy:
419
+ raise TypeError("source-mix method requires its exact allocator")
420
+ definition += b"\x00" + json.dumps(
421
+ implementation.to_record(),
422
+ allow_nan=False,
423
+ ensure_ascii=True,
424
+ separators=(",", ":"),
425
+ sort_keys=True,
426
+ ).encode("ascii")
427
+ elif (
428
+ role is ReferenceCampaignPolicyRole.PORTFOLIO_SELECTION
429
+ and minimum_intervention_projection
430
+ ):
431
+ policy_id, definition = _MINIMUM_INTERVENTION_HORIZON_PORTFOLIO_POLICY
432
+ if type(implementation) is not HorizonBoundedStructuralPosteriorSlatePolicy:
433
+ raise TypeError("minimum-intervention method requires its exact allocator")
434
+ definition += b"\x00" + json.dumps(
435
+ implementation.to_record(),
436
+ allow_nan=False,
437
+ ensure_ascii=True,
438
+ separators=(",", ":"),
439
+ sort_keys=True,
440
+ ).encode("ascii")
441
+ elif (
442
+ role is ReferenceCampaignPolicyRole.PORTFOLIO_SELECTION
443
+ and constraint_decoupled_acquisition
444
+ ):
445
+ if target_conditioned_acquisition:
446
+ policy_id, definition = (
447
+ _CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_PORTFOLIO_POLICY
448
+ )
449
+ if type(implementation) is not TargetConditionedSlateAllocatorAdapter:
450
+ raise TypeError(
451
+ "constraint-decoupled target method requires its exact allocator"
452
+ )
453
+ else:
454
+ policy_id, definition = _CONSTRAINT_DECOUPLED_HORIZON_PORTFOLIO_POLICY
455
+ if type(implementation) is not (
456
+ HorizonBoundedStructuralPosteriorSlatePolicy
457
+ ):
458
+ raise TypeError(
459
+ "constraint-decoupled horizon method requires its exact allocator"
460
+ )
461
+ definition += b"\x00" + json.dumps(
462
+ implementation.to_record(),
463
+ allow_nan=False,
464
+ ensure_ascii=True,
465
+ separators=(",", ":"),
466
+ sort_keys=True,
467
+ ).encode("ascii")
468
+ elif (
469
+ role is ReferenceCampaignPolicyRole.PORTFOLIO_SELECTION
470
+ and target_conditioned_acquisition
471
+ ):
472
+ policy_id, definition = _TARGET_CONDITIONED_PORTFOLIO_POLICY
473
+ if type(implementation) is not TargetConditionedSlateAllocatorAdapter:
474
+ raise TypeError("target-conditioned method requires its exact allocator")
475
+ definition += b"\x00" + json.dumps(
476
+ implementation.to_record(),
477
+ allow_nan=False,
478
+ ensure_ascii=True,
479
+ separators=(",", ":"),
480
+ sort_keys=True,
481
+ ).encode("ascii")
482
+ elif (
483
+ role is ReferenceCampaignPolicyRole.PORTFOLIO_SELECTION
484
+ and horizon_bounded_acquisition
485
+ ):
486
+ policy_id, definition = _HORIZON_BOUNDED_PORTFOLIO_POLICY
487
+ if type(implementation) is not HorizonBoundedStructuralPosteriorSlatePolicy:
488
+ raise TypeError("horizon-bounded method requires its exact allocator")
489
+ definition += b"\x00" + json.dumps(
490
+ implementation.to_record(),
491
+ allow_nan=False,
492
+ ensure_ascii=True,
493
+ separators=(",", ":"),
494
+ sort_keys=True,
495
+ ).encode("ascii")
496
+ elif (
497
+ role is ReferenceCampaignPolicyRole.PORTFOLIO_SELECTION
498
+ and operator_stratified_acquisition
499
+ ):
500
+ policy_id, definition = _OPERATOR_STRATIFIED_PORTFOLIO_POLICY
501
+ if type(implementation) is not (
502
+ OperatorStratifiedStructuralPosteriorSlatePolicy
503
+ ):
504
+ raise TypeError("operator-stratified method requires its exact allocator")
505
+ definition += b"\x00" + json.dumps(
506
+ implementation.to_record(),
507
+ allow_nan=False,
508
+ ensure_ascii=True,
509
+ separators=(",", ":"),
510
+ sort_keys=True,
511
+ ).encode("ascii")
512
+ elif (
513
+ role is ReferenceCampaignPolicyRole.PORTFOLIO_SELECTION
514
+ and hierarchical_proposal_support
515
+ ):
516
+ policy_id, definition = _HIERARCHICAL_PORTFOLIO_POLICY
517
+ else:
518
+ policy_id, definition = _POLICY_IDS[role]
519
+ return CampaignPolicyBinding(
520
+ implementation=implementation,
521
+ policy_id=policy_id,
522
+ policy_version=1,
523
+ definition_sha256=hashlib.sha256(definition).hexdigest(),
524
+ )
525
+
526
+
527
+ def _archive_context_binding(
528
+ implementation: CampaignPortfolioArchiveContextProjector,
529
+ ) -> CampaignPolicyBinding:
530
+ if not isinstance(implementation, CampaignPortfolioArchiveContextProjector):
531
+ raise TypeError(
532
+ "archive_context must satisfy the generic archive-context projector port"
533
+ )
534
+ return CampaignPolicyBinding(
535
+ implementation=implementation,
536
+ policy_id=implementation.projector_id,
537
+ policy_version=implementation.projector_version,
538
+ definition_sha256=implementation.definition_sha256,
539
+ )
540
+
541
+
542
+ def _method_identity(
543
+ *,
544
+ hierarchical_proposal_support: bool,
545
+ frontier_context: bool,
546
+ context_local_successor: bool = False,
547
+ operator_stratified_acquisition: bool = False,
548
+ horizon_bounded_acquisition: bool = False,
549
+ target_conditioned_acquisition: bool = False,
550
+ stagnation_aware_parent_selection: bool = False,
551
+ constraint_decoupled_acquisition: bool = False,
552
+ minimum_intervention_projection: bool = False,
553
+ evidence_calibrated_source_mix: bool = False,
554
+ contextual_search_allocation: bool = False,
555
+ residual_frontier_planning: bool = False,
556
+ ) -> tuple[str, int]:
557
+ if sum(
558
+ (
559
+ operator_stratified_acquisition,
560
+ horizon_bounded_acquisition,
561
+ target_conditioned_acquisition,
562
+ )
563
+ ) > 1:
564
+ raise ValueError("acquisition treatments are mutually exclusive")
565
+ if residual_frontier_planning:
566
+ if not contextual_search_allocation:
567
+ raise ValueError(
568
+ "residual frontier planning requires contextual search allocation"
569
+ )
570
+ if not (
571
+ hierarchical_proposal_support
572
+ and frontier_context
573
+ and context_local_successor
574
+ and horizon_bounded_acquisition
575
+ and constraint_decoupled_acquisition
576
+ and minimum_intervention_projection
577
+ and evidence_calibrated_source_mix
578
+ ) or stagnation_aware_parent_selection:
579
+ raise ValueError(
580
+ "residual-frontier successor requires the complete V21 stack "
581
+ "and its joint residual parent policy"
582
+ )
583
+ return (
584
+ RESIDUAL_FRONTIER_AGENT_EVOLVE_METHOD_ID,
585
+ RESIDUAL_FRONTIER_AGENT_EVOLVE_METHOD_VERSION,
586
+ )
587
+ if contextual_search_allocation:
588
+ if not evidence_calibrated_source_mix:
589
+ raise ValueError(
590
+ "contextual search allocation requires evidence-calibrated source mix"
591
+ )
592
+ if not (
593
+ hierarchical_proposal_support
594
+ and frontier_context
595
+ and context_local_successor
596
+ and horizon_bounded_acquisition
597
+ and stagnation_aware_parent_selection
598
+ and constraint_decoupled_acquisition
599
+ and minimum_intervention_projection
600
+ ):
601
+ raise ValueError(
602
+ "contextual-search successor requires the complete V11 stack"
603
+ )
604
+ return (
605
+ CONTEXTUAL_SEARCH_AGENT_EVOLVE_METHOD_ID,
606
+ CONTEXTUAL_SEARCH_AGENT_EVOLVE_METHOD_VERSION,
607
+ )
608
+ if evidence_calibrated_source_mix:
609
+ if not minimum_intervention_projection:
610
+ raise ValueError(
611
+ "evidence-calibrated source mix requires minimum intervention"
612
+ )
613
+ if not (
614
+ hierarchical_proposal_support
615
+ and frontier_context
616
+ and context_local_successor
617
+ and horizon_bounded_acquisition
618
+ and stagnation_aware_parent_selection
619
+ and constraint_decoupled_acquisition
620
+ ):
621
+ raise ValueError(
622
+ "evidence-calibrated source successor requires the complete V10 stack"
623
+ )
624
+ return (
625
+ EVIDENCE_CALIBRATED_SOURCE_MIX_AGENT_EVOLVE_METHOD_ID,
626
+ EVIDENCE_CALIBRATED_SOURCE_MIX_AGENT_EVOLVE_METHOD_VERSION,
627
+ )
628
+ if minimum_intervention_projection:
629
+ if not constraint_decoupled_acquisition:
630
+ raise ValueError(
631
+ "minimum intervention requires constraint-decoupled acquisition"
632
+ )
633
+ if not (
634
+ hierarchical_proposal_support
635
+ and frontier_context
636
+ and context_local_successor
637
+ and horizon_bounded_acquisition
638
+ and stagnation_aware_parent_selection
639
+ ):
640
+ raise ValueError(
641
+ "minimum-intervention successor requires the complete V9 stack"
642
+ )
643
+ return (
644
+ MINIMUM_INTERVENTION_AGENT_EVOLVE_METHOD_ID,
645
+ MINIMUM_INTERVENTION_AGENT_EVOLVE_METHOD_VERSION,
646
+ )
647
+ if constraint_decoupled_acquisition:
648
+ if target_conditioned_acquisition:
649
+ if not (
650
+ hierarchical_proposal_support
651
+ and frontier_context
652
+ and context_local_successor
653
+ ) or stagnation_aware_parent_selection:
654
+ raise ValueError(
655
+ "constraint-decoupled target successor requires hierarchical "
656
+ "support, authenticated frontier context, context-local memory, "
657
+ "and the target parent policy"
658
+ )
659
+ return (
660
+ CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_ID,
661
+ CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_VERSION,
662
+ )
663
+ if not (
664
+ hierarchical_proposal_support
665
+ and frontier_context
666
+ and context_local_successor
667
+ and horizon_bounded_acquisition
668
+ and stagnation_aware_parent_selection
669
+ ):
670
+ raise ValueError(
671
+ "constraint-decoupled successor requires the complete V8 stack"
672
+ )
673
+ return (
674
+ CONSTRAINT_DECOUPLED_AGENT_EVOLVE_METHOD_ID,
675
+ CONSTRAINT_DECOUPLED_AGENT_EVOLVE_METHOD_VERSION,
676
+ )
677
+ if target_conditioned_acquisition:
678
+ if not (
679
+ hierarchical_proposal_support
680
+ and frontier_context
681
+ and context_local_successor
682
+ ) or stagnation_aware_parent_selection:
683
+ raise ValueError(
684
+ "target-conditioned successor requires hierarchical support, "
685
+ "authenticated frontier context, context-local memory, and the "
686
+ "target parent policy"
687
+ )
688
+ return (
689
+ TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_ID,
690
+ TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_VERSION,
691
+ )
692
+ if stagnation_aware_parent_selection:
693
+ if not (
694
+ hierarchical_proposal_support
695
+ and frontier_context
696
+ and context_local_successor
697
+ and horizon_bounded_acquisition
698
+ ):
699
+ raise ValueError(
700
+ "stagnation-aware successor requires hierarchical support, "
701
+ "authenticated frontier context, context-local memory, and "
702
+ "horizon-bounded acquisition"
703
+ )
704
+ return (
705
+ STAGNATION_AWARE_AGENT_EVOLVE_METHOD_ID,
706
+ STAGNATION_AWARE_AGENT_EVOLVE_METHOD_VERSION,
707
+ )
708
+ if horizon_bounded_acquisition:
709
+ if not (
710
+ hierarchical_proposal_support
711
+ and frontier_context
712
+ and context_local_successor
713
+ ):
714
+ raise ValueError(
715
+ "horizon-bounded successor requires hierarchical support, "
716
+ "authenticated frontier context, and context-local memory"
717
+ )
718
+ return (
719
+ HORIZON_BOUNDED_AGENT_EVOLVE_METHOD_ID,
720
+ HORIZON_BOUNDED_AGENT_EVOLVE_METHOD_VERSION,
721
+ )
722
+ if operator_stratified_acquisition:
723
+ if not (
724
+ hierarchical_proposal_support
725
+ and frontier_context
726
+ and context_local_successor
727
+ ):
728
+ raise ValueError(
729
+ "operator-stratified successor requires hierarchical support, "
730
+ "authenticated frontier context, and context-local memory"
731
+ )
732
+ return (
733
+ OPERATOR_STRATIFIED_AGENT_EVOLVE_METHOD_ID,
734
+ OPERATOR_STRATIFIED_AGENT_EVOLVE_METHOD_VERSION,
735
+ )
736
+ if context_local_successor:
737
+ if not hierarchical_proposal_support or not frontier_context:
738
+ raise ValueError(
739
+ "context-local successor requires hierarchical support and "
740
+ "authenticated frontier context"
741
+ )
742
+ return (
743
+ CONTEXT_LOCAL_AGENT_EVOLVE_METHOD_ID,
744
+ CONTEXT_LOCAL_AGENT_EVOLVE_METHOD_VERSION,
745
+ )
746
+ if hierarchical_proposal_support and frontier_context:
747
+ return (
748
+ FRONTIER_HIERARCHICAL_AGENT_EVOLVE_METHOD_ID,
749
+ FRONTIER_HIERARCHICAL_AGENT_EVOLVE_METHOD_VERSION,
750
+ )
751
+ if hierarchical_proposal_support:
752
+ return (
753
+ HIERARCHICAL_AGENT_EVOLVE_METHOD_ID,
754
+ HIERARCHICAL_AGENT_EVOLVE_METHOD_VERSION,
755
+ )
756
+ if frontier_context:
757
+ return (
758
+ FRONTIER_AGENT_EVOLVE_METHOD_ID,
759
+ FRONTIER_AGENT_EVOLVE_METHOD_VERSION,
760
+ )
761
+ return (
762
+ REFERENCE_AGENT_EVOLVE_METHOD_ID,
763
+ REFERENCE_AGENT_EVOLVE_METHOD_VERSION,
764
+ )
765
+
766
+
767
+ @dataclass(frozen=True, slots=True)
768
+ class ReferenceCampaignImplementations:
769
+ """Runtime objects hidden behind the stable reference policy identities."""
770
+
771
+ parent_selection: object
772
+ memory_assignment: object
773
+ portfolio_selection: object
774
+ recombination: object
775
+ reflection: object
776
+ archive_context: CampaignPortfolioArchiveContextProjector | None = None
777
+ variation_topology: CampaignPolicyBinding | None = None
778
+ contextual_outcomes: CampaignPolicyBinding | None = None
779
+
780
+ def __post_init__(self) -> None:
781
+ for name in (
782
+ "parent_selection",
783
+ "memory_assignment",
784
+ "portfolio_selection",
785
+ "recombination",
786
+ "reflection",
787
+ ):
788
+ if getattr(self, name) is None:
789
+ raise ValueError(f"{name} implementation cannot be None")
790
+ if self.archive_context is not None and not isinstance(
791
+ self.archive_context,
792
+ CampaignPortfolioArchiveContextProjector,
793
+ ):
794
+ raise TypeError(
795
+ "archive_context must satisfy the generic archive-context "
796
+ "projector port or be None"
797
+ )
798
+ for name in ("variation_topology", "contextual_outcomes"):
799
+ value = getattr(self, name)
800
+ if value is not None:
801
+ if type(value) is not CampaignPolicyBinding:
802
+ raise TypeError(
803
+ f"{name} must be an exact CampaignPolicyBinding or None"
804
+ )
805
+ CampaignPolicyBinding.__post_init__(value)
806
+ if (self.variation_topology is None) is not (self.contextual_outcomes is None):
807
+ raise ValueError(
808
+ "variation_topology and contextual_outcomes must be bound together"
809
+ )
810
+
811
+ def bindings(
812
+ self,
813
+ *,
814
+ hierarchical_proposal_support: bool = False,
815
+ operator_stratified_acquisition: bool = False,
816
+ horizon_bounded_acquisition: bool = False,
817
+ target_conditioned_acquisition: bool = False,
818
+ constraint_decoupled_acquisition: bool = False,
819
+ minimum_intervention_projection: bool = False,
820
+ evidence_calibrated_source_mix: bool = False,
821
+ contextual_search_allocation: bool = False,
822
+ residual_frontier_planning: bool = False,
823
+ ) -> dict[ReferenceCampaignPolicyRole, CampaignPolicyBinding]:
824
+ self.__post_init__()
825
+ if type(hierarchical_proposal_support) is not bool:
826
+ raise TypeError("hierarchical_proposal_support must be an exact bool")
827
+ if type(operator_stratified_acquisition) is not bool:
828
+ raise TypeError("operator_stratified_acquisition must be an exact bool")
829
+ if type(horizon_bounded_acquisition) is not bool:
830
+ raise TypeError("horizon_bounded_acquisition must be an exact bool")
831
+ if type(target_conditioned_acquisition) is not bool:
832
+ raise TypeError("target_conditioned_acquisition must be an exact bool")
833
+ if type(constraint_decoupled_acquisition) is not bool:
834
+ raise TypeError("constraint_decoupled_acquisition must be an exact bool")
835
+ if type(minimum_intervention_projection) is not bool:
836
+ raise TypeError("minimum_intervention_projection must be an exact bool")
837
+ if type(evidence_calibrated_source_mix) is not bool:
838
+ raise TypeError("evidence_calibrated_source_mix must be an exact bool")
839
+ if type(contextual_search_allocation) is not bool:
840
+ raise TypeError("contextual_search_allocation must be an exact bool")
841
+ if type(residual_frontier_planning) is not bool:
842
+ raise TypeError("residual_frontier_planning must be an exact bool")
843
+ if sum(
844
+ (
845
+ operator_stratified_acquisition,
846
+ horizon_bounded_acquisition,
847
+ target_conditioned_acquisition,
848
+ )
849
+ ) > 1:
850
+ raise ValueError("acquisition treatments are mutually exclusive")
851
+ if operator_stratified_acquisition and not hierarchical_proposal_support:
852
+ raise ValueError(
853
+ "operator-stratified acquisition requires hierarchical support"
854
+ )
855
+ if horizon_bounded_acquisition and not hierarchical_proposal_support:
856
+ raise ValueError(
857
+ "horizon-bounded acquisition requires hierarchical support"
858
+ )
859
+ if target_conditioned_acquisition and not hierarchical_proposal_support:
860
+ raise ValueError(
861
+ "target-conditioned acquisition requires hierarchical support"
862
+ )
863
+ if constraint_decoupled_acquisition and not (
864
+ horizon_bounded_acquisition or target_conditioned_acquisition
865
+ ):
866
+ raise ValueError(
867
+ "constraint-decoupled acquisition requires horizon bounds or a "
868
+ "target-conditioned allocator"
869
+ )
870
+ if minimum_intervention_projection and not constraint_decoupled_acquisition:
871
+ raise ValueError(
872
+ "minimum intervention requires constraint-decoupled acquisition"
873
+ )
874
+ if evidence_calibrated_source_mix and not minimum_intervention_projection:
875
+ raise ValueError(
876
+ "evidence-calibrated source mix requires minimum intervention"
877
+ )
878
+ if contextual_search_allocation and not evidence_calibrated_source_mix:
879
+ raise ValueError(
880
+ "contextual search allocation requires evidence-calibrated source mix"
881
+ )
882
+ if residual_frontier_planning and not contextual_search_allocation:
883
+ raise ValueError(
884
+ "residual frontier planning requires contextual search allocation"
885
+ )
886
+ context_local_memory = self.variation_topology is not None
887
+ bindings = {
888
+ role: _binding(
889
+ role,
890
+ getattr(self, role.value),
891
+ hierarchical_proposal_support=hierarchical_proposal_support,
892
+ context_local_memory=context_local_memory,
893
+ operator_stratified_acquisition=(operator_stratified_acquisition),
894
+ horizon_bounded_acquisition=horizon_bounded_acquisition,
895
+ target_conditioned_acquisition=target_conditioned_acquisition,
896
+ constraint_decoupled_acquisition=(constraint_decoupled_acquisition),
897
+ minimum_intervention_projection=(minimum_intervention_projection),
898
+ evidence_calibrated_source_mix=(evidence_calibrated_source_mix),
899
+ contextual_search_allocation=contextual_search_allocation,
900
+ residual_frontier_planning=residual_frontier_planning,
901
+ )
902
+ for role in ReferenceCampaignPolicyRole
903
+ if role
904
+ not in {
905
+ ReferenceCampaignPolicyRole.ARCHIVE_CONTEXT,
906
+ ReferenceCampaignPolicyRole.VARIATION_TOPOLOGY,
907
+ ReferenceCampaignPolicyRole.CONTEXTUAL_OUTCOMES,
908
+ }
909
+ }
910
+ if self.archive_context is not None:
911
+ bindings[ReferenceCampaignPolicyRole.ARCHIVE_CONTEXT] = (
912
+ _archive_context_binding(self.archive_context)
913
+ )
914
+ if self.variation_topology is not None:
915
+ bindings[ReferenceCampaignPolicyRole.VARIATION_TOPOLOGY] = (
916
+ self.variation_topology
917
+ )
918
+ assert self.contextual_outcomes is not None
919
+ bindings[ReferenceCampaignPolicyRole.CONTEXTUAL_OUTCOMES] = (
920
+ reference_multi_horizon_contextual_outcomes_binding(
921
+ self.contextual_outcomes.implementation
922
+ )
923
+ if contextual_search_allocation
924
+ else self.contextual_outcomes
925
+ )
926
+ return bindings
927
+
928
+
929
+ def reference_atomic_variation_topology_binding(
930
+ implementation: object,
931
+ ) -> CampaignPolicyBinding:
932
+ """Authenticate the complete parent-bound atomic finite-action topology."""
933
+
934
+ if implementation is None:
935
+ raise ValueError("variation-topology implementation cannot be None")
936
+ policy_id, definition = _ATOMIC_VARIATION_TOPOLOGY_POLICY
937
+ return CampaignPolicyBinding(
938
+ implementation=implementation,
939
+ policy_id=policy_id,
940
+ policy_version=1,
941
+ definition_sha256=hashlib.sha256(definition).hexdigest(),
942
+ )
943
+
944
+
945
+ def reference_contextual_outcomes_binding(
946
+ implementation: object,
947
+ ) -> CampaignPolicyBinding:
948
+ """Authenticate bounded parent-local prior-outcome retrieval."""
949
+
950
+ if implementation is None:
951
+ raise ValueError("contextual-outcome implementation cannot be None")
952
+ policy_id, definition = _CONTEXTUAL_OUTCOMES_POLICY
953
+ return CampaignPolicyBinding(
954
+ implementation=implementation,
955
+ policy_id=policy_id,
956
+ policy_version=1,
957
+ definition_sha256=hashlib.sha256(definition).hexdigest(),
958
+ )
959
+
960
+
961
+ def reference_multi_horizon_contextual_outcomes_binding(
962
+ implementation: object,
963
+ ) -> CampaignPolicyBinding:
964
+ """Authenticate actionable stage and terminal outcome credit."""
965
+
966
+ if implementation is None:
967
+ raise ValueError("contextual-outcome implementation cannot be None")
968
+ policy_id, definition = _MULTI_HORIZON_CONTEXTUAL_OUTCOMES_POLICY
969
+ return CampaignPolicyBinding(
970
+ implementation=implementation,
971
+ policy_id=policy_id,
972
+ policy_version=2,
973
+ definition_sha256=hashlib.sha256(definition).hexdigest(),
974
+ )
975
+
976
+
977
+ def reference_hierarchical_r2_variation_topology_binding(
978
+ implementation: object,
979
+ *,
980
+ max_composite_options: int,
981
+ required_composite_proposals: int,
982
+ ) -> CampaignPolicyBinding:
983
+ """Authenticate bounded engine-materialized radius-two proposal strata."""
984
+
985
+ if implementation is None:
986
+ raise ValueError("variation-topology implementation cannot be None")
987
+ if type(max_composite_options) is not int or max_composite_options <= 0:
988
+ raise ValueError("max_composite_options must be a positive exact integer")
989
+ if (
990
+ type(required_composite_proposals) is not int
991
+ or not 1 <= required_composite_proposals < 8
992
+ ):
993
+ raise ValueError("required_composite_proposals must lie in [1, 8)")
994
+ record = {
995
+ "schema_version": 2,
996
+ "radius": 2,
997
+ "max_composite_options": max_composite_options,
998
+ "required_composite_proposals": required_composite_proposals,
999
+ "required_composite_proposals_semantics": (
1000
+ "preferred_then_nearest_exact_k8_capacity_projection"
1001
+ ),
1002
+ "capacity_projection_inputs": (
1003
+ "current_parent_atomic_and_materialized_composite_counts"
1004
+ ),
1005
+ "retain_all_atomic_options": True,
1006
+ "pair_prefilter": "disjoint_parent_relative_typed_patch_paths",
1007
+ "pair_admission": "engine_replay_union_and_exact_rediff",
1008
+ "ranked_union_member_kinds": ["atomic", "compose_r2"],
1009
+ "provider_materialization_authority": False,
1010
+ "outcomes_consulted": False,
1011
+ }
1012
+ definition_sha256 = hashlib.sha256(
1013
+ _HIERARCHICAL_R2_VARIATION_TOPOLOGY_DOMAIN
1014
+ + json.dumps(
1015
+ record,
1016
+ allow_nan=False,
1017
+ ensure_ascii=True,
1018
+ separators=(",", ":"),
1019
+ sort_keys=True,
1020
+ ).encode("ascii")
1021
+ ).hexdigest()
1022
+ return CampaignPolicyBinding(
1023
+ implementation=implementation,
1024
+ policy_id=_HIERARCHICAL_R2_VARIATION_TOPOLOGY_POLICY_ID,
1025
+ policy_version=2,
1026
+ definition_sha256=definition_sha256,
1027
+ )
1028
+
1029
+
1030
+ def reference_campaign_experiment_profile(
1031
+ *,
1032
+ profile_id: str,
1033
+ model_execution: OpenRouterModelExecutionProfile,
1034
+ implementations: ReferenceCampaignImplementations,
1035
+ candidate_pool_size: int | None,
1036
+ evaluator_concurrency: int,
1037
+ agent_concurrency: int,
1038
+ agent_queue_capacity: int,
1039
+ hierarchical_proposal_support: bool = False,
1040
+ operator_stratified_acquisition: bool = False,
1041
+ horizon_bounded_acquisition: bool = False,
1042
+ target_conditioned_acquisition: bool = False,
1043
+ constraint_decoupled_acquisition: bool = False,
1044
+ minimum_intervention_projection: bool = False,
1045
+ evidence_calibrated_source_mix: bool = False,
1046
+ contextual_search_allocation: bool = False,
1047
+ prompt_arm: WorkloadPromptArm = WorkloadPromptArm.SEMANTIC,
1048
+ scale_shape: PortfolioScaleShape = REFERENCE_36_OFFSPRING_SCALE_SHAPE,
1049
+ model_selection_size: int = 8,
1050
+ ) -> CampaignExperimentProfile:
1051
+ """Bind one executable cell to the shared successor-method identity."""
1052
+
1053
+ if type(implementations) is not ReferenceCampaignImplementations:
1054
+ raise TypeError("implementations must be exact")
1055
+ if candidate_pool_size is not None:
1056
+ raise ValueError(
1057
+ "the reference successor requires the complete finite contract"
1058
+ )
1059
+ if type(hierarchical_proposal_support) is not bool:
1060
+ raise TypeError("hierarchical_proposal_support must be an exact bool")
1061
+ if type(operator_stratified_acquisition) is not bool:
1062
+ raise TypeError("operator_stratified_acquisition must be an exact bool")
1063
+ if type(horizon_bounded_acquisition) is not bool:
1064
+ raise TypeError("horizon_bounded_acquisition must be an exact bool")
1065
+ if type(target_conditioned_acquisition) is not bool:
1066
+ raise TypeError("target_conditioned_acquisition must be an exact bool")
1067
+ if type(constraint_decoupled_acquisition) is not bool:
1068
+ raise TypeError("constraint_decoupled_acquisition must be an exact bool")
1069
+ if type(minimum_intervention_projection) is not bool:
1070
+ raise TypeError("minimum_intervention_projection must be an exact bool")
1071
+ if type(evidence_calibrated_source_mix) is not bool:
1072
+ raise TypeError("evidence_calibrated_source_mix must be an exact bool")
1073
+ if type(contextual_search_allocation) is not bool:
1074
+ raise TypeError("contextual_search_allocation must be an exact bool")
1075
+ if sum(
1076
+ (
1077
+ operator_stratified_acquisition,
1078
+ horizon_bounded_acquisition,
1079
+ target_conditioned_acquisition,
1080
+ )
1081
+ ) > 1:
1082
+ raise ValueError("acquisition treatments are mutually exclusive")
1083
+ if constraint_decoupled_acquisition and not (
1084
+ horizon_bounded_acquisition or target_conditioned_acquisition
1085
+ ):
1086
+ raise ValueError(
1087
+ "constraint-decoupled acquisition requires horizon-bounded or "
1088
+ "target-conditioned acquisition"
1089
+ )
1090
+ if target_conditioned_acquisition != (
1091
+ type(implementations.portfolio_selection)
1092
+ is TargetConditionedSlateAllocatorAdapter
1093
+ ):
1094
+ raise ValueError(
1095
+ "target-conditioned treatment flag differs from its allocator"
1096
+ )
1097
+ if minimum_intervention_projection and not constraint_decoupled_acquisition:
1098
+ raise ValueError(
1099
+ "minimum intervention requires constraint-decoupled acquisition"
1100
+ )
1101
+ if evidence_calibrated_source_mix and not minimum_intervention_projection:
1102
+ raise ValueError("evidence-calibrated source mix requires minimum intervention")
1103
+ if contextual_search_allocation and not evidence_calibrated_source_mix:
1104
+ raise ValueError(
1105
+ "contextual search allocation requires evidence-calibrated source mix"
1106
+ )
1107
+ if operator_stratified_acquisition and (
1108
+ not hierarchical_proposal_support
1109
+ or implementations.archive_context is None
1110
+ or implementations.variation_topology is None
1111
+ or implementations.variation_topology.policy_id
1112
+ != _HIERARCHICAL_R2_VARIATION_TOPOLOGY_POLICY_ID
1113
+ ):
1114
+ raise ValueError(
1115
+ "operator-stratified acquisition requires the complete "
1116
+ "context-local hierarchical successor stack"
1117
+ )
1118
+ if horizon_bounded_acquisition and (
1119
+ not hierarchical_proposal_support
1120
+ or implementations.archive_context is None
1121
+ or implementations.variation_topology is None
1122
+ or implementations.variation_topology.policy_id
1123
+ != _HIERARCHICAL_R2_VARIATION_TOPOLOGY_POLICY_ID
1124
+ ):
1125
+ raise ValueError(
1126
+ "horizon-bounded acquisition requires the complete "
1127
+ "context-local hierarchical successor stack"
1128
+ )
1129
+ if target_conditioned_acquisition and (
1130
+ not hierarchical_proposal_support
1131
+ or implementations.archive_context is None
1132
+ or implementations.variation_topology is None
1133
+ or implementations.variation_topology.policy_id
1134
+ != _HIERARCHICAL_R2_VARIATION_TOPOLOGY_POLICY_ID
1135
+ ):
1136
+ raise ValueError(
1137
+ "target-conditioned acquisition requires the complete context-local "
1138
+ "hierarchical successor stack"
1139
+ )
1140
+ if type(scale_shape) is not PortfolioScaleShape:
1141
+ raise TypeError("scale_shape must be an exact PortfolioScaleShape")
1142
+ scale_shape.__post_init__()
1143
+ if type(model_selection_size) is not int or model_selection_size <= 0:
1144
+ raise ValueError("model_selection_size must be a positive exact integer")
1145
+ residual_frontier_planning = (
1146
+ type(implementations.parent_selection)
1147
+ is ResidualHypervolumeCampaignParentSelector
1148
+ )
1149
+ bindings = implementations.bindings(
1150
+ hierarchical_proposal_support=hierarchical_proposal_support,
1151
+ operator_stratified_acquisition=operator_stratified_acquisition,
1152
+ horizon_bounded_acquisition=horizon_bounded_acquisition,
1153
+ target_conditioned_acquisition=target_conditioned_acquisition,
1154
+ constraint_decoupled_acquisition=constraint_decoupled_acquisition,
1155
+ minimum_intervention_projection=minimum_intervention_projection,
1156
+ evidence_calibrated_source_mix=evidence_calibrated_source_mix,
1157
+ contextual_search_allocation=contextual_search_allocation,
1158
+ residual_frontier_planning=residual_frontier_planning,
1159
+ )
1160
+ context_local_successor = implementations.variation_topology is not None
1161
+ stagnation_aware_parent_selection = (
1162
+ type(implementations.parent_selection)
1163
+ is StagnationAwareDiverseCampaignParentSelector
1164
+ )
1165
+ method_id, method_version = _method_identity(
1166
+ hierarchical_proposal_support=hierarchical_proposal_support,
1167
+ frontier_context=implementations.archive_context is not None,
1168
+ context_local_successor=context_local_successor,
1169
+ operator_stratified_acquisition=operator_stratified_acquisition,
1170
+ horizon_bounded_acquisition=horizon_bounded_acquisition,
1171
+ target_conditioned_acquisition=target_conditioned_acquisition,
1172
+ stagnation_aware_parent_selection=(stagnation_aware_parent_selection),
1173
+ constraint_decoupled_acquisition=constraint_decoupled_acquisition,
1174
+ minimum_intervention_projection=minimum_intervention_projection,
1175
+ evidence_calibrated_source_mix=evidence_calibrated_source_mix,
1176
+ contextual_search_allocation=contextual_search_allocation,
1177
+ residual_frontier_planning=residual_frontier_planning,
1178
+ )
1179
+ return CampaignExperimentProfile(
1180
+ profile_id=profile_id,
1181
+ profile_version=1,
1182
+ method_id=method_id,
1183
+ method_version=method_version,
1184
+ scale_shape=scale_shape,
1185
+ candidate_pool_size=candidate_pool_size,
1186
+ model_selection_size=model_selection_size,
1187
+ prompt_arm=prompt_arm,
1188
+ parent_selection=bindings[ReferenceCampaignPolicyRole.PARENT_SELECTION],
1189
+ memory_assignment=bindings[ReferenceCampaignPolicyRole.MEMORY_ASSIGNMENT],
1190
+ portfolio_selection=bindings[ReferenceCampaignPolicyRole.PORTFOLIO_SELECTION],
1191
+ recombination=bindings[ReferenceCampaignPolicyRole.RECOMBINATION],
1192
+ reflection=bindings[ReferenceCampaignPolicyRole.REFLECTION],
1193
+ model_execution=model_execution,
1194
+ archive_context=bindings.get(ReferenceCampaignPolicyRole.ARCHIVE_CONTEXT),
1195
+ variation_topology=bindings.get(ReferenceCampaignPolicyRole.VARIATION_TOPOLOGY),
1196
+ contextual_outcomes=bindings.get(
1197
+ ReferenceCampaignPolicyRole.CONTEXTUAL_OUTCOMES
1198
+ ),
1199
+ evaluator_concurrency=evaluator_concurrency,
1200
+ agent_concurrency=agent_concurrency,
1201
+ agent_queue_capacity=agent_queue_capacity,
1202
+ reflection_supervision=CampaignReflectionSupervisionPolicy(
1203
+ ReflectionFailureMode.BEST_EFFORT_DEGRADED
1204
+ ),
1205
+ )
1206
+
1207
+
1208
+ def rebind_reference_campaign_implementations(
1209
+ profile: CampaignExperimentProfile,
1210
+ implementations: ReferenceCampaignImplementations,
1211
+ ) -> CampaignExperimentProfile:
1212
+ """Swap runtime objects without changing any scientific method identity."""
1213
+
1214
+ if type(profile) is not CampaignExperimentProfile:
1215
+ raise TypeError("profile must be exact")
1216
+ profile.__post_init__()
1217
+ method_identity = (profile.method_id, profile.method_version)
1218
+ known_identities = {
1219
+ _method_identity(
1220
+ hierarchical_proposal_support=hierarchical,
1221
+ frontier_context=frontier,
1222
+ )
1223
+ for hierarchical in (False, True)
1224
+ for frontier in (False, True)
1225
+ }
1226
+ known_identities.add(
1227
+ _method_identity(
1228
+ hierarchical_proposal_support=True,
1229
+ frontier_context=True,
1230
+ context_local_successor=True,
1231
+ )
1232
+ )
1233
+ known_identities.add(
1234
+ _method_identity(
1235
+ hierarchical_proposal_support=True,
1236
+ frontier_context=True,
1237
+ context_local_successor=True,
1238
+ target_conditioned_acquisition=True,
1239
+ )
1240
+ )
1241
+ known_identities.add(
1242
+ _method_identity(
1243
+ hierarchical_proposal_support=True,
1244
+ frontier_context=True,
1245
+ context_local_successor=True,
1246
+ target_conditioned_acquisition=True,
1247
+ constraint_decoupled_acquisition=True,
1248
+ )
1249
+ )
1250
+ known_identities.add(
1251
+ _method_identity(
1252
+ hierarchical_proposal_support=True,
1253
+ frontier_context=True,
1254
+ context_local_successor=True,
1255
+ operator_stratified_acquisition=True,
1256
+ )
1257
+ )
1258
+ known_identities.add(
1259
+ _method_identity(
1260
+ hierarchical_proposal_support=True,
1261
+ frontier_context=True,
1262
+ context_local_successor=True,
1263
+ horizon_bounded_acquisition=True,
1264
+ )
1265
+ )
1266
+ known_identities.add(
1267
+ _method_identity(
1268
+ hierarchical_proposal_support=True,
1269
+ frontier_context=True,
1270
+ context_local_successor=True,
1271
+ horizon_bounded_acquisition=True,
1272
+ stagnation_aware_parent_selection=True,
1273
+ )
1274
+ )
1275
+ known_identities.add(
1276
+ _method_identity(
1277
+ hierarchical_proposal_support=True,
1278
+ frontier_context=True,
1279
+ context_local_successor=True,
1280
+ horizon_bounded_acquisition=True,
1281
+ stagnation_aware_parent_selection=True,
1282
+ constraint_decoupled_acquisition=True,
1283
+ )
1284
+ )
1285
+ known_identities.add(
1286
+ _method_identity(
1287
+ hierarchical_proposal_support=True,
1288
+ frontier_context=True,
1289
+ context_local_successor=True,
1290
+ horizon_bounded_acquisition=True,
1291
+ stagnation_aware_parent_selection=True,
1292
+ constraint_decoupled_acquisition=True,
1293
+ minimum_intervention_projection=True,
1294
+ )
1295
+ )
1296
+ known_identities.add(
1297
+ _method_identity(
1298
+ hierarchical_proposal_support=True,
1299
+ frontier_context=True,
1300
+ context_local_successor=True,
1301
+ horizon_bounded_acquisition=True,
1302
+ stagnation_aware_parent_selection=True,
1303
+ constraint_decoupled_acquisition=True,
1304
+ minimum_intervention_projection=True,
1305
+ evidence_calibrated_source_mix=True,
1306
+ )
1307
+ )
1308
+ known_identities.add(
1309
+ _method_identity(
1310
+ hierarchical_proposal_support=True,
1311
+ frontier_context=True,
1312
+ context_local_successor=True,
1313
+ horizon_bounded_acquisition=True,
1314
+ stagnation_aware_parent_selection=True,
1315
+ constraint_decoupled_acquisition=True,
1316
+ minimum_intervention_projection=True,
1317
+ evidence_calibrated_source_mix=True,
1318
+ contextual_search_allocation=True,
1319
+ )
1320
+ )
1321
+ known_identities.add(
1322
+ _method_identity(
1323
+ hierarchical_proposal_support=True,
1324
+ frontier_context=True,
1325
+ context_local_successor=True,
1326
+ horizon_bounded_acquisition=True,
1327
+ constraint_decoupled_acquisition=True,
1328
+ minimum_intervention_projection=True,
1329
+ evidence_calibrated_source_mix=True,
1330
+ contextual_search_allocation=True,
1331
+ residual_frontier_planning=True,
1332
+ )
1333
+ )
1334
+ if method_identity not in known_identities:
1335
+ raise ValueError("profile is not the reference AgentEvolve method")
1336
+ is_hierarchical = method_identity in {
1337
+ _method_identity(
1338
+ hierarchical_proposal_support=True,
1339
+ frontier_context=frontier,
1340
+ )
1341
+ for frontier in (False, True)
1342
+ }
1343
+ is_operator_stratified = method_identity == (
1344
+ OPERATOR_STRATIFIED_AGENT_EVOLVE_METHOD_ID,
1345
+ OPERATOR_STRATIFIED_AGENT_EVOLVE_METHOD_VERSION,
1346
+ )
1347
+ is_horizon_bounded = method_identity == (
1348
+ HORIZON_BOUNDED_AGENT_EVOLVE_METHOD_ID,
1349
+ HORIZON_BOUNDED_AGENT_EVOLVE_METHOD_VERSION,
1350
+ )
1351
+ is_stagnation_aware = method_identity == (
1352
+ STAGNATION_AWARE_AGENT_EVOLVE_METHOD_ID,
1353
+ STAGNATION_AWARE_AGENT_EVOLVE_METHOD_VERSION,
1354
+ )
1355
+ is_constraint_decoupled = method_identity == (
1356
+ CONSTRAINT_DECOUPLED_AGENT_EVOLVE_METHOD_ID,
1357
+ CONSTRAINT_DECOUPLED_AGENT_EVOLVE_METHOD_VERSION,
1358
+ )
1359
+ is_target_conditioned = method_identity in {
1360
+ (
1361
+ TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_ID,
1362
+ TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_VERSION,
1363
+ ),
1364
+ (
1365
+ CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_ID,
1366
+ CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_VERSION,
1367
+ ),
1368
+ }
1369
+ is_constraint_decoupled_target = method_identity == (
1370
+ CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_ID,
1371
+ CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_VERSION,
1372
+ )
1373
+ is_minimum_intervention = method_identity == (
1374
+ MINIMUM_INTERVENTION_AGENT_EVOLVE_METHOD_ID,
1375
+ MINIMUM_INTERVENTION_AGENT_EVOLVE_METHOD_VERSION,
1376
+ )
1377
+ is_evidence_calibrated_source_mix = method_identity == (
1378
+ EVIDENCE_CALIBRATED_SOURCE_MIX_AGENT_EVOLVE_METHOD_ID,
1379
+ EVIDENCE_CALIBRATED_SOURCE_MIX_AGENT_EVOLVE_METHOD_VERSION,
1380
+ )
1381
+ is_residual_frontier = method_identity == (
1382
+ RESIDUAL_FRONTIER_AGENT_EVOLVE_METHOD_ID,
1383
+ RESIDUAL_FRONTIER_AGENT_EVOLVE_METHOD_VERSION,
1384
+ )
1385
+ is_contextual_search = method_identity in {
1386
+ (
1387
+ CONTEXTUAL_SEARCH_AGENT_EVOLVE_METHOD_ID,
1388
+ CONTEXTUAL_SEARCH_AGENT_EVOLVE_METHOD_VERSION,
1389
+ ),
1390
+ (
1391
+ RESIDUAL_FRONTIER_AGENT_EVOLVE_METHOD_ID,
1392
+ RESIDUAL_FRONTIER_AGENT_EVOLVE_METHOD_VERSION,
1393
+ ),
1394
+ }
1395
+ is_evidence_calibrated_source_mix = (
1396
+ is_evidence_calibrated_source_mix or is_contextual_search
1397
+ )
1398
+ is_minimum_intervention = (
1399
+ is_minimum_intervention or is_evidence_calibrated_source_mix
1400
+ )
1401
+ is_constraint_decoupled = (
1402
+ is_constraint_decoupled
1403
+ or is_minimum_intervention
1404
+ or is_constraint_decoupled_target
1405
+ )
1406
+ is_stagnation_aware = is_stagnation_aware or (
1407
+ is_constraint_decoupled
1408
+ and not is_target_conditioned
1409
+ and not is_residual_frontier
1410
+ )
1411
+ is_horizon_bounded = (
1412
+ is_horizon_bounded or is_stagnation_aware or is_residual_frontier
1413
+ )
1414
+ is_context_local = method_identity in {
1415
+ (
1416
+ CONTEXT_LOCAL_AGENT_EVOLVE_METHOD_ID,
1417
+ CONTEXT_LOCAL_AGENT_EVOLVE_METHOD_VERSION,
1418
+ ),
1419
+ (
1420
+ OPERATOR_STRATIFIED_AGENT_EVOLVE_METHOD_ID,
1421
+ OPERATOR_STRATIFIED_AGENT_EVOLVE_METHOD_VERSION,
1422
+ ),
1423
+ (
1424
+ HORIZON_BOUNDED_AGENT_EVOLVE_METHOD_ID,
1425
+ HORIZON_BOUNDED_AGENT_EVOLVE_METHOD_VERSION,
1426
+ ),
1427
+ (
1428
+ STAGNATION_AWARE_AGENT_EVOLVE_METHOD_ID,
1429
+ STAGNATION_AWARE_AGENT_EVOLVE_METHOD_VERSION,
1430
+ ),
1431
+ (
1432
+ CONSTRAINT_DECOUPLED_AGENT_EVOLVE_METHOD_ID,
1433
+ CONSTRAINT_DECOUPLED_AGENT_EVOLVE_METHOD_VERSION,
1434
+ ),
1435
+ (
1436
+ MINIMUM_INTERVENTION_AGENT_EVOLVE_METHOD_ID,
1437
+ MINIMUM_INTERVENTION_AGENT_EVOLVE_METHOD_VERSION,
1438
+ ),
1439
+ (
1440
+ EVIDENCE_CALIBRATED_SOURCE_MIX_AGENT_EVOLVE_METHOD_ID,
1441
+ EVIDENCE_CALIBRATED_SOURCE_MIX_AGENT_EVOLVE_METHOD_VERSION,
1442
+ ),
1443
+ (
1444
+ CONTEXTUAL_SEARCH_AGENT_EVOLVE_METHOD_ID,
1445
+ CONTEXTUAL_SEARCH_AGENT_EVOLVE_METHOD_VERSION,
1446
+ ),
1447
+ (
1448
+ RESIDUAL_FRONTIER_AGENT_EVOLVE_METHOD_ID,
1449
+ RESIDUAL_FRONTIER_AGENT_EVOLVE_METHOD_VERSION,
1450
+ ),
1451
+ (
1452
+ TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_ID,
1453
+ TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_VERSION,
1454
+ ),
1455
+ (
1456
+ CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_ID,
1457
+ CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_VERSION,
1458
+ ),
1459
+ }
1460
+ is_hierarchical = is_hierarchical or is_context_local
1461
+ has_frontier_context = method_identity in {
1462
+ _method_identity(
1463
+ hierarchical_proposal_support=hierarchical,
1464
+ frontier_context=True,
1465
+ )
1466
+ for hierarchical in (False, True)
1467
+ }
1468
+ has_frontier_context = has_frontier_context or is_context_local
1469
+ if (implementations.archive_context is not None) is not has_frontier_context:
1470
+ raise ValueError(
1471
+ "runtime archive-context implementation differs from method identity"
1472
+ )
1473
+ if (implementations.variation_topology is not None) is not is_context_local:
1474
+ raise ValueError(
1475
+ "runtime contextual/variation implementations differ from method identity"
1476
+ )
1477
+ if (
1478
+ type(implementations.parent_selection)
1479
+ is StagnationAwareDiverseCampaignParentSelector
1480
+ ) is not is_stagnation_aware:
1481
+ raise ValueError(
1482
+ "runtime stagnation-aware parent implementation differs from "
1483
+ "method identity"
1484
+ )
1485
+ if (
1486
+ type(implementations.parent_selection)
1487
+ is ResidualHypervolumeCampaignParentSelector
1488
+ ) is not is_residual_frontier:
1489
+ raise ValueError(
1490
+ "runtime residual-frontier parent implementation differs from "
1491
+ "method identity"
1492
+ )
1493
+ if (
1494
+ (is_operator_stratified or is_horizon_bounded or is_target_conditioned)
1495
+ and implementations.variation_topology is not None
1496
+ and implementations.variation_topology.policy_id
1497
+ != _HIERARCHICAL_R2_VARIATION_TOPOLOGY_POLICY_ID
1498
+ ):
1499
+ raise ValueError(
1500
+ "operator-stratified runtime requires hierarchical-r2 topology"
1501
+ )
1502
+ bindings = implementations.bindings(
1503
+ hierarchical_proposal_support=is_hierarchical,
1504
+ operator_stratified_acquisition=is_operator_stratified,
1505
+ horizon_bounded_acquisition=is_horizon_bounded,
1506
+ target_conditioned_acquisition=is_target_conditioned,
1507
+ constraint_decoupled_acquisition=is_constraint_decoupled,
1508
+ minimum_intervention_projection=is_minimum_intervention,
1509
+ evidence_calibrated_source_mix=is_evidence_calibrated_source_mix,
1510
+ contextual_search_allocation=is_contextual_search,
1511
+ residual_frontier_planning=is_residual_frontier,
1512
+ )
1513
+ rebound = replace(
1514
+ profile,
1515
+ parent_selection=bindings[ReferenceCampaignPolicyRole.PARENT_SELECTION],
1516
+ memory_assignment=bindings[ReferenceCampaignPolicyRole.MEMORY_ASSIGNMENT],
1517
+ portfolio_selection=bindings[ReferenceCampaignPolicyRole.PORTFOLIO_SELECTION],
1518
+ recombination=bindings[ReferenceCampaignPolicyRole.RECOMBINATION],
1519
+ reflection=bindings[ReferenceCampaignPolicyRole.REFLECTION],
1520
+ archive_context=bindings.get(ReferenceCampaignPolicyRole.ARCHIVE_CONTEXT),
1521
+ variation_topology=bindings.get(ReferenceCampaignPolicyRole.VARIATION_TOPOLOGY),
1522
+ contextual_outcomes=bindings.get(
1523
+ ReferenceCampaignPolicyRole.CONTEXTUAL_OUTCOMES
1524
+ ),
1525
+ )
1526
+ if rebound.experiment_definition_sha256 != profile.experiment_definition_sha256:
1527
+ raise AssertionError("runtime rebinding changed experiment identity")
1528
+ return rebound
1529
+
1530
+
1531
+ __all__ = [
1532
+ "CONSTRAINT_DECOUPLED_AGENT_EVOLVE_METHOD_ID",
1533
+ "CONSTRAINT_DECOUPLED_AGENT_EVOLVE_METHOD_VERSION",
1534
+ "CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_ID",
1535
+ "CONSTRAINT_DECOUPLED_TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_VERSION",
1536
+ "CONTEXTUAL_SEARCH_AGENT_EVOLVE_METHOD_ID",
1537
+ "CONTEXTUAL_SEARCH_AGENT_EVOLVE_METHOD_VERSION",
1538
+ "RESIDUAL_FRONTIER_AGENT_EVOLVE_METHOD_ID",
1539
+ "RESIDUAL_FRONTIER_AGENT_EVOLVE_METHOD_VERSION",
1540
+ "EVIDENCE_CALIBRATED_SOURCE_MIX_AGENT_EVOLVE_METHOD_ID",
1541
+ "EVIDENCE_CALIBRATED_SOURCE_MIX_AGENT_EVOLVE_METHOD_VERSION",
1542
+ "MINIMUM_INTERVENTION_AGENT_EVOLVE_METHOD_ID",
1543
+ "MINIMUM_INTERVENTION_AGENT_EVOLVE_METHOD_VERSION",
1544
+ "FRONTIER_AGENT_EVOLVE_METHOD_ID",
1545
+ "FRONTIER_AGENT_EVOLVE_METHOD_VERSION",
1546
+ "FRONTIER_HIERARCHICAL_AGENT_EVOLVE_METHOD_ID",
1547
+ "FRONTIER_HIERARCHICAL_AGENT_EVOLVE_METHOD_VERSION",
1548
+ "CONTEXT_LOCAL_AGENT_EVOLVE_METHOD_ID",
1549
+ "CONTEXT_LOCAL_AGENT_EVOLVE_METHOD_VERSION",
1550
+ "HORIZON_BOUNDED_AGENT_EVOLVE_METHOD_ID",
1551
+ "HORIZON_BOUNDED_AGENT_EVOLVE_METHOD_VERSION",
1552
+ "STAGNATION_AWARE_AGENT_EVOLVE_METHOD_ID",
1553
+ "STAGNATION_AWARE_AGENT_EVOLVE_METHOD_VERSION",
1554
+ "TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_ID",
1555
+ "TARGET_CONDITIONED_AGENT_EVOLVE_METHOD_VERSION",
1556
+ "OPERATOR_STRATIFIED_AGENT_EVOLVE_METHOD_ID",
1557
+ "OPERATOR_STRATIFIED_AGENT_EVOLVE_METHOD_VERSION",
1558
+ "REFERENCE_AGENT_EVOLVE_METHOD_ID",
1559
+ "REFERENCE_AGENT_EVOLVE_METHOD_VERSION",
1560
+ "HIERARCHICAL_AGENT_EVOLVE_METHOD_ID",
1561
+ "HIERARCHICAL_AGENT_EVOLVE_METHOD_VERSION",
1562
+ "ReferenceCampaignImplementations",
1563
+ "ReferenceCampaignPolicyRole",
1564
+ "rebind_reference_campaign_implementations",
1565
+ "reference_atomic_variation_topology_binding",
1566
+ "reference_campaign_experiment_profile",
1567
+ "reference_contextual_outcomes_binding",
1568
+ "reference_multi_horizon_contextual_outcomes_binding",
1569
+ "reference_hierarchical_r2_variation_topology_binding",
1570
+ ]