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,183 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::FreeEnergy::Helpers::Belief do
|
|
4
|
+
subject(:belief) do
|
|
5
|
+
described_class.new(
|
|
6
|
+
id: :belief_one,
|
|
7
|
+
content: 'weather model',
|
|
8
|
+
domain: :environment,
|
|
9
|
+
prediction: { temperature: 0.7, humidity: 0.5 },
|
|
10
|
+
precision: 0.6
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe '#initialize' do
|
|
15
|
+
it 'sets id' do
|
|
16
|
+
expect(belief.id).to eq(:belief_one)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'sets content' do
|
|
20
|
+
expect(belief.content).to eq('weather model')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'sets domain' do
|
|
24
|
+
expect(belief.domain).to eq(:environment)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'sets prediction' do
|
|
28
|
+
expect(belief.prediction).to eq({ temperature: 0.7, humidity: 0.5 })
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'sets precision' do
|
|
32
|
+
expect(belief.precision).to eq(0.6)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'clamps precision to ceiling' do
|
|
36
|
+
b = described_class.new(id: :x, content: 'test', precision: 1.5)
|
|
37
|
+
expect(b.precision).to eq(Legion::Extensions::Agentic::Inference::FreeEnergy::Helpers::Constants::PRECISION_CEILING)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'clamps precision to floor' do
|
|
41
|
+
b = described_class.new(id: :x, content: 'test', precision: -0.5)
|
|
42
|
+
expect(b.precision).to eq(Legion::Extensions::Agentic::Inference::FreeEnergy::Helpers::Constants::PRECISION_FLOOR)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'starts with zero prediction error' do
|
|
46
|
+
expect(belief.prediction_error).to eq(0.0)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'starts with nil last_observation' do
|
|
50
|
+
expect(belief.last_observation).to be_nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'is not surprising initially' do
|
|
54
|
+
expect(belief.surprising?).to be false
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe '#observe' do
|
|
59
|
+
it 'sets last_observation' do
|
|
60
|
+
belief.observe(observation: { temperature: 0.7, humidity: 0.5 })
|
|
61
|
+
expect(belief.last_observation).to eq({ temperature: 0.7, humidity: 0.5 })
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'computes low error for matching observation' do
|
|
65
|
+
belief.observe(observation: { temperature: 0.7, humidity: 0.5 })
|
|
66
|
+
expect(belief.prediction_error).to eq(0.0)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'computes high error for divergent observation' do
|
|
70
|
+
belief.observe(observation: { temperature: 0.0, humidity: 0.0 })
|
|
71
|
+
expect(belief.prediction_error).to be > 0.3
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'updates precision upward on low error' do
|
|
75
|
+
original = belief.precision
|
|
76
|
+
belief.observe(observation: { temperature: 0.7, humidity: 0.5 })
|
|
77
|
+
expect(belief.precision).to be > original
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'updates precision downward on high error' do
|
|
81
|
+
original = belief.precision
|
|
82
|
+
belief.observe(observation: { temperature: 0.0, humidity: 0.0 })
|
|
83
|
+
expect(belief.precision).to be < original
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'returns self for chaining' do
|
|
87
|
+
expect(belief.observe(observation: {})).to be(belief)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'updates updated_at' do
|
|
91
|
+
before = belief.updated_at
|
|
92
|
+
sleep 0.01
|
|
93
|
+
belief.observe(observation: { temperature: 0.5 })
|
|
94
|
+
expect(belief.updated_at).to be > before
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe '#free_energy' do
|
|
99
|
+
it 'returns zero when no observation made' do
|
|
100
|
+
expect(belief.free_energy).to eq(0.0)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it 'returns precision-weighted prediction error' do
|
|
104
|
+
belief.observe(observation: { temperature: 0.0, humidity: 0.0 })
|
|
105
|
+
expect(belief.free_energy).to be > 0.0
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'is higher when precision is higher' do
|
|
109
|
+
high_prec = described_class.new(id: :hp, content: 'test', prediction: { v: 0.9 }, precision: 0.9)
|
|
110
|
+
low_prec = described_class.new(id: :lp, content: 'test', prediction: { v: 0.9 }, precision: 0.2)
|
|
111
|
+
|
|
112
|
+
high_prec.observe(observation: { v: 0.0 })
|
|
113
|
+
low_prec.observe(observation: { v: 0.0 })
|
|
114
|
+
|
|
115
|
+
expect(high_prec.free_energy).to be > low_prec.free_energy
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe '#surprise_label' do
|
|
120
|
+
it 'returns :trivial when no error' do
|
|
121
|
+
expect(belief.surprise_label).to eq(:trivial)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it 'returns non-trivial label for larger errors' do
|
|
125
|
+
belief.observe(observation: { temperature: 0.0, humidity: 0.0 })
|
|
126
|
+
expect(belief.surprise_label).not_to eq(:trivial)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
describe '#revise_prediction' do
|
|
131
|
+
it 'moves prediction toward observation' do
|
|
132
|
+
belief.observe(observation: { temperature: 1.0, humidity: 0.5 })
|
|
133
|
+
belief.revise_prediction(observation: { temperature: 1.0 })
|
|
134
|
+
expect(belief.prediction[:temperature]).to be > 0.7
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'preserves unobserved prediction keys' do
|
|
138
|
+
belief.revise_prediction(observation: { temperature: 1.0 })
|
|
139
|
+
expect(belief.prediction[:humidity]).to eq(0.5)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'replaces non-numeric values' do
|
|
143
|
+
b = described_class.new(id: :x, content: 'test', prediction: { color: :red })
|
|
144
|
+
b.revise_prediction(observation: { color: :blue })
|
|
145
|
+
expect(b.prediction[:color]).to eq(:blue)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe '#stale?' do
|
|
150
|
+
it 'is not stale immediately' do
|
|
151
|
+
expect(belief.stale?).to be false
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it 'is stale after threshold' do
|
|
155
|
+
future = Time.now.utc + 200
|
|
156
|
+
expect(belief.stale?(now: future)).to be true
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
describe '#decay_precision' do
|
|
161
|
+
it 'moves precision toward default' do
|
|
162
|
+
belief.decay_precision
|
|
163
|
+
expect(belief.precision).to be < 0.6
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it 'moves low precision toward default' do
|
|
167
|
+
b = described_class.new(id: :x, content: 'test', precision: 0.2)
|
|
168
|
+
b.decay_precision
|
|
169
|
+
expect(b.precision).to be > 0.2
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
describe '#to_h' do
|
|
174
|
+
it 'returns a hash with expected keys' do
|
|
175
|
+
h = belief.to_h
|
|
176
|
+
expect(h).to include(
|
|
177
|
+
:id, :domain, :content, :prediction, :last_observation,
|
|
178
|
+
:prediction_error, :precision, :free_energy, :surprise_label,
|
|
179
|
+
:surprising, :created_at, :updated_at
|
|
180
|
+
)
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::FreeEnergy::Helpers::FreeEnergyEngine do
|
|
4
|
+
subject(:engine) { described_class.new }
|
|
5
|
+
|
|
6
|
+
let(:constants) { Legion::Extensions::Agentic::Inference::FreeEnergy::Helpers::Constants }
|
|
7
|
+
|
|
8
|
+
describe '#initialize' do
|
|
9
|
+
it 'starts with empty beliefs' do
|
|
10
|
+
expect(engine.beliefs).to be_empty
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'starts with empty history' do
|
|
14
|
+
expect(engine.history).to be_empty
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe '#add_belief' do
|
|
19
|
+
it 'creates a belief' do
|
|
20
|
+
belief = engine.add_belief(content: 'test model', domain: :test)
|
|
21
|
+
expect(belief).to be_a(Legion::Extensions::Agentic::Inference::FreeEnergy::Helpers::Belief)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'assigns sequential IDs' do
|
|
25
|
+
first = engine.add_belief(content: 'first')
|
|
26
|
+
second = engine.add_belief(content: 'second')
|
|
27
|
+
expect(first.id).to be_a(Symbol)
|
|
28
|
+
expect(second.id).not_to eq(first.id)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'stores the belief' do
|
|
32
|
+
belief = engine.add_belief(content: 'stored')
|
|
33
|
+
expect(engine.beliefs[belief.id]).to be(belief)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'respects MAX_BELIEFS limit' do
|
|
37
|
+
constants::MAX_BELIEFS.times { |i| engine.add_belief(content: "belief #{i}") }
|
|
38
|
+
expect(engine.add_belief(content: 'overflow')).to be_nil
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'records history event' do
|
|
42
|
+
engine.add_belief(content: 'tracked')
|
|
43
|
+
expect(engine.history.last[:type]).to eq(:add_belief)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe '#observe' do
|
|
48
|
+
let!(:belief) { engine.add_belief(content: 'weather', prediction: { temp: 0.7 }) }
|
|
49
|
+
|
|
50
|
+
it 'updates the belief with observation' do
|
|
51
|
+
result = engine.observe(belief_id: belief.id, observation: { temp: 0.7 })
|
|
52
|
+
expect(result.prediction_error).to eq(0.0)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'returns nil for unknown belief' do
|
|
56
|
+
expect(engine.observe(belief_id: :nonexistent, observation: {})).to be_nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'records history event' do
|
|
60
|
+
engine.observe(belief_id: belief.id, observation: { temp: 0.5 })
|
|
61
|
+
expect(engine.history.last[:type]).to eq(:observe)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe '#minimize_perceptual' do
|
|
66
|
+
let!(:belief) { engine.add_belief(content: 'model', prediction: { v: 0.3 }) }
|
|
67
|
+
|
|
68
|
+
it 'revises prediction toward observation' do
|
|
69
|
+
engine.observe(belief_id: belief.id, observation: { v: 0.9 })
|
|
70
|
+
engine.minimize_perceptual(belief_id: belief.id)
|
|
71
|
+
expect(belief.prediction[:v]).to be > 0.3
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'returns nil for unknown belief' do
|
|
75
|
+
expect(engine.minimize_perceptual(belief_id: :nonexistent)).to be_nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'returns nil when no observation exists' do
|
|
79
|
+
expect(engine.minimize_perceptual(belief_id: belief.id)).to be_nil
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe '#minimize_active' do
|
|
84
|
+
let!(:belief) { engine.add_belief(content: 'model', prediction: { v: 0.8 }) }
|
|
85
|
+
|
|
86
|
+
it 'returns an action plan' do
|
|
87
|
+
action = engine.minimize_active(belief_id: belief.id)
|
|
88
|
+
expect(action[:type]).to eq(:active_inference)
|
|
89
|
+
expect(action[:target]).to eq(belief.prediction)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'returns nil for unknown belief' do
|
|
93
|
+
expect(engine.minimize_active(belief_id: :nonexistent)).to be_nil
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
describe '#minimize' do
|
|
98
|
+
let!(:belief) { engine.add_belief(content: 'model', prediction: { v: 0.5 }) }
|
|
99
|
+
|
|
100
|
+
it 'delegates to perceptual mode' do
|
|
101
|
+
engine.observe(belief_id: belief.id, observation: { v: 0.9 })
|
|
102
|
+
result = engine.minimize(belief_id: belief.id, mode: :perceptual)
|
|
103
|
+
expect(result).to be_a(Legion::Extensions::Agentic::Inference::FreeEnergy::Helpers::Belief)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it 'delegates to active mode' do
|
|
107
|
+
result = engine.minimize(belief_id: belief.id, mode: :active)
|
|
108
|
+
expect(result[:type]).to eq(:active_inference)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe '#total_free_energy' do
|
|
113
|
+
it 'returns zero with no beliefs' do
|
|
114
|
+
expect(engine.total_free_energy).to eq(0.0)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it 'returns average free energy across beliefs' do
|
|
118
|
+
b = engine.add_belief(content: 'test', prediction: { v: 0.9 })
|
|
119
|
+
engine.observe(belief_id: b.id, observation: { v: 0.0 })
|
|
120
|
+
expect(engine.total_free_energy).to be > 0.0
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
describe '#surprise_level' do
|
|
125
|
+
it 'returns :trivial with no beliefs' do
|
|
126
|
+
expect(engine.surprise_level).to eq(:trivial)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it 'reflects high surprise when predictions fail' do
|
|
130
|
+
b = engine.add_belief(content: 'test', prediction: { v: 1.0 }, precision: 0.9)
|
|
131
|
+
engine.observe(belief_id: b.id, observation: { v: 0.0 })
|
|
132
|
+
expect(engine.surprise_level).not_to eq(:trivial)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe '#high_surprise_beliefs' do
|
|
137
|
+
it 'returns empty when no surprises' do
|
|
138
|
+
engine.add_belief(content: 'calm')
|
|
139
|
+
expect(engine.high_surprise_beliefs).to be_empty
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'returns surprised beliefs' do
|
|
143
|
+
b = engine.add_belief(content: 'shock', prediction: { v: 1.0 }, precision: 0.9)
|
|
144
|
+
engine.observe(belief_id: b.id, observation: { v: 0.0 })
|
|
145
|
+
expect(engine.high_surprise_beliefs.size).to eq(1)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe '#domain_free_energy' do
|
|
150
|
+
it 'returns zero for empty domain' do
|
|
151
|
+
expect(engine.domain_free_energy(domain: :test)).to eq(0.0)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it 'computes free energy for domain only' do
|
|
155
|
+
b_env = engine.add_belief(content: 'env', domain: :environment, prediction: { v: 1.0 }, precision: 0.9)
|
|
156
|
+
engine.add_belief(content: 'social', domain: :social, prediction: { v: 1.0 }, precision: 0.9)
|
|
157
|
+
engine.observe(belief_id: b_env.id, observation: { v: 0.0 })
|
|
158
|
+
expect(engine.domain_free_energy(domain: :environment)).to be > 0.0
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
describe '#most_surprising' do
|
|
163
|
+
it 'returns beliefs sorted by free energy descending' do
|
|
164
|
+
high = engine.add_belief(content: 'a', prediction: { v: 1.0 }, precision: 0.9)
|
|
165
|
+
low = engine.add_belief(content: 'b', prediction: { v: 0.5 }, precision: 0.3)
|
|
166
|
+
engine.observe(belief_id: high.id, observation: { v: 0.0 })
|
|
167
|
+
engine.observe(belief_id: low.id, observation: { v: 0.0 })
|
|
168
|
+
|
|
169
|
+
result = engine.most_surprising(limit: 2)
|
|
170
|
+
expect(result.first[:free_energy]).to be >= result.last[:free_energy]
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
describe '#most_precise' do
|
|
175
|
+
it 'returns beliefs sorted by precision descending' do
|
|
176
|
+
engine.add_belief(content: 'low', precision: 0.2)
|
|
177
|
+
engine.add_belief(content: 'high', precision: 0.8)
|
|
178
|
+
|
|
179
|
+
result = engine.most_precise(limit: 2)
|
|
180
|
+
expect(result.first[:precision]).to be >= result.last[:precision]
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
describe '#decay_stale' do
|
|
185
|
+
it 'decays precision of stale beliefs' do
|
|
186
|
+
b = engine.add_belief(content: 'old', precision: 0.8)
|
|
187
|
+
allow(Time).to receive(:now).and_return(Time.now.utc + 200)
|
|
188
|
+
original = b.precision
|
|
189
|
+
engine.decay_stale
|
|
190
|
+
expect(b.precision).not_to eq(original)
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
describe '#remove_belief' do
|
|
195
|
+
it 'removes a belief' do
|
|
196
|
+
b = engine.add_belief(content: 'temporary')
|
|
197
|
+
engine.remove_belief(belief_id: b.id)
|
|
198
|
+
expect(engine.beliefs).to be_empty
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
describe '#to_h' do
|
|
203
|
+
it 'returns stats hash' do
|
|
204
|
+
h = engine.to_h
|
|
205
|
+
expect(h).to include(
|
|
206
|
+
:belief_count, :total_free_energy, :surprise_level,
|
|
207
|
+
:high_surprise_count, :mean_precision, :history_size
|
|
208
|
+
)
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::FreeEnergy::Runners::FreeEnergy do
|
|
4
|
+
let(:runner_host) do
|
|
5
|
+
Object.new.tap { |o| o.extend(described_class) }
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
describe '#add_generative_belief' do
|
|
9
|
+
it 'creates a belief successfully' do
|
|
10
|
+
result = runner_host.add_generative_belief(content: 'test model', domain: :test)
|
|
11
|
+
expect(result[:success]).to be true
|
|
12
|
+
expect(result[:belief_id]).to be_a(Symbol)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'accepts prediction and precision' do
|
|
16
|
+
result = runner_host.add_generative_belief(
|
|
17
|
+
content: 'weather', prediction: { temp: 0.7 }, precision: 0.8
|
|
18
|
+
)
|
|
19
|
+
expect(result[:precision]).to eq(0.8)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe '#observe_outcome' do
|
|
24
|
+
let!(:belief_id) do
|
|
25
|
+
runner_host.add_generative_belief(content: 'model', prediction: { v: 0.7 })[:belief_id]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'returns prediction error' do
|
|
29
|
+
result = runner_host.observe_outcome(belief_id: belief_id, observation: { v: 0.7 })
|
|
30
|
+
expect(result[:success]).to be true
|
|
31
|
+
expect(result[:prediction_error]).to eq(0.0)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'detects surprise' do
|
|
35
|
+
result = runner_host.observe_outcome(belief_id: belief_id, observation: { v: 0.0 })
|
|
36
|
+
expect(result[:prediction_error]).to be > 0.0
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'returns failure for unknown belief' do
|
|
40
|
+
result = runner_host.observe_outcome(belief_id: :nonexistent, observation: {})
|
|
41
|
+
expect(result[:success]).to be false
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe '#minimize_free_energy' do
|
|
46
|
+
let!(:belief_id) do
|
|
47
|
+
runner_host.add_generative_belief(content: 'model', prediction: { v: 0.3 })[:belief_id]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'performs perceptual inference' do
|
|
51
|
+
runner_host.observe_outcome(belief_id: belief_id, observation: { v: 0.9 })
|
|
52
|
+
result = runner_host.minimize_free_energy(belief_id: belief_id, mode: :perceptual)
|
|
53
|
+
expect(result[:success]).to be true
|
|
54
|
+
expect(result[:mode]).to eq(:perceptual)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'performs active inference' do
|
|
58
|
+
result = runner_host.minimize_free_energy(belief_id: belief_id, mode: :active)
|
|
59
|
+
expect(result[:success]).to be true
|
|
60
|
+
expect(result[:mode]).to eq(:active)
|
|
61
|
+
expect(result[:type]).to eq(:active_inference)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'returns failure for unknown belief' do
|
|
65
|
+
result = runner_host.minimize_free_energy(belief_id: :nonexistent)
|
|
66
|
+
expect(result[:success]).to be false
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe '#compute_free_energy' do
|
|
71
|
+
it 'returns total free energy' do
|
|
72
|
+
result = runner_host.compute_free_energy
|
|
73
|
+
expect(result[:success]).to be true
|
|
74
|
+
expect(result).to include(:total_free_energy, :surprise_level, :high_surprise_count)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe '#surprise_assessment' do
|
|
79
|
+
it 'returns surprise assessment' do
|
|
80
|
+
result = runner_host.surprise_assessment
|
|
81
|
+
expect(result[:success]).to be true
|
|
82
|
+
expect(result).to include(:surprise_level, :most_surprising, :most_precise)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe '#high_surprise_beliefs' do
|
|
87
|
+
it 'returns empty list when calm' do
|
|
88
|
+
result = runner_host.high_surprise_beliefs
|
|
89
|
+
expect(result[:success]).to be true
|
|
90
|
+
expect(result[:count]).to eq(0)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe '#domain_free_energy' do
|
|
95
|
+
it 'returns domain-specific free energy' do
|
|
96
|
+
runner_host.add_generative_belief(content: 'env model', domain: :environment)
|
|
97
|
+
result = runner_host.domain_free_energy(domain: :environment)
|
|
98
|
+
expect(result[:success]).to be true
|
|
99
|
+
expect(result[:domain]).to eq(:environment)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
describe '#update_free_energy' do
|
|
104
|
+
it 'decays stale beliefs and returns stats' do
|
|
105
|
+
result = runner_host.update_free_energy
|
|
106
|
+
expect(result[:success]).to be true
|
|
107
|
+
expect(result).to include(:belief_count, :total_free_energy)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
describe '#free_energy_stats' do
|
|
112
|
+
it 'returns engine statistics' do
|
|
113
|
+
result = runner_host.free_energy_stats
|
|
114
|
+
expect(result[:success]).to be true
|
|
115
|
+
expect(result).to include(:belief_count, :surprise_level)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/gravity/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Gravity::Client do
|
|
6
|
+
it 'responds to all runner methods' do
|
|
7
|
+
client = described_class.new
|
|
8
|
+
expect(client).to respond_to(:create_attractor)
|
|
9
|
+
expect(client).to respond_to(:add_thought)
|
|
10
|
+
expect(client).to respond_to(:tick_gravity)
|
|
11
|
+
expect(client).to respond_to(:accrete)
|
|
12
|
+
expect(client).to respond_to(:erode)
|
|
13
|
+
expect(client).to respond_to(:strongest_attractors)
|
|
14
|
+
expect(client).to respond_to(:thought_distribution)
|
|
15
|
+
expect(client).to respond_to(:cognitive_density_map)
|
|
16
|
+
expect(client).to respond_to(:gravity_report)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'initializes with a fresh gravity engine' do
|
|
20
|
+
client = described_class.new
|
|
21
|
+
result = client.gravity_report
|
|
22
|
+
expect(result[:report][:total_attractors]).to eq(0)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Gravity::Helpers::Attractor do
|
|
4
|
+
subject(:attractor) { described_class.new(content: 'test thought', domain: :curiosity) }
|
|
5
|
+
|
|
6
|
+
describe '#initialize' do
|
|
7
|
+
it 'assigns a uuid id' do
|
|
8
|
+
expect(attractor.id).to match(/\A[0-9a-f-]{36}\z/)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'sets content' do
|
|
12
|
+
expect(attractor.content).to eq('test thought')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'sets domain' do
|
|
16
|
+
expect(attractor.domain).to eq(:curiosity)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'sets default mass' do
|
|
20
|
+
expect(attractor.mass).to eq(1.0)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'accepts custom mass' do
|
|
24
|
+
a = described_class.new(content: 'x', mass: 2.5)
|
|
25
|
+
expect(a.mass).to eq(2.5)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'sets created_at' do
|
|
29
|
+
expect(attractor.created_at).to be_a(Time)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'initializes reinforcement_count to 0' do
|
|
33
|
+
expect(attractor.reinforcement_count).to eq(0)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe '#accrete!' do
|
|
38
|
+
it 'increases mass by default accretion amount' do
|
|
39
|
+
attractor.accrete!
|
|
40
|
+
expect(attractor.mass).to be_within(0.001).of(1.15)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'increases mass by custom amount' do
|
|
44
|
+
attractor.accrete!(0.5)
|
|
45
|
+
expect(attractor.mass).to be_within(0.001).of(1.5)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'increments reinforcement_count' do
|
|
49
|
+
attractor.accrete!
|
|
50
|
+
expect(attractor.reinforcement_count).to eq(1)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'returns self for chaining' do
|
|
54
|
+
expect(attractor.accrete!).to eq(attractor)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe '#erode!' do
|
|
59
|
+
it 'decreases mass by default erosion amount' do
|
|
60
|
+
attractor.erode!
|
|
61
|
+
expect(attractor.mass).to be_within(0.001).of(0.95)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'does not go below zero' do
|
|
65
|
+
a = described_class.new(content: 'x', mass: 0.03)
|
|
66
|
+
a.erode!(0.1)
|
|
67
|
+
expect(a.mass).to eq(0.0)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'returns self for chaining' do
|
|
71
|
+
expect(attractor.erode!).to eq(attractor)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe '#pull_strength_at' do
|
|
76
|
+
it 'returns positive pull for distance within pull_radius' do
|
|
77
|
+
strength = attractor.pull_strength_at(distance: 0.5)
|
|
78
|
+
expect(strength).to be > 0
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'returns zero for distance beyond pull_radius' do
|
|
82
|
+
strength = attractor.pull_strength_at(distance: 2.0)
|
|
83
|
+
expect(strength).to eq(0.0)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'returns zero for zero distance' do
|
|
87
|
+
strength = attractor.pull_strength_at(distance: 0)
|
|
88
|
+
expect(strength).to eq(0.0)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'returns stronger pull for heavier attractors' do
|
|
92
|
+
heavy = described_class.new(content: 'heavy', mass: 3.0)
|
|
93
|
+
light = described_class.new(content: 'light', mass: 0.5)
|
|
94
|
+
expect(heavy.pull_strength_at(distance: 0.5)).to be > light.pull_strength_at(distance: 0.5)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'returns stronger pull for closer distance' do
|
|
98
|
+
close_pull = attractor.pull_strength_at(distance: 0.3)
|
|
99
|
+
far_pull = attractor.pull_strength_at(distance: 0.8)
|
|
100
|
+
expect(close_pull).to be > far_pull
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe '#collapsed?' do
|
|
105
|
+
it 'returns false for normal mass' do
|
|
106
|
+
expect(attractor.collapsed?).to be false
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it 'returns true when mass is below collapse threshold' do
|
|
110
|
+
a = described_class.new(content: 'x', mass: 0.05)
|
|
111
|
+
expect(a.collapsed?).to be true
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe '#supermassive?' do
|
|
116
|
+
it 'returns false for normal mass' do
|
|
117
|
+
expect(attractor.supermassive?).to be false
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'returns true for mass at or above supermassive threshold' do
|
|
121
|
+
a = described_class.new(content: 'x', mass: 3.0)
|
|
122
|
+
expect(a.supermassive?).to be true
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
describe '#mass_label' do
|
|
127
|
+
it 'returns a symbol label' do
|
|
128
|
+
expect(attractor.mass_label).to be_a(Symbol)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it 'returns :nascent for default mass' do
|
|
132
|
+
expect(attractor.mass_label).to eq(:nascent)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe '#to_h' do
|
|
137
|
+
it 'returns a hash with expected keys' do
|
|
138
|
+
h = attractor.to_h
|
|
139
|
+
expect(h).to include(:id, :content, :domain, :mass, :pull_radius, :decay_rate,
|
|
140
|
+
:reinforcement_count, :collapsed, :supermassive, :mass_label, :created_at)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|