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.
- agent_evolve/__init__.py +722 -0
- agent_evolve/agentic.py +2800 -0
- agent_evolve/api.py +767 -0
- agent_evolve/application/__init__.py +1580 -0
- agent_evolve/application/action_allocation.py +744 -0
- agent_evolve/application/action_allocation_frame.py +347 -0
- agent_evolve/application/action_allocation_frame_commit.py +185 -0
- agent_evolve/application/action_allocation_frame_commit_v3.py +184 -0
- agent_evolve/application/action_allocation_frame_v3.py +338 -0
- agent_evolve/application/action_archive_value.py +497 -0
- agent_evolve/application/action_evidence_consistency.py +455 -0
- agent_evolve/application/action_forecast_partitioning.py +1471 -0
- agent_evolve/application/action_metric_projection.py +211 -0
- agent_evolve/application/action_role_value.py +680 -0
- agent_evolve/application/action_score_authorities.py +363 -0
- agent_evolve/application/action_structural_signature.py +116 -0
- agent_evolve/application/action_target_realization.py +402 -0
- agent_evolve/application/agentic_evolution.py +7734 -0
- agent_evolve/application/agentic_portfolio_residual_expert.py +835 -0
- agent_evolve/application/anchor_residual_identification.py +463 -0
- agent_evolve/application/archive_conditioned_action_target.py +208 -0
- agent_evolve/application/artifact_journal.py +246 -0
- agent_evolve/application/artifact_replay.py +347 -0
- agent_evolve/application/budgeted_optimizer.py +1828 -0
- agent_evolve/application/calibrated_campaign.py +485 -0
- agent_evolve/application/calibrated_current_prefix_forecast_opportunity.py +322 -0
- agent_evolve/application/calibrated_positive_gain_opportunity.py +1581 -0
- agent_evolve/application/campaign_capacity_recourse.py +254 -0
- agent_evolve/application/campaign_contextual_outcomes.py +119 -0
- agent_evolve/application/campaign_diagnostic_blocks.py +930 -0
- agent_evolve/application/campaign_evidence_registry.py +262 -0
- agent_evolve/application/campaign_execution.py +2537 -0
- agent_evolve/application/campaign_generation_audit.py +942 -0
- agent_evolve/application/campaign_learning.py +1812 -0
- agent_evolve/application/campaign_learning_runtime.py +1977 -0
- agent_evolve/application/campaign_search_phase.py +227 -0
- agent_evolve/application/campaign_selector_context_extension.py +220 -0
- agent_evolve/application/campaign_variation_envelope.py +649 -0
- agent_evolve/application/campaign_variation_trace.py +451 -0
- agent_evolve/application/candidate_archive_consequence.py +128 -0
- agent_evolve/application/causal_opportunity_portfolio_gate.py +385 -0
- agent_evolve/application/composite_outcome_updater.py +145 -0
- agent_evolve/application/composition_portfolio_selection.py +363 -0
- agent_evolve/application/concurrent_stage.py +144 -0
- agent_evolve/application/contextual_action_allocation.py +181 -0
- agent_evolve/application/contextual_campaign_outcomes.py +267 -0
- agent_evolve/application/contextual_campaign_planning.py +1366 -0
- agent_evolve/application/contextual_delayed_credit.py +651 -0
- agent_evolve/application/contextual_search_controller.py +2374 -0
- agent_evolve/application/current_prefix_forecast_opportunity.py +714 -0
- agent_evolve/application/decision_metric_projection.py +112 -0
- agent_evolve/application/derived_action_semantics.py +129 -0
- agent_evolve/application/detailed_evaluation.py +449 -0
- agent_evolve/application/earned_lineage.py +1011 -0
- agent_evolve/application/effective_choice_audit.py +484 -0
- agent_evolve/application/empirical_consequence_calibration.py +908 -0
- agent_evolve/application/evaluation_accounting.py +325 -0
- agent_evolve/application/evaluation_cache.py +199 -0
- agent_evolve/application/evaluation_escrow.py +547 -0
- agent_evolve/application/evaluation_recourse.py +253 -0
- agent_evolve/application/event_recorder.py +151 -0
- agent_evolve/application/evolution_campaign.py +1840 -0
- agent_evolve/application/executable_hypothesis.py +323 -0
- agent_evolve/application/factorial_branch_pilot.py +772 -0
- agent_evolve/application/finite_acquisition_capacity_recourse.py +672 -0
- agent_evolve/application/finite_acquisition_residual_expert.py +373 -0
- agent_evolve/application/finite_acquisition_variation_envelope.py +802 -0
- agent_evolve/application/finite_action_hypothesis_semantics.py +446 -0
- agent_evolve/application/finite_action_selection.py +188 -0
- agent_evolve/application/finite_action_set.py +306 -0
- agent_evolve/application/finite_action_transition.py +537 -0
- agent_evolve/application/finite_variation_eligibility.py +296 -0
- agent_evolve/application/forecast_geometry_portfolio.py +799 -0
- agent_evolve/application/forecast_opportunity_shadow_calibration.py +316 -0
- agent_evolve/application/front_proximity_admission.py +311 -0
- agent_evolve/application/front_proximity_parent_basis.py +458 -0
- agent_evolve/application/frozen_hurdle_score.py +659 -0
- agent_evolve/application/g3_causal_screen.py +2257 -0
- agent_evolve/application/g3_causal_validation.py +1046 -0
- agent_evolve/application/g3_postseal_curation.py +818 -0
- agent_evolve/application/gated_agentic_generator.py +205 -0
- agent_evolve/application/generation_feedback.py +293 -0
- agent_evolve/application/generative_proposal_journal.py +185 -0
- agent_evolve/application/geometry_conditional_elasticity.py +453 -0
- agent_evolve/application/global_wave_action_allocation.py +1151 -0
- agent_evolve/application/head_mass_conditional_seat.py +268 -0
- agent_evolve/application/identifiable_reflection_evidence.py +1147 -0
- agent_evolve/application/identifiable_reflection_learning.py +395 -0
- agent_evolve/application/identifiable_reflection_request.py +364 -0
- agent_evolve/application/in_memory_residual_archive.py +341 -0
- agent_evolve/application/insight_memory.py +1804 -0
- agent_evolve/application/live_runtime_manifest.py +758 -0
- agent_evolve/application/llm_task_queue.py +769 -0
- agent_evolve/application/matched_finite_action_block.py +409 -0
- agent_evolve/application/materialized_action_broker.py +2328 -0
- agent_evolve/application/materialized_action_constraints.py +83 -0
- agent_evolve/application/materialized_variation.py +211 -0
- agent_evolve/application/multi_option_evolution.py +1536 -0
- agent_evolve/application/outcome_adaptive_action_racing.py +2827 -0
- agent_evolve/application/outcome_adaptive_residual_campaign_runtime.py +580 -0
- agent_evolve/application/outcome_adaptive_residual_portfolio_evolution.py +3671 -0
- agent_evolve/application/outcome_conditioned_portfolio_selection.py +1374 -0
- agent_evolve/application/outcome_relation.py +193 -0
- agent_evolve/application/paired_allocation_comparison.py +241 -0
- agent_evolve/application/paired_block_schedule.py +127 -0
- agent_evolve/application/parent_measurement.py +226 -0
- agent_evolve/application/pareto_archive.py +811 -0
- agent_evolve/application/portfolio_campaign_runtime.py +4739 -0
- agent_evolve/application/portfolio_evolution.py +2950 -0
- agent_evolve/application/portfolio_hypothesis_observations.py +814 -0
- agent_evolve/application/portfolio_memory_attribution.py +581 -0
- agent_evolve/application/portfolio_memory_dose.py +788 -0
- agent_evolve/application/portfolio_memory_matched_control.py +938 -0
- agent_evolve/application/portfolio_memory_transfer.py +297 -0
- agent_evolve/application/portfolio_optimization_memory.py +363 -0
- agent_evolve/application/portfolio_outcome_feedback.py +1613 -0
- agent_evolve/application/portfolio_projection.py +335 -0
- agent_evolve/application/portfolio_recombination.py +2032 -0
- agent_evolve/application/post_evolution_reflection.py +834 -0
- agent_evolve/application/postcommit_rank_authority.py +245 -0
- agent_evolve/application/precommitted_portfolio_racing.py +2762 -0
- agent_evolve/application/prequential_archive_opportunity_calibration.py +1154 -0
- agent_evolve/application/prequential_residual_exploration.py +343 -0
- agent_evolve/application/prequential_score_portfolio.py +954 -0
- agent_evolve/application/projections.py +292 -0
- agent_evolve/application/protected_action_committee.py +1027 -0
- agent_evolve/application/protected_branch_pilot.py +376 -0
- agent_evolve/application/protected_current_prefix_forecast_opportunity.py +552 -0
- agent_evolve/application/provider_replay.py +910 -0
- agent_evolve/application/rank_balanced_causal_pilot.py +1372 -0
- agent_evolve/application/recombination_residual_expert.py +403 -0
- agent_evolve/application/reflection_workflow.py +571 -0
- agent_evolve/application/region_conditional_credit.py +911 -0
- agent_evolve/application/residual_campaign_runtime.py +531 -0
- agent_evolve/application/residual_headroom_campaign_runtime.py +459 -0
- agent_evolve/application/residual_headroom_ledger.py +1544 -0
- agent_evolve/application/residual_learning_transaction.py +396 -0
- agent_evolve/application/residual_portfolio_evolution.py +1228 -0
- agent_evolve/application/residual_reachability.py +749 -0
- agent_evolve/application/residual_stage_credit.py +499 -0
- agent_evolve/application/same_prefix_paired_audit.py +1580 -0
- agent_evolve/application/semantic_coverage_score_portfolio.py +838 -0
- agent_evolve/application/sequential_lineage_allocation.py +1017 -0
- agent_evolve/application/sequential_market_replay.py +1395 -0
- agent_evolve/application/sequential_residual_campaign_runtime.py +305 -0
- agent_evolve/application/sequential_residual_portfolio_evolution.py +940 -0
- agent_evolve/application/single_score_action_allocation.py +299 -0
- agent_evolve/application/source_exposure_allocation.py +906 -0
- agent_evolve/application/staged_memory.py +210 -0
- agent_evolve/application/stratified_cold_start_allocation.py +732 -0
- agent_evolve/application/support_guarded_hurdle_score.py +549 -0
- agent_evolve/application/target_conditioned_action_forecast.py +595 -0
- agent_evolve/application/target_conditioned_campaign.py +566 -0
- agent_evolve/application/treatment_assignment.py +201 -0
- agent_evolve/application/trusted_objective_evidence.py +217 -0
- agent_evolve/application/two_stage_action_evolution.py +1131 -0
- agent_evolve/application/v8lite_allocation_policy.py +1083 -0
- agent_evolve/application/v9_candidate_policy.py +1303 -0
- agent_evolve/bootstrap.py +108 -0
- agent_evolve/campaign_presets.py +517 -0
- agent_evolve/campaign_profiles.py +452 -0
- agent_evolve/campaign_variation_topology.py +288 -0
- agent_evolve/campaign_workload.py +950 -0
- agent_evolve/cli.py +797 -0
- agent_evolve/contract.py +241 -0
- agent_evolve/core/__init__.py +91 -0
- agent_evolve/core/action_semantics.py +411 -0
- agent_evolve/core/authored.py +105 -0
- agent_evolve/core/formatting.py +286 -0
- agent_evolve/core/optimization_semantics.py +324 -0
- agent_evolve/core/problem.py +167 -0
- agent_evolve/core/results.py +323 -0
- agent_evolve/core/stats.py +70 -0
- agent_evolve/core/telemetry.py +100 -0
- agent_evolve/domain/__init__.py +89 -0
- agent_evolve/domain/artifact.py +162 -0
- agent_evolve/domain/durable_text.py +68 -0
- agent_evolve/domain/event.py +1454 -0
- agent_evolve/domain/finite_action_set.py +426 -0
- agent_evolve/domain/finite_variation.py +526 -0
- agent_evolve/domain/generative_emission.py +559 -0
- agent_evolve/domain/ids.py +163 -0
- agent_evolve/domain/inline_text.py +106 -0
- agent_evolve/domain/insight.py +27 -0
- agent_evolve/domain/lineage.py +737 -0
- agent_evolve/domain/llm_task_queue.py +960 -0
- agent_evolve/domain/outcome.py +96 -0
- agent_evolve/domain/patch.py +854 -0
- agent_evolve/domain/typed_json.py +542 -0
- agent_evolve/domain/variation_space.py +158 -0
- agent_evolve/driver.py +1014 -0
- agent_evolve/harness/__init__.py +29 -0
- agent_evolve/harness/base.py +242 -0
- agent_evolve/harness/directives.py +163 -0
- agent_evolve/harness/generative_seal.py +479 -0
- agent_evolve/harness/registry.py +41 -0
- agent_evolve/infrastructure/__init__.py +39 -0
- agent_evolve/infrastructure/artifacts/__init__.py +6 -0
- agent_evolve/infrastructure/artifacts/_verification.py +67 -0
- agent_evolve/infrastructure/artifacts/filesystem.py +343 -0
- agent_evolve/infrastructure/artifacts/in_memory.py +73 -0
- agent_evolve/infrastructure/asyncio_runtime.py +109 -0
- agent_evolve/infrastructure/authored_runtime.py +188 -0
- agent_evolve/infrastructure/authored_worker.py +171 -0
- agent_evolve/infrastructure/clock.py +53 -0
- agent_evolve/infrastructure/events/__init__.py +6 -0
- agent_evolve/infrastructure/events/_validation.py +89 -0
- agent_evolve/infrastructure/events/in_memory.py +56 -0
- agent_evolve/infrastructure/events/jsonl.py +193 -0
- agent_evolve/infrastructure/exception_provenance.py +215 -0
- agent_evolve/infrastructure/ids.py +118 -0
- agent_evolve/infrastructure/lineage_codec.py +1836 -0
- agent_evolve/infrastructure/outcome_adaptive_phase_journal.py +170 -0
- agent_evolve/infrastructure/residual_headroom_journal.py +221 -0
- agent_evolve/infrastructure/resource_lease.py +370 -0
- agent_evolve/infrastructure/sanitization/__init__.py +8 -0
- agent_evolve/infrastructure/sanitization/strict_json.py +484 -0
- agent_evolve/infrastructure/sequential_phase_journal.py +170 -0
- agent_evolve/infrastructure/stream_liveness.py +383 -0
- agent_evolve/infrastructure/subprocess_boundary.py +136 -0
- agent_evolve/integrations/__init__.py +1 -0
- agent_evolve/integrations/botorch/__init__.py +28 -0
- agent_evolve/integrations/botorch/finite_qlognehvi.py +190 -0
- agent_evolve/integrations/botorch/finite_qlognehvi_batch.py +155 -0
- agent_evolve/integrations/botorch/finite_qlognehvi_batch_identity.py +20 -0
- agent_evolve/integrations/botorch/finite_qlognehvi_batch_worker.py +55 -0
- agent_evolve/integrations/botorch/finite_qlognehvi_identity.py +22 -0
- agent_evolve/integrations/botorch/finite_qlognehvi_worker.py +55 -0
- agent_evolve/integrations/botorch/subprocess_qlognehvi.py +261 -0
- agent_evolve/integrations/botorch/subprocess_qlognehvi_batch.py +273 -0
- agent_evolve/integrations/completion.py +242 -0
- agent_evolve/integrations/pydantic_ai/__init__.py +441 -0
- agent_evolve/integrations/pydantic_ai/action_forecast.py +1068 -0
- agent_evolve/integrations/pydantic_ai/agentic_generator.py +2308 -0
- agent_evolve/integrations/pydantic_ai/async_generator.py +1604 -0
- agent_evolve/integrations/pydantic_ai/boundary_codec.py +1526 -0
- agent_evolve/integrations/pydantic_ai/calibrated_portfolio_campaign.py +756 -0
- agent_evolve/integrations/pydantic_ai/calibrated_portfolio_selection.py +7537 -0
- agent_evolve/integrations/pydantic_ai/campaign_acquisition.py +609 -0
- agent_evolve/integrations/pydantic_ai/execution_binding.py +138 -0
- agent_evolve/integrations/pydantic_ai/forecast_geometry_action_committee.py +217 -0
- agent_evolve/integrations/pydantic_ai/harness.py +159 -0
- agent_evolve/integrations/pydantic_ai/heterogeneous_model_execution.py +306 -0
- agent_evolve/integrations/pydantic_ai/hierarchical_residual_adaptive_semantic_view.py +179 -0
- agent_evolve/integrations/pydantic_ai/json_schema_dialect.py +108 -0
- agent_evolve/integrations/pydantic_ai/materialized_hierarchical_residual_expert.py +952 -0
- agent_evolve/integrations/pydantic_ai/materialized_portfolio_judge.py +520 -0
- agent_evolve/integrations/pydantic_ai/model_execution_profile.py +659 -0
- agent_evolve/integrations/pydantic_ai/outbound_request_manifest.py +1170 -0
- agent_evolve/integrations/pydantic_ai/portable_residual_consequence_features.py +575 -0
- agent_evolve/integrations/pydantic_ai/portfolio_selection.py +422 -0
- agent_evolve/integrations/pydantic_ai/progress_aware_openrouter.py +416 -0
- agent_evolve/integrations/pydantic_ai/provider_attempt_join.py +1523 -0
- agent_evolve/integrations/pydantic_ai/provider_free_calibrated_runner.py +607 -0
- agent_evolve/integrations/pydantic_ai/queued_runner.py +2634 -0
- agent_evolve/integrations/pydantic_ai/reconciled_residual_reachability.py +1417 -0
- agent_evolve/integrations/pydantic_ai/residual_forecast_geometry.py +445 -0
- agent_evolve/integrations/pydantic_ai/residual_reachability.py +674 -0
- agent_evolve/integrations/pydantic_ai/residual_semantic_cells.py +239 -0
- agent_evolve/integrations/pydantic_ai/sealed_output_replay.py +1068 -0
- agent_evolve/integrations/pydantic_ai/semantic_coverage_residual_portfolio.py +770 -0
- agent_evolve/integrations/pydantic_ai/semantic_decision_replay.py +383 -0
- agent_evolve/integrations/pydantic_ai/support_adaptive_residual_portfolio.py +135 -0
- agent_evolve/integrations/pydantic_ai/trusted_residual_prompt_context.py +143 -0
- agent_evolve/integrations/pydantic_ai/validated_openrouter_model.py +107 -0
- agent_evolve/integrations/pymoo_adapter.py +242 -0
- agent_evolve/policies/__init__.py +17 -0
- agent_evolve/policies/check.py +469 -0
- agent_evolve/policies/emit_scaffold.py +451 -0
- agent_evolve/policies/feedback/__init__.py +37 -0
- agent_evolve/policies/feedback/held_out_asn.py +1325 -0
- agent_evolve/policies/genetic.py +607 -0
- agent_evolve/policies/llm_backoff.py +183 -0
- agent_evolve/policies/llm_chooser.py +226 -0
- agent_evolve/policies/llm_generator.py +1760 -0
- agent_evolve/policies/llm_init.py +267 -0
- agent_evolve/policies/llm_operator.py +109 -0
- agent_evolve/policies/llm_prior.py +194 -0
- agent_evolve/policies/llm_surrogate.py +334 -0
- agent_evolve/policies/measurement_evidence.py +704 -0
- agent_evolve/policies/memory/__init__.py +223 -0
- agent_evolve/policies/memory/balanced_subset_blocks.py +707 -0
- agent_evolve/policies/memory/compatibility_matching.py +593 -0
- agent_evolve/policies/memory/global_falsification.py +1841 -0
- agent_evolve/policies/memory/prompt_shape.py +503 -0
- agent_evolve/policies/memory/randomized_subset.py +714 -0
- agent_evolve/policies/memory/staged_causal.py +1270 -0
- agent_evolve/policies/memory/treatment_compliance.py +759 -0
- agent_evolve/policies/objective_resolution/__init__.py +17 -0
- agent_evolve/policies/objective_resolution/fixed_grid.py +364 -0
- agent_evolve/policies/operator_portfolio.py +407 -0
- agent_evolve/policies/reguidance.py +1133 -0
- agent_evolve/policies/reward/__init__.py +83 -0
- agent_evolve/policies/reward/affine_candidate_consequence.py +156 -0
- agent_evolve/policies/reward/affine_candidate_consequence_3d.py +159 -0
- agent_evolve/policies/reward/affine_hypervolume.py +490 -0
- agent_evolve/policies/reward/affine_hypervolume_3d.py +567 -0
- agent_evolve/policies/reward/contextual_marginal_utility.py +318 -0
- agent_evolve/policies/reward/frozen_archive.py +360 -0
- agent_evolve/policies/reward/frozen_wave_archive.py +368 -0
- agent_evolve/policies/search_state.py +208 -0
- agent_evolve/policies/selection/__init__.py +345 -0
- agent_evolve/policies/selection/acquisition_certified_slate.py +684 -0
- agent_evolve/policies/selection/affine_frontier_context.py +330 -0
- agent_evolve/policies/selection/affine_frontier_target.py +473 -0
- agent_evolve/policies/selection/archive_elite.py +1346 -0
- agent_evolve/policies/selection/calibrated_portfolio_binding.py +640 -0
- agent_evolve/policies/selection/calibrated_slate.py +1394 -0
- agent_evolve/policies/selection/calibrated_slate_codec.py +579 -0
- agent_evolve/policies/selection/common_candidate_pool.py +685 -0
- agent_evolve/policies/selection/diagnostic_sampling.py +319 -0
- agent_evolve/policies/selection/disjoint_pairs.py +479 -0
- agent_evolve/policies/selection/elite_explorer.py +719 -0
- agent_evolve/policies/selection/finite_action.py +187 -0
- agent_evolve/policies/selection/finite_option_prompt_projection.py +377 -0
- agent_evolve/policies/selection/finite_palette_evidence.py +247 -0
- agent_evolve/policies/selection/forecast_calibration.py +922 -0
- agent_evolve/policies/selection/frontier_probe_slate.py +814 -0
- agent_evolve/policies/selection/frozen_archive_pairs.py +762 -0
- agent_evolve/policies/selection/full_support_slate.py +91 -0
- agent_evolve/policies/selection/meaningful_direction.py +240 -0
- agent_evolve/policies/selection/memory_dose_feasibility.py +259 -0
- agent_evolve/policies/selection/model_anchored_slate.py +826 -0
- agent_evolve/policies/selection/phenotype_recourse.py +979 -0
- agent_evolve/policies/selection/proposal_support.py +368 -0
- agent_evolve/policies/selection/random_portfolio.py +254 -0
- agent_evolve/policies/selection/regret_bounded_slate.py +1084 -0
- agent_evolve/policies/selection/residual_frontier.py +463 -0
- agent_evolve/policies/selection/residual_frontier_target.py +605 -0
- agent_evolve/policies/selection/structural_posterior_slate.py +1571 -0
- agent_evolve/policies/selection/target_conditioned_allocator.py +648 -0
- agent_evolve/policies/selection/target_conditioned_features.py +812 -0
- agent_evolve/policies/selection/target_conditioned_prequential.py +1527 -0
- agent_evolve/policies/selection/task_keyed_palette.py +906 -0
- agent_evolve/policies/semantics.py +147 -0
- agent_evolve/policies/structure.py +362 -0
- agent_evolve/policies/structured_output_budget.py +62 -0
- agent_evolve/policies/surrogate.py +696 -0
- agent_evolve/policies/variation/__init__.py +1 -0
- agent_evolve/policies/variation/compositional_finite_catalog.py +426 -0
- agent_evolve/policies/variation/crossover_inheritance.py +575 -0
- agent_evolve/policies/variation/disjoint_recombination.py +611 -0
- agent_evolve/policies/variation/exact_composition_capacity.py +214 -0
- agent_evolve/policies/variation/exact_parent_crossover.py +950 -0
- agent_evolve/policies/variation/multiscale_restart_catalog.py +372 -0
- agent_evolve/policies/variation/source_union_finite_catalog.py +403 -0
- agent_evolve/policies/variation/typed_patch.py +1981 -0
- agent_evolve/policies/weighted_prior.py +394 -0
- agent_evolve/ports/__init__.py +383 -0
- agent_evolve/ports/action_allocation.py +733 -0
- agent_evolve/ports/action_allocation_frame.py +1153 -0
- agent_evolve/ports/action_allocation_frame_commit.py +294 -0
- agent_evolve/ports/action_allocation_frame_commit_v3.py +432 -0
- agent_evolve/ports/action_allocation_frame_v3.py +995 -0
- agent_evolve/ports/action_forecast.py +1568 -0
- agent_evolve/ports/action_metric_projection.py +165 -0
- agent_evolve/ports/agentic_generator.py +1561 -0
- agent_evolve/ports/archive_context.py +136 -0
- agent_evolve/ports/artifact_sanitizer.py +44 -0
- agent_evolve/ports/artifact_store.py +225 -0
- agent_evolve/ports/clock.py +13 -0
- agent_evolve/ports/contextual_search_allocation.py +827 -0
- agent_evolve/ports/decision_metric_projection.py +258 -0
- agent_evolve/ports/event_store.py +55 -0
- agent_evolve/ports/executable_hypothesis.py +557 -0
- agent_evolve/ports/finite_acquisition.py +377 -0
- agent_evolve/ports/finite_acquisition_batch.py +296 -0
- agent_evolve/ports/finite_acquisition_batch_json.py +164 -0
- agent_evolve/ports/finite_acquisition_json.py +247 -0
- agent_evolve/ports/finite_acquisition_space.py +168 -0
- agent_evolve/ports/finite_action_selection.py +348 -0
- agent_evolve/ports/finite_action_set.py +256 -0
- agent_evolve/ports/frontier_target.py +396 -0
- agent_evolve/ports/generation_failure.py +43 -0
- agent_evolve/ports/hard_feasibility.py +233 -0
- agent_evolve/ports/id_factory.py +34 -0
- agent_evolve/ports/llm_task_queue.py +93 -0
- agent_evolve/ports/objective_resolution.py +419 -0
- agent_evolve/ports/paired_allocation_comparison.py +401 -0
- agent_evolve/ports/paired_block_schedule.py +475 -0
- agent_evolve/ports/parent_measurement.py +336 -0
- agent_evolve/ports/portfolio_memory_dose.py +643 -0
- agent_evolve/ports/portfolio_selection.py +3169 -0
- agent_evolve/ports/postcommit_rank_authority.py +467 -0
- agent_evolve/ports/presented_action_evidence.py +794 -0
- agent_evolve/ports/resource_lease.py +162 -0
- agent_evolve/ports/structured_generator.py +734 -0
- agent_evolve/ports/structured_output_budget.py +120 -0
- agent_evolve/ports/subprocess_boundary.py +138 -0
- agent_evolve/ports/treatment_assignment.py +466 -0
- agent_evolve/ports/variation_catalog.py +76 -0
- agent_evolve/ports/variation_source.py +226 -0
- agent_evolve/proposal_mode.py +157 -0
- agent_evolve/proposers/__init__.py +10 -0
- agent_evolve/proposers/random_proposer.py +188 -0
- agent_evolve/provider_accounting.py +163 -0
- agent_evolve/py.typed +0 -0
- agent_evolve/reference_method.py +1570 -0
- agent_evolve/session/__init__.py +11 -0
- agent_evolve/session/authorship.py +864 -0
- agent_evolve/session/evaluate.py +236 -0
- agent_evolve/session/fidelity.py +237 -0
- agent_evolve/session/genetic_loop.py +742 -0
- agent_evolve/session/loop.py +803 -0
- agent_evolve/session/screening.py +671 -0
- agent_evolve/settings.py +376 -0
- agent_evolve/workload_kit.py +368 -0
- agent_evolve/workload_prompt.py +398 -0
- agentevolve_optimizer-0.5.0.dist-info/METADATA +599 -0
- agentevolve_optimizer-0.5.0.dist-info/RECORD +414 -0
- agentevolve_optimizer-0.5.0.dist-info/WHEEL +5 -0
- agentevolve_optimizer-0.5.0.dist-info/entry_points.txt +2 -0
- agentevolve_optimizer-0.5.0.dist-info/licenses/LICENSE +21 -0
- agentevolve_optimizer-0.5.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
"""Capacity-complete recourse backed by a generic finite acquisition expert."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import hashlib
|
|
7
|
+
import json
|
|
8
|
+
import re
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
|
|
11
|
+
from agent_evolve.application.agentic_evolution import (
|
|
12
|
+
AgenticEvolutionEngine,
|
|
13
|
+
EvolutionCandidate,
|
|
14
|
+
)
|
|
15
|
+
from agent_evolve.application.campaign_capacity_recourse import (
|
|
16
|
+
CampaignCapacityRecourseRequest,
|
|
17
|
+
CampaignCapacityRecourseResult,
|
|
18
|
+
)
|
|
19
|
+
from agent_evolve.domain.patch import require_sha256
|
|
20
|
+
from agent_evolve.domain.ids import CandidateId
|
|
21
|
+
from agent_evolve.domain.typed_json import (
|
|
22
|
+
FrozenJsonObject,
|
|
23
|
+
freeze_json,
|
|
24
|
+
thaw_json,
|
|
25
|
+
typed_json_sha256,
|
|
26
|
+
)
|
|
27
|
+
from agent_evolve.policies.selection.phenotype_recourse import (
|
|
28
|
+
PhenotypeIdentity,
|
|
29
|
+
PhenotypeIdentityPolicy,
|
|
30
|
+
)
|
|
31
|
+
from agent_evolve.ports.finite_acquisition import (
|
|
32
|
+
FiniteAcquisitionCandidate,
|
|
33
|
+
FiniteAcquisitionDecision,
|
|
34
|
+
FiniteAcquisitionObjective,
|
|
35
|
+
FiniteAcquisitionObservation,
|
|
36
|
+
FiniteAcquisitionPolicy,
|
|
37
|
+
FiniteAcquisitionRequest,
|
|
38
|
+
)
|
|
39
|
+
from agent_evolve.ports.finite_acquisition_space import (
|
|
40
|
+
FiniteAcquisitionSpace,
|
|
41
|
+
FiniteAcquisitionSpaceRequest,
|
|
42
|
+
validate_finite_acquisition_space_candidates,
|
|
43
|
+
validate_finite_acquisition_space_identity,
|
|
44
|
+
)
|
|
45
|
+
from agent_evolve.ports.hard_feasibility import (
|
|
46
|
+
HardFeasibilityPort,
|
|
47
|
+
HardFeasibilityRequest,
|
|
48
|
+
HardFeasibilityVerdict,
|
|
49
|
+
assess_hard_feasibility,
|
|
50
|
+
hard_feasibility_decision_batch_sha256,
|
|
51
|
+
validate_hard_feasibility_port,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
POLICY_ID = "finite_acquisition_capacity_recourse"
|
|
56
|
+
POLICY_VERSION = 1
|
|
57
|
+
_TOKEN = re.compile(r"^[a-z][a-z0-9_.:-]{0,127}$")
|
|
58
|
+
_DEFINITION_DOMAIN = b"agent-evolve:finite-acquisition-capacity-recourse:def:v1\x00"
|
|
59
|
+
_PROPOSAL_MEMBER_DOMAIN = (
|
|
60
|
+
b"agent-evolve:finite-acquisition-capacity-proposal-member:v1\x00"
|
|
61
|
+
)
|
|
62
|
+
_PROPOSAL_DOMAIN = b"agent-evolve:finite-acquisition-capacity-proposal:v1\x00"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _canonical_json(value: object) -> bytes:
|
|
66
|
+
return json.dumps(
|
|
67
|
+
value,
|
|
68
|
+
allow_nan=False,
|
|
69
|
+
ensure_ascii=True,
|
|
70
|
+
separators=(",", ":"),
|
|
71
|
+
sort_keys=True,
|
|
72
|
+
).encode("ascii", errors="strict")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _acquisition_identity(
|
|
76
|
+
policy: FiniteAcquisitionPolicy,
|
|
77
|
+
) -> tuple[str, int, str]:
|
|
78
|
+
if not isinstance(policy, FiniteAcquisitionPolicy):
|
|
79
|
+
raise TypeError("acquisition must implement FiniteAcquisitionPolicy")
|
|
80
|
+
values = (
|
|
81
|
+
getattr(policy, "policy_id", None),
|
|
82
|
+
getattr(policy, "policy_version", None),
|
|
83
|
+
getattr(policy, "definition_sha256", None),
|
|
84
|
+
)
|
|
85
|
+
if type(values[0]) is not str or _TOKEN.fullmatch(values[0]) is None:
|
|
86
|
+
raise ValueError("acquisition policy_id has invalid syntax")
|
|
87
|
+
if type(values[1]) is not int or values[1] <= 0:
|
|
88
|
+
raise ValueError("acquisition policy_version must be positive")
|
|
89
|
+
require_sha256(values[2], "acquisition definition_sha256")
|
|
90
|
+
return values # type: ignore[return-value]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _phenotype(
|
|
94
|
+
policy: PhenotypeIdentityPolicy,
|
|
95
|
+
configuration: FrozenJsonObject,
|
|
96
|
+
) -> str:
|
|
97
|
+
identity = policy.identify(thaw_json(configuration))
|
|
98
|
+
if type(identity) is not PhenotypeIdentity:
|
|
99
|
+
raise TypeError("phenotype policy must return exact PhenotypeIdentity")
|
|
100
|
+
PhenotypeIdentity.__post_init__(identity)
|
|
101
|
+
if (
|
|
102
|
+
identity.policy_id != policy.policy_id
|
|
103
|
+
or identity.policy_version != policy.policy_version
|
|
104
|
+
):
|
|
105
|
+
raise ValueError("phenotype policy returned a foreign identity")
|
|
106
|
+
return identity.value_sha256
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@dataclass(frozen=True, slots=True)
|
|
110
|
+
class FiniteAcquisitionCapacityProposalMember:
|
|
111
|
+
"""One unevaluated, fully materialized acquisition nomination."""
|
|
112
|
+
|
|
113
|
+
target_candidate_id: CandidateId
|
|
114
|
+
acquisition_candidate_id: str
|
|
115
|
+
configuration: FrozenJsonObject
|
|
116
|
+
phenotype_identity_sha256: str
|
|
117
|
+
native_rank: int
|
|
118
|
+
member_sha256: str = field(init=False, default="")
|
|
119
|
+
|
|
120
|
+
def __post_init__(self) -> None:
|
|
121
|
+
if type(self.target_candidate_id) is not CandidateId:
|
|
122
|
+
raise TypeError("target_candidate_id must be exact")
|
|
123
|
+
CandidateId.__post_init__(self.target_candidate_id)
|
|
124
|
+
if (
|
|
125
|
+
type(self.acquisition_candidate_id) is not str
|
|
126
|
+
or not self.acquisition_candidate_id
|
|
127
|
+
):
|
|
128
|
+
raise ValueError("acquisition_candidate_id must be non-empty")
|
|
129
|
+
if type(self.configuration) is not FrozenJsonObject:
|
|
130
|
+
raise TypeError("configuration must be an exact frozen object")
|
|
131
|
+
require_sha256(
|
|
132
|
+
self.phenotype_identity_sha256,
|
|
133
|
+
"phenotype_identity_sha256",
|
|
134
|
+
)
|
|
135
|
+
if type(self.native_rank) is not int or self.native_rank <= 0:
|
|
136
|
+
raise ValueError("native_rank must be positive")
|
|
137
|
+
computed = hashlib.sha256(
|
|
138
|
+
_PROPOSAL_MEMBER_DOMAIN + _canonical_json(self._unsigned_record())
|
|
139
|
+
).hexdigest()
|
|
140
|
+
if self.member_sha256 not in ("", computed):
|
|
141
|
+
raise ValueError("member_sha256 does not authenticate the proposal")
|
|
142
|
+
object.__setattr__(self, "member_sha256", computed)
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def configuration_sha256(self) -> str:
|
|
146
|
+
return typed_json_sha256(self.configuration)
|
|
147
|
+
|
|
148
|
+
def _unsigned_record(self) -> dict[str, object]:
|
|
149
|
+
return {
|
|
150
|
+
"schema_version": 1,
|
|
151
|
+
"target_candidate_id": self.target_candidate_id.value,
|
|
152
|
+
"acquisition_candidate_id": self.acquisition_candidate_id,
|
|
153
|
+
"configuration_sha256": self.configuration_sha256,
|
|
154
|
+
"phenotype_identity_sha256": self.phenotype_identity_sha256,
|
|
155
|
+
"native_rank": self.native_rank,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
def to_record(self) -> dict[str, object]:
|
|
159
|
+
self.__post_init__()
|
|
160
|
+
return {**self._unsigned_record(), "member_sha256": self.member_sha256}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
@dataclass(frozen=True, slots=True)
|
|
164
|
+
class FiniteAcquisitionCapacityProposal:
|
|
165
|
+
"""Replayable pre-evaluation acquisition transaction for a missing slate."""
|
|
166
|
+
|
|
167
|
+
request_sha256: str
|
|
168
|
+
generation: int
|
|
169
|
+
policy_id: str
|
|
170
|
+
policy_version: int
|
|
171
|
+
policy_definition_sha256: str
|
|
172
|
+
decision: FiniteAcquisitionDecision
|
|
173
|
+
members: tuple[FiniteAcquisitionCapacityProposalMember, ...]
|
|
174
|
+
evidence: FrozenJsonObject
|
|
175
|
+
proposal_sha256: str = field(init=False, default="")
|
|
176
|
+
|
|
177
|
+
def __post_init__(self) -> None:
|
|
178
|
+
require_sha256(self.request_sha256, "request_sha256")
|
|
179
|
+
if type(self.generation) is not int or self.generation <= 0:
|
|
180
|
+
raise ValueError("generation must be positive")
|
|
181
|
+
if type(self.policy_id) is not str or _TOKEN.fullmatch(self.policy_id) is None:
|
|
182
|
+
raise ValueError("policy_id has invalid syntax")
|
|
183
|
+
if type(self.policy_version) is not int or self.policy_version <= 0:
|
|
184
|
+
raise ValueError("policy_version must be positive")
|
|
185
|
+
require_sha256(self.policy_definition_sha256, "policy_definition_sha256")
|
|
186
|
+
if type(self.decision) is not FiniteAcquisitionDecision:
|
|
187
|
+
raise TypeError("decision must be exact")
|
|
188
|
+
self.decision.__post_init__()
|
|
189
|
+
if type(self.members) is not tuple or not self.members:
|
|
190
|
+
raise ValueError("members must be a non-empty exact tuple")
|
|
191
|
+
for member in self.members:
|
|
192
|
+
if type(member) is not FiniteAcquisitionCapacityProposalMember:
|
|
193
|
+
raise TypeError("members must contain exact proposal members")
|
|
194
|
+
member.__post_init__()
|
|
195
|
+
if tuple(value.native_rank for value in self.members) != tuple(
|
|
196
|
+
range(1, len(self.members) + 1)
|
|
197
|
+
):
|
|
198
|
+
raise ValueError("proposal native ranks must be contiguous")
|
|
199
|
+
if tuple(
|
|
200
|
+
(value.acquisition_candidate_id, value.configuration_sha256)
|
|
201
|
+
for value in self.members
|
|
202
|
+
) != tuple(
|
|
203
|
+
(value.candidate_id, value.configuration_sha256)
|
|
204
|
+
for value in self.decision.selected
|
|
205
|
+
):
|
|
206
|
+
raise ValueError("proposal members differ from the acquisition decision")
|
|
207
|
+
if len({value.target_candidate_id for value in self.members}) != len(
|
|
208
|
+
self.members
|
|
209
|
+
):
|
|
210
|
+
raise ValueError("proposal target candidate IDs must be unique")
|
|
211
|
+
if len({value.phenotype_identity_sha256 for value in self.members}) != len(
|
|
212
|
+
self.members
|
|
213
|
+
):
|
|
214
|
+
raise ValueError("proposal member phenotypes must be unique")
|
|
215
|
+
if type(self.evidence) is not FrozenJsonObject:
|
|
216
|
+
raise TypeError("evidence must be an exact frozen object")
|
|
217
|
+
computed = hashlib.sha256(
|
|
218
|
+
_PROPOSAL_DOMAIN + _canonical_json(self._unsigned_record())
|
|
219
|
+
).hexdigest()
|
|
220
|
+
if self.proposal_sha256 not in ("", computed):
|
|
221
|
+
raise ValueError("proposal_sha256 does not authenticate the proposal")
|
|
222
|
+
object.__setattr__(self, "proposal_sha256", computed)
|
|
223
|
+
|
|
224
|
+
def _unsigned_record(self) -> dict[str, object]:
|
|
225
|
+
return {
|
|
226
|
+
"schema_version": 1,
|
|
227
|
+
"request_sha256": self.request_sha256,
|
|
228
|
+
"generation": self.generation,
|
|
229
|
+
"policy_id": self.policy_id,
|
|
230
|
+
"policy_version": self.policy_version,
|
|
231
|
+
"policy_definition_sha256": self.policy_definition_sha256,
|
|
232
|
+
"decision": self.decision.to_record(),
|
|
233
|
+
"members": [value.to_record() for value in self.members],
|
|
234
|
+
"evidence": thaw_json(self.evidence),
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
def to_record(self) -> dict[str, object]:
|
|
238
|
+
self.__post_init__()
|
|
239
|
+
return {**self._unsigned_record(), "proposal_sha256": self.proposal_sha256}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
@dataclass(frozen=True, slots=True)
|
|
243
|
+
class FiniteAcquisitionCapacityRecourse:
|
|
244
|
+
"""Refit on the current real archive and fill every missing occurrence."""
|
|
245
|
+
|
|
246
|
+
objectives: tuple[FiniteAcquisitionObjective, ...]
|
|
247
|
+
space: FiniteAcquisitionSpace
|
|
248
|
+
acquisition: FiniteAcquisitionPolicy
|
|
249
|
+
phenotype_identity: PhenotypeIdentityPolicy
|
|
250
|
+
engine: AgenticEvolutionEngine
|
|
251
|
+
hard_feasibility: HardFeasibilityPort | None = None
|
|
252
|
+
pool_size: int = 8192
|
|
253
|
+
seed: int = 0
|
|
254
|
+
policy_id: str = field(init=False, default=POLICY_ID)
|
|
255
|
+
policy_version: int = field(init=False, default=POLICY_VERSION)
|
|
256
|
+
definition_sha256: str = field(init=False, default="")
|
|
257
|
+
|
|
258
|
+
def __post_init__(self) -> None:
|
|
259
|
+
if type(self.objectives) is not tuple or len(self.objectives) < 2:
|
|
260
|
+
raise ValueError("objectives must contain at least two exact axes")
|
|
261
|
+
for value in self.objectives:
|
|
262
|
+
if type(value) is not FiniteAcquisitionObjective:
|
|
263
|
+
raise TypeError("objectives must contain exact acquisition axes")
|
|
264
|
+
value.__post_init__()
|
|
265
|
+
metric_ids = tuple(value.metric_id for value in self.objectives)
|
|
266
|
+
if metric_ids != tuple(sorted(set(metric_ids))):
|
|
267
|
+
raise ValueError("objective axes must be unique and metric-sorted")
|
|
268
|
+
space_identity = validate_finite_acquisition_space_identity(self.space)
|
|
269
|
+
acquisition_identity = _acquisition_identity(self.acquisition)
|
|
270
|
+
if not isinstance(self.engine, AgenticEvolutionEngine):
|
|
271
|
+
raise TypeError("engine must be an AgenticEvolutionEngine")
|
|
272
|
+
if not callable(getattr(self.phenotype_identity, "identify", None)):
|
|
273
|
+
raise TypeError("phenotype_identity must implement identify")
|
|
274
|
+
phenotype_identity = (
|
|
275
|
+
getattr(self.phenotype_identity, "policy_id", None),
|
|
276
|
+
getattr(self.phenotype_identity, "policy_version", None),
|
|
277
|
+
)
|
|
278
|
+
PhenotypeIdentity(
|
|
279
|
+
policy_id=phenotype_identity[0],
|
|
280
|
+
policy_version=phenotype_identity[1],
|
|
281
|
+
value_sha256="0" * 64,
|
|
282
|
+
)
|
|
283
|
+
hard_feasibility_identity = (
|
|
284
|
+
None
|
|
285
|
+
if self.hard_feasibility is None
|
|
286
|
+
else validate_hard_feasibility_port(self.hard_feasibility)
|
|
287
|
+
)
|
|
288
|
+
if type(self.pool_size) is not int or self.pool_size < 16:
|
|
289
|
+
raise ValueError("pool_size must be at least 16")
|
|
290
|
+
if type(self.seed) is not int or self.seed < 0:
|
|
291
|
+
raise ValueError("seed must be non-negative")
|
|
292
|
+
definition = {
|
|
293
|
+
"schema_version": 1,
|
|
294
|
+
"policy_id": POLICY_ID,
|
|
295
|
+
"policy_version": POLICY_VERSION,
|
|
296
|
+
"objectives": [value.to_record() for value in self.objectives],
|
|
297
|
+
"space": {
|
|
298
|
+
"space_id": space_identity[0],
|
|
299
|
+
"space_version": space_identity[1],
|
|
300
|
+
"definition_sha256": space_identity[2],
|
|
301
|
+
},
|
|
302
|
+
"acquisition": {
|
|
303
|
+
"policy_id": acquisition_identity[0],
|
|
304
|
+
"policy_version": acquisition_identity[1],
|
|
305
|
+
"definition_sha256": acquisition_identity[2],
|
|
306
|
+
},
|
|
307
|
+
"phenotype_identity": {
|
|
308
|
+
"policy_id": phenotype_identity[0],
|
|
309
|
+
"policy_version": phenotype_identity[1],
|
|
310
|
+
},
|
|
311
|
+
"hard_feasibility": (
|
|
312
|
+
None
|
|
313
|
+
if hard_feasibility_identity is None
|
|
314
|
+
else {
|
|
315
|
+
"policy_id": hard_feasibility_identity[0],
|
|
316
|
+
"policy_version": hard_feasibility_identity[1],
|
|
317
|
+
"definition_sha256": hard_feasibility_identity[2],
|
|
318
|
+
"rejection_authority": "exact_infeasibility_only",
|
|
319
|
+
}
|
|
320
|
+
),
|
|
321
|
+
"pool_size": self.pool_size,
|
|
322
|
+
"seed": self.seed,
|
|
323
|
+
"state_binding": "strictly_prior_real_outcomes",
|
|
324
|
+
"capacity_contract": "exact_missing_occurrences",
|
|
325
|
+
}
|
|
326
|
+
computed = hashlib.sha256(
|
|
327
|
+
_DEFINITION_DOMAIN + _canonical_json(definition)
|
|
328
|
+
).hexdigest()
|
|
329
|
+
if self.definition_sha256 not in ("", computed):
|
|
330
|
+
raise ValueError("definition_sha256 does not authenticate the policy")
|
|
331
|
+
object.__setattr__(self, "definition_sha256", computed)
|
|
332
|
+
|
|
333
|
+
def _observations(
|
|
334
|
+
self,
|
|
335
|
+
request: CampaignCapacityRecourseRequest,
|
|
336
|
+
) -> tuple[FiniteAcquisitionObservation, ...]:
|
|
337
|
+
metric_ids = tuple(value.metric_id for value in self.objectives)
|
|
338
|
+
by_configuration: dict[str, FiniteAcquisitionObservation] = {}
|
|
339
|
+
for candidate in request.state.candidates:
|
|
340
|
+
if not candidate.valid or type(candidate.configuration) is not FrozenJsonObject:
|
|
341
|
+
continue
|
|
342
|
+
objective_map = candidate.objective_map
|
|
343
|
+
if any(metric_id not in objective_map for metric_id in metric_ids):
|
|
344
|
+
raise ValueError("real observation omits a configured objective axis")
|
|
345
|
+
configuration_sha256 = candidate.occurrence.configuration_hash
|
|
346
|
+
observation = FiniteAcquisitionObservation(
|
|
347
|
+
candidate_id=f"obs-{configuration_sha256[:32]}",
|
|
348
|
+
configuration_sha256=configuration_sha256,
|
|
349
|
+
features=self.space.features(candidate.configuration),
|
|
350
|
+
objectives=tuple(
|
|
351
|
+
(metric_id, objective_map[metric_id]) for metric_id in metric_ids
|
|
352
|
+
),
|
|
353
|
+
)
|
|
354
|
+
previous = by_configuration.get(configuration_sha256)
|
|
355
|
+
if previous is not None and previous != observation:
|
|
356
|
+
raise ValueError("one configuration has conflicting real observations")
|
|
357
|
+
by_configuration[configuration_sha256] = observation
|
|
358
|
+
observations = tuple(
|
|
359
|
+
by_configuration[key] for key in sorted(by_configuration)
|
|
360
|
+
)
|
|
361
|
+
if not observations:
|
|
362
|
+
raise ValueError("capacity recourse requires prior successful observations")
|
|
363
|
+
return observations
|
|
364
|
+
|
|
365
|
+
def propose(
|
|
366
|
+
self,
|
|
367
|
+
request: CampaignCapacityRecourseRequest,
|
|
368
|
+
) -> FiniteAcquisitionCapacityProposal:
|
|
369
|
+
"""Materialize a fresh ranked slate without evaluating any member."""
|
|
370
|
+
self.__post_init__()
|
|
371
|
+
if type(request) is not CampaignCapacityRecourseRequest:
|
|
372
|
+
raise TypeError("request must be exact")
|
|
373
|
+
request.__post_init__()
|
|
374
|
+
needed = request.missing_candidate_occurrences
|
|
375
|
+
observations = self._observations(request)
|
|
376
|
+
|
|
377
|
+
configurations_by_sha256: dict[str, FrozenJsonObject] = {}
|
|
378
|
+
for candidate in request.state.candidates:
|
|
379
|
+
if type(candidate.configuration) is FrozenJsonObject:
|
|
380
|
+
configurations_by_sha256[
|
|
381
|
+
candidate.occurrence.configuration_hash
|
|
382
|
+
] = candidate.configuration
|
|
383
|
+
known_configuration_sha256s = tuple(sorted(configurations_by_sha256))
|
|
384
|
+
space_request = FiniteAcquisitionSpaceRequest(
|
|
385
|
+
campaign_scope_sha256=request.campaign_scope_sha256,
|
|
386
|
+
cutoff_index=request.state.unique_evaluations,
|
|
387
|
+
pool_size=self.pool_size,
|
|
388
|
+
seed=self.seed + request.generation,
|
|
389
|
+
observed_configurations=tuple(
|
|
390
|
+
configurations_by_sha256[value]
|
|
391
|
+
for value in known_configuration_sha256s
|
|
392
|
+
),
|
|
393
|
+
excluded_configuration_sha256s=known_configuration_sha256s,
|
|
394
|
+
)
|
|
395
|
+
materializations = self.space.candidates(space_request)
|
|
396
|
+
validate_finite_acquisition_space_candidates(
|
|
397
|
+
request=space_request,
|
|
398
|
+
candidates=materializations,
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
known_phenotypes = {
|
|
402
|
+
_phenotype(self.phenotype_identity, value)
|
|
403
|
+
for value in configurations_by_sha256.values()
|
|
404
|
+
}
|
|
405
|
+
accepted_phenotypes = set(known_phenotypes)
|
|
406
|
+
eligible_configurations: dict[str, FrozenJsonObject] = {}
|
|
407
|
+
acquisition_candidates: list[FiniteAcquisitionCandidate] = []
|
|
408
|
+
seen_features: set[tuple[float, ...]] = set()
|
|
409
|
+
phenotype_rejections: list[dict[str, str]] = []
|
|
410
|
+
feasibility_infeasible_sha256s: list[str] = []
|
|
411
|
+
feasibility_rejection_witnesses: list[dict[str, object]] = []
|
|
412
|
+
feasibility_decision_sha256s: list[str] = []
|
|
413
|
+
feasibility_verdict_counts = {
|
|
414
|
+
HardFeasibilityVerdict.FEASIBLE.value: 0,
|
|
415
|
+
HardFeasibilityVerdict.INFEASIBLE.value: 0,
|
|
416
|
+
HardFeasibilityVerdict.UNKNOWN.value: 0,
|
|
417
|
+
}
|
|
418
|
+
for configuration in materializations:
|
|
419
|
+
configuration_sha256 = typed_json_sha256(configuration)
|
|
420
|
+
if self.hard_feasibility is not None:
|
|
421
|
+
feasibility = assess_hard_feasibility(
|
|
422
|
+
self.hard_feasibility,
|
|
423
|
+
HardFeasibilityRequest(
|
|
424
|
+
campaign_scope_sha256=request.campaign_scope_sha256,
|
|
425
|
+
cutoff_index=request.state.unique_evaluations,
|
|
426
|
+
configuration=configuration,
|
|
427
|
+
),
|
|
428
|
+
)
|
|
429
|
+
feasibility_decision_sha256s.append(feasibility.decision_sha256)
|
|
430
|
+
feasibility_verdict_counts[feasibility.verdict.value] += 1
|
|
431
|
+
if feasibility.verdict is HardFeasibilityVerdict.INFEASIBLE:
|
|
432
|
+
feasibility_infeasible_sha256s.append(
|
|
433
|
+
feasibility.decision_sha256
|
|
434
|
+
)
|
|
435
|
+
if len(feasibility_rejection_witnesses) < 8:
|
|
436
|
+
feasibility_rejection_witnesses.append(
|
|
437
|
+
{
|
|
438
|
+
"configuration_sha256": configuration_sha256,
|
|
439
|
+
"decision": feasibility.to_record(),
|
|
440
|
+
}
|
|
441
|
+
)
|
|
442
|
+
continue
|
|
443
|
+
phenotype_sha256 = _phenotype(self.phenotype_identity, configuration)
|
|
444
|
+
if phenotype_sha256 in accepted_phenotypes:
|
|
445
|
+
phenotype_rejections.append(
|
|
446
|
+
{
|
|
447
|
+
"configuration_sha256": configuration_sha256,
|
|
448
|
+
"phenotype_sha256": phenotype_sha256,
|
|
449
|
+
}
|
|
450
|
+
)
|
|
451
|
+
continue
|
|
452
|
+
features = self.space.features(configuration)
|
|
453
|
+
if features in seen_features:
|
|
454
|
+
continue
|
|
455
|
+
candidate = FiniteAcquisitionCandidate(
|
|
456
|
+
candidate_id=f"capacity-{configuration_sha256[:32]}",
|
|
457
|
+
configuration_sha256=configuration_sha256,
|
|
458
|
+
features=features,
|
|
459
|
+
)
|
|
460
|
+
acquisition_candidates.append(candidate)
|
|
461
|
+
eligible_configurations[configuration_sha256] = configuration
|
|
462
|
+
seen_features.add(features)
|
|
463
|
+
accepted_phenotypes.add(phenotype_sha256)
|
|
464
|
+
if len(acquisition_candidates) < needed:
|
|
465
|
+
raise ValueError("screened acquisition reservoir cannot fill capacity")
|
|
466
|
+
|
|
467
|
+
acquisition_request = FiniteAcquisitionRequest(
|
|
468
|
+
campaign_scope_sha256=request.campaign_scope_sha256,
|
|
469
|
+
cutoff_index=request.state.unique_evaluations,
|
|
470
|
+
batch_size=needed,
|
|
471
|
+
seed=self.seed + request.generation,
|
|
472
|
+
objectives=self.objectives,
|
|
473
|
+
observations=observations,
|
|
474
|
+
candidates=tuple(acquisition_candidates),
|
|
475
|
+
)
|
|
476
|
+
decision = self.acquisition.select(acquisition_request)
|
|
477
|
+
if type(decision) is not FiniteAcquisitionDecision:
|
|
478
|
+
raise TypeError("acquisition returned a foreign decision")
|
|
479
|
+
decision.__post_init__()
|
|
480
|
+
if decision.request_sha256 != acquisition_request.request_sha256:
|
|
481
|
+
raise ValueError("acquisition decision targets another request")
|
|
482
|
+
if (
|
|
483
|
+
decision.policy_id,
|
|
484
|
+
decision.policy_version,
|
|
485
|
+
decision.policy_definition_sha256,
|
|
486
|
+
) != _acquisition_identity(self.acquisition):
|
|
487
|
+
raise ValueError("acquisition decision has a foreign policy identity")
|
|
488
|
+
if len(decision.selected) != needed:
|
|
489
|
+
raise ValueError("acquisition decision did not fill missing capacity")
|
|
490
|
+
candidate_by_id = {
|
|
491
|
+
value.candidate_id: value for value in acquisition_candidates
|
|
492
|
+
}
|
|
493
|
+
selected_configurations: list[FrozenJsonObject] = []
|
|
494
|
+
for selected in decision.selected:
|
|
495
|
+
candidate = candidate_by_id.get(selected.candidate_id)
|
|
496
|
+
if (
|
|
497
|
+
candidate is None
|
|
498
|
+
or candidate.configuration_sha256
|
|
499
|
+
!= selected.configuration_sha256
|
|
500
|
+
):
|
|
501
|
+
raise ValueError("acquisition selected outside the sealed reservoir")
|
|
502
|
+
selected_configurations.append(
|
|
503
|
+
eligible_configurations[selected.configuration_sha256]
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
members = tuple(
|
|
507
|
+
FiniteAcquisitionCapacityProposalMember(
|
|
508
|
+
target_candidate_id=self.engine.ids.new_candidate_id(),
|
|
509
|
+
acquisition_candidate_id=selected.candidate_id,
|
|
510
|
+
configuration=configuration,
|
|
511
|
+
phenotype_identity_sha256=_phenotype(
|
|
512
|
+
self.phenotype_identity,
|
|
513
|
+
configuration,
|
|
514
|
+
),
|
|
515
|
+
native_rank=rank,
|
|
516
|
+
)
|
|
517
|
+
for rank, (selected, configuration) in enumerate(
|
|
518
|
+
zip(decision.selected, selected_configurations, strict=True),
|
|
519
|
+
start=1,
|
|
520
|
+
)
|
|
521
|
+
)
|
|
522
|
+
evidence = freeze_json(
|
|
523
|
+
{
|
|
524
|
+
"schema_version": 1,
|
|
525
|
+
"space_request": space_request.to_record(),
|
|
526
|
+
"acquisition_request_sha256": acquisition_request.request_sha256,
|
|
527
|
+
"acquisition_decision": decision.to_record(),
|
|
528
|
+
"raw_reservoir_count": len(materializations),
|
|
529
|
+
"eligible_reservoir_count": len(acquisition_candidates),
|
|
530
|
+
"strictly_prior_observation_count": len(observations),
|
|
531
|
+
"hard_feasibility": {
|
|
532
|
+
"enabled": self.hard_feasibility is not None,
|
|
533
|
+
"verdict_counts": feasibility_verdict_counts,
|
|
534
|
+
"decision_count": len(feasibility_decision_sha256s),
|
|
535
|
+
"decision_batch_sha256": (
|
|
536
|
+
hard_feasibility_decision_batch_sha256(
|
|
537
|
+
feasibility_decision_sha256s
|
|
538
|
+
)
|
|
539
|
+
),
|
|
540
|
+
"infeasible_decision_count": len(
|
|
541
|
+
feasibility_infeasible_sha256s
|
|
542
|
+
),
|
|
543
|
+
"infeasible_decision_batch_sha256": (
|
|
544
|
+
hard_feasibility_decision_batch_sha256(
|
|
545
|
+
feasibility_infeasible_sha256s
|
|
546
|
+
)
|
|
547
|
+
),
|
|
548
|
+
"rejection_witnesses": feasibility_rejection_witnesses,
|
|
549
|
+
"rejection_witness_limit": 8,
|
|
550
|
+
"rejection_witness_sampling": (
|
|
551
|
+
"first_in_authenticated_space_order"
|
|
552
|
+
),
|
|
553
|
+
"rejection_authority": "exact_infeasibility_only",
|
|
554
|
+
"unknown_disposition": "retain",
|
|
555
|
+
"outcome_access": False,
|
|
556
|
+
},
|
|
557
|
+
"phenotype_rejections": phenotype_rejections,
|
|
558
|
+
"selected_configuration_sha256s": [
|
|
559
|
+
value.configuration_sha256 for value in decision.selected
|
|
560
|
+
],
|
|
561
|
+
"current_or_future_outcomes_consulted": False,
|
|
562
|
+
"capacity_requested": needed,
|
|
563
|
+
"evaluation_deferred": True,
|
|
564
|
+
"workload_model_provider_branches": False,
|
|
565
|
+
}
|
|
566
|
+
)
|
|
567
|
+
if type(evidence) is not FrozenJsonObject: # pragma: no cover
|
|
568
|
+
raise AssertionError("capacity recourse evidence is not an object")
|
|
569
|
+
return FiniteAcquisitionCapacityProposal(
|
|
570
|
+
request_sha256=request.request_sha256,
|
|
571
|
+
generation=request.generation,
|
|
572
|
+
policy_id=self.policy_id,
|
|
573
|
+
policy_version=self.policy_version,
|
|
574
|
+
policy_definition_sha256=self.definition_sha256,
|
|
575
|
+
decision=decision,
|
|
576
|
+
members=members,
|
|
577
|
+
evidence=evidence,
|
|
578
|
+
)
|
|
579
|
+
|
|
580
|
+
async def evaluate_members(
|
|
581
|
+
self,
|
|
582
|
+
proposal: FiniteAcquisitionCapacityProposal,
|
|
583
|
+
target_candidate_ids: tuple[CandidateId, ...],
|
|
584
|
+
) -> tuple[EvolutionCandidate, ...]:
|
|
585
|
+
"""Evaluate a broker-selected subset of one sealed proposal."""
|
|
586
|
+
|
|
587
|
+
self.__post_init__()
|
|
588
|
+
if type(proposal) is not FiniteAcquisitionCapacityProposal:
|
|
589
|
+
raise TypeError("proposal must be exact")
|
|
590
|
+
proposal.__post_init__()
|
|
591
|
+
if (
|
|
592
|
+
proposal.policy_id,
|
|
593
|
+
proposal.policy_version,
|
|
594
|
+
proposal.policy_definition_sha256,
|
|
595
|
+
) != (self.policy_id, self.policy_version, self.definition_sha256):
|
|
596
|
+
raise ValueError("proposal is bound to another recourse policy")
|
|
597
|
+
if type(target_candidate_ids) is not tuple or not target_candidate_ids:
|
|
598
|
+
raise ValueError("target_candidate_ids must be a non-empty exact tuple")
|
|
599
|
+
if len(set(target_candidate_ids)) != len(target_candidate_ids):
|
|
600
|
+
raise ValueError("target_candidate_ids must be unique")
|
|
601
|
+
by_id = {value.target_candidate_id: value for value in proposal.members}
|
|
602
|
+
try:
|
|
603
|
+
selected = tuple(by_id[value] for value in target_candidate_ids)
|
|
604
|
+
except KeyError as error:
|
|
605
|
+
raise ValueError("broker selected outside the sealed proposal") from error
|
|
606
|
+
if tuple(sorted(selected, key=lambda value: value.native_rank)) != selected:
|
|
607
|
+
raise ValueError("selected proposal members must preserve native order")
|
|
608
|
+
candidates = await asyncio.gather(
|
|
609
|
+
*(
|
|
610
|
+
self.engine.register_materialized_candidate(
|
|
611
|
+
thaw_json(member.configuration),
|
|
612
|
+
label=(
|
|
613
|
+
f"campaign_g{proposal.generation:02d}_capacity_recourse_"
|
|
614
|
+
f"r{member.native_rank:03d}"
|
|
615
|
+
),
|
|
616
|
+
generation=proposal.generation,
|
|
617
|
+
proposal_source_id=self.policy_id,
|
|
618
|
+
proposal_source_version=self.policy_version,
|
|
619
|
+
proposal_source_definition_sha256=self.definition_sha256,
|
|
620
|
+
proposal_decision_sha256=proposal.decision.decision_sha256,
|
|
621
|
+
proposal_rank=member.native_rank,
|
|
622
|
+
candidate_id=member.target_candidate_id,
|
|
623
|
+
)
|
|
624
|
+
for member in selected
|
|
625
|
+
)
|
|
626
|
+
)
|
|
627
|
+
return tuple(candidates)
|
|
628
|
+
|
|
629
|
+
async def fill(
|
|
630
|
+
self,
|
|
631
|
+
request: CampaignCapacityRecourseRequest,
|
|
632
|
+
) -> CampaignCapacityRecourseResult:
|
|
633
|
+
"""Preserve the capacity-port behavior through propose/evaluate phases."""
|
|
634
|
+
|
|
635
|
+
proposal = self.propose(request)
|
|
636
|
+
candidates = await self.evaluate_members(
|
|
637
|
+
proposal,
|
|
638
|
+
tuple(value.target_candidate_id for value in proposal.members),
|
|
639
|
+
)
|
|
640
|
+
evidence_record = thaw_json(proposal.evidence)
|
|
641
|
+
if type(evidence_record) is not dict: # pragma: no cover
|
|
642
|
+
raise AssertionError("capacity proposal evidence is not an object")
|
|
643
|
+
evidence_record.update(
|
|
644
|
+
{
|
|
645
|
+
"proposal_sha256": proposal.proposal_sha256,
|
|
646
|
+
"selected_candidate_ids": [
|
|
647
|
+
value.candidate_id.value for value in candidates
|
|
648
|
+
],
|
|
649
|
+
"capacity_realized": len(candidates),
|
|
650
|
+
"evaluation_deferred": False,
|
|
651
|
+
}
|
|
652
|
+
)
|
|
653
|
+
evidence = freeze_json(evidence_record)
|
|
654
|
+
if type(evidence) is not FrozenJsonObject: # pragma: no cover
|
|
655
|
+
raise AssertionError("capacity recourse evidence is not an object")
|
|
656
|
+
return CampaignCapacityRecourseResult(
|
|
657
|
+
request_sha256=request.request_sha256,
|
|
658
|
+
policy_id=self.policy_id,
|
|
659
|
+
policy_version=self.policy_version,
|
|
660
|
+
policy_definition_sha256=self.definition_sha256,
|
|
661
|
+
candidates=tuple(candidates),
|
|
662
|
+
evidence=evidence,
|
|
663
|
+
)
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
__all__ = [
|
|
667
|
+
"FiniteAcquisitionCapacityProposal",
|
|
668
|
+
"FiniteAcquisitionCapacityProposalMember",
|
|
669
|
+
"FiniteAcquisitionCapacityRecourse",
|
|
670
|
+
"POLICY_ID",
|
|
671
|
+
"POLICY_VERSION",
|
|
672
|
+
]
|