lex-agentic-inference 0.1.0
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +13 -0
- data/lex-agentic-inference.gemspec +30 -0
- data/lib/legion/extensions/agentic/inference/abductive/client.rb +25 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/abduction_engine.rb +164 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/constants.rb +39 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/hypothesis.rb +106 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/observation.rb +39 -0
- data/lib/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning.rb +129 -0
- data/lib/legion/extensions/agentic/inference/abductive/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/abductive.rb +20 -0
- data/lib/legion/extensions/agentic/inference/affordance/actors/scan.rb +31 -0
- data/lib/legion/extensions/agentic/inference/affordance/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb +123 -0
- data/lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb +75 -0
- data/lib/legion/extensions/agentic/inference/affordance/helpers/constants.rb +42 -0
- data/lib/legion/extensions/agentic/inference/affordance/runners/affordance.rb +90 -0
- data/lib/legion/extensions/agentic/inference/affordance/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/affordance.rb +19 -0
- data/lib/legion/extensions/agentic/inference/analogical/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/analogical/helpers/analogy_engine.rb +209 -0
- data/lib/legion/extensions/agentic/inference/analogical/helpers/constants.rb +38 -0
- data/lib/legion/extensions/agentic/inference/analogical/helpers/structure_map.rb +113 -0
- data/lib/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning.rb +106 -0
- data/lib/legion/extensions/agentic/inference/analogical/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/analogical.rb +19 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb +102 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument_engine.rb +131 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/constants.rb +44 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping.rb +78 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping.rb +19 -0
- data/lib/legion/extensions/agentic/inference/bayesian/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/bayesian/helpers/belief.rb +96 -0
- data/lib/legion/extensions/agentic/inference/bayesian/helpers/belief_network.rb +147 -0
- data/lib/legion/extensions/agentic/inference/bayesian/helpers/constants.rb +36 -0
- data/lib/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief.rb +125 -0
- data/lib/legion/extensions/agentic/inference/bayesian/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/bayesian.rb +19 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/belief.rb +155 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/belief_network.rb +193 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/constants.rb +54 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/evidence.rb +49 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb +89 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/belief_revision.rb +21 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/client.rb +27 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb +92 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine.rb +159 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution.rb +111 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution.rb +18 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/client.rb +24 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_edge.rb +101 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_graph.rb +184 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/constants.rb +40 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning.rb +111 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning.rb +19 -0
- data/lib/legion/extensions/agentic/inference/coherence/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/coherence/helpers/coherence_engine.rb +170 -0
- data/lib/legion/extensions/agentic/inference/coherence/helpers/constants.rb +35 -0
- data/lib/legion/extensions/agentic/inference/coherence/helpers/proposition.rb +100 -0
- data/lib/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence.rb +123 -0
- data/lib/legion/extensions/agentic/inference/coherence/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/coherence.rb +19 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/helpers/constants.rb +40 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/helpers/counterfactual_engine.rb +157 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb +98 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/runners/counterfactual.rb +106 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/counterfactual.rb +19 -0
- data/lib/legion/extensions/agentic/inference/debugging/client.rb +30 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb +51 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/constants.rb +58 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/correction.rb +56 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/debugging_engine.rb +156 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/reasoning_error.rb +97 -0
- data/lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb +178 -0
- data/lib/legion/extensions/agentic/inference/debugging/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/debugging.rb +21 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/client.rb +27 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb +120 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop.rb +122 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb +124 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition.rb +18 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/client.rb +17 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/constants.rb +47 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/expectation.rb +82 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/violation_engine.rb +126 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb +76 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation.rb +19 -0
- data/lib/legion/extensions/agentic/inference/free_energy/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/free_energy/helpers/belief.rb +127 -0
- data/lib/legion/extensions/agentic/inference/free_energy/helpers/constants.rb +58 -0
- data/lib/legion/extensions/agentic/inference/free_energy/helpers/free_energy_engine.rb +156 -0
- data/lib/legion/extensions/agentic/inference/free_energy/runners/free_energy.rb +97 -0
- data/lib/legion/extensions/agentic/inference/free_energy/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/free_energy.rb +19 -0
- data/lib/legion/extensions/agentic/inference/gravity/client.rb +29 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb +77 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/constants.rb +76 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb +164 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb +64 -0
- data/lib/legion/extensions/agentic/inference/gravity/runners/gravity.rb +132 -0
- data/lib/legion/extensions/agentic/inference/gravity/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/gravity.rb +20 -0
- data/lib/legion/extensions/agentic/inference/horizon/actors/adjust.rb +45 -0
- data/lib/legion/extensions/agentic/inference/horizon/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/horizon/helpers/constants.rb +43 -0
- data/lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb +110 -0
- data/lib/legion/extensions/agentic/inference/horizon/helpers/projection.rb +59 -0
- data/lib/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon.rb +107 -0
- data/lib/legion/extensions/agentic/inference/horizon/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/horizon.rb +19 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/constants.rb +37 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb +83 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine.rb +97 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb +115 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing.rb +19 -0
- data/lib/legion/extensions/agentic/inference/intuition/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/constants.rb +60 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb +66 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb +157 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/pattern.rb +105 -0
- data/lib/legion/extensions/agentic/inference/intuition/runners/intuition.rb +87 -0
- data/lib/legion/extensions/agentic/inference/intuition/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/intuition.rb +20 -0
- data/lib/legion/extensions/agentic/inference/magnet/client.rb +29 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/constants.rb +57 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/field.rb +105 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/magnet_engine.rb +179 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb +80 -0
- data/lib/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet.rb +124 -0
- data/lib/legion/extensions/agentic/inference/magnet/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/magnet.rb +21 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/client.rb +17 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/constants.rb +65 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb +112 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb +127 -0
- data/lib/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum.rb +101 -0
- data/lib/legion/extensions/agentic/inference/momentum/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/momentum.rb +19 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/constants.rb +34 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field.rb +154 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb +100 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb +120 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference.rb +19 -0
- data/lib/legion/extensions/agentic/inference/prediction/actors/expire_predictions.rb +45 -0
- data/lib/legion/extensions/agentic/inference/prediction/client.rb +27 -0
- data/lib/legion/extensions/agentic/inference/prediction/helpers/modes.rb +28 -0
- data/lib/legion/extensions/agentic/inference/prediction/helpers/prediction_store.rb +66 -0
- data/lib/legion/extensions/agentic/inference/prediction/runners/prediction.rb +146 -0
- data/lib/legion/extensions/agentic/inference/prediction/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/prediction.rb +18 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/constants.rb +46 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/generative_model.rb +187 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb +59 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding.rb +171 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding.rb +20 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/constants.rb +35 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/generative_model.rb +142 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/predictive_processor.rb +129 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb +104 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing.rb +19 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb +98 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/helpers/constants.rb +41 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine.rb +104 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/runners/reality_testing.rb +94 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/reality_testing.rb +19 -0
- data/lib/legion/extensions/agentic/inference/schema/client.rb +26 -0
- data/lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb +70 -0
- data/lib/legion/extensions/agentic/inference/schema/helpers/constants.rb +50 -0
- data/lib/legion/extensions/agentic/inference/schema/helpers/world_model.rb +173 -0
- data/lib/legion/extensions/agentic/inference/schema/runners/schema.rb +101 -0
- data/lib/legion/extensions/agentic/inference/schema/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/schema.rb +19 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/constants.rb +42 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb +66 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/tolerance_engine.rb +139 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb +129 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance.rb +19 -0
- data/lib/legion/extensions/agentic/inference/version.rb +11 -0
- data/lib/legion/extensions/agentic/inference.rb +44 -0
- data/spec/legion/extensions/agentic/inference/abductive/client_spec.rb +25 -0
- data/spec/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning_spec.rb +349 -0
- data/spec/legion/extensions/agentic/inference/affordance/client_spec.rb +26 -0
- data/spec/legion/extensions/agentic/inference/affordance/helpers/affordance_field_spec.rb +131 -0
- data/spec/legion/extensions/agentic/inference/affordance/helpers/affordance_item_spec.rb +107 -0
- data/spec/legion/extensions/agentic/inference/affordance/runners/affordance_spec.rb +78 -0
- data/spec/legion/extensions/agentic/inference/analogical/client_spec.rb +31 -0
- data/spec/legion/extensions/agentic/inference/analogical/helpers/analogy_engine_spec.rb +276 -0
- data/spec/legion/extensions/agentic/inference/analogical/helpers/structure_map_spec.rb +255 -0
- data/spec/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning_spec.rb +213 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/client_spec.rb +18 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/helpers/argument_engine_spec.rb +218 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/helpers/argument_spec.rb +231 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping_spec.rb +171 -0
- data/spec/legion/extensions/agentic/inference/bayesian/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/inference/bayesian/helpers/belief_network_spec.rb +178 -0
- data/spec/legion/extensions/agentic/inference/bayesian/helpers/belief_spec.rb +137 -0
- data/spec/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief_spec.rb +176 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/client_spec.rb +31 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/helpers/belief_network_spec.rb +176 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/helpers/belief_spec.rb +153 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/helpers/evidence_spec.rb +51 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/runners/belief_revision_spec.rb +106 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/client_spec.rb +24 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine_spec.rb +181 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_spec.rb +108 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution_spec.rb +142 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/client_spec.rb +35 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_edge_spec.rb +158 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_graph_spec.rb +259 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning_spec.rb +161 -0
- data/spec/legion/extensions/agentic/inference/coherence/client_spec.rb +17 -0
- data/spec/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence_spec.rb +267 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/client_spec.rb +48 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/helpers/constants_spec.rb +55 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/helpers/counterfactual_engine_spec.rb +234 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/helpers/scenario_spec.rb +193 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/runners/counterfactual_spec.rb +179 -0
- data/spec/legion/extensions/agentic/inference/debugging/client_spec.rb +46 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/causal_trace_spec.rb +84 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/constants_spec.rb +97 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/correction_spec.rb +98 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/debugging_engine_spec.rb +290 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/reasoning_error_spec.rb +164 -0
- data/spec/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging_spec.rb +301 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/client_spec.rb +19 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine_spec.rb +181 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop_spec.rb +184 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition_spec.rb +214 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/expectation_violation_spec.rb +11 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/helpers/expectation_spec.rb +102 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/helpers/violation_engine_spec.rb +121 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation_spec.rb +59 -0
- data/spec/legion/extensions/agentic/inference/free_energy/client_spec.rb +46 -0
- data/spec/legion/extensions/agentic/inference/free_energy/helpers/belief_spec.rb +183 -0
- data/spec/legion/extensions/agentic/inference/free_energy/helpers/free_energy_engine_spec.rb +211 -0
- data/spec/legion/extensions/agentic/inference/free_energy/runners/free_energy_spec.rb +118 -0
- data/spec/legion/extensions/agentic/inference/gravity/client_spec.rb +24 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/attractor_spec.rb +143 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/constants_spec.rb +107 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/gravity_engine_spec.rb +193 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought_spec.rb +103 -0
- data/spec/legion/extensions/agentic/inference/gravity/runners/gravity_spec.rb +159 -0
- data/spec/legion/extensions/agentic/inference/horizon/client_spec.rb +58 -0
- data/spec/legion/extensions/agentic/inference/horizon/helpers/constants_spec.rb +98 -0
- data/spec/legion/extensions/agentic/inference/horizon/helpers/horizon_engine_spec.rb +325 -0
- data/spec/legion/extensions/agentic/inference/horizon/helpers/projection_spec.rb +155 -0
- data/spec/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon_spec.rb +269 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/constants_spec.rb +38 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine_spec.rb +182 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_spec.rb +172 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/hypothesis_testing_spec.rb +16 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing_spec.rb +159 -0
- data/spec/legion/extensions/agentic/inference/intuition/client_spec.rb +33 -0
- data/spec/legion/extensions/agentic/inference/intuition/helpers/heuristic_spec.rb +82 -0
- data/spec/legion/extensions/agentic/inference/intuition/helpers/intuition_engine_spec.rb +163 -0
- data/spec/legion/extensions/agentic/inference/intuition/helpers/pattern_spec.rb +160 -0
- data/spec/legion/extensions/agentic/inference/intuition/runners/intuition_spec.rb +107 -0
- data/spec/legion/extensions/agentic/inference/magnet/client_spec.rb +30 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/constants_spec.rb +120 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/field_spec.rb +193 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/magnet_engine_spec.rb +281 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/pole_spec.rb +211 -0
- data/spec/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet_spec.rb +201 -0
- data/spec/legion/extensions/agentic/inference/momentum/cognitive_momentum_spec.rb +11 -0
- data/spec/legion/extensions/agentic/inference/momentum/helpers/idea_spec.rb +152 -0
- data/spec/legion/extensions/agentic/inference/momentum/helpers/momentum_engine_spec.rb +154 -0
- data/spec/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum_spec.rb +97 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/client_spec.rb +39 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/constants_spec.rb +97 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field_spec.rb +270 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis_spec.rb +206 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference_spec.rb +305 -0
- data/spec/legion/extensions/agentic/inference/prediction/actors/expire_predictions_spec.rb +46 -0
- data/spec/legion/extensions/agentic/inference/prediction/client_spec.rb +14 -0
- data/spec/legion/extensions/agentic/inference/prediction/helpers/modes_spec.rb +118 -0
- data/spec/legion/extensions/agentic/inference/prediction/helpers/prediction_store_spec.rb +262 -0
- data/spec/legion/extensions/agentic/inference/prediction/runners/prediction_spec.rb +116 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/client_spec.rb +74 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/helpers/generative_model_spec.rb +194 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error_spec.rb +109 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding_spec.rb +210 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/client_spec.rb +82 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/helpers/generative_model_spec.rb +220 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/helpers/predictive_processor_spec.rb +206 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing_spec.rb +213 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/client_spec.rb +29 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/helpers/belief_spec.rb +197 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/helpers/constants_spec.rb +78 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine_spec.rb +191 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/runners/reality_testing_spec.rb +154 -0
- data/spec/legion/extensions/agentic/inference/schema/client_spec.rb +53 -0
- data/spec/legion/extensions/agentic/inference/schema/helpers/causal_relation_spec.rb +108 -0
- data/spec/legion/extensions/agentic/inference/schema/helpers/constants_spec.rb +54 -0
- data/spec/legion/extensions/agentic/inference/schema/helpers/world_model_spec.rb +179 -0
- data/spec/legion/extensions/agentic/inference/schema/runners/schema_spec.rb +146 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/client_spec.rb +18 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/constants_spec.rb +62 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision_spec.rb +125 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/tolerance_engine_spec.rb +184 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance_spec.rb +157 -0
- data/spec/spec_helper.rb +46 -0
- metadata +412 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/horizon/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Horizon::Runners::CognitiveHorizon do
|
|
6
|
+
let(:client) { Legion::Extensions::Agentic::Inference::Horizon::Client.new }
|
|
7
|
+
|
|
8
|
+
describe '#get_horizon' do
|
|
9
|
+
it 'returns found: true' do
|
|
10
|
+
result = client.get_horizon
|
|
11
|
+
expect(result[:found]).to be true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'includes a horizon report' do
|
|
15
|
+
result = client.get_horizon
|
|
16
|
+
expect(result[:horizon]).to be_a(Hash)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'horizon report includes current_horizon' do
|
|
20
|
+
result = client.get_horizon
|
|
21
|
+
expect(result[:horizon]).to have_key(:current_horizon)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'horizon report includes construal_label' do
|
|
25
|
+
result = client.get_horizon
|
|
26
|
+
expect(result[:horizon]).to have_key(:construal_label)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'horizon report includes effective_horizon' do
|
|
30
|
+
result = client.get_horizon
|
|
31
|
+
expect(result[:horizon]).to have_key(:effective_horizon)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe '#expand_horizon' do
|
|
36
|
+
it 'returns expanded: true' do
|
|
37
|
+
result = client.expand_horizon
|
|
38
|
+
expect(result[:expanded]).to be true
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'after is greater than before' do
|
|
42
|
+
result = client.expand_horizon
|
|
43
|
+
expect(result[:after]).to be > result[:before]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'returns the default amount' do
|
|
47
|
+
result = client.expand_horizon
|
|
48
|
+
expect(result[:amount]).to eq(Legion::Extensions::Agentic::Inference::Horizon::Helpers::Constants::HORIZON_EXPAND)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'accepts custom amount' do
|
|
52
|
+
result = client.expand_horizon(amount: 0.2)
|
|
53
|
+
expect(result[:amount]).to eq(0.2)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'does not exceed 1.0' do
|
|
57
|
+
10.times { client.expand_horizon(amount: 0.2) }
|
|
58
|
+
result = client.get_horizon
|
|
59
|
+
expect(result[:horizon][:current_horizon]).to be <= 1.0
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe '#contract_horizon' do
|
|
64
|
+
it 'returns contracted: true' do
|
|
65
|
+
result = client.contract_horizon
|
|
66
|
+
expect(result[:contracted]).to be true
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'after is less than before' do
|
|
70
|
+
result = client.contract_horizon
|
|
71
|
+
expect(result[:after]).to be < result[:before]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'returns the default amount' do
|
|
75
|
+
result = client.contract_horizon
|
|
76
|
+
expect(result[:amount]).to eq(Legion::Extensions::Agentic::Inference::Horizon::Helpers::Constants::HORIZON_CONTRACT)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'does not go below MIN_HORIZON' do
|
|
80
|
+
10.times { client.contract_horizon(amount: 0.2) }
|
|
81
|
+
result = client.get_horizon
|
|
82
|
+
expect(result[:horizon][:current_horizon]).to be >= Legion::Extensions::Agentic::Inference::Horizon::Helpers::Constants::MIN_HORIZON
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe '#apply_stress' do
|
|
87
|
+
it 'returns stress_applied: true' do
|
|
88
|
+
result = client.apply_stress(level: 0.5)
|
|
89
|
+
expect(result[:stress_applied]).to be true
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'records the stress level' do
|
|
93
|
+
result = client.apply_stress(level: 0.6)
|
|
94
|
+
expect(result[:stress_level]).to eq(0.6)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'decreases the horizon' do
|
|
98
|
+
result = client.apply_stress(level: 0.8)
|
|
99
|
+
expect(result[:after]).to be <= result[:before]
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'contracts horizon with high stress' do
|
|
103
|
+
initial = client.get_horizon[:horizon][:current_horizon]
|
|
104
|
+
client.apply_stress(level: 1.0)
|
|
105
|
+
final = client.get_horizon[:horizon][:current_horizon]
|
|
106
|
+
expect(final).to be < initial
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
describe '#relieve_stress' do
|
|
111
|
+
before { client.apply_stress(level: 0.8) }
|
|
112
|
+
|
|
113
|
+
it 'returns relieved: true' do
|
|
114
|
+
result = client.relieve_stress
|
|
115
|
+
expect(result[:relieved]).to be true
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'reduces stress level' do
|
|
119
|
+
result = client.relieve_stress
|
|
120
|
+
expect(result[:after]).to be < result[:before]
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'accepts custom amount' do
|
|
124
|
+
result = client.relieve_stress(amount: 0.3)
|
|
125
|
+
expect(result[:amount]).to eq(0.3)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
describe '#add_projection' do
|
|
130
|
+
it 'returns a hash with an id' do
|
|
131
|
+
result = client.add_projection(description: 'Future state')
|
|
132
|
+
expect(result[:id]).to match(/\A[0-9a-f-]{36}\z/)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it 'includes description' do
|
|
136
|
+
result = client.add_projection(description: 'Future state')
|
|
137
|
+
expect(result[:description]).to eq('Future state')
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'uses default domain :general' do
|
|
141
|
+
result = client.add_projection(description: 'x')
|
|
142
|
+
expect(result[:domain]).to eq(:general)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it 'accepts custom domain' do
|
|
146
|
+
result = client.add_projection(description: 'x', domain: :ops)
|
|
147
|
+
expect(result[:domain]).to eq(:ops)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it 'returns horizon_distance' do
|
|
151
|
+
result = client.add_projection(description: 'x', horizon_distance: 0.7)
|
|
152
|
+
expect(result[:horizon_distance]).to eq(0.7)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it 'returns construal_level' do
|
|
156
|
+
result = client.add_projection(description: 'x')
|
|
157
|
+
expect(result[:construal_level]).to be_a(Symbol)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
describe '#projections_within_horizon' do
|
|
162
|
+
before do
|
|
163
|
+
client.add_projection(description: 'near', horizon_distance: 0.1)
|
|
164
|
+
client.add_projection(description: 'far', horizon_distance: 0.99)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it 'returns count' do
|
|
168
|
+
result = client.projections_within_horizon
|
|
169
|
+
expect(result[:count]).to be_a(Integer)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it 'returns projections array' do
|
|
173
|
+
result = client.projections_within_horizon
|
|
174
|
+
expect(result[:projections]).to be_an(Array)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it 'includes effective_horizon' do
|
|
178
|
+
result = client.projections_within_horizon
|
|
179
|
+
expect(result[:effective_horizon]).to be_a(Float)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it 'all returned projections are within effective_horizon' do
|
|
183
|
+
result = client.projections_within_horizon
|
|
184
|
+
result[:projections].each do |p|
|
|
185
|
+
expect(p[:horizon_distance]).to be <= result[:effective_horizon]
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
describe '#beyond_horizon_projections' do
|
|
191
|
+
before do
|
|
192
|
+
client.add_projection(description: 'near', horizon_distance: 0.1)
|
|
193
|
+
client.add_projection(description: 'far', horizon_distance: 0.99)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it 'returns count' do
|
|
197
|
+
result = client.beyond_horizon_projections
|
|
198
|
+
expect(result[:count]).to be_a(Integer)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it 'all returned projections are beyond effective_horizon' do
|
|
202
|
+
result = client.beyond_horizon_projections
|
|
203
|
+
eff = result[:effective_horizon]
|
|
204
|
+
result[:projections].each do |p|
|
|
205
|
+
expect(p[:horizon_distance]).to be > eff
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it 'within + beyond == total' do
|
|
210
|
+
within_count = client.projections_within_horizon[:count]
|
|
211
|
+
beyond_count = client.beyond_horizon_projections[:count]
|
|
212
|
+
total = client.horizon_status[:total_projections]
|
|
213
|
+
expect(within_count + beyond_count).to eq(total)
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
describe '#nearest_projections' do
|
|
218
|
+
before do
|
|
219
|
+
[0.9, 0.1, 0.5].each { |d| client.add_projection(description: "p#{d}", horizon_distance: d) }
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
it 'returns count' do
|
|
223
|
+
result = client.nearest_projections(count: 2)
|
|
224
|
+
expect(result[:count]).to eq(2)
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
it 'returns projections sorted nearest first' do
|
|
228
|
+
result = client.nearest_projections(count: 2)
|
|
229
|
+
distances = result[:projections].map { |p| p[:horizon_distance] }
|
|
230
|
+
expect(distances).to eq(distances.sort)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
it 'defaults to count=5' do
|
|
234
|
+
5.times { |i| client.add_projection(description: "extra #{i}", horizon_distance: 0.3) }
|
|
235
|
+
result = client.nearest_projections
|
|
236
|
+
expect(result[:count]).to be <= 5
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
describe '#farthest_projections' do
|
|
241
|
+
before do
|
|
242
|
+
[0.9, 0.1, 0.5].each { |d| client.add_projection(description: "p#{d}", horizon_distance: d) }
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it 'returns projections sorted farthest first' do
|
|
246
|
+
result = client.farthest_projections(count: 2)
|
|
247
|
+
distances = result[:projections].map { |p| p[:horizon_distance] }
|
|
248
|
+
expect(distances).to eq(distances.sort.reverse)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
it 'returns correct count' do
|
|
252
|
+
result = client.farthest_projections(count: 2)
|
|
253
|
+
expect(result[:count]).to eq(2)
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
describe '#horizon_status' do
|
|
258
|
+
it 'returns total_projections' do
|
|
259
|
+
client.add_projection(description: 'test')
|
|
260
|
+
result = client.horizon_status
|
|
261
|
+
expect(result[:total_projections]).to eq(1)
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
it 'includes a report hash' do
|
|
265
|
+
result = client.horizon_status
|
|
266
|
+
expect(result[:report]).to be_a(Hash)
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/hypothesis_testing/helpers/constants'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::HypothesisTesting::Helpers::Constants do
|
|
6
|
+
it 'defines MAX_HYPOTHESES as 300' do
|
|
7
|
+
expect(described_class::MAX_HYPOTHESES).to eq(300)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'defines CONFIRMATION_THRESHOLD as 0.8' do
|
|
11
|
+
expect(described_class::CONFIRMATION_THRESHOLD).to eq(0.8)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'defines DISCONFIRMATION_THRESHOLD as 0.2' do
|
|
15
|
+
expect(described_class::DISCONFIRMATION_THRESHOLD).to eq(0.2)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'defines EVIDENCE_WEIGHT as 0.1' do
|
|
19
|
+
expect(described_class::EVIDENCE_WEIGHT).to eq(0.1)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'defines PRIOR_DEFAULT as 0.5' do
|
|
23
|
+
expect(described_class::PRIOR_DEFAULT).to eq(0.5)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'defines all five STATUS_LABELS keys' do
|
|
27
|
+
expect(described_class::STATUS_LABELS.keys).to match_array(%i[proposed testing confirmed disconfirmed inconclusive])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'defines five CONFIDENCE_LABELS entries' do
|
|
31
|
+
expect(described_class::CONFIDENCE_LABELS.size).to eq(5)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'includes certain, confident, leaning, uncertain, agnostic labels' do
|
|
35
|
+
labels = described_class::CONFIDENCE_LABELS.map { |_, label| label }
|
|
36
|
+
expect(labels).to match_array(%w[certain confident leaning uncertain agnostic])
|
|
37
|
+
end
|
|
38
|
+
end
|
data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine_spec.rb
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/hypothesis_testing/helpers/constants'
|
|
4
|
+
require 'legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis'
|
|
5
|
+
require 'legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine'
|
|
6
|
+
|
|
7
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::HypothesisTesting::Helpers::HypothesisEngine do
|
|
8
|
+
subject(:engine) { described_class.new }
|
|
9
|
+
|
|
10
|
+
describe '#propose' do
|
|
11
|
+
it 'returns a Hypothesis object' do
|
|
12
|
+
h = engine.propose(description: 'test', domain: 'logic')
|
|
13
|
+
expect(h).to be_a(Legion::Extensions::Agentic::Inference::HypothesisTesting::Helpers::Hypothesis)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'stores the hypothesis' do
|
|
17
|
+
h = engine.propose(description: 'stored')
|
|
18
|
+
expect(engine.hypotheses[h.id]).to eq(h)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'assigns the given domain' do
|
|
22
|
+
h = engine.propose(description: 'domain test', domain: 'physics')
|
|
23
|
+
expect(h.domain).to eq('physics')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'uses default domain general when not specified' do
|
|
27
|
+
h = engine.propose(description: 'default domain')
|
|
28
|
+
expect(h.domain).to eq('general')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'assigns the given prior' do
|
|
32
|
+
h = engine.propose(description: 'prior test', prior: 0.3)
|
|
33
|
+
expect(h.prior).to eq(0.3)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'evicts oldest when MAX_HYPOTHESES is reached' do
|
|
37
|
+
max = Legion::Extensions::Agentic::Inference::HypothesisTesting::Helpers::Constants::MAX_HYPOTHESES
|
|
38
|
+
max.times { |i| engine.propose(description: "h#{i}") }
|
|
39
|
+
expect(engine.hypotheses.size).to eq(max)
|
|
40
|
+
oldest_id = engine.hypotheses.values.min_by(&:created_at).id
|
|
41
|
+
engine.propose(description: 'overflow')
|
|
42
|
+
expect(engine.hypotheses.key?(oldest_id)).to be false
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe '#test_hypothesis' do
|
|
47
|
+
it 'updates posterior when hypothesis exists' do
|
|
48
|
+
h = engine.propose(description: 'testable', prior: 0.5)
|
|
49
|
+
prior = h.posterior
|
|
50
|
+
engine.test_hypothesis(hypothesis_id: h.id, evidence_strength: 1.0, supporting: true)
|
|
51
|
+
expect(h.posterior).to be > prior
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'returns nil for unknown hypothesis_id' do
|
|
55
|
+
result = engine.test_hypothesis(hypothesis_id: 'nonexistent', evidence_strength: 0.5, supporting: true)
|
|
56
|
+
expect(result).to be_nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'auto-confirms when posterior crosses CONFIRMATION_THRESHOLD' do
|
|
60
|
+
h = engine.propose(description: 'high prior', prior: 0.79)
|
|
61
|
+
engine.test_hypothesis(hypothesis_id: h.id, evidence_strength: 1.0, supporting: true)
|
|
62
|
+
expect(h.status).to eq(:confirmed)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'auto-disconfirms when posterior falls below DISCONFIRMATION_THRESHOLD' do
|
|
66
|
+
h = engine.propose(description: 'low prior', prior: 0.21)
|
|
67
|
+
engine.test_hypothesis(hypothesis_id: h.id, evidence_strength: 1.0, supporting: false)
|
|
68
|
+
expect(h.status).to eq(:disconfirmed)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe '#evaluate' do
|
|
73
|
+
it 'returns nil for unknown hypothesis_id' do
|
|
74
|
+
expect(engine.evaluate('nonexistent')).to be_nil
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'confirms when posterior >= CONFIRMATION_THRESHOLD' do
|
|
78
|
+
h = engine.propose(description: 'evaluate confirm', prior: 0.9)
|
|
79
|
+
engine.evaluate(h.id)
|
|
80
|
+
expect(h.status).to eq(:confirmed)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'disconfirms when posterior <= DISCONFIRMATION_THRESHOLD' do
|
|
84
|
+
h = engine.propose(description: 'evaluate disconfirm', prior: 0.1)
|
|
85
|
+
engine.evaluate(h.id)
|
|
86
|
+
expect(h.status).to eq(:disconfirmed)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it 'does not re-evaluate an already confirmed hypothesis' do
|
|
90
|
+
h = engine.propose(description: 'already confirmed', prior: 0.5)
|
|
91
|
+
h.confirm!
|
|
92
|
+
engine.evaluate(h.id)
|
|
93
|
+
expect(h.status).to eq(:confirmed)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe '#competing_hypotheses' do
|
|
98
|
+
it 'returns all hypotheses in the given domain' do
|
|
99
|
+
engine.propose(description: 'h1', domain: 'physics')
|
|
100
|
+
engine.propose(description: 'h2', domain: 'physics')
|
|
101
|
+
engine.propose(description: 'h3', domain: 'chemistry')
|
|
102
|
+
result = engine.competing_hypotheses(domain: 'physics')
|
|
103
|
+
expect(result.size).to eq(2)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it 'returns an empty array when no hypotheses match the domain' do
|
|
107
|
+
engine.propose(description: 'other', domain: 'biology')
|
|
108
|
+
expect(engine.competing_hypotheses(domain: 'astronomy')).to be_empty
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe '#most_confident' do
|
|
113
|
+
it 'returns hypotheses sorted by descending posterior' do
|
|
114
|
+
h1 = engine.propose(description: 'low', prior: 0.2)
|
|
115
|
+
h2 = engine.propose(description: 'high', prior: 0.9)
|
|
116
|
+
h3 = engine.propose(description: 'mid', prior: 0.5)
|
|
117
|
+
result = engine.most_confident(limit: 3)
|
|
118
|
+
expect(result.map(&:id)).to eq([h2.id, h3.id, h1.id])
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it 'respects the limit parameter' do
|
|
122
|
+
5.times { |i| engine.propose(description: "h#{i}", prior: i * 0.1) }
|
|
123
|
+
expect(engine.most_confident(limit: 3).size).to eq(3)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe '#confirmation_rate' do
|
|
128
|
+
it 'returns 0.0 when no hypotheses have been resolved' do
|
|
129
|
+
engine.propose(description: 'unresolved')
|
|
130
|
+
expect(engine.confirmation_rate).to eq(0.0)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'computes rate correctly with mixed outcomes' do
|
|
134
|
+
h1 = engine.propose(description: 'h1', prior: 0.9)
|
|
135
|
+
h1.confirm!
|
|
136
|
+
h2 = engine.propose(description: 'h2', prior: 0.1)
|
|
137
|
+
h2.disconfirm!
|
|
138
|
+
expect(engine.confirmation_rate).to eq(0.5)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'returns 1.0 when all resolved hypotheses are confirmed' do
|
|
142
|
+
h = engine.propose(description: 'confirmed', prior: 0.9)
|
|
143
|
+
h.confirm!
|
|
144
|
+
expect(engine.confirmation_rate).to eq(1.0)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
describe '#hypothesis_report' do
|
|
149
|
+
it 'includes total, by_status, confirmation_rate, most_confident' do
|
|
150
|
+
engine.propose(description: 'a')
|
|
151
|
+
engine.propose(description: 'b')
|
|
152
|
+
report = engine.hypothesis_report
|
|
153
|
+
expect(report.keys).to include(:total, :by_status, :confirmation_rate, :most_confident)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'reports correct total count' do
|
|
157
|
+
3.times { |i| engine.propose(description: "h#{i}") }
|
|
158
|
+
expect(engine.hypothesis_report[:total]).to eq(3)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it 'limits most_confident to 3 entries' do
|
|
162
|
+
5.times { |i| engine.propose(description: "h#{i}") }
|
|
163
|
+
expect(engine.hypothesis_report[:most_confident].size).to be <= 3
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
describe '#to_h' do
|
|
168
|
+
it 'includes hypotheses array, confirmation_rate, and total' do
|
|
169
|
+
engine.propose(description: 'serialized')
|
|
170
|
+
result = engine.to_h
|
|
171
|
+
expect(result.keys).to include(:hypotheses, :confirmation_rate, :total)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it 'returns each hypothesis as a hash' do
|
|
175
|
+
engine.propose(description: 'one')
|
|
176
|
+
engine.to_h[:hypotheses].each do |h|
|
|
177
|
+
expect(h).to be_a(Hash)
|
|
178
|
+
expect(h.keys).to include(:id, :description, :status)
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/hypothesis_testing/helpers/constants'
|
|
4
|
+
require 'legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis'
|
|
5
|
+
|
|
6
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::HypothesisTesting::Helpers::Hypothesis do
|
|
7
|
+
subject(:hypothesis) { described_class.new(description: 'test hypothesis', domain: 'logic') }
|
|
8
|
+
|
|
9
|
+
describe '#initialize' do
|
|
10
|
+
it 'assigns a uuid id' do
|
|
11
|
+
expect(hypothesis.id).to match(/\A[0-9a-f-]{36}\z/)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'sets description' do
|
|
15
|
+
expect(hypothesis.description).to eq('test hypothesis')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'sets domain' do
|
|
19
|
+
expect(hypothesis.domain).to eq('logic')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'defaults prior to PRIOR_DEFAULT' do
|
|
23
|
+
h = described_class.new(description: 'default prior')
|
|
24
|
+
expect(h.prior).to eq(Legion::Extensions::Agentic::Inference::HypothesisTesting::Helpers::Constants::PRIOR_DEFAULT)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'sets posterior to prior at creation' do
|
|
28
|
+
h = described_class.new(description: 'check posterior', prior: 0.3)
|
|
29
|
+
expect(h.posterior).to eq(0.3)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'starts with evidence_count of 0' do
|
|
33
|
+
expect(hypothesis.evidence_count).to eq(0)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'starts with status :proposed' do
|
|
37
|
+
expect(hypothesis.status).to eq(:proposed)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'clamps prior above 1.0 to 1.0' do
|
|
41
|
+
h = described_class.new(description: 'high', prior: 1.5)
|
|
42
|
+
expect(h.prior).to eq(1.0)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'clamps prior below 0.0 to 0.0' do
|
|
46
|
+
h = described_class.new(description: 'low', prior: -0.1)
|
|
47
|
+
expect(h.prior).to eq(0.0)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe '#update_posterior!' do
|
|
52
|
+
it 'increases posterior with supporting evidence' do
|
|
53
|
+
before = hypothesis.posterior
|
|
54
|
+
hypothesis.update_posterior!(evidence_strength: 1.0, supporting: true)
|
|
55
|
+
expect(hypothesis.posterior).to be > before
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'decreases posterior with contradicting evidence' do
|
|
59
|
+
h = described_class.new(description: 'contra', prior: 0.8)
|
|
60
|
+
h.update_posterior!(evidence_strength: 1.0, supporting: false)
|
|
61
|
+
expect(h.posterior).to be < 0.8
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'transitions status to :testing' do
|
|
65
|
+
hypothesis.update_posterior!(evidence_strength: 0.5, supporting: true)
|
|
66
|
+
expect(hypothesis.status).to eq(:testing)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'increments evidence_count' do
|
|
70
|
+
hypothesis.update_posterior!(evidence_strength: 0.5, supporting: true)
|
|
71
|
+
expect(hypothesis.evidence_count).to eq(1)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'keeps posterior within [0.0, 1.0]' do
|
|
75
|
+
10.times { hypothesis.update_posterior!(evidence_strength: 1.0, supporting: true) }
|
|
76
|
+
expect(hypothesis.posterior).to be <= 1.0
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'does not update a confirmed hypothesis' do
|
|
80
|
+
hypothesis.confirm!
|
|
81
|
+
prior_posterior = hypothesis.posterior
|
|
82
|
+
hypothesis.update_posterior!(evidence_strength: 1.0, supporting: false)
|
|
83
|
+
expect(hypothesis.posterior).to eq(prior_posterior)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'does not update a disconfirmed hypothesis' do
|
|
87
|
+
hypothesis.disconfirm!
|
|
88
|
+
prior_posterior = hypothesis.posterior
|
|
89
|
+
hypothesis.update_posterior!(evidence_strength: 1.0, supporting: true)
|
|
90
|
+
expect(hypothesis.posterior).to eq(prior_posterior)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'clamps evidence_strength above 1.0' do
|
|
94
|
+
hypothesis.update_posterior!(evidence_strength: 5.0, supporting: true)
|
|
95
|
+
expect(hypothesis.posterior).to be <= 1.0
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'rounds posterior to 10 decimal places' do
|
|
99
|
+
hypothesis.update_posterior!(evidence_strength: 0.7, supporting: true)
|
|
100
|
+
expect(hypothesis.posterior.to_s.split('.').last.length).to be <= 10
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe '#confirm!' do
|
|
105
|
+
it 'sets status to :confirmed' do
|
|
106
|
+
hypothesis.confirm!
|
|
107
|
+
expect(hypothesis.status).to eq(:confirmed)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'raises posterior to at least CONFIRMATION_THRESHOLD' do
|
|
111
|
+
h = described_class.new(description: 'near confirm', prior: 0.75)
|
|
112
|
+
h.confirm!
|
|
113
|
+
expect(h.posterior).to be >= Legion::Extensions::Agentic::Inference::HypothesisTesting::Helpers::Constants::CONFIRMATION_THRESHOLD
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe '#disconfirm!' do
|
|
118
|
+
it 'sets status to :disconfirmed' do
|
|
119
|
+
hypothesis.disconfirm!
|
|
120
|
+
expect(hypothesis.status).to eq(:disconfirmed)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'lowers posterior to at most DISCONFIRMATION_THRESHOLD' do
|
|
124
|
+
h = described_class.new(description: 'near disconfirm', prior: 0.25)
|
|
125
|
+
h.disconfirm!
|
|
126
|
+
expect(h.posterior).to be <= Legion::Extensions::Agentic::Inference::HypothesisTesting::Helpers::Constants::DISCONFIRMATION_THRESHOLD
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
describe '#confidence_label' do
|
|
131
|
+
it 'returns certain for posterior >= 0.9' do
|
|
132
|
+
h = described_class.new(description: 'certain', prior: 0.95)
|
|
133
|
+
expect(h.confidence_label).to eq('certain')
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it 'returns confident for posterior in [0.7, 0.9)' do
|
|
137
|
+
h = described_class.new(description: 'confident', prior: 0.8)
|
|
138
|
+
expect(h.confidence_label).to eq('confident')
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'returns leaning for posterior in [0.5, 0.7)' do
|
|
142
|
+
h = described_class.new(description: 'leaning', prior: 0.6)
|
|
143
|
+
expect(h.confidence_label).to eq('leaning')
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it 'returns uncertain for posterior in [0.3, 0.5)' do
|
|
147
|
+
h = described_class.new(description: 'uncertain', prior: 0.4)
|
|
148
|
+
expect(h.confidence_label).to eq('uncertain')
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it 'returns agnostic for posterior in [0.0, 0.3)' do
|
|
152
|
+
h = described_class.new(description: 'agnostic', prior: 0.1)
|
|
153
|
+
expect(h.confidence_label).to eq('agnostic')
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
describe '#to_h' do
|
|
158
|
+
it 'returns a hash with all required keys' do
|
|
159
|
+
result = hypothesis.to_h
|
|
160
|
+
expect(result.keys).to include(:id, :description, :domain, :prior, :posterior,
|
|
161
|
+
:evidence_count, :status, :confidence_label, :created_at)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'returns correct id' do
|
|
165
|
+
expect(hypothesis.to_h[:id]).to eq(hypothesis.id)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it 'returns correct status' do
|
|
169
|
+
expect(hypothesis.to_h[:status]).to eq(:proposed)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/hypothesis_testing/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::HypothesisTesting::Client do
|
|
6
|
+
it 'responds to all runner methods' do
|
|
7
|
+
client = described_class.new
|
|
8
|
+
expect(client).to respond_to(:propose_hypothesis)
|
|
9
|
+
expect(client).to respond_to(:test_hypothesis)
|
|
10
|
+
expect(client).to respond_to(:evaluate_hypothesis)
|
|
11
|
+
expect(client).to respond_to(:competing_hypotheses)
|
|
12
|
+
expect(client).to respond_to(:most_confident_hypotheses)
|
|
13
|
+
expect(client).to respond_to(:hypothesis_report)
|
|
14
|
+
expect(client).to respond_to(:get_hypothesis)
|
|
15
|
+
end
|
|
16
|
+
end
|