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,206 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::PredictiveProcessing::Helpers::PredictiveProcessor do
|
|
4
|
+
subject(:processor) { described_class.new }
|
|
5
|
+
|
|
6
|
+
describe '#add_model' do
|
|
7
|
+
it 'adds a new model for a domain' do
|
|
8
|
+
result = processor.add_model(domain: :perception)
|
|
9
|
+
expect(result[:added]).to be true
|
|
10
|
+
expect(result[:domain]).to eq(:perception)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'returns model_id on success' do
|
|
14
|
+
result = processor.add_model(domain: :cognition)
|
|
15
|
+
expect(result[:model_id]).to match(/\A[0-9a-f-]{36}\z/)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'rejects duplicate domains' do
|
|
19
|
+
processor.add_model(domain: :dup)
|
|
20
|
+
result = processor.add_model(domain: :dup)
|
|
21
|
+
expect(result[:added]).to be false
|
|
22
|
+
expect(result[:reason]).to eq(:already_exists)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'rejects when at model limit' do
|
|
26
|
+
20.times { |i| processor.add_model(domain: :"domain_#{i}") }
|
|
27
|
+
result = processor.add_model(domain: :overflow)
|
|
28
|
+
expect(result[:added]).to be false
|
|
29
|
+
expect(result[:reason]).to eq(:limit_reached)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '#predict' do
|
|
34
|
+
it 'returns a prediction hash for a known domain' do
|
|
35
|
+
processor.add_model(domain: :action)
|
|
36
|
+
result = processor.predict(domain: :action, context: { urgency: 0.8 })
|
|
37
|
+
expect(result[:expected_value]).to be_a(Float)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'auto-creates model for unknown domain (within limit)' do
|
|
41
|
+
result = processor.predict(domain: :new_domain, context: {})
|
|
42
|
+
expect(result[:expected_value]).to be_a(Float)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'includes domain in prediction' do
|
|
46
|
+
result = processor.predict(domain: :emotion, context: {})
|
|
47
|
+
expect(result[:domain]).to eq(:emotion)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe '#observe' do
|
|
52
|
+
before { processor.add_model(domain: :vision) }
|
|
53
|
+
|
|
54
|
+
it 'returns observed: true for known domain' do
|
|
55
|
+
result = processor.observe(domain: :vision, actual: 0.7, predicted: 0.5)
|
|
56
|
+
expect(result[:observed]).to be true
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'returns prediction_error' do
|
|
60
|
+
result = processor.observe(domain: :vision, actual: 0.8, predicted: 0.5)
|
|
61
|
+
expect(result[:prediction_error]).to be_a(Float)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'returns inference_mode' do
|
|
65
|
+
result = processor.observe(domain: :vision, actual: 0.8, predicted: 0.5)
|
|
66
|
+
expect(described_class::INFERENCE_MODES).to include(result[:inference_mode])
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'returns observed: false for unknown domain' do
|
|
70
|
+
result = processor.observe(domain: :unknown, actual: 0.5, predicted: 0.5)
|
|
71
|
+
expect(result[:observed]).to be false
|
|
72
|
+
expect(result[:reason]).to eq(:domain_not_found)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'returns free_energy after observation' do
|
|
76
|
+
result = processor.observe(domain: :vision, actual: 1.0, predicted: 0.0)
|
|
77
|
+
expect(result[:free_energy]).to be_a(Float)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe '#inference_mode' do
|
|
82
|
+
it 'returns :perceptual for unknown domain' do
|
|
83
|
+
expect(processor.inference_mode(:nonexistent)).to eq(:perceptual)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'returns a valid inference mode for known domain' do
|
|
87
|
+
processor.add_model(domain: :memory)
|
|
88
|
+
mode = processor.inference_mode(:memory)
|
|
89
|
+
expect(described_class::INFERENCE_MODES).to include(mode)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'returns :active or :hybrid when free energy is high' do
|
|
93
|
+
processor.add_model(domain: :surprise)
|
|
94
|
+
5.times { processor.observe(domain: :surprise, actual: 1.0, predicted: 0.0) }
|
|
95
|
+
mode = processor.inference_mode(:surprise)
|
|
96
|
+
expect(%i[active hybrid]).to include(mode)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe '#free_energy_for' do
|
|
101
|
+
it 'returns nil for unknown domain' do
|
|
102
|
+
expect(processor.free_energy_for(:unknown)).to be_nil
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'returns a float for known domain' do
|
|
106
|
+
processor.add_model(domain: :planning)
|
|
107
|
+
expect(processor.free_energy_for(:planning)).to be_a(Float)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
describe '#global_free_energy' do
|
|
112
|
+
it 'returns 0.0 with no models' do
|
|
113
|
+
expect(processor.global_free_energy).to eq(0.0)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'returns average free energy across models' do
|
|
117
|
+
processor.add_model(domain: :d1)
|
|
118
|
+
processor.add_model(domain: :d2)
|
|
119
|
+
expect(processor.global_free_energy).to be_a(Float)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
describe '#precision_weight' do
|
|
124
|
+
it 'returns DEFAULT_PRECISION for unknown domain' do
|
|
125
|
+
expect(processor.precision_weight(:unknown)).to eq(described_class::DEFAULT_PRECISION)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it 'returns model precision for known domain' do
|
|
129
|
+
processor.add_model(domain: :known)
|
|
130
|
+
expect(processor.precision_weight(:known)).to be_a(Float)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
describe '#models_needing_update' do
|
|
135
|
+
it 'returns empty hash when all models are stable' do
|
|
136
|
+
expect(processor.models_needing_update).to be_empty
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it 'returns domains with high free energy' do
|
|
140
|
+
processor.add_model(domain: :erratic)
|
|
141
|
+
5.times { processor.observe(domain: :erratic, actual: 1.0, predicted: 0.0) }
|
|
142
|
+
needing = processor.models_needing_update
|
|
143
|
+
expect(needing).to have_key(:erratic)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
describe '#stable_models' do
|
|
148
|
+
it 'returns all models initially (all stable)' do
|
|
149
|
+
processor.add_model(domain: :calm)
|
|
150
|
+
expect(processor.stable_models).to have_key(:calm)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it 'excludes surprised models' do
|
|
154
|
+
processor.add_model(domain: :upset)
|
|
155
|
+
5.times { processor.observe(domain: :upset, actual: 1.0, predicted: 0.0) }
|
|
156
|
+
expect(processor.stable_models).not_to have_key(:upset)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
describe '#active_inference_candidates' do
|
|
161
|
+
it 'returns empty array when all models have low free energy' do
|
|
162
|
+
expect(processor.active_inference_candidates).to be_empty
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it 'returns domains exceeding active inference threshold' do
|
|
166
|
+
processor.add_model(domain: :high_fe)
|
|
167
|
+
5.times { processor.observe(domain: :high_fe, actual: 1.0, predicted: 0.0) }
|
|
168
|
+
expect(processor.active_inference_candidates).to include(:high_fe)
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
describe '#tick' do
|
|
173
|
+
it 'decays precision on all models' do
|
|
174
|
+
processor.add_model(domain: :tickable)
|
|
175
|
+
before = processor.models[:tickable].precision
|
|
176
|
+
processor.tick
|
|
177
|
+
expect(processor.models[:tickable].precision).to be < before
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'does not raise with no models' do
|
|
181
|
+
expect { processor.tick }.not_to raise_error
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
describe '#to_h' do
|
|
186
|
+
it 'includes model_count' do
|
|
187
|
+
processor.add_model(domain: :counted)
|
|
188
|
+
expect(processor.to_h[:model_count]).to eq(1)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it 'includes global_free_energy' do
|
|
192
|
+
expect(processor.to_h[:global_free_energy]).to be_a(Float)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
it 'includes models hash' do
|
|
196
|
+
processor.add_model(domain: :listed)
|
|
197
|
+
expect(processor.to_h[:models]).to have_key(:listed)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it 'includes counts for needing update and stable' do
|
|
201
|
+
h = processor.to_h
|
|
202
|
+
expect(h).to have_key(:models_needing_update)
|
|
203
|
+
expect(h).to have_key(:stable_model_count)
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::PredictiveProcessing::Runners::PredictiveProcessing do
|
|
4
|
+
let(:client) { Legion::Extensions::Agentic::Inference::PredictiveProcessing::Client.new }
|
|
5
|
+
|
|
6
|
+
describe '#add_generative_model' do
|
|
7
|
+
it 'adds a model for a valid domain' do
|
|
8
|
+
result = client.add_generative_model(domain: :perception)
|
|
9
|
+
expect(result[:added]).to be true
|
|
10
|
+
expect(result[:domain]).to eq(:perception)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'returns error for nil domain' do
|
|
14
|
+
result = client.add_generative_model(domain: nil)
|
|
15
|
+
expect(result[:added]).to be false
|
|
16
|
+
expect(result[:reason]).to eq(:missing_domain)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'returns error for empty string domain' do
|
|
20
|
+
result = client.add_generative_model(domain: '')
|
|
21
|
+
expect(result[:added]).to be false
|
|
22
|
+
expect(result[:reason]).to eq(:missing_domain)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'returns model_id on success' do
|
|
26
|
+
result = client.add_generative_model(domain: :with_id)
|
|
27
|
+
expect(result[:model_id]).to match(/\A[0-9a-f-]{36}\z/)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'rejects duplicate domain' do
|
|
31
|
+
client.add_generative_model(domain: :dup)
|
|
32
|
+
result = client.add_generative_model(domain: :dup)
|
|
33
|
+
expect(result[:added]).to be false
|
|
34
|
+
expect(result[:reason]).to eq(:already_exists)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe '#predict_from_model' do
|
|
39
|
+
before { client.add_generative_model(domain: :action) }
|
|
40
|
+
|
|
41
|
+
it 'returns a prediction for known domain' do
|
|
42
|
+
result = client.predict_from_model(domain: :action, context: {})
|
|
43
|
+
expect(result[:predicted]).to be true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'includes domain in result' do
|
|
47
|
+
result = client.predict_from_model(domain: :action)
|
|
48
|
+
expect(result[:domain]).to eq(:action)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'includes prediction hash' do
|
|
52
|
+
result = client.predict_from_model(domain: :action, context: { val: 1 })
|
|
53
|
+
expect(result[:prediction]).to be_a(Hash)
|
|
54
|
+
expect(result[:prediction][:expected_value]).to be_a(Float)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'returns error for nil domain' do
|
|
58
|
+
result = client.predict_from_model(domain: nil)
|
|
59
|
+
expect(result[:predicted]).to be false
|
|
60
|
+
expect(result[:reason]).to eq(:missing_domain)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'auto-creates model for unknown domain' do
|
|
64
|
+
result = client.predict_from_model(domain: :auto_created, context: {})
|
|
65
|
+
expect(result[:predicted]).to be true
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe '#observe_outcome' do
|
|
70
|
+
before { client.add_generative_model(domain: :vision) }
|
|
71
|
+
|
|
72
|
+
it 'returns observed: true for known domain' do
|
|
73
|
+
result = client.observe_outcome(domain: :vision, actual: 0.7, predicted: 0.5)
|
|
74
|
+
expect(result[:observed]).to be true
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'includes inference_mode' do
|
|
78
|
+
result = client.observe_outcome(domain: :vision, actual: 0.6, predicted: 0.5)
|
|
79
|
+
expect(Legion::Extensions::Agentic::Inference::PredictiveProcessing::Helpers::Constants::INFERENCE_MODES)
|
|
80
|
+
.to include(result[:inference_mode])
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'returns error for nil domain' do
|
|
84
|
+
result = client.observe_outcome(domain: nil, actual: 0.5, predicted: 0.5)
|
|
85
|
+
expect(result[:observed]).to be false
|
|
86
|
+
expect(result[:reason]).to eq(:missing_domain)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it 'returns false for unknown domain' do
|
|
90
|
+
result = client.observe_outcome(domain: :unknown_x, actual: 0.5, predicted: 0.5)
|
|
91
|
+
expect(result[:observed]).to be false
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'includes free_energy in result' do
|
|
95
|
+
result = client.observe_outcome(domain: :vision, actual: 0.9, predicted: 0.1)
|
|
96
|
+
expect(result[:free_energy]).to be_a(Float)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe '#inference_mode' do
|
|
101
|
+
it 'returns mode for known domain' do
|
|
102
|
+
client.add_generative_model(domain: :motor)
|
|
103
|
+
result = client.inference_mode(domain: :motor)
|
|
104
|
+
expect(result[:domain]).to eq(:motor)
|
|
105
|
+
expect(Legion::Extensions::Agentic::Inference::PredictiveProcessing::Helpers::Constants::INFERENCE_MODES)
|
|
106
|
+
.to include(result[:mode])
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it 'returns error for nil domain' do
|
|
110
|
+
result = client.inference_mode(domain: nil)
|
|
111
|
+
expect(result[:mode]).to be_nil
|
|
112
|
+
expect(result[:reason]).to eq(:missing_domain)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'returns :perceptual for unknown domain' do
|
|
116
|
+
result = client.inference_mode(domain: :unregistered)
|
|
117
|
+
expect(result[:mode]).to eq(:perceptual)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
describe '#free_energy' do
|
|
122
|
+
it 'returns global free energy when no domain given' do
|
|
123
|
+
result = client.free_energy
|
|
124
|
+
expect(result).to have_key(:global_free_energy)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'returns domain free energy when domain given' do
|
|
128
|
+
client.add_generative_model(domain: :fe_domain)
|
|
129
|
+
result = client.free_energy(domain: :fe_domain)
|
|
130
|
+
expect(result[:domain]).to eq(:fe_domain)
|
|
131
|
+
expect(result[:free_energy]).to be_a(Float)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'returns not_found for unknown domain' do
|
|
135
|
+
result = client.free_energy(domain: :no_such)
|
|
136
|
+
expect(result[:reason]).to eq(:domain_not_found)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
describe '#models_needing_update' do
|
|
141
|
+
it 'returns count and models hash' do
|
|
142
|
+
result = client.models_needing_update
|
|
143
|
+
expect(result).to have_key(:count)
|
|
144
|
+
expect(result).to have_key(:models)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it 'returns 0 when no models exist' do
|
|
148
|
+
expect(client.models_needing_update[:count]).to eq(0)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it 'returns surprised models' do
|
|
152
|
+
client.add_generative_model(domain: :volatile)
|
|
153
|
+
5.times { client.observe_outcome(domain: :volatile, actual: 1.0, predicted: 0.0) }
|
|
154
|
+
result = client.models_needing_update
|
|
155
|
+
expect(result[:count]).to be >= 1
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
describe '#active_inference_candidates' do
|
|
160
|
+
it 'returns count and domains array' do
|
|
161
|
+
result = client.active_inference_candidates
|
|
162
|
+
expect(result).to have_key(:count)
|
|
163
|
+
expect(result).to have_key(:domains)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it 'returns 0 when no high-free-energy models' do
|
|
167
|
+
expect(client.active_inference_candidates[:count]).to eq(0)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it 'includes domains with high free energy' do
|
|
171
|
+
client.add_generative_model(domain: :erratic)
|
|
172
|
+
5.times { client.observe_outcome(domain: :erratic, actual: 1.0, predicted: 0.0) }
|
|
173
|
+
result = client.active_inference_candidates
|
|
174
|
+
expect(result[:domains]).to include(:erratic)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
describe '#update_predictive_processing' do
|
|
179
|
+
it 'ticks the processor' do
|
|
180
|
+
result = client.update_predictive_processing
|
|
181
|
+
expect(result[:ticked]).to be true
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it 'reports model count' do
|
|
185
|
+
client.add_generative_model(domain: :tracked)
|
|
186
|
+
result = client.update_predictive_processing
|
|
187
|
+
expect(result[:model_count]).to eq(1)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
describe '#predictive_processing_stats' do
|
|
192
|
+
it 'returns success: true' do
|
|
193
|
+
result = client.predictive_processing_stats
|
|
194
|
+
expect(result[:success]).to be true
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it 'returns stats hash' do
|
|
198
|
+
result = client.predictive_processing_stats
|
|
199
|
+
expect(result[:stats]).to be_a(Hash)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it 'includes global_free_energy in stats' do
|
|
203
|
+
result = client.predictive_processing_stats
|
|
204
|
+
expect(result[:stats]).to have_key(:global_free_energy)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
it 'reflects added models in stats' do
|
|
208
|
+
client.add_generative_model(domain: :counted)
|
|
209
|
+
result = client.predictive_processing_stats
|
|
210
|
+
expect(result[:stats][:model_count]).to eq(1)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/reality_testing/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::RealityTesting::Client do
|
|
6
|
+
let(:client) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'responds to all runner methods' do
|
|
9
|
+
expect(client).to respond_to(:create_belief)
|
|
10
|
+
expect(client).to respond_to(:test_belief)
|
|
11
|
+
expect(client).to respond_to(:get_belief)
|
|
12
|
+
expect(client).to respond_to(:beliefs_needing_testing)
|
|
13
|
+
expect(client).to respond_to(:strongest_beliefs)
|
|
14
|
+
expect(client).to respond_to(:weakest_beliefs)
|
|
15
|
+
expect(client).to respond_to(:beliefs_by_domain)
|
|
16
|
+
expect(client).to respond_to(:overall_coherence)
|
|
17
|
+
expect(client).to respond_to(:decay_beliefs)
|
|
18
|
+
expect(client).to respond_to(:prune_rejected_beliefs)
|
|
19
|
+
expect(client).to respond_to(:reality_report)
|
|
20
|
+
expect(client).to respond_to(:reality_status)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'maintains isolated state per instance' do
|
|
24
|
+
client_a = described_class.new
|
|
25
|
+
client_b = described_class.new
|
|
26
|
+
client_a.create_belief(claim: 'only in A')
|
|
27
|
+
expect(client_b.reality_status[:total_beliefs]).to eq(0)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::RealityTesting::Helpers::Belief do
|
|
4
|
+
subject(:belief) { described_class.new(id: 'b1', claim: 'The sky is blue', domain: :perception) }
|
|
5
|
+
|
|
6
|
+
describe '#initialize' do
|
|
7
|
+
it 'sets id' do
|
|
8
|
+
expect(belief.id).to eq('b1')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'sets claim' do
|
|
12
|
+
expect(belief.claim).to eq('The sky is blue')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'sets domain' do
|
|
16
|
+
expect(belief.domain).to eq(:perception)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'sets default confidence' do
|
|
20
|
+
expect(belief.confidence).to eq(0.5)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'clamps confidence above 1.0' do
|
|
24
|
+
b = described_class.new(id: 'x', claim: 'test', confidence: 1.5)
|
|
25
|
+
expect(b.confidence).to eq(1.0)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'clamps confidence below 0.0' do
|
|
29
|
+
b = described_class.new(id: 'x', claim: 'test', confidence: -0.5)
|
|
30
|
+
expect(b.confidence).to eq(0.0)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'initializes evidence counts to zero' do
|
|
34
|
+
expect(belief.evidence_count).to eq(0)
|
|
35
|
+
expect(belief.confirming_count).to eq(0)
|
|
36
|
+
expect(belief.disconfirming_count).to eq(0)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe '#test_with_evidence!' do
|
|
41
|
+
it 'increments evidence_count for any type' do
|
|
42
|
+
belief.test_with_evidence!(evidence_type: :confirming)
|
|
43
|
+
expect(belief.evidence_count).to eq(1)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'increases confidence for confirming evidence' do
|
|
47
|
+
before = belief.confidence
|
|
48
|
+
belief.test_with_evidence!(evidence_type: :confirming)
|
|
49
|
+
expect(belief.confidence).to be > before
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'decreases confidence for disconfirming evidence' do
|
|
53
|
+
before = belief.confidence
|
|
54
|
+
belief.test_with_evidence!(evidence_type: :disconfirming)
|
|
55
|
+
expect(belief.confidence).to be < before
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'does not change confidence for neutral evidence' do
|
|
59
|
+
before = belief.confidence
|
|
60
|
+
belief.test_with_evidence!(evidence_type: :neutral)
|
|
61
|
+
expect(belief.confidence).to eq(before)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'nudges confidence toward 0.5 for ambiguous evidence when above' do
|
|
65
|
+
b = described_class.new(id: 'x', claim: 'test', confidence: 0.8)
|
|
66
|
+
before = b.confidence
|
|
67
|
+
b.test_with_evidence!(evidence_type: :ambiguous)
|
|
68
|
+
expect(b.confidence).to be < before
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'nudges confidence toward 0.5 for ambiguous evidence when below' do
|
|
72
|
+
b = described_class.new(id: 'x', claim: 'test', confidence: 0.2)
|
|
73
|
+
before = b.confidence
|
|
74
|
+
b.test_with_evidence!(evidence_type: :ambiguous)
|
|
75
|
+
expect(b.confidence).to be > before
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'tracks confirming_count' do
|
|
79
|
+
belief.test_with_evidence!(evidence_type: :confirming)
|
|
80
|
+
expect(belief.confirming_count).to eq(1)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'tracks disconfirming_count' do
|
|
84
|
+
belief.test_with_evidence!(evidence_type: :disconfirming)
|
|
85
|
+
expect(belief.disconfirming_count).to eq(1)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'raises for unknown evidence_type' do
|
|
89
|
+
expect { belief.test_with_evidence!(evidence_type: :unknown) }.to raise_error(ArgumentError)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'returns self for chaining' do
|
|
93
|
+
result = belief.test_with_evidence!(evidence_type: :neutral)
|
|
94
|
+
expect(result).to be(belief)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe '#confidence_label' do
|
|
99
|
+
it 'returns :certain at 1.0' do
|
|
100
|
+
b = described_class.new(id: 'x', claim: 'test', confidence: 1.0)
|
|
101
|
+
expect(b.confidence_label).to eq(:certain)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'returns :tentative at 0.5' do
|
|
105
|
+
expect(belief.confidence_label).to eq(:tentative)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'returns :rejected near 0.0' do
|
|
109
|
+
b = described_class.new(id: 'x', claim: 'test', confidence: 0.05)
|
|
110
|
+
expect(b.confidence_label).to eq(:rejected)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe '#validity' do
|
|
115
|
+
it 'returns 0.5 when no evidence' do
|
|
116
|
+
expect(belief.validity).to eq(0.5)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it 'returns 1.0 with only confirming evidence' do
|
|
120
|
+
3.times { belief.test_with_evidence!(evidence_type: :confirming) }
|
|
121
|
+
expect(belief.validity).to eq(1.0)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it 'returns 0.0 with only disconfirming evidence' do
|
|
125
|
+
3.times { belief.test_with_evidence!(evidence_type: :disconfirming) }
|
|
126
|
+
expect(belief.validity).to eq(0.0)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it 'returns 0.5 with equal confirming and disconfirming' do
|
|
130
|
+
belief.test_with_evidence!(evidence_type: :confirming)
|
|
131
|
+
belief.test_with_evidence!(evidence_type: :disconfirming)
|
|
132
|
+
expect(belief.validity).to eq(0.5)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe '#validity_label' do
|
|
137
|
+
it 'returns :validated with all confirming' do
|
|
138
|
+
3.times { belief.test_with_evidence!(evidence_type: :confirming) }
|
|
139
|
+
expect(belief.validity_label).to eq(:validated)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'returns :refuted with all disconfirming' do
|
|
143
|
+
3.times { belief.test_with_evidence!(evidence_type: :disconfirming) }
|
|
144
|
+
expect(belief.validity_label).to eq(:refuted)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
describe '#needs_testing?' do
|
|
149
|
+
it 'returns true at default confidence 0.5' do
|
|
150
|
+
expect(belief.needs_testing?).to be true
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it 'returns false at high confidence' do
|
|
154
|
+
b = described_class.new(id: 'x', claim: 'test', confidence: 0.9)
|
|
155
|
+
expect(b.needs_testing?).to be false
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it 'returns false at low confidence' do
|
|
159
|
+
b = described_class.new(id: 'x', claim: 'test', confidence: 0.1)
|
|
160
|
+
expect(b.needs_testing?).to be false
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
describe '#decay!' do
|
|
165
|
+
it 'reduces confidence by CONFIDENCE_DECAY' do
|
|
166
|
+
before = belief.confidence
|
|
167
|
+
belief.decay!
|
|
168
|
+
expect(belief.confidence).to be_within(0.001).of(before - 0.02)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it 'floors at 0.0' do
|
|
172
|
+
b = described_class.new(id: 'x', claim: 'test', confidence: 0.01)
|
|
173
|
+
b.decay!
|
|
174
|
+
expect(b.confidence).to eq(0.0)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it 'returns self' do
|
|
178
|
+
expect(belief.decay!).to be(belief)
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
describe '#to_h' do
|
|
183
|
+
it 'includes all expected keys' do
|
|
184
|
+
h = belief.to_h
|
|
185
|
+
expect(h).to include(
|
|
186
|
+
:id, :claim, :domain, :confidence, :confidence_label,
|
|
187
|
+
:evidence_count, :confirming_count, :disconfirming_count,
|
|
188
|
+
:validity, :validity_label, :needs_testing, :created_at, :last_tested_at
|
|
189
|
+
)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it 'sets last_tested_at after testing' do
|
|
193
|
+
belief.test_with_evidence!(evidence_type: :confirming)
|
|
194
|
+
expect(belief.to_h[:last_tested_at]).not_to be_nil
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
end
|