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
data/spec/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing_spec.rb
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/hypothesis_testing/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::HypothesisTesting::Runners::HypothesisTesting do
|
|
6
|
+
let(:client) { Legion::Extensions::Agentic::Inference::HypothesisTesting::Client.new }
|
|
7
|
+
|
|
8
|
+
describe '#propose_hypothesis' do
|
|
9
|
+
it 'returns a hypothesis_id uuid' do
|
|
10
|
+
result = client.propose_hypothesis(description: 'water boils at 100C')
|
|
11
|
+
expect(result[:hypothesis_id]).to match(/\A[0-9a-f-]{36}\z/)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'returns the description' do
|
|
15
|
+
result = client.propose_hypothesis(description: 'gravity exists')
|
|
16
|
+
expect(result[:description]).to eq('gravity exists')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'returns the domain' do
|
|
20
|
+
result = client.propose_hypothesis(description: 'test', domain: 'physics')
|
|
21
|
+
expect(result[:domain]).to eq('physics')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'defaults domain to general' do
|
|
25
|
+
result = client.propose_hypothesis(description: 'test')
|
|
26
|
+
expect(result[:domain]).to eq('general')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'returns status :proposed' do
|
|
30
|
+
result = client.propose_hypothesis(description: 'test')
|
|
31
|
+
expect(result[:status]).to eq(:proposed)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'returns a confidence_label' do
|
|
35
|
+
result = client.propose_hypothesis(description: 'test', prior: 0.9)
|
|
36
|
+
expect(result[:confidence_label]).to eq('certain')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'sets prior and posterior to the given prior' do
|
|
40
|
+
result = client.propose_hypothesis(description: 'test', prior: 0.7)
|
|
41
|
+
expect(result[:prior]).to eq(0.7)
|
|
42
|
+
expect(result[:posterior]).to eq(0.7)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe '#test_hypothesis' do
|
|
47
|
+
let(:proposed) { client.propose_hypothesis(description: 'testable') }
|
|
48
|
+
|
|
49
|
+
it 'returns tested: true for a known hypothesis' do
|
|
50
|
+
result = client.test_hypothesis(hypothesis_id: proposed[:hypothesis_id], evidence_strength: 0.5, supporting: true)
|
|
51
|
+
expect(result[:tested]).to be true
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'returns tested: false for an unknown id' do
|
|
55
|
+
result = client.test_hypothesis(hypothesis_id: 'missing', evidence_strength: 0.5, supporting: true)
|
|
56
|
+
expect(result[:tested]).to be false
|
|
57
|
+
expect(result[:reason]).to eq(:not_found)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'includes updated posterior' do
|
|
61
|
+
result = client.test_hypothesis(hypothesis_id: proposed[:hypothesis_id], evidence_strength: 1.0, supporting: true)
|
|
62
|
+
expect(result[:posterior]).to be > proposed[:posterior]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'includes updated evidence_count' do
|
|
66
|
+
result = client.test_hypothesis(hypothesis_id: proposed[:hypothesis_id], evidence_strength: 0.5, supporting: true)
|
|
67
|
+
expect(result[:evidence_count]).to eq(1)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'includes status' do
|
|
71
|
+
result = client.test_hypothesis(hypothesis_id: proposed[:hypothesis_id], evidence_strength: 0.5, supporting: true)
|
|
72
|
+
expect(result.key?(:status)).to be true
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'returns :confirmed status when posterior crosses threshold' do
|
|
76
|
+
h = client.propose_hypothesis(description: 'high prior', prior: 0.79)
|
|
77
|
+
result = client.test_hypothesis(hypothesis_id: h[:hypothesis_id], evidence_strength: 1.0, supporting: true)
|
|
78
|
+
expect(result[:status]).to eq(:confirmed)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe '#evaluate_hypothesis' do
|
|
83
|
+
it 'returns found: false for unknown id' do
|
|
84
|
+
result = client.evaluate_hypothesis(hypothesis_id: 'ghost')
|
|
85
|
+
expect(result[:found]).to be false
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'returns found: true for known hypothesis' do
|
|
89
|
+
h = client.propose_hypothesis(description: 'evaluatable')
|
|
90
|
+
result = client.evaluate_hypothesis(hypothesis_id: h[:hypothesis_id])
|
|
91
|
+
expect(result[:found]).to be true
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'confirms hypothesis when posterior is above threshold' do
|
|
95
|
+
h = client.propose_hypothesis(description: 'high', prior: 0.9)
|
|
96
|
+
result = client.evaluate_hypothesis(hypothesis_id: h[:hypothesis_id])
|
|
97
|
+
expect(result[:status]).to eq(:confirmed)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe '#competing_hypotheses' do
|
|
102
|
+
it 'returns hypotheses in the given domain' do
|
|
103
|
+
client.propose_hypothesis(description: 'h1', domain: 'biology')
|
|
104
|
+
client.propose_hypothesis(description: 'h2', domain: 'biology')
|
|
105
|
+
client.propose_hypothesis(description: 'h3', domain: 'chemistry')
|
|
106
|
+
result = client.competing_hypotheses(domain: 'biology')
|
|
107
|
+
expect(result[:count]).to eq(2)
|
|
108
|
+
expect(result[:domain]).to eq('biology')
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'returns empty list for unrepresented domain' do
|
|
112
|
+
result = client.competing_hypotheses(domain: 'astrology')
|
|
113
|
+
expect(result[:count]).to eq(0)
|
|
114
|
+
expect(result[:hypotheses]).to be_empty
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe '#most_confident_hypotheses' do
|
|
119
|
+
it 'returns hypotheses sorted by descending posterior' do
|
|
120
|
+
client.propose_hypothesis(description: 'low', prior: 0.2)
|
|
121
|
+
client.propose_hypothesis(description: 'high', prior: 0.9)
|
|
122
|
+
result = client.most_confident_hypotheses(limit: 2)
|
|
123
|
+
expect(result[:hypotheses].first[:posterior]).to be >= result[:hypotheses].last[:posterior]
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'respects the limit' do
|
|
127
|
+
5.times { |i| client.propose_hypothesis(description: "h#{i}") }
|
|
128
|
+
result = client.most_confident_hypotheses(limit: 3)
|
|
129
|
+
expect(result[:count]).to be <= 3
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
describe '#hypothesis_report' do
|
|
134
|
+
it 'includes total, by_status, confirmation_rate, most_confident' do
|
|
135
|
+
client.propose_hypothesis(description: 'reported')
|
|
136
|
+
result = client.hypothesis_report
|
|
137
|
+
expect(result.keys).to include(:total, :by_status, :confirmation_rate, :most_confident)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'counts total correctly' do
|
|
141
|
+
3.times { |i| client.propose_hypothesis(description: "h#{i}") }
|
|
142
|
+
expect(client.hypothesis_report[:total]).to eq(3)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
describe '#get_hypothesis' do
|
|
147
|
+
it 'returns found: false for unknown id' do
|
|
148
|
+
result = client.get_hypothesis(hypothesis_id: 'nope')
|
|
149
|
+
expect(result[:found]).to be false
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it 'returns found: true and hypothesis hash for known id' do
|
|
153
|
+
h = client.propose_hypothesis(description: 'gettable')
|
|
154
|
+
result = client.get_hypothesis(hypothesis_id: h[:hypothesis_id])
|
|
155
|
+
expect(result[:found]).to be true
|
|
156
|
+
expect(result[:hypothesis][:id]).to eq(h[:hypothesis_id])
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Intuition::Client do
|
|
4
|
+
subject(:client) { described_class.new }
|
|
5
|
+
|
|
6
|
+
it 'includes the Intuition runner' do
|
|
7
|
+
expect(client).to respond_to(:intuit_response)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'accepts an injected engine' do
|
|
11
|
+
engine = Legion::Extensions::Agentic::Inference::Intuition::Helpers::IntuitionEngine.new
|
|
12
|
+
c = described_class.new(engine: engine)
|
|
13
|
+
expect(c.intuition_stats[:success]).to be true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'supports full learn-recognize-reinforce cycle' do
|
|
17
|
+
cue = { weather: :sunny, wind: :low }
|
|
18
|
+
created = client.learn_intuitive_pattern(cue: cue, response: :go_outside, strength: 0.6)
|
|
19
|
+
expect(created[:success]).to be true
|
|
20
|
+
|
|
21
|
+
result = client.intuit_response(input_cue: cue)
|
|
22
|
+
expect(result[:response]).to eq(:go_outside)
|
|
23
|
+
|
|
24
|
+
reinforced = client.reinforce_intuition(pattern_id: created[:pattern_id], success: true)
|
|
25
|
+
expect(reinforced[:strength]).to be > 0.6
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'supports heuristic lifecycle' do
|
|
29
|
+
created = client.add_intuitive_heuristic(name: 'quick scan', heuristic_type: :recognition)
|
|
30
|
+
applied = client.apply_intuitive_heuristic(heuristic_id: created[:heuristic_id])
|
|
31
|
+
expect(applied[:uses]).to eq(1)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Intuition::Helpers::Heuristic do
|
|
4
|
+
subject(:heuristic) do
|
|
5
|
+
described_class.new(
|
|
6
|
+
id: :heur_one,
|
|
7
|
+
name: 'take the best',
|
|
8
|
+
heuristic_type: :take_the_best,
|
|
9
|
+
domain: :decision
|
|
10
|
+
)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '#initialize' do
|
|
14
|
+
it 'sets attributes' do
|
|
15
|
+
expect(heuristic.name).to eq('take the best')
|
|
16
|
+
expect(heuristic.heuristic_type).to eq(:take_the_best)
|
|
17
|
+
expect(heuristic.domain).to eq(:decision)
|
|
18
|
+
expect(heuristic.uses).to eq(0)
|
|
19
|
+
expect(heuristic.successes).to eq(0)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'defaults invalid type to :fast_and_frugal' do
|
|
23
|
+
h = described_class.new(id: :x, name: 'test', heuristic_type: :bogus)
|
|
24
|
+
expect(h.heuristic_type).to eq(:fast_and_frugal)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe '#apply' do
|
|
29
|
+
it 'increments uses' do
|
|
30
|
+
heuristic.apply
|
|
31
|
+
expect(heuristic.uses).to eq(1)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe '#record_outcome' do
|
|
36
|
+
it 'increments successes on success' do
|
|
37
|
+
heuristic.record_outcome(success: true)
|
|
38
|
+
expect(heuristic.successes).to eq(1)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'does not increment on failure' do
|
|
42
|
+
heuristic.record_outcome(success: false)
|
|
43
|
+
expect(heuristic.successes).to eq(0)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe '#success_rate' do
|
|
48
|
+
it 'returns 0.0 with no uses' do
|
|
49
|
+
expect(heuristic.success_rate).to eq(0.0)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'calculates correctly' do
|
|
53
|
+
3.times { heuristic.apply }
|
|
54
|
+
2.times { heuristic.record_outcome(success: true) }
|
|
55
|
+
heuristic.record_outcome(success: false)
|
|
56
|
+
expect(heuristic.success_rate).to be_within(0.01).of(0.67)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe '#effective?' do
|
|
61
|
+
it 'returns false with few uses' do
|
|
62
|
+
expect(heuristic.effective?).to be false
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'returns true with enough successful uses' do
|
|
66
|
+
4.times do
|
|
67
|
+
heuristic.apply
|
|
68
|
+
heuristic.record_outcome(success: true)
|
|
69
|
+
end
|
|
70
|
+
expect(heuristic.effective?).to be true
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe '#to_h' do
|
|
75
|
+
it 'returns expected keys' do
|
|
76
|
+
expect(heuristic.to_h).to include(
|
|
77
|
+
:id, :name, :heuristic_type, :domain,
|
|
78
|
+
:uses, :successes, :success_rate, :effective
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Intuition::Helpers::IntuitionEngine do
|
|
4
|
+
subject(:eng) { described_class.new }
|
|
5
|
+
|
|
6
|
+
let(:cue) { { color: :red, shape: :circle } }
|
|
7
|
+
|
|
8
|
+
describe '#learn_pattern' do
|
|
9
|
+
it 'creates a pattern' do
|
|
10
|
+
pattern = eng.learn_pattern(cue: cue, response: :stop)
|
|
11
|
+
expect(pattern).to be_a(Legion::Extensions::Agentic::Inference::Intuition::Helpers::Pattern)
|
|
12
|
+
expect(eng.patterns.size).to eq(1)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'enforces MAX_PATTERNS' do
|
|
16
|
+
200.times { |i| eng.learn_pattern(cue: { n: i }, response: :x) }
|
|
17
|
+
expect(eng.learn_pattern(cue: { n: :overflow }, response: :x)).to be_nil
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'records event' do
|
|
21
|
+
eng.learn_pattern(cue: cue, response: :stop)
|
|
22
|
+
expect(eng.history.size).to eq(1)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe '#recognize' do
|
|
27
|
+
it 'finds matching patterns' do
|
|
28
|
+
eng.learn_pattern(cue: cue, response: :stop, domain: :traffic)
|
|
29
|
+
matches = eng.recognize(input_cue: { color: :red, shape: :circle })
|
|
30
|
+
expect(matches.size).to eq(1)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'filters by domain' do
|
|
34
|
+
eng.learn_pattern(cue: cue, response: :stop, domain: :traffic)
|
|
35
|
+
eng.learn_pattern(cue: cue, response: :danger, domain: :safety)
|
|
36
|
+
matches = eng.recognize(input_cue: cue, domain: :traffic)
|
|
37
|
+
expect(matches.size).to eq(1)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'returns empty for no match' do
|
|
41
|
+
eng.learn_pattern(cue: { x: 1 }, response: :y)
|
|
42
|
+
matches = eng.recognize(input_cue: { a: 2, b: 3 })
|
|
43
|
+
expect(matches).to be_empty
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'sorts by match score descending' do
|
|
47
|
+
eng.learn_pattern(cue: { color: :red }, response: :partial)
|
|
48
|
+
eng.learn_pattern(cue: { color: :red, shape: :circle }, response: :exact)
|
|
49
|
+
matches = eng.recognize(input_cue: cue)
|
|
50
|
+
expect(matches.first[:score]).to be >= matches.last[:score]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe '#intuit' do
|
|
55
|
+
it 'returns best matching response' do
|
|
56
|
+
eng.learn_pattern(cue: cue, response: :stop, strength: 0.8)
|
|
57
|
+
result = eng.intuit(input_cue: cue)
|
|
58
|
+
expect(result[:response]).to eq(:stop)
|
|
59
|
+
expect(result[:confidence]).to eq(0.8)
|
|
60
|
+
expect(result).to have_key(:mode)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'returns nil when no match' do
|
|
64
|
+
result = eng.intuit(input_cue: { unknown: :thing })
|
|
65
|
+
expect(result).to be_nil
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'returns :compiled_expertise mode for expert patterns' do
|
|
69
|
+
p = eng.learn_pattern(cue: cue, response: :stop, strength: 0.85)
|
|
70
|
+
10.times { p.reinforce(success: true) }
|
|
71
|
+
result = eng.intuit(input_cue: cue)
|
|
72
|
+
expect(result[:mode]).to eq(:compiled_expertise)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe '#reinforce_pattern' do
|
|
77
|
+
it 'reinforces on success' do
|
|
78
|
+
pattern = eng.learn_pattern(cue: cue, response: :stop)
|
|
79
|
+
original = pattern.strength
|
|
80
|
+
eng.reinforce_pattern(pattern_id: pattern.id, success: true)
|
|
81
|
+
expect(pattern.strength).to be > original
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'returns nil for unknown pattern' do
|
|
85
|
+
expect(eng.reinforce_pattern(pattern_id: :bogus, success: true)).to be_nil
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe '#add_heuristic' do
|
|
90
|
+
it 'creates a heuristic' do
|
|
91
|
+
h = eng.add_heuristic(name: 'recognition', heuristic_type: :recognition)
|
|
92
|
+
expect(h).to be_a(Legion::Extensions::Agentic::Inference::Intuition::Helpers::Heuristic)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'enforces MAX_HEURISTICS' do
|
|
96
|
+
50.times { |i| eng.add_heuristic(name: "h_#{i}", heuristic_type: :recognition) }
|
|
97
|
+
expect(eng.add_heuristic(name: 'overflow', heuristic_type: :recognition)).to be_nil
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe '#apply_heuristic' do
|
|
102
|
+
it 'applies and returns hash' do
|
|
103
|
+
h = eng.add_heuristic(name: 'test', heuristic_type: :satisficing)
|
|
104
|
+
result = eng.apply_heuristic(heuristic_id: h.id)
|
|
105
|
+
expect(result[:uses]).to eq(1)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'returns nil for unknown heuristic' do
|
|
109
|
+
expect(eng.apply_heuristic(heuristic_id: :bogus)).to be_nil
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe '#reliable_patterns and #expert_patterns' do
|
|
114
|
+
it 'returns reliable patterns' do
|
|
115
|
+
p = eng.learn_pattern(cue: cue, response: :stop, strength: 0.7)
|
|
116
|
+
3.times { p.reinforce(success: true) }
|
|
117
|
+
expect(eng.reliable_patterns.size).to eq(1)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'returns expert patterns' do
|
|
121
|
+
p = eng.learn_pattern(cue: cue, response: :stop, strength: 0.85)
|
|
122
|
+
10.times { p.reinforce(success: true) }
|
|
123
|
+
expect(eng.expert_patterns.size).to eq(1)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe '#effective_heuristics' do
|
|
128
|
+
it 'returns effective heuristics' do
|
|
129
|
+
h = eng.add_heuristic(name: 'test', heuristic_type: :recognition)
|
|
130
|
+
4.times do
|
|
131
|
+
h.apply
|
|
132
|
+
h.record_outcome(success: true)
|
|
133
|
+
end
|
|
134
|
+
expect(eng.effective_heuristics.size).to eq(1)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
describe '#patterns_in' do
|
|
139
|
+
it 'filters by domain' do
|
|
140
|
+
eng.learn_pattern(cue: { x: 1 }, response: :a, domain: :traffic)
|
|
141
|
+
eng.learn_pattern(cue: { y: 2 }, response: :b, domain: :safety)
|
|
142
|
+
expect(eng.patterns_in(domain: :traffic).size).to eq(1)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
describe '#decay_all' do
|
|
147
|
+
it 'decays all patterns' do
|
|
148
|
+
p = eng.learn_pattern(cue: cue, response: :stop, strength: 0.8)
|
|
149
|
+
original = p.strength
|
|
150
|
+
eng.decay_all
|
|
151
|
+
expect(p.strength).to be < original
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
describe '#to_h' do
|
|
156
|
+
it 'returns expected keys' do
|
|
157
|
+
expect(eng.to_h).to include(
|
|
158
|
+
:pattern_count, :heuristic_count, :reliable_pattern_count,
|
|
159
|
+
:expert_pattern_count, :effective_heuristic_count, :history_size
|
|
160
|
+
)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Intuition::Helpers::Pattern do
|
|
4
|
+
subject(:pattern) do
|
|
5
|
+
described_class.new(
|
|
6
|
+
id: :pat_one,
|
|
7
|
+
cue: { color: :red, shape: :circle },
|
|
8
|
+
response: :stop,
|
|
9
|
+
domain: :traffic
|
|
10
|
+
)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '#initialize' do
|
|
14
|
+
it 'sets attributes' do
|
|
15
|
+
expect(pattern.cue).to eq({ color: :red, shape: :circle })
|
|
16
|
+
expect(pattern.response).to eq(:stop)
|
|
17
|
+
expect(pattern.domain).to eq(:traffic)
|
|
18
|
+
expect(pattern.encounters).to eq(0)
|
|
19
|
+
expect(pattern.state).to eq(:developing)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'clamps strength' do
|
|
23
|
+
p = described_class.new(id: :x, cue: {}, response: :y, strength: 2.0)
|
|
24
|
+
expect(p.strength).to eq(0.95)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe '#match_score' do
|
|
29
|
+
it 'returns 1.0 for exact match' do
|
|
30
|
+
score = pattern.match_score({ color: :red, shape: :circle })
|
|
31
|
+
expect(score).to eq(1.0)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'returns partial score for partial match' do
|
|
35
|
+
score = pattern.match_score({ color: :red, shape: :square })
|
|
36
|
+
expect(score).to eq(0.5)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'returns 0.0 for no match' do
|
|
40
|
+
score = pattern.match_score({ color: :blue, shape: :square })
|
|
41
|
+
expect(score).to eq(0.0)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'returns 0.0 for non-hash input' do
|
|
45
|
+
expect(pattern.match_score('not a hash')).to eq(0.0)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'handles disjoint keys' do
|
|
49
|
+
score = pattern.match_score({ size: :large, weight: :heavy })
|
|
50
|
+
expect(score).to eq(0.0)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe '#recognized?' do
|
|
55
|
+
it 'returns true for high match' do
|
|
56
|
+
expect(pattern.recognized?({ color: :red, shape: :circle })).to be true
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'returns false for low match' do
|
|
60
|
+
expect(pattern.recognized?({ color: :blue, shape: :square })).to be false
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe '#reinforce' do
|
|
65
|
+
it 'increases strength on success' do
|
|
66
|
+
original = pattern.strength
|
|
67
|
+
pattern.reinforce(success: true)
|
|
68
|
+
expect(pattern.strength).to be > original
|
|
69
|
+
expect(pattern.encounters).to eq(1)
|
|
70
|
+
expect(pattern.successes).to eq(1)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'decreases strength on failure' do
|
|
74
|
+
original = pattern.strength
|
|
75
|
+
pattern.reinforce(success: false)
|
|
76
|
+
expect(pattern.strength).to be < original
|
|
77
|
+
expect(pattern.encounters).to eq(1)
|
|
78
|
+
expect(pattern.successes).to eq(0)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'clamps to ceiling' do
|
|
82
|
+
p = described_class.new(id: :x, cue: {}, response: :y, strength: 0.92)
|
|
83
|
+
p.reinforce(success: true)
|
|
84
|
+
expect(p.strength).to be <= 0.95
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe '#decay' do
|
|
89
|
+
it 'reduces strength' do
|
|
90
|
+
original = pattern.strength
|
|
91
|
+
pattern.decay
|
|
92
|
+
expect(pattern.strength).to be < original
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'does not go below floor' do
|
|
96
|
+
p = described_class.new(id: :x, cue: {}, response: :y, strength: 0.06)
|
|
97
|
+
p.decay
|
|
98
|
+
expect(p.strength).to be >= 0.05
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
describe '#success_rate' do
|
|
103
|
+
it 'returns 0.0 with no encounters' do
|
|
104
|
+
expect(pattern.success_rate).to eq(0.0)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it 'calculates correctly' do
|
|
108
|
+
pattern.reinforce(success: true)
|
|
109
|
+
pattern.reinforce(success: false)
|
|
110
|
+
expect(pattern.success_rate).to eq(0.5)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe '#reliable? and #expert?' do
|
|
115
|
+
it 'starts as not reliable' do
|
|
116
|
+
expect(pattern.reliable?).to be false
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it 'becomes reliable with enough encounters and strength' do
|
|
120
|
+
p = described_class.new(id: :x, cue: {}, response: :y, strength: 0.7)
|
|
121
|
+
3.times { p.reinforce(success: true) }
|
|
122
|
+
expect(p.reliable?).to be true
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it 'becomes expert with many encounters and high strength' do
|
|
126
|
+
p = described_class.new(id: :x, cue: {}, response: :y, strength: 0.85)
|
|
127
|
+
10.times { p.reinforce(success: true) }
|
|
128
|
+
expect(p.expert?).to be true
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe '#state transitions' do
|
|
133
|
+
it 'starts as developing at default strength' do
|
|
134
|
+
expect(pattern.state).to eq(:developing)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'transitions through states with reinforcement' do
|
|
138
|
+
p = described_class.new(id: :x, cue: {}, response: :y, strength: 0.3)
|
|
139
|
+
expect(p.state).to eq(:nascent)
|
|
140
|
+
4.times { p.reinforce(success: true) }
|
|
141
|
+
expect(%i[developing reliable]).to include(p.state)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
describe '#confidence_label' do
|
|
146
|
+
it 'returns a symbol' do
|
|
147
|
+
expect(pattern.confidence_label).to be_a(Symbol)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
describe '#to_h' do
|
|
152
|
+
it 'returns expected keys' do
|
|
153
|
+
expect(pattern.to_h).to include(
|
|
154
|
+
:id, :cue, :response, :domain, :strength,
|
|
155
|
+
:encounters, :successes, :success_rate, :state,
|
|
156
|
+
:confidence_label, :reliable, :expert
|
|
157
|
+
)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::Intuition::Runners::Intuition do
|
|
4
|
+
let(:host) do
|
|
5
|
+
obj = Object.new
|
|
6
|
+
obj.extend(described_class)
|
|
7
|
+
obj
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
let(:cue) { { color: :red, shape: :circle } }
|
|
11
|
+
|
|
12
|
+
describe '#learn_intuitive_pattern' do
|
|
13
|
+
it 'creates a pattern' do
|
|
14
|
+
result = host.learn_intuitive_pattern(cue: cue, response: :stop)
|
|
15
|
+
expect(result[:success]).to be true
|
|
16
|
+
expect(result[:pattern_id]).to be_a(Symbol)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe '#intuitive_recognize' do
|
|
21
|
+
it 'recognizes patterns' do
|
|
22
|
+
host.learn_intuitive_pattern(cue: cue, response: :stop)
|
|
23
|
+
result = host.intuitive_recognize(input_cue: cue)
|
|
24
|
+
expect(result[:success]).to be true
|
|
25
|
+
expect(result[:count]).to eq(1)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe '#intuit_response' do
|
|
30
|
+
it 'returns the intuited response' do
|
|
31
|
+
host.learn_intuitive_pattern(cue: cue, response: :stop, strength: 0.8)
|
|
32
|
+
result = host.intuit_response(input_cue: cue)
|
|
33
|
+
expect(result[:success]).to be true
|
|
34
|
+
expect(result[:response]).to eq(:stop)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'returns failure for no match' do
|
|
38
|
+
result = host.intuit_response(input_cue: { unknown: :thing })
|
|
39
|
+
expect(result[:success]).to be false
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe '#reinforce_intuition' do
|
|
44
|
+
it 'reinforces a pattern' do
|
|
45
|
+
created = host.learn_intuitive_pattern(cue: cue, response: :stop)
|
|
46
|
+
result = host.reinforce_intuition(pattern_id: created[:pattern_id], success: true)
|
|
47
|
+
expect(result[:success]).to be true
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'returns failure for unknown pattern' do
|
|
51
|
+
result = host.reinforce_intuition(pattern_id: :bogus, success: true)
|
|
52
|
+
expect(result[:success]).to be false
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe '#add_intuitive_heuristic' do
|
|
57
|
+
it 'creates a heuristic' do
|
|
58
|
+
result = host.add_intuitive_heuristic(name: 'test', heuristic_type: :recognition)
|
|
59
|
+
expect(result[:success]).to be true
|
|
60
|
+
expect(result[:heuristic_id]).to be_a(Symbol)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe '#apply_intuitive_heuristic' do
|
|
65
|
+
it 'applies a heuristic' do
|
|
66
|
+
created = host.add_intuitive_heuristic(name: 'test', heuristic_type: :satisficing)
|
|
67
|
+
result = host.apply_intuitive_heuristic(heuristic_id: created[:heuristic_id])
|
|
68
|
+
expect(result[:success]).to be true
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'returns failure for unknown heuristic' do
|
|
72
|
+
result = host.apply_intuitive_heuristic(heuristic_id: :bogus)
|
|
73
|
+
expect(result[:success]).to be false
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe '#reliable_intuitions' do
|
|
78
|
+
it 'returns reliable patterns' do
|
|
79
|
+
result = host.reliable_intuitions
|
|
80
|
+
expect(result[:success]).to be true
|
|
81
|
+
expect(result[:count]).to eq(0)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe '#expert_intuitions' do
|
|
86
|
+
it 'returns expert patterns' do
|
|
87
|
+
result = host.expert_intuitions
|
|
88
|
+
expect(result[:success]).to be true
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe '#update_intuition' do
|
|
93
|
+
it 'decays and returns stats' do
|
|
94
|
+
result = host.update_intuition
|
|
95
|
+
expect(result[:success]).to be true
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe '#intuition_stats' do
|
|
100
|
+
it 'returns stats' do
|
|
101
|
+
result = host.intuition_stats
|
|
102
|
+
expect(result[:success]).to be true
|
|
103
|
+
expect(result).to have_key(:pattern_count)
|
|
104
|
+
expect(result).to have_key(:heuristic_count)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|