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,756 @@
|
|
|
1
|
+
"""Authenticated campaign bridge for the calibrated K8-to-K4 selector.
|
|
2
|
+
|
|
3
|
+
One coordinator owns the immutable pre-call input binding for each logical
|
|
4
|
+
selector request. The provider adapter, campaign plaintext audit, and strict
|
|
5
|
+
post-evaluation prediction decoder all resolve through that same registry.
|
|
6
|
+
This prevents a campaign from silently using three independently reconstructed
|
|
7
|
+
views of what the model saw.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from agent_evolve.application.portfolio_evolution import PortfolioVariationWaveResult
|
|
16
|
+
from agent_evolve.integrations.pydantic_ai.calibrated_portfolio_selection import (
|
|
17
|
+
CalibratedPortfolioAllocator,
|
|
18
|
+
PydanticAIAcquisitionCertifiedResidualPortfolioSelectionPolicy,
|
|
19
|
+
PydanticAIRegretBoundedInformationPortfolioSelectionPolicy,
|
|
20
|
+
PydanticAICalibratedPortfolioSelectionPolicy,
|
|
21
|
+
PydanticAIConstraintDecoupledHorizonPortfolioSelectionPolicy,
|
|
22
|
+
PydanticAIConstraintDecoupledTargetConditionedPortfolioSelectionPolicy,
|
|
23
|
+
PydanticAIContextualSearchAllocationPortfolioSelectionPolicy,
|
|
24
|
+
PydanticAIEvidenceCalibratedSourceMixPortfolioSelectionPolicy,
|
|
25
|
+
PydanticAIMinimumInterventionHorizonPortfolioSelectionPolicy,
|
|
26
|
+
PydanticAIFrontierProbeCalibratedPortfolioSelectionPolicy,
|
|
27
|
+
PydanticAIFullSupportCalibratedPortfolioSelectionPolicy,
|
|
28
|
+
PydanticAIHorizonBoundedCalibratedPortfolioSelectionPolicy,
|
|
29
|
+
PydanticAIModelAnchoredCalibratedPortfolioSelectionPolicy,
|
|
30
|
+
PydanticAIOperatorStratifiedCalibratedPortfolioSelectionPolicy,
|
|
31
|
+
PydanticAIStructuralPosteriorCalibratedPortfolioSelectionPolicy,
|
|
32
|
+
PydanticAITargetConditionedCalibratedPortfolioSelectionPolicy,
|
|
33
|
+
decode_calibrated_portfolio_audit,
|
|
34
|
+
render_calibrated_portfolio_selection_prompt_for_allocator,
|
|
35
|
+
)
|
|
36
|
+
from agent_evolve.integrations.pydantic_ai.agentic_generator import LowLevelRunner
|
|
37
|
+
from agent_evolve.domain.typed_json import thaw_json
|
|
38
|
+
from agent_evolve.policies.selection.calibrated_slate import (
|
|
39
|
+
SlateAllocationMode,
|
|
40
|
+
TraceCalibratedSlatePolicy,
|
|
41
|
+
)
|
|
42
|
+
from agent_evolve.policies.selection.model_anchored_slate import (
|
|
43
|
+
ModelAnchoredCalibratedSlatePolicy,
|
|
44
|
+
)
|
|
45
|
+
from agent_evolve.policies.selection.structural_posterior_slate import (
|
|
46
|
+
HorizonBoundedStructuralPosteriorSlatePolicy,
|
|
47
|
+
OperatorStratifiedStructuralPosteriorSlatePolicy,
|
|
48
|
+
StructuralPosteriorSlatePolicy,
|
|
49
|
+
)
|
|
50
|
+
from agent_evolve.policies.selection.frontier_probe_slate import (
|
|
51
|
+
FrontierProbeSlatePolicy,
|
|
52
|
+
)
|
|
53
|
+
from agent_evolve.policies.selection.full_support_slate import (
|
|
54
|
+
FullSupportSlatePolicy,
|
|
55
|
+
)
|
|
56
|
+
from agent_evolve.policies.selection.target_conditioned_allocator import (
|
|
57
|
+
TargetConditionedAllocationContext,
|
|
58
|
+
TargetConditionedAllocationContextKey,
|
|
59
|
+
TargetConditionedAllocationContextRegistrar,
|
|
60
|
+
TargetConditionedSlateAllocatorAdapter,
|
|
61
|
+
)
|
|
62
|
+
from agent_evolve.policies.selection.target_conditioned_prequential import (
|
|
63
|
+
TargetConditionedSlateDecision,
|
|
64
|
+
)
|
|
65
|
+
from agent_evolve.policies.selection.acquisition_certified_slate import (
|
|
66
|
+
AcquisitionCertifiedSlateContextProvider,
|
|
67
|
+
AcquisitionCertifiedSlatePolicy,
|
|
68
|
+
)
|
|
69
|
+
from agent_evolve.policies.selection.regret_bounded_slate import (
|
|
70
|
+
RegretBoundedSlatePolicy,
|
|
71
|
+
)
|
|
72
|
+
from agent_evolve.policies.selection.calibrated_portfolio_binding import (
|
|
73
|
+
CalibratedPortfolioInputBinding,
|
|
74
|
+
)
|
|
75
|
+
from agent_evolve.policies.selection.forecast_calibration import (
|
|
76
|
+
ForecastPredictionReceipt,
|
|
77
|
+
)
|
|
78
|
+
from agent_evolve.ports.portfolio_selection import (
|
|
79
|
+
PortfolioSelectionRequest,
|
|
80
|
+
PortfolioSelectionResult,
|
|
81
|
+
)
|
|
82
|
+
from agent_evolve.ports.contextual_search_allocation import (
|
|
83
|
+
ContextualPortfolioAllocationRealization,
|
|
84
|
+
)
|
|
85
|
+
from agent_evolve.ports.variation_source import finite_variation_source_by_option
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@dataclass(frozen=True, slots=True)
|
|
89
|
+
class _RegisteredCalibratedPortfolioInput:
|
|
90
|
+
request: PortfolioSelectionRequest
|
|
91
|
+
binding: CalibratedPortfolioInputBinding
|
|
92
|
+
|
|
93
|
+
def __post_init__(self) -> None:
|
|
94
|
+
if type(self.request) is not PortfolioSelectionRequest:
|
|
95
|
+
raise TypeError("request must be exact PortfolioSelectionRequest")
|
|
96
|
+
self.request.__post_init__()
|
|
97
|
+
if type(self.binding) is not CalibratedPortfolioInputBinding:
|
|
98
|
+
raise TypeError("binding must be exact CalibratedPortfolioInputBinding")
|
|
99
|
+
self.binding.require_request(self.request)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@dataclass(slots=True)
|
|
103
|
+
class CalibratedPortfolioCampaignCoordinator:
|
|
104
|
+
"""Single source of truth for calibrated selector campaign evidence.
|
|
105
|
+
|
|
106
|
+
A wave factory must call :meth:`register` after it has built the public
|
|
107
|
+
request and before the selector can execute it. Registration is append
|
|
108
|
+
only: even an identical second registration is rejected, so a later stage
|
|
109
|
+
cannot replace pre-call calibration or structural evidence.
|
|
110
|
+
|
|
111
|
+
The object directly satisfies both dependencies needed by a calibrated
|
|
112
|
+
campaign::
|
|
113
|
+
|
|
114
|
+
selector = PydanticAICalibratedPortfolioSelectionPolicy(
|
|
115
|
+
generate_once=runner,
|
|
116
|
+
binding_for=coordinator.binding_for,
|
|
117
|
+
)
|
|
118
|
+
runtime.selector_request_prompt_renderer = coordinator
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
allocator: CalibratedPortfolioAllocator = TraceCalibratedSlatePolicy(
|
|
122
|
+
SlateAllocationMode.CALIBRATED_FOUR_ROLE
|
|
123
|
+
)
|
|
124
|
+
constraint_decoupled: bool = False
|
|
125
|
+
minimum_intervention_projection: bool = False
|
|
126
|
+
evidence_calibrated_source_mix: bool = False
|
|
127
|
+
contextual_search_allocation: bool = False
|
|
128
|
+
_entries: dict[str, _RegisteredCalibratedPortfolioInput] = field(
|
|
129
|
+
init=False,
|
|
130
|
+
default_factory=dict,
|
|
131
|
+
repr=False,
|
|
132
|
+
)
|
|
133
|
+
_decoded_results: dict[str, tuple[PortfolioVariationWaveResult, Any]] = field(
|
|
134
|
+
init=False,
|
|
135
|
+
default_factory=dict,
|
|
136
|
+
repr=False,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
def __post_init__(self) -> None:
|
|
140
|
+
if type(self.constraint_decoupled) is not bool:
|
|
141
|
+
raise TypeError("constraint_decoupled must be an exact bool")
|
|
142
|
+
if type(self.minimum_intervention_projection) is not bool:
|
|
143
|
+
raise TypeError("minimum_intervention_projection must be an exact bool")
|
|
144
|
+
if type(self.evidence_calibrated_source_mix) is not bool:
|
|
145
|
+
raise TypeError("evidence_calibrated_source_mix must be an exact bool")
|
|
146
|
+
if type(self.contextual_search_allocation) is not bool:
|
|
147
|
+
raise TypeError("contextual_search_allocation must be an exact bool")
|
|
148
|
+
if self.contextual_search_allocation and not (
|
|
149
|
+
self.evidence_calibrated_source_mix
|
|
150
|
+
and self.minimum_intervention_projection
|
|
151
|
+
and self.constraint_decoupled
|
|
152
|
+
):
|
|
153
|
+
raise ValueError(
|
|
154
|
+
"contextual search allocation requires evidence-calibrated "
|
|
155
|
+
"source mix, minimum intervention, and constraint-decoupled "
|
|
156
|
+
"authority"
|
|
157
|
+
)
|
|
158
|
+
if (
|
|
159
|
+
self.evidence_calibrated_source_mix
|
|
160
|
+
and not self.minimum_intervention_projection
|
|
161
|
+
):
|
|
162
|
+
raise ValueError(
|
|
163
|
+
"evidence-calibrated source mix requires minimum intervention"
|
|
164
|
+
)
|
|
165
|
+
if self.minimum_intervention_projection and not self.constraint_decoupled:
|
|
166
|
+
raise ValueError(
|
|
167
|
+
"minimum intervention requires constraint-decoupled authority"
|
|
168
|
+
)
|
|
169
|
+
if self.constraint_decoupled and type(self.allocator) not in {
|
|
170
|
+
HorizonBoundedStructuralPosteriorSlatePolicy,
|
|
171
|
+
TargetConditionedSlateAllocatorAdapter,
|
|
172
|
+
AcquisitionCertifiedSlatePolicy,
|
|
173
|
+
RegretBoundedSlatePolicy,
|
|
174
|
+
}:
|
|
175
|
+
raise TypeError(
|
|
176
|
+
"constraint-decoupled acquisition requires the horizon-bounded "
|
|
177
|
+
"target-conditioned, acquisition-certified, or regret-bounded "
|
|
178
|
+
"allocator"
|
|
179
|
+
)
|
|
180
|
+
if (
|
|
181
|
+
type(self.allocator) is TargetConditionedSlateAllocatorAdapter
|
|
182
|
+
and (
|
|
183
|
+
self.minimum_intervention_projection
|
|
184
|
+
or self.evidence_calibrated_source_mix
|
|
185
|
+
or self.contextual_search_allocation
|
|
186
|
+
)
|
|
187
|
+
):
|
|
188
|
+
raise ValueError(
|
|
189
|
+
"target-conditioned constraint decoupling does not imply the "
|
|
190
|
+
"horizon-only projection or source-mix treatments"
|
|
191
|
+
)
|
|
192
|
+
if type(self.allocator) is TraceCalibratedSlatePolicy:
|
|
193
|
+
self.allocator.__post_init__()
|
|
194
|
+
if self.allocator.mode is not SlateAllocationMode.CALIBRATED_FOUR_ROLE:
|
|
195
|
+
raise ValueError(
|
|
196
|
+
"campaign coordinator requires calibrated four-role mode"
|
|
197
|
+
)
|
|
198
|
+
return
|
|
199
|
+
if type(self.allocator) is ModelAnchoredCalibratedSlatePolicy:
|
|
200
|
+
self.allocator.__post_init__()
|
|
201
|
+
return
|
|
202
|
+
if type(self.allocator) is StructuralPosteriorSlatePolicy:
|
|
203
|
+
self.allocator.__post_init__()
|
|
204
|
+
return
|
|
205
|
+
if type(self.allocator) is OperatorStratifiedStructuralPosteriorSlatePolicy:
|
|
206
|
+
self.allocator.__post_init__()
|
|
207
|
+
return
|
|
208
|
+
if type(self.allocator) is HorizonBoundedStructuralPosteriorSlatePolicy:
|
|
209
|
+
self.allocator.__post_init__()
|
|
210
|
+
return
|
|
211
|
+
if type(self.allocator) is FrontierProbeSlatePolicy:
|
|
212
|
+
self.allocator.__post_init__()
|
|
213
|
+
return
|
|
214
|
+
if type(self.allocator) is FullSupportSlatePolicy:
|
|
215
|
+
return
|
|
216
|
+
if type(self.allocator) is TargetConditionedSlateAllocatorAdapter:
|
|
217
|
+
self.allocator.__post_init__()
|
|
218
|
+
if not isinstance(
|
|
219
|
+
self.allocator.context_provider,
|
|
220
|
+
TargetConditionedAllocationContextRegistrar,
|
|
221
|
+
):
|
|
222
|
+
raise TypeError(
|
|
223
|
+
"campaign target-conditioned context provider must support "
|
|
224
|
+
"append-only registration"
|
|
225
|
+
)
|
|
226
|
+
return
|
|
227
|
+
if type(self.allocator) in {
|
|
228
|
+
AcquisitionCertifiedSlatePolicy,
|
|
229
|
+
RegretBoundedSlatePolicy,
|
|
230
|
+
}:
|
|
231
|
+
self.allocator.__post_init__()
|
|
232
|
+
if not isinstance(
|
|
233
|
+
self.allocator.context_provider,
|
|
234
|
+
AcquisitionCertifiedSlateContextProvider,
|
|
235
|
+
):
|
|
236
|
+
raise TypeError(
|
|
237
|
+
"campaign acquisition-certified provider must expose contexts"
|
|
238
|
+
)
|
|
239
|
+
return
|
|
240
|
+
raise TypeError("allocator must be an exact supported calibrated policy")
|
|
241
|
+
|
|
242
|
+
def build_selector(
|
|
243
|
+
self,
|
|
244
|
+
generate_once: LowLevelRunner,
|
|
245
|
+
) -> (
|
|
246
|
+
PydanticAICalibratedPortfolioSelectionPolicy
|
|
247
|
+
| PydanticAIConstraintDecoupledHorizonPortfolioSelectionPolicy
|
|
248
|
+
| PydanticAIConstraintDecoupledTargetConditionedPortfolioSelectionPolicy
|
|
249
|
+
| PydanticAIContextualSearchAllocationPortfolioSelectionPolicy
|
|
250
|
+
| PydanticAIEvidenceCalibratedSourceMixPortfolioSelectionPolicy
|
|
251
|
+
| PydanticAIMinimumInterventionHorizonPortfolioSelectionPolicy
|
|
252
|
+
| PydanticAIModelAnchoredCalibratedPortfolioSelectionPolicy
|
|
253
|
+
| PydanticAIStructuralPosteriorCalibratedPortfolioSelectionPolicy
|
|
254
|
+
| PydanticAIOperatorStratifiedCalibratedPortfolioSelectionPolicy
|
|
255
|
+
| PydanticAIHorizonBoundedCalibratedPortfolioSelectionPolicy
|
|
256
|
+
| PydanticAIFrontierProbeCalibratedPortfolioSelectionPolicy
|
|
257
|
+
| PydanticAIFullSupportCalibratedPortfolioSelectionPolicy
|
|
258
|
+
| PydanticAITargetConditionedCalibratedPortfolioSelectionPolicy
|
|
259
|
+
| PydanticAIAcquisitionCertifiedResidualPortfolioSelectionPolicy
|
|
260
|
+
| PydanticAIRegretBoundedInformationPortfolioSelectionPolicy
|
|
261
|
+
):
|
|
262
|
+
"""Build a selector sharing this coordinator's trusted allocator."""
|
|
263
|
+
|
|
264
|
+
self.__post_init__()
|
|
265
|
+
if self.constraint_decoupled:
|
|
266
|
+
if type(self.allocator) is AcquisitionCertifiedSlatePolicy:
|
|
267
|
+
return PydanticAIAcquisitionCertifiedResidualPortfolioSelectionPolicy(
|
|
268
|
+
generate_once=generate_once,
|
|
269
|
+
binding_for=self.binding_for,
|
|
270
|
+
allocator=self.allocator,
|
|
271
|
+
)
|
|
272
|
+
if type(self.allocator) is RegretBoundedSlatePolicy:
|
|
273
|
+
return PydanticAIRegretBoundedInformationPortfolioSelectionPolicy(
|
|
274
|
+
generate_once=generate_once,
|
|
275
|
+
binding_for=self.binding_for,
|
|
276
|
+
allocator=self.allocator,
|
|
277
|
+
)
|
|
278
|
+
if type(self.allocator) is TargetConditionedSlateAllocatorAdapter:
|
|
279
|
+
return (
|
|
280
|
+
PydanticAIConstraintDecoupledTargetConditionedPortfolioSelectionPolicy(
|
|
281
|
+
generate_once=generate_once,
|
|
282
|
+
binding_for=self.binding_for,
|
|
283
|
+
allocator=self.allocator,
|
|
284
|
+
)
|
|
285
|
+
)
|
|
286
|
+
assert type(self.allocator) is HorizonBoundedStructuralPosteriorSlatePolicy
|
|
287
|
+
if self.minimum_intervention_projection:
|
|
288
|
+
if self.contextual_search_allocation:
|
|
289
|
+
return PydanticAIContextualSearchAllocationPortfolioSelectionPolicy(
|
|
290
|
+
generate_once=generate_once,
|
|
291
|
+
binding_for=self.binding_for,
|
|
292
|
+
allocator=self.allocator,
|
|
293
|
+
)
|
|
294
|
+
if self.evidence_calibrated_source_mix:
|
|
295
|
+
return (
|
|
296
|
+
PydanticAIEvidenceCalibratedSourceMixPortfolioSelectionPolicy(
|
|
297
|
+
generate_once=generate_once,
|
|
298
|
+
binding_for=self.binding_for,
|
|
299
|
+
allocator=self.allocator,
|
|
300
|
+
)
|
|
301
|
+
)
|
|
302
|
+
return PydanticAIMinimumInterventionHorizonPortfolioSelectionPolicy(
|
|
303
|
+
generate_once=generate_once,
|
|
304
|
+
binding_for=self.binding_for,
|
|
305
|
+
allocator=self.allocator,
|
|
306
|
+
)
|
|
307
|
+
return PydanticAIConstraintDecoupledHorizonPortfolioSelectionPolicy(
|
|
308
|
+
generate_once=generate_once,
|
|
309
|
+
binding_for=self.binding_for,
|
|
310
|
+
allocator=self.allocator,
|
|
311
|
+
)
|
|
312
|
+
if type(self.allocator) is TraceCalibratedSlatePolicy:
|
|
313
|
+
return PydanticAICalibratedPortfolioSelectionPolicy(
|
|
314
|
+
generate_once=generate_once,
|
|
315
|
+
binding_for=self.binding_for,
|
|
316
|
+
allocator=self.allocator,
|
|
317
|
+
)
|
|
318
|
+
if type(self.allocator) is ModelAnchoredCalibratedSlatePolicy:
|
|
319
|
+
return PydanticAIModelAnchoredCalibratedPortfolioSelectionPolicy(
|
|
320
|
+
generate_once=generate_once,
|
|
321
|
+
binding_for=self.binding_for,
|
|
322
|
+
allocator=self.allocator,
|
|
323
|
+
)
|
|
324
|
+
if type(self.allocator) is StructuralPosteriorSlatePolicy:
|
|
325
|
+
return PydanticAIStructuralPosteriorCalibratedPortfolioSelectionPolicy(
|
|
326
|
+
generate_once=generate_once,
|
|
327
|
+
binding_for=self.binding_for,
|
|
328
|
+
allocator=self.allocator,
|
|
329
|
+
)
|
|
330
|
+
if type(self.allocator) is OperatorStratifiedStructuralPosteriorSlatePolicy:
|
|
331
|
+
return PydanticAIOperatorStratifiedCalibratedPortfolioSelectionPolicy(
|
|
332
|
+
generate_once=generate_once,
|
|
333
|
+
binding_for=self.binding_for,
|
|
334
|
+
allocator=self.allocator,
|
|
335
|
+
)
|
|
336
|
+
if type(self.allocator) is HorizonBoundedStructuralPosteriorSlatePolicy:
|
|
337
|
+
return PydanticAIHorizonBoundedCalibratedPortfolioSelectionPolicy(
|
|
338
|
+
generate_once=generate_once,
|
|
339
|
+
binding_for=self.binding_for,
|
|
340
|
+
allocator=self.allocator,
|
|
341
|
+
)
|
|
342
|
+
if type(self.allocator) is FrontierProbeSlatePolicy:
|
|
343
|
+
return PydanticAIFrontierProbeCalibratedPortfolioSelectionPolicy(
|
|
344
|
+
generate_once=generate_once,
|
|
345
|
+
binding_for=self.binding_for,
|
|
346
|
+
allocator=self.allocator,
|
|
347
|
+
)
|
|
348
|
+
if type(self.allocator) is FullSupportSlatePolicy:
|
|
349
|
+
return PydanticAIFullSupportCalibratedPortfolioSelectionPolicy(
|
|
350
|
+
generate_once=generate_once,
|
|
351
|
+
binding_for=self.binding_for,
|
|
352
|
+
allocator=self.allocator,
|
|
353
|
+
)
|
|
354
|
+
if type(self.allocator) is TargetConditionedSlateAllocatorAdapter:
|
|
355
|
+
return PydanticAITargetConditionedCalibratedPortfolioSelectionPolicy(
|
|
356
|
+
generate_once=generate_once,
|
|
357
|
+
binding_for=self.binding_for,
|
|
358
|
+
allocator=self.allocator,
|
|
359
|
+
)
|
|
360
|
+
raise AssertionError("coordinator allocator changed after validation")
|
|
361
|
+
|
|
362
|
+
def register(
|
|
363
|
+
self,
|
|
364
|
+
request: PortfolioSelectionRequest,
|
|
365
|
+
binding: CalibratedPortfolioInputBinding,
|
|
366
|
+
*,
|
|
367
|
+
target_conditioned_context: TargetConditionedAllocationContext | None = None,
|
|
368
|
+
) -> None:
|
|
369
|
+
"""Seal exactly one authenticated binding for ``request``."""
|
|
370
|
+
|
|
371
|
+
entry = _RegisteredCalibratedPortfolioInput(request, binding)
|
|
372
|
+
request_sha256 = request.request_sha256
|
|
373
|
+
if request_sha256 in self._entries:
|
|
374
|
+
raise ValueError("calibrated campaign request is already registered")
|
|
375
|
+
if type(self.allocator) is TargetConditionedSlateAllocatorAdapter:
|
|
376
|
+
if type(target_conditioned_context) is not (
|
|
377
|
+
TargetConditionedAllocationContext
|
|
378
|
+
):
|
|
379
|
+
raise TypeError(
|
|
380
|
+
"target-conditioned campaigns require one exact pre-call context"
|
|
381
|
+
)
|
|
382
|
+
registrar = self.allocator.context_provider
|
|
383
|
+
if not isinstance(registrar, TargetConditionedAllocationContextRegistrar):
|
|
384
|
+
raise TypeError("target-conditioned context provider cannot register")
|
|
385
|
+
observed_transitions = tuple(
|
|
386
|
+
(
|
|
387
|
+
transition.option_id,
|
|
388
|
+
transition.option_identity_sha256,
|
|
389
|
+
transition.parent_configuration_sha256,
|
|
390
|
+
transition.child_configuration_sha256,
|
|
391
|
+
)
|
|
392
|
+
for transition in target_conditioned_context.transition_receipts
|
|
393
|
+
)
|
|
394
|
+
if observed_transitions:
|
|
395
|
+
expected_transitions = tuple(
|
|
396
|
+
(
|
|
397
|
+
option.option_id,
|
|
398
|
+
option.identity_sha256,
|
|
399
|
+
option.parent_configuration_sha256,
|
|
400
|
+
option.child_configuration_sha256,
|
|
401
|
+
)
|
|
402
|
+
for option in sorted(
|
|
403
|
+
request.finite_variation_contract.options,
|
|
404
|
+
key=lambda value: value.option_id,
|
|
405
|
+
)
|
|
406
|
+
)
|
|
407
|
+
if observed_transitions != expected_transitions:
|
|
408
|
+
raise ValueError(
|
|
409
|
+
"precomputed target-conditioned transitions must exactly "
|
|
410
|
+
"cover the finite variation contract"
|
|
411
|
+
)
|
|
412
|
+
registrar.register(
|
|
413
|
+
TargetConditionedAllocationContextKey(
|
|
414
|
+
scope_sha256=binding.context.scope.scope_sha256,
|
|
415
|
+
wave_index=binding.context.wave_index,
|
|
416
|
+
parent_configuration_sha256=(
|
|
417
|
+
binding.context.parent_candidate_identity_sha256
|
|
418
|
+
),
|
|
419
|
+
finite_contract_sha256=(
|
|
420
|
+
request.finite_variation_contract.identity_sha256
|
|
421
|
+
),
|
|
422
|
+
),
|
|
423
|
+
target_conditioned_context,
|
|
424
|
+
request.finite_variation_contract,
|
|
425
|
+
)
|
|
426
|
+
elif target_conditioned_context is not None:
|
|
427
|
+
raise ValueError(
|
|
428
|
+
"target_conditioned_context is only valid for its exact allocator"
|
|
429
|
+
)
|
|
430
|
+
self._entries[request_sha256] = entry
|
|
431
|
+
|
|
432
|
+
def _entry_for(
|
|
433
|
+
self,
|
|
434
|
+
request: PortfolioSelectionRequest,
|
|
435
|
+
) -> _RegisteredCalibratedPortfolioInput:
|
|
436
|
+
if type(request) is not PortfolioSelectionRequest:
|
|
437
|
+
raise TypeError("request must be exact PortfolioSelectionRequest")
|
|
438
|
+
request.__post_init__()
|
|
439
|
+
entry = self._entries.get(request.request_sha256)
|
|
440
|
+
if entry is None:
|
|
441
|
+
raise ValueError("calibrated campaign request is foreign or unregistered")
|
|
442
|
+
entry.__post_init__()
|
|
443
|
+
if request != entry.request:
|
|
444
|
+
raise ValueError("calibrated campaign request differs from registration")
|
|
445
|
+
return entry
|
|
446
|
+
|
|
447
|
+
def binding_for(
|
|
448
|
+
self,
|
|
449
|
+
request: PortfolioSelectionRequest,
|
|
450
|
+
) -> CalibratedPortfolioInputBinding:
|
|
451
|
+
"""Supply the selector only its prospectively registered binding."""
|
|
452
|
+
|
|
453
|
+
entry = self._entry_for(request)
|
|
454
|
+
entry.binding.require_request(request)
|
|
455
|
+
return entry.binding
|
|
456
|
+
|
|
457
|
+
def render(self, request: PortfolioSelectionRequest) -> str:
|
|
458
|
+
"""Render the exact calibrated provider prompt from the sealed binding."""
|
|
459
|
+
|
|
460
|
+
return render_calibrated_portfolio_selection_prompt_for_allocator(
|
|
461
|
+
request,
|
|
462
|
+
self.binding_for(request),
|
|
463
|
+
self.allocator,
|
|
464
|
+
constraint_decoupled=self.constraint_decoupled,
|
|
465
|
+
minimum_intervention_projection=(self.minimum_intervention_projection),
|
|
466
|
+
evidence_calibrated_source_mix=(self.evidence_calibrated_source_mix),
|
|
467
|
+
contextual_search_allocation=self.contextual_search_allocation,
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
def _decode_result(self, result: PortfolioVariationWaveResult) -> Any:
|
|
471
|
+
"""Strictly replay one immutable wave result at most once per instance."""
|
|
472
|
+
|
|
473
|
+
if type(result) is not PortfolioVariationWaveResult:
|
|
474
|
+
raise TypeError("result must be exact PortfolioVariationWaveResult")
|
|
475
|
+
result.__post_init__()
|
|
476
|
+
key = result.receipt.receipt_sha256
|
|
477
|
+
cached = self._decoded_results.get(key)
|
|
478
|
+
if cached is not None and cached[0] is result:
|
|
479
|
+
return cached[1]
|
|
480
|
+
entry = self._entries.get(result.receipt.request_sha256)
|
|
481
|
+
if entry is None:
|
|
482
|
+
raise ValueError("portfolio result belongs to a foreign campaign request")
|
|
483
|
+
entry.__post_init__()
|
|
484
|
+
if result.receipt.selection_call_id != entry.request.call_id:
|
|
485
|
+
raise ValueError("portfolio result names a foreign selector call")
|
|
486
|
+
audit = result.supplemental_selection_audit
|
|
487
|
+
if audit is None:
|
|
488
|
+
raise ValueError("calibrated portfolio result omitted supplemental audit")
|
|
489
|
+
decoded = decode_calibrated_portfolio_audit(
|
|
490
|
+
audit,
|
|
491
|
+
request=entry.request,
|
|
492
|
+
binding=entry.binding,
|
|
493
|
+
allocator=self.allocator,
|
|
494
|
+
)
|
|
495
|
+
self._decoded_results[key] = (result, decoded)
|
|
496
|
+
return decoded
|
|
497
|
+
|
|
498
|
+
def decode_target_conditioned_allocation(
|
|
499
|
+
self,
|
|
500
|
+
result: PortfolioVariationWaveResult,
|
|
501
|
+
) -> TargetConditionedSlateDecision:
|
|
502
|
+
"""Strictly replay one result and return its exact T-RAP decision."""
|
|
503
|
+
|
|
504
|
+
if type(result) is not PortfolioVariationWaveResult:
|
|
505
|
+
raise TypeError("result must be exact PortfolioVariationWaveResult")
|
|
506
|
+
result.__post_init__()
|
|
507
|
+
entry = self._entries.get(result.receipt.request_sha256)
|
|
508
|
+
if entry is None:
|
|
509
|
+
raise ValueError("portfolio result belongs to a foreign campaign request")
|
|
510
|
+
entry.__post_init__()
|
|
511
|
+
if type(self.allocator) is not TargetConditionedSlateAllocatorAdapter:
|
|
512
|
+
raise ValueError("campaign allocator is not target-conditioned")
|
|
513
|
+
if result.receipt.selection_call_id != entry.request.call_id:
|
|
514
|
+
raise ValueError("portfolio result names a foreign selector call")
|
|
515
|
+
audit = result.supplemental_selection_audit
|
|
516
|
+
if audit is None:
|
|
517
|
+
raise ValueError("target-conditioned result omitted supplemental audit")
|
|
518
|
+
decoded = self._decode_result(result)
|
|
519
|
+
allocation = decoded.allocation
|
|
520
|
+
if type(allocation) is not TargetConditionedSlateDecision:
|
|
521
|
+
raise TypeError("decoded allocation is not an exact T-RAP decision")
|
|
522
|
+
selected = tuple(value.option_id for value in allocation.selected)
|
|
523
|
+
evaluated = tuple(
|
|
524
|
+
value.materialization.option_id for value in result.receipt.members
|
|
525
|
+
)
|
|
526
|
+
if selected != evaluated:
|
|
527
|
+
raise ValueError("decoded T-RAP decision differs from evaluated members")
|
|
528
|
+
return allocation
|
|
529
|
+
|
|
530
|
+
def decode_target_conditioned_context(
|
|
531
|
+
self,
|
|
532
|
+
result: PortfolioVariationWaveResult,
|
|
533
|
+
) -> TargetConditionedAllocationContext:
|
|
534
|
+
"""Recover the independently registered pre-call context after replay."""
|
|
535
|
+
|
|
536
|
+
allocation = self.decode_target_conditioned_allocation(result)
|
|
537
|
+
assert type(self.allocator) is TargetConditionedSlateAllocatorAdapter
|
|
538
|
+
context = self.allocator.context_provider.context_for(
|
|
539
|
+
allocation.request.allocation_request
|
|
540
|
+
)
|
|
541
|
+
if type(context) is not TargetConditionedAllocationContext:
|
|
542
|
+
raise TypeError("registered provider returned a foreign T-RAP context")
|
|
543
|
+
context.__post_init__()
|
|
544
|
+
if (
|
|
545
|
+
context.frontier_target != allocation.request.frontier_target
|
|
546
|
+
or context.state != allocation.request.state
|
|
547
|
+
):
|
|
548
|
+
raise ValueError("registered context differs from decoded T-RAP decision")
|
|
549
|
+
return context
|
|
550
|
+
|
|
551
|
+
def decode_selected_predictions(
|
|
552
|
+
self,
|
|
553
|
+
result: PortfolioVariationWaveResult,
|
|
554
|
+
) -> tuple[ForecastPredictionReceipt, ...]:
|
|
555
|
+
"""Strictly replay one result and return only its evaluated K4 forecasts."""
|
|
556
|
+
|
|
557
|
+
if type(result) is not PortfolioVariationWaveResult:
|
|
558
|
+
raise TypeError("result must be exact PortfolioVariationWaveResult")
|
|
559
|
+
result.__post_init__()
|
|
560
|
+
entry = self._entries.get(result.receipt.request_sha256)
|
|
561
|
+
if entry is None:
|
|
562
|
+
raise ValueError("portfolio result belongs to a foreign campaign request")
|
|
563
|
+
entry.__post_init__()
|
|
564
|
+
request = entry.request
|
|
565
|
+
if result.receipt.selection_call_id != request.call_id:
|
|
566
|
+
raise ValueError("portfolio result names a foreign selector call")
|
|
567
|
+
audit = result.supplemental_selection_audit
|
|
568
|
+
if audit is None:
|
|
569
|
+
raise ValueError("calibrated portfolio result omitted supplemental audit")
|
|
570
|
+
decoded = self._decode_result(result)
|
|
571
|
+
predictions = decoded.selected_prediction_receipts
|
|
572
|
+
selected_option_ids = tuple(
|
|
573
|
+
member.materialization.option_id for member in result.receipt.members
|
|
574
|
+
)
|
|
575
|
+
predicted_option_ids = tuple(
|
|
576
|
+
dict.fromkeys(value.option_id for value in predictions)
|
|
577
|
+
)
|
|
578
|
+
if predicted_option_ids != selected_option_ids:
|
|
579
|
+
raise ValueError(
|
|
580
|
+
"decoded forecasts differ from evaluated portfolio member order"
|
|
581
|
+
)
|
|
582
|
+
if len(predictions) != (
|
|
583
|
+
len(selected_option_ids) * len(request.required_metric_ids)
|
|
584
|
+
):
|
|
585
|
+
raise ValueError("decoded forecasts do not exactly cover evaluated metrics")
|
|
586
|
+
return predictions
|
|
587
|
+
|
|
588
|
+
def decode_selected_source_ids(
|
|
589
|
+
self,
|
|
590
|
+
result: PortfolioVariationWaveResult,
|
|
591
|
+
) -> tuple[str, ...]:
|
|
592
|
+
"""Replay one result and return sealed finite-variation source labels.
|
|
593
|
+
|
|
594
|
+
Model retention versus deterministic engine insertion remains in the
|
|
595
|
+
reconciliation receipt as a separate provenance axis. Source credit
|
|
596
|
+
instead follows the option's prospectively sealed catalogue metadata,
|
|
597
|
+
with ordinary local options inheriting the framework ``primary`` arm.
|
|
598
|
+
No outcome, workload, model-route, or provider field participates.
|
|
599
|
+
"""
|
|
600
|
+
|
|
601
|
+
if type(result) is not PortfolioVariationWaveResult:
|
|
602
|
+
raise TypeError("result must be exact PortfolioVariationWaveResult")
|
|
603
|
+
result.__post_init__()
|
|
604
|
+
entry = self._entries.get(result.receipt.request_sha256)
|
|
605
|
+
if entry is None:
|
|
606
|
+
raise ValueError("portfolio result belongs to a foreign campaign request")
|
|
607
|
+
entry.__post_init__()
|
|
608
|
+
audit = result.supplemental_selection_audit
|
|
609
|
+
if audit is None:
|
|
610
|
+
raise ValueError("calibrated portfolio result omitted supplemental audit")
|
|
611
|
+
# Exact replay authenticates the complete payload before the source
|
|
612
|
+
# projection below reads its reconciliation evidence.
|
|
613
|
+
self._decode_result(result)
|
|
614
|
+
payload = thaw_json(audit.payload)
|
|
615
|
+
if type(payload) is not dict:
|
|
616
|
+
raise AssertionError("calibrated audit payload did not thaw to an object")
|
|
617
|
+
reconciliation = payload.get("semantic_reconciliation")
|
|
618
|
+
selected = tuple(
|
|
619
|
+
member.materialization.option_id for member in result.receipt.members
|
|
620
|
+
)
|
|
621
|
+
if reconciliation is None:
|
|
622
|
+
if self.constraint_decoupled:
|
|
623
|
+
raise ValueError("constraint-decoupled source decode needs reconciliation")
|
|
624
|
+
elif type(reconciliation) is not dict:
|
|
625
|
+
raise TypeError("semantic reconciliation must be an exact object")
|
|
626
|
+
else:
|
|
627
|
+
members = reconciliation.get("members")
|
|
628
|
+
if type(members) is not list:
|
|
629
|
+
raise TypeError("semantic reconciliation omitted members")
|
|
630
|
+
reconciled_option_ids = tuple(
|
|
631
|
+
member.get("option_id")
|
|
632
|
+
for member in members
|
|
633
|
+
if type(member) is dict and type(member.get("option_id")) is str
|
|
634
|
+
)
|
|
635
|
+
if len(reconciled_option_ids) != len(members) or len(
|
|
636
|
+
set(reconciled_option_ids)
|
|
637
|
+
) != len(reconciled_option_ids):
|
|
638
|
+
raise ValueError(
|
|
639
|
+
"semantic reconciliation option identities are invalid"
|
|
640
|
+
)
|
|
641
|
+
if not set(selected).issubset(reconciled_option_ids):
|
|
642
|
+
raise ValueError("selected portfolio escapes semantic reconciliation")
|
|
643
|
+
source_by_option = finite_variation_source_by_option(
|
|
644
|
+
entry.request.finite_variation_contract
|
|
645
|
+
)
|
|
646
|
+
if not set(selected).issubset(source_by_option):
|
|
647
|
+
raise ValueError("selected portfolio escapes finite source attribution")
|
|
648
|
+
return tuple(source_by_option[option_id] for option_id in selected)
|
|
649
|
+
|
|
650
|
+
def decode_contextual_allocation_realization(
|
|
651
|
+
self,
|
|
652
|
+
result: PortfolioVariationWaveResult | PortfolioSelectionResult,
|
|
653
|
+
) -> ContextualPortfolioAllocationRealization | None:
|
|
654
|
+
"""Project an authenticated selector receipt into the generic port.
|
|
655
|
+
|
|
656
|
+
The calibrated integration owns finite-set reconciliation. Only its
|
|
657
|
+
requested and realized arm counts cross the inverted API; candidate
|
|
658
|
+
fields and workload/model/provider identifiers remain private here.
|
|
659
|
+
"""
|
|
660
|
+
|
|
661
|
+
if type(result) is PortfolioVariationWaveResult:
|
|
662
|
+
result.__post_init__()
|
|
663
|
+
request_sha256 = result.receipt.request_sha256
|
|
664
|
+
audit = result.supplemental_selection_audit
|
|
665
|
+
elif type(result) is PortfolioSelectionResult:
|
|
666
|
+
result.__post_init__()
|
|
667
|
+
request_sha256 = result.decision.request_sha256
|
|
668
|
+
audit = result.supplemental_audit
|
|
669
|
+
else:
|
|
670
|
+
raise TypeError(
|
|
671
|
+
"result must be exact PortfolioVariationWaveResult or "
|
|
672
|
+
"PortfolioSelectionResult"
|
|
673
|
+
)
|
|
674
|
+
entry = self._entries.get(request_sha256)
|
|
675
|
+
if entry is None:
|
|
676
|
+
raise ValueError("portfolio result belongs to a foreign campaign request")
|
|
677
|
+
entry.__post_init__()
|
|
678
|
+
if audit is None:
|
|
679
|
+
raise ValueError("calibrated portfolio result omitted supplemental audit")
|
|
680
|
+
decode_calibrated_portfolio_audit(
|
|
681
|
+
audit,
|
|
682
|
+
request=entry.request,
|
|
683
|
+
binding=entry.binding,
|
|
684
|
+
allocator=self.allocator,
|
|
685
|
+
)
|
|
686
|
+
contract = entry.binding.contextual_allocation
|
|
687
|
+
if contract is None:
|
|
688
|
+
return None
|
|
689
|
+
payload = thaw_json(audit.payload)
|
|
690
|
+
if type(payload) is not dict:
|
|
691
|
+
raise AssertionError("calibrated audit payload did not thaw to an object")
|
|
692
|
+
reconciliation = payload.get("semantic_reconciliation")
|
|
693
|
+
if type(reconciliation) is not dict:
|
|
694
|
+
raise ValueError("contextual selection omitted semantic reconciliation")
|
|
695
|
+
projection = reconciliation.get("contextual_allocation_projection")
|
|
696
|
+
if type(projection) is not dict:
|
|
697
|
+
raise ValueError("contextual selection omitted allocation projection")
|
|
698
|
+
|
|
699
|
+
def counts(name: str) -> tuple[tuple[str, int], ...]:
|
|
700
|
+
value = projection.get(name)
|
|
701
|
+
if type(value) is not list:
|
|
702
|
+
raise TypeError(f"{name} must be an exact list")
|
|
703
|
+
rows = tuple(
|
|
704
|
+
(row[0], row[1]) for row in value if type(row) is list and len(row) == 2
|
|
705
|
+
)
|
|
706
|
+
if len(rows) != len(value):
|
|
707
|
+
raise TypeError(f"{name} contains a malformed count")
|
|
708
|
+
return rows
|
|
709
|
+
|
|
710
|
+
realization = ContextualPortfolioAllocationRealization(
|
|
711
|
+
campaign_scope_sha256=contract.campaign_scope_sha256,
|
|
712
|
+
query_sha256=contract.query_sha256,
|
|
713
|
+
decision_sha256=contract.decision_sha256,
|
|
714
|
+
contract_sha256=contract.contract_sha256,
|
|
715
|
+
controller_wave_index=contract.controller_wave_index,
|
|
716
|
+
slice_id=contract.slice_id,
|
|
717
|
+
requested_source_target_counts=counts("requested_source_target_counts"),
|
|
718
|
+
requested_operator_target_counts=counts("requested_operator_target_counts"),
|
|
719
|
+
realized_source_target_counts=counts("realized_source_target_counts"),
|
|
720
|
+
realized_operator_target_counts=counts("realized_operator_target_counts"),
|
|
721
|
+
requested_minimum_single_path_interventions=(
|
|
722
|
+
contract.minimum_single_path_interventions
|
|
723
|
+
),
|
|
724
|
+
realized_single_path_interventions=(
|
|
725
|
+
projection.get("realized_single_path_interventions", 0)
|
|
726
|
+
),
|
|
727
|
+
requested_minimum_disjoint_parent_patch_pairs=(
|
|
728
|
+
contract.minimum_disjoint_parent_patch_pairs
|
|
729
|
+
),
|
|
730
|
+
realized_disjoint_parent_patch_pairs=(
|
|
731
|
+
projection.get("realized_disjoint_parent_patch_pairs", 0)
|
|
732
|
+
),
|
|
733
|
+
)
|
|
734
|
+
realization.require_contract(contract)
|
|
735
|
+
if projection.get("source_l1_deviation") != realization.source_l1_deviation:
|
|
736
|
+
raise ValueError("source allocation projection L1 drifted")
|
|
737
|
+
if projection.get("operator_l1_deviation") != (
|
|
738
|
+
realization.operator_l1_deviation
|
|
739
|
+
):
|
|
740
|
+
raise ValueError("operator allocation projection L1 drifted")
|
|
741
|
+
if projection.get("exact") is not realization.exact:
|
|
742
|
+
raise ValueError("allocation projection exact verdict drifted")
|
|
743
|
+
if projection.get("objective_values_consulted") is not False:
|
|
744
|
+
raise ValueError("allocation projection consulted objective values")
|
|
745
|
+
if projection.get("workload_identifiers_consulted") is not False:
|
|
746
|
+
raise ValueError("allocation projection consulted workload identifiers")
|
|
747
|
+
return realization
|
|
748
|
+
|
|
749
|
+
@property
|
|
750
|
+
def registered_request_count(self) -> int:
|
|
751
|
+
"""Number of append-only pre-call request bindings."""
|
|
752
|
+
|
|
753
|
+
return len(self._entries)
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
__all__ = ["CalibratedPortfolioCampaignCoordinator"]
|