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,157 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module Intuition
|
|
8
|
+
module Helpers
|
|
9
|
+
class IntuitionEngine
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :patterns, :heuristics, :history
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@patterns = {}
|
|
16
|
+
@heuristics = {}
|
|
17
|
+
@pattern_count = 0
|
|
18
|
+
@heuristic_count = 0
|
|
19
|
+
@history = []
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def learn_pattern(cue:, response:, domain: :general, strength: DEFAULT_CONFIDENCE)
|
|
23
|
+
return nil if @patterns.size >= MAX_PATTERNS
|
|
24
|
+
|
|
25
|
+
@pattern_count += 1
|
|
26
|
+
pattern = Pattern.new(
|
|
27
|
+
id: :"pat_#{@pattern_count}",
|
|
28
|
+
cue: cue,
|
|
29
|
+
response: response,
|
|
30
|
+
domain: domain,
|
|
31
|
+
strength: strength
|
|
32
|
+
)
|
|
33
|
+
@patterns[pattern.id] = pattern
|
|
34
|
+
record_event(:learn, pattern_id: pattern.id)
|
|
35
|
+
pattern
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def recognize(input_cue:, domain: nil)
|
|
39
|
+
candidates = domain ? domain_patterns(domain) : @patterns.values
|
|
40
|
+
matches = candidates.filter_map do |p|
|
|
41
|
+
score = p.match_score(input_cue)
|
|
42
|
+
{ pattern: p, score: score } if score >= RECOGNITION_THRESHOLD
|
|
43
|
+
end
|
|
44
|
+
matches.sort_by { |m| -m[:score] }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def intuit(input_cue:, domain: nil)
|
|
48
|
+
matches = recognize(input_cue: input_cue, domain: domain)
|
|
49
|
+
return nil if matches.empty?
|
|
50
|
+
|
|
51
|
+
best = matches.first
|
|
52
|
+
record_event(:intuit, pattern_id: best[:pattern].id, score: best[:score])
|
|
53
|
+
{
|
|
54
|
+
response: best[:pattern].response,
|
|
55
|
+
pattern_id: best[:pattern].id,
|
|
56
|
+
confidence: best[:pattern].strength,
|
|
57
|
+
match: best[:score],
|
|
58
|
+
mode: intuition_mode(best)
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def reinforce_pattern(pattern_id:, success:)
|
|
63
|
+
pattern = @patterns[pattern_id]
|
|
64
|
+
return nil unless pattern
|
|
65
|
+
|
|
66
|
+
pattern.reinforce(success: success)
|
|
67
|
+
record_event(:reinforce, pattern_id: pattern_id, success: success)
|
|
68
|
+
pattern.strength
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def add_heuristic(name:, heuristic_type:, domain: :general)
|
|
72
|
+
return nil if @heuristics.size >= MAX_HEURISTICS
|
|
73
|
+
|
|
74
|
+
@heuristic_count += 1
|
|
75
|
+
heuristic = Heuristic.new(
|
|
76
|
+
id: :"heur_#{@heuristic_count}",
|
|
77
|
+
name: name,
|
|
78
|
+
heuristic_type: heuristic_type,
|
|
79
|
+
domain: domain
|
|
80
|
+
)
|
|
81
|
+
@heuristics[heuristic.id] = heuristic
|
|
82
|
+
heuristic
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def apply_heuristic(heuristic_id:)
|
|
86
|
+
heuristic = @heuristics[heuristic_id]
|
|
87
|
+
return nil unless heuristic
|
|
88
|
+
|
|
89
|
+
heuristic.apply
|
|
90
|
+
record_event(:apply_heuristic, heuristic_id: heuristic_id)
|
|
91
|
+
heuristic.to_h
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def record_heuristic_outcome(heuristic_id:, success:)
|
|
95
|
+
heuristic = @heuristics[heuristic_id]
|
|
96
|
+
return nil unless heuristic
|
|
97
|
+
|
|
98
|
+
heuristic.record_outcome(success: success)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def reliable_patterns
|
|
102
|
+
@patterns.values.select(&:reliable?).map(&:to_h)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def expert_patterns
|
|
106
|
+
@patterns.values.select(&:expert?).map(&:to_h)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def effective_heuristics
|
|
110
|
+
@heuristics.values.select(&:effective?).map(&:to_h)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def patterns_in(domain:)
|
|
114
|
+
domain_patterns(domain).map(&:to_h)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def decay_all
|
|
118
|
+
@patterns.each_value(&:decay)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def to_h
|
|
122
|
+
{
|
|
123
|
+
pattern_count: @patterns.size,
|
|
124
|
+
heuristic_count: @heuristics.size,
|
|
125
|
+
reliable_pattern_count: @patterns.values.count(&:reliable?),
|
|
126
|
+
expert_pattern_count: @patterns.values.count(&:expert?),
|
|
127
|
+
effective_heuristic_count: @heuristics.values.count(&:effective?),
|
|
128
|
+
history_size: @history.size
|
|
129
|
+
}
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
private
|
|
133
|
+
|
|
134
|
+
def domain_patterns(domain)
|
|
135
|
+
@patterns.values.select { |p| p.domain == domain }
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def intuition_mode(match)
|
|
139
|
+
pattern = match[:pattern]
|
|
140
|
+
return :compiled_expertise if pattern.expert?
|
|
141
|
+
return :pattern_match if pattern.reliable?
|
|
142
|
+
return :recognition_primed if match[:score] >= 0.8
|
|
143
|
+
|
|
144
|
+
:gut_feeling
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def record_event(type, **details)
|
|
148
|
+
@history << { type: type, at: Time.now.utc }.merge(details)
|
|
149
|
+
@history.shift while @history.size > MAX_HISTORY
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module Intuition
|
|
8
|
+
module Helpers
|
|
9
|
+
class Pattern
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :id, :cue, :domain, :response, :strength,
|
|
13
|
+
:encounters, :successes, :state
|
|
14
|
+
|
|
15
|
+
def initialize(id:, cue:, response:, domain: :general, strength: DEFAULT_CONFIDENCE)
|
|
16
|
+
@id = id
|
|
17
|
+
@cue = cue
|
|
18
|
+
@response = response
|
|
19
|
+
@domain = domain
|
|
20
|
+
@strength = strength.to_f.clamp(CONFIDENCE_FLOOR, CONFIDENCE_CEILING)
|
|
21
|
+
@encounters = 0
|
|
22
|
+
@successes = 0
|
|
23
|
+
@state = compute_state
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def match_score(input_cue)
|
|
27
|
+
return 0.0 unless input_cue.is_a?(Hash) && @cue.is_a?(Hash)
|
|
28
|
+
|
|
29
|
+
shared = @cue.keys & input_cue.keys
|
|
30
|
+
return 0.0 if shared.empty?
|
|
31
|
+
|
|
32
|
+
matches = shared.count { |k| @cue[k] == input_cue[k] }
|
|
33
|
+
matches.to_f / [@cue.size, input_cue.size].max
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def recognized?(input_cue)
|
|
37
|
+
match_score(input_cue) >= RECOGNITION_THRESHOLD
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def reinforce(success:)
|
|
41
|
+
@encounters += 1
|
|
42
|
+
@successes += 1 if success
|
|
43
|
+
shift = success ? REINFORCEMENT_RATE : -REINFORCEMENT_RATE
|
|
44
|
+
@strength = (@strength + shift).clamp(CONFIDENCE_FLOOR, CONFIDENCE_CEILING)
|
|
45
|
+
@state = compute_state
|
|
46
|
+
@strength
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def decay
|
|
50
|
+
@strength = (@strength - DECAY_RATE).clamp(CONFIDENCE_FLOOR, CONFIDENCE_CEILING)
|
|
51
|
+
@state = compute_state
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def success_rate
|
|
55
|
+
return 0.0 if @encounters.zero?
|
|
56
|
+
|
|
57
|
+
@successes.to_f / @encounters
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def reliable?
|
|
61
|
+
@strength >= STATE_THRESHOLDS[:reliable] && @encounters >= 3
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def expert?
|
|
65
|
+
@strength >= STATE_THRESHOLDS[:expert] && @encounters >= 10
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def confidence_label
|
|
69
|
+
CONFIDENCE_LABELS.each { |range, lbl| return lbl if range.cover?(@strength) }
|
|
70
|
+
:noise
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def to_h
|
|
74
|
+
{
|
|
75
|
+
id: @id,
|
|
76
|
+
cue: @cue,
|
|
77
|
+
response: @response,
|
|
78
|
+
domain: @domain,
|
|
79
|
+
strength: @strength.round(4),
|
|
80
|
+
encounters: @encounters,
|
|
81
|
+
successes: @successes,
|
|
82
|
+
success_rate: success_rate.round(4),
|
|
83
|
+
state: @state,
|
|
84
|
+
confidence_label: confidence_label,
|
|
85
|
+
reliable: reliable?,
|
|
86
|
+
expert: expert?
|
|
87
|
+
}
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private
|
|
91
|
+
|
|
92
|
+
def compute_state
|
|
93
|
+
return :expert if @strength >= STATE_THRESHOLDS[:expert]
|
|
94
|
+
return :reliable if @strength >= STATE_THRESHOLDS[:reliable]
|
|
95
|
+
return :developing if @strength >= STATE_THRESHOLDS[:developing]
|
|
96
|
+
|
|
97
|
+
:nascent
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module Intuition
|
|
8
|
+
module Runners
|
|
9
|
+
module Intuition
|
|
10
|
+
include Helpers::Constants
|
|
11
|
+
include Legion::Extensions::Helpers::Lex if defined?(Legion::Extensions::Helpers::Lex)
|
|
12
|
+
|
|
13
|
+
def learn_intuitive_pattern(cue:, response:, domain: :general, strength: DEFAULT_CONFIDENCE, **)
|
|
14
|
+
pattern = engine.learn_pattern(cue: cue, response: response, domain: domain, strength: strength)
|
|
15
|
+
return { success: false, reason: :limit_reached } unless pattern
|
|
16
|
+
|
|
17
|
+
{ success: true, pattern_id: pattern.id, strength: pattern.strength }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def intuitive_recognize(input_cue:, domain: nil, **)
|
|
21
|
+
matches = engine.recognize(input_cue: input_cue, domain: domain)
|
|
22
|
+
{
|
|
23
|
+
success: true,
|
|
24
|
+
matches: matches.map { |m| { pattern_id: m[:pattern].id, score: m[:score].round(4) } },
|
|
25
|
+
count: matches.size
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def intuit_response(input_cue:, domain: nil, **)
|
|
30
|
+
result = engine.intuit(input_cue: input_cue, domain: domain)
|
|
31
|
+
return { success: false, reason: :no_match } unless result
|
|
32
|
+
|
|
33
|
+
{ success: true }.merge(result)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def reinforce_intuition(pattern_id:, success:, **)
|
|
37
|
+
result = engine.reinforce_pattern(pattern_id: pattern_id, success: success)
|
|
38
|
+
return { success: false, reason: :not_found } unless result
|
|
39
|
+
|
|
40
|
+
{ success: true, pattern_id: pattern_id, strength: result.round(4) }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def add_intuitive_heuristic(name:, heuristic_type:, domain: :general, **)
|
|
44
|
+
heuristic = engine.add_heuristic(name: name, heuristic_type: heuristic_type, domain: domain)
|
|
45
|
+
return { success: false, reason: :limit_reached } unless heuristic
|
|
46
|
+
|
|
47
|
+
{ success: true, heuristic_id: heuristic.id }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def apply_intuitive_heuristic(heuristic_id:, **)
|
|
51
|
+
result = engine.apply_heuristic(heuristic_id: heuristic_id)
|
|
52
|
+
return { success: false, reason: :not_found } unless result
|
|
53
|
+
|
|
54
|
+
{ success: true }.merge(result)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def reliable_intuitions(**)
|
|
58
|
+
patterns = engine.reliable_patterns
|
|
59
|
+
{ success: true, patterns: patterns, count: patterns.size }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def expert_intuitions(**)
|
|
63
|
+
patterns = engine.expert_patterns
|
|
64
|
+
{ success: true, patterns: patterns, count: patterns.size }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def update_intuition(**)
|
|
68
|
+
engine.decay_all
|
|
69
|
+
{ success: true }.merge(engine.to_h)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def intuition_stats(**)
|
|
73
|
+
{ success: true }.merge(engine.to_h)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def engine
|
|
79
|
+
@engine ||= Helpers::IntuitionEngine.new
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/intuition/version'
|
|
4
|
+
require 'legion/extensions/agentic/inference/intuition/helpers/constants'
|
|
5
|
+
require 'legion/extensions/agentic/inference/intuition/helpers/pattern'
|
|
6
|
+
require 'legion/extensions/agentic/inference/intuition/helpers/heuristic'
|
|
7
|
+
require 'legion/extensions/agentic/inference/intuition/helpers/intuition_engine'
|
|
8
|
+
require 'legion/extensions/agentic/inference/intuition/runners/intuition'
|
|
9
|
+
require 'legion/extensions/agentic/inference/intuition/client'
|
|
10
|
+
|
|
11
|
+
module Legion
|
|
12
|
+
module Extensions
|
|
13
|
+
module Agentic
|
|
14
|
+
module Inference
|
|
15
|
+
module Intuition
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/magnet/helpers/constants'
|
|
4
|
+
require 'legion/extensions/agentic/inference/magnet/helpers/pole'
|
|
5
|
+
require 'legion/extensions/agentic/inference/magnet/helpers/field'
|
|
6
|
+
require 'legion/extensions/agentic/inference/magnet/helpers/magnet_engine'
|
|
7
|
+
require 'legion/extensions/agentic/inference/magnet/runners/cognitive_magnet'
|
|
8
|
+
|
|
9
|
+
module Legion
|
|
10
|
+
module Extensions
|
|
11
|
+
module Agentic
|
|
12
|
+
module Inference
|
|
13
|
+
module Magnet
|
|
14
|
+
class Client
|
|
15
|
+
include Runners::CognitiveMagnet
|
|
16
|
+
|
|
17
|
+
def initialize(**)
|
|
18
|
+
@magnet_engine = Helpers::MagnetEngine.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
attr_reader :magnet_engine
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module Magnet
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
POLARITY_TYPES = %i[positive negative neutral bipolar].freeze
|
|
11
|
+
MATERIAL_TYPES = %i[iron cobalt nickel lodestone ferrite].freeze
|
|
12
|
+
MAX_POLES = 500
|
|
13
|
+
MAX_FIELDS = 50
|
|
14
|
+
ATTRACTION_RATE = 0.08
|
|
15
|
+
REPULSION_RATE = 0.06
|
|
16
|
+
DECAY_RATE = 0.02
|
|
17
|
+
|
|
18
|
+
STRENGTH_LABELS = {
|
|
19
|
+
(0.0..0.1) => :negligible,
|
|
20
|
+
(0.1..0.3) => :faint,
|
|
21
|
+
(0.3..0.5) => :moderate,
|
|
22
|
+
(0.5..0.7) => :strong,
|
|
23
|
+
(0.7..0.9) => :intense,
|
|
24
|
+
(0.9..1.0) => :overwhelming
|
|
25
|
+
}.freeze
|
|
26
|
+
|
|
27
|
+
ALIGNMENT_LABELS = {
|
|
28
|
+
(0.0..0.2) => :chaotic,
|
|
29
|
+
(0.2..0.4) => :discordant,
|
|
30
|
+
(0.4..0.6) => :neutral,
|
|
31
|
+
(0.6..0.8) => :coherent,
|
|
32
|
+
(0.8..1.0) => :perfect
|
|
33
|
+
}.freeze
|
|
34
|
+
|
|
35
|
+
module_function
|
|
36
|
+
|
|
37
|
+
def label_for(table, value)
|
|
38
|
+
table.each do |range, label|
|
|
39
|
+
return label if range.cover?(value)
|
|
40
|
+
end
|
|
41
|
+
:unknown
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def valid_polarity?(polarity)
|
|
45
|
+
POLARITY_TYPES.include?(polarity)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def valid_material?(material)
|
|
49
|
+
MATERIAL_TYPES.include?(material)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Inference
|
|
9
|
+
module Magnet
|
|
10
|
+
module Helpers
|
|
11
|
+
class Field
|
|
12
|
+
attr_reader :id, :name, :pole_ids, :alignment, :flux_density, :created_at
|
|
13
|
+
|
|
14
|
+
def initialize(name:)
|
|
15
|
+
@id = SecureRandom.uuid
|
|
16
|
+
@name = name
|
|
17
|
+
@pole_ids = []
|
|
18
|
+
@alignment = 0.0
|
|
19
|
+
@flux_density = 0.0
|
|
20
|
+
@created_at = Time.now.utc
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def add_pole(pole_id)
|
|
24
|
+
return false if @pole_ids.include?(pole_id)
|
|
25
|
+
|
|
26
|
+
@pole_ids << pole_id
|
|
27
|
+
true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def remove_pole(pole_id)
|
|
31
|
+
removed = @pole_ids.delete(pole_id)
|
|
32
|
+
!removed.nil?
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def calculate_alignment!(poles)
|
|
36
|
+
field_poles = poles.values.select { |p| @pole_ids.include?(p.id) }
|
|
37
|
+
return self if field_poles.empty?
|
|
38
|
+
|
|
39
|
+
@flux_density = field_poles.sum(&:strength) / field_poles.size.to_f
|
|
40
|
+
@alignment = compute_alignment(field_poles).round(10)
|
|
41
|
+
self
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def coherent?
|
|
45
|
+
@alignment >= 0.6
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def chaotic?
|
|
49
|
+
@alignment < 0.2
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def alignment_label
|
|
53
|
+
Constants.label_for(Constants::ALIGNMENT_LABELS, @alignment)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def pole_count
|
|
57
|
+
@pole_ids.size
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def to_h
|
|
61
|
+
{
|
|
62
|
+
id: @id,
|
|
63
|
+
name: @name,
|
|
64
|
+
pole_ids: @pole_ids.dup,
|
|
65
|
+
alignment: @alignment,
|
|
66
|
+
flux_density: @flux_density,
|
|
67
|
+
pole_count: pole_count,
|
|
68
|
+
coherent: coherent?,
|
|
69
|
+
chaotic: chaotic?,
|
|
70
|
+
alignment_label: alignment_label,
|
|
71
|
+
created_at: @created_at
|
|
72
|
+
}
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def compute_alignment(field_poles)
|
|
78
|
+
return 0.0 if field_poles.size < 2
|
|
79
|
+
|
|
80
|
+
total_pairs = 0
|
|
81
|
+
aligned_weight = 0.0
|
|
82
|
+
|
|
83
|
+
field_poles.combination(2) do |a, b|
|
|
84
|
+
total_pairs += 1
|
|
85
|
+
pair_weight = (a.strength + b.strength) / 2.0
|
|
86
|
+
|
|
87
|
+
if a.attracts?(b)
|
|
88
|
+
aligned_weight += pair_weight
|
|
89
|
+
elsif a.repels?(b)
|
|
90
|
+
aligned_weight -= pair_weight * 0.5
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
return 0.5 if total_pairs.zero?
|
|
95
|
+
|
|
96
|
+
raw = aligned_weight / total_pairs.to_f
|
|
97
|
+
((raw + 1.0) / 2.0).clamp(0.0, 1.0)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|