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,193 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module BeliefRevision
|
|
8
|
+
module Helpers
|
|
9
|
+
class BeliefNetwork
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :beliefs, :links, :history
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@beliefs = {}
|
|
16
|
+
@links = []
|
|
17
|
+
@counter = 0
|
|
18
|
+
@ev_count = 0
|
|
19
|
+
@history = []
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def add_belief(proposition:, domain: :general, credence: DEFAULT_CREDENCE)
|
|
23
|
+
return nil if @beliefs.size >= MAX_BELIEFS
|
|
24
|
+
|
|
25
|
+
@counter += 1
|
|
26
|
+
belief_id = :"belief_#{@counter}"
|
|
27
|
+
belief = Belief.new(id: belief_id, proposition: proposition, domain: domain, credence: credence)
|
|
28
|
+
@beliefs[belief_id] = belief
|
|
29
|
+
belief
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def add_evidence(belief_id:, evidence_type:, content:, direction: :support, weight: EVIDENCE_WEIGHT,
|
|
33
|
+
source: :unknown)
|
|
34
|
+
belief = @beliefs[belief_id]
|
|
35
|
+
return nil unless belief
|
|
36
|
+
|
|
37
|
+
@ev_count += 1
|
|
38
|
+
ev = Evidence.new(id: :"ev_#{@ev_count}", evidence_type: evidence_type,
|
|
39
|
+
content: content, weight: weight, source: source)
|
|
40
|
+
result = direction == :support ? belief.add_supporting_evidence(ev) : belief.add_opposing_evidence(ev)
|
|
41
|
+
propagate_evidence(belief_id, direction) if result
|
|
42
|
+
record_event(:evidence, belief_id: belief_id, direction: direction)
|
|
43
|
+
result
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def link_beliefs(from_id:, to_id:, link_type:)
|
|
47
|
+
return nil unless @beliefs.key?(from_id) && @beliefs.key?(to_id)
|
|
48
|
+
return nil unless LINK_TYPES.include?(link_type)
|
|
49
|
+
return nil if @links.size >= MAX_LINKS
|
|
50
|
+
|
|
51
|
+
link = { from: from_id, to: to_id, type: link_type }
|
|
52
|
+
@links << link
|
|
53
|
+
link
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def revise_belief(belief_id:, new_credence:)
|
|
57
|
+
belief = @beliefs[belief_id]
|
|
58
|
+
return nil unless belief
|
|
59
|
+
|
|
60
|
+
belief.revise(new_credence: new_credence)
|
|
61
|
+
record_event(:revision, belief_id: belief_id, new_credence: new_credence)
|
|
62
|
+
belief
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def contradictions
|
|
66
|
+
pairs = []
|
|
67
|
+
ids = @beliefs.keys
|
|
68
|
+
ids.combination(2) do |a, b|
|
|
69
|
+
pairs << [a, b] if @beliefs[a].contradicts?(@beliefs[b]) && linked?(a, b)
|
|
70
|
+
end
|
|
71
|
+
pairs
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def beliefs_in(domain:)
|
|
75
|
+
@beliefs.values.select { |b| b.domain == domain }.map(&:to_h)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def believed
|
|
79
|
+
@beliefs.values.select(&:believed?).map(&:to_h)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def disbelieved
|
|
83
|
+
@beliefs.values.select(&:disbelieved?).map(&:to_h)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def entrenched
|
|
87
|
+
@beliefs.values.select { |b| b.state == :entrenched }.map(&:to_h)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def supported_beliefs(belief_id:)
|
|
91
|
+
linked_ids = @links.select { |l| l[:from] == belief_id && l[:type] == :supports }.map { |l| l[:to] }
|
|
92
|
+
linked_ids.filter_map { |id| @beliefs[id]&.to_h }
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def undermining_beliefs(belief_id:)
|
|
96
|
+
linked_ids = @links.select { |l| l[:to] == belief_id && l[:type] == :undermines }.map { |l| l[:from] }
|
|
97
|
+
linked_ids.filter_map { |id| @beliefs[id]&.to_h }
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def decay_all
|
|
101
|
+
@beliefs.each_value(&:decay)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def coherence_score
|
|
105
|
+
return 1.0 if @links.empty?
|
|
106
|
+
|
|
107
|
+
coherent = @links.count { |l| link_coherent?(l) }
|
|
108
|
+
coherent.to_f / @links.size
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def to_h
|
|
112
|
+
{
|
|
113
|
+
belief_count: @beliefs.size,
|
|
114
|
+
link_count: @links.size,
|
|
115
|
+
believed_count: @beliefs.values.count(&:believed?),
|
|
116
|
+
disbelieved_count: @beliefs.values.count(&:disbelieved?),
|
|
117
|
+
entrenched_count: @beliefs.values.count { |b| b.state == :entrenched },
|
|
118
|
+
contradiction_count: contradictions.size,
|
|
119
|
+
coherence: coherence_score.round(4),
|
|
120
|
+
history_size: @history.size
|
|
121
|
+
}
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
PROPAGATION_SIGNS = {
|
|
125
|
+
%i[supports support] => 1,
|
|
126
|
+
%i[supports oppose] => -1,
|
|
127
|
+
%i[undermines support] => -1,
|
|
128
|
+
%i[undermines oppose] => 1
|
|
129
|
+
}.freeze
|
|
130
|
+
|
|
131
|
+
private
|
|
132
|
+
|
|
133
|
+
def propagate_evidence(belief_id, direction)
|
|
134
|
+
@links.each do |link|
|
|
135
|
+
next unless link[:from] == belief_id
|
|
136
|
+
|
|
137
|
+
target = @beliefs[link[:to]]
|
|
138
|
+
next unless target
|
|
139
|
+
|
|
140
|
+
apply_propagation(target, link[:type], direction)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def apply_propagation(target, link_type, direction)
|
|
145
|
+
return if target.protected?
|
|
146
|
+
|
|
147
|
+
shift = propagation_shift(link_type, direction)
|
|
148
|
+
return if shift.zero?
|
|
149
|
+
|
|
150
|
+
target.revise(new_credence: target.credence + shift)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def propagation_shift(link_type, direction)
|
|
154
|
+
sign = PROPAGATION_SIGNS.fetch([link_type, direction], 0)
|
|
155
|
+
EVIDENCE_WEIGHT * 0.5 * sign
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def linked?(id_a, id_b)
|
|
159
|
+
@links.any? do |l|
|
|
160
|
+
(l[:from] == id_a && l[:to] == id_b) || (l[:from] == id_b && l[:to] == id_a)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def link_coherent?(link)
|
|
165
|
+
from = @beliefs[link[:from]]
|
|
166
|
+
to = @beliefs[link[:to]]
|
|
167
|
+
return true unless from && to
|
|
168
|
+
|
|
169
|
+
check_link_coherence(from, to, link[:type])
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def check_link_coherence(from, to, type)
|
|
173
|
+
return support_coherent?(from, to) if type == :supports
|
|
174
|
+
return from.believed? != to.believed? if type == :undermines
|
|
175
|
+
|
|
176
|
+
true
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def support_coherent?(from, to)
|
|
180
|
+
from.believed? == to.believed?
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def record_event(type, **details)
|
|
184
|
+
@history << { type: type, at: Time.now.utc }.merge(details)
|
|
185
|
+
@history.shift while @history.size > MAX_HISTORY
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module BeliefRevision
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
MAX_BELIEFS = 200
|
|
11
|
+
MAX_EVIDENCE_PER_BELIEF = 50
|
|
12
|
+
MAX_LINKS = 500
|
|
13
|
+
MAX_HISTORY = 300
|
|
14
|
+
|
|
15
|
+
DEFAULT_CREDENCE = 0.5
|
|
16
|
+
CREDENCE_FLOOR = 0.01
|
|
17
|
+
CREDENCE_CEILING = 0.99
|
|
18
|
+
ENTRENCHMENT_ALPHA = 0.05
|
|
19
|
+
EVIDENCE_WEIGHT = 0.15
|
|
20
|
+
DECAY_RATE = 0.005
|
|
21
|
+
CONTRADICTION_THRESHOLD = 0.3
|
|
22
|
+
|
|
23
|
+
EVIDENCE_TYPES = %i[
|
|
24
|
+
observation testimony inference analogy
|
|
25
|
+
authority memory simulation
|
|
26
|
+
].freeze
|
|
27
|
+
|
|
28
|
+
LINK_TYPES = %i[supports undermines entails independent].freeze
|
|
29
|
+
|
|
30
|
+
BELIEF_STATES = %i[
|
|
31
|
+
tentative held entrenched protected
|
|
32
|
+
].freeze
|
|
33
|
+
|
|
34
|
+
CREDENCE_LABELS = {
|
|
35
|
+
(0.9..) => :near_certain,
|
|
36
|
+
(0.7...0.9) => :confident,
|
|
37
|
+
(0.5...0.7) => :leaning,
|
|
38
|
+
(0.3...0.5) => :uncertain,
|
|
39
|
+
(0.1...0.3) => :doubtful,
|
|
40
|
+
(..0.1) => :disbelieved
|
|
41
|
+
}.freeze
|
|
42
|
+
|
|
43
|
+
STATE_THRESHOLDS = {
|
|
44
|
+
entrenched: 0.85,
|
|
45
|
+
held: 0.6,
|
|
46
|
+
tentative: 0.3
|
|
47
|
+
}.freeze
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module BeliefRevision
|
|
8
|
+
module Helpers
|
|
9
|
+
class Evidence
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :id, :evidence_type, :content, :weight, :source, :created_at
|
|
13
|
+
|
|
14
|
+
def initialize(id:, evidence_type:, content:, weight: EVIDENCE_WEIGHT, source: :unknown)
|
|
15
|
+
raise ArgumentError, "invalid type: #{evidence_type}" unless EVIDENCE_TYPES.include?(evidence_type)
|
|
16
|
+
|
|
17
|
+
@id = id
|
|
18
|
+
@evidence_type = evidence_type
|
|
19
|
+
@content = content
|
|
20
|
+
@weight = weight.to_f.clamp(0.0, 1.0)
|
|
21
|
+
@source = source
|
|
22
|
+
@created_at = Time.now.utc
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def strong?
|
|
26
|
+
@weight >= 0.5
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def weak?
|
|
30
|
+
@weight < 0.2
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_h
|
|
34
|
+
{
|
|
35
|
+
id: @id,
|
|
36
|
+
evidence_type: @evidence_type,
|
|
37
|
+
content: @content,
|
|
38
|
+
weight: @weight.round(4),
|
|
39
|
+
source: @source,
|
|
40
|
+
created_at: @created_at
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module BeliefRevision
|
|
8
|
+
module Runners
|
|
9
|
+
module BeliefRevision
|
|
10
|
+
include Helpers::Constants
|
|
11
|
+
include Legion::Extensions::Helpers::Lex if defined?(Legion::Extensions::Helpers::Lex)
|
|
12
|
+
|
|
13
|
+
def add_belief(proposition:, domain: :general, credence: DEFAULT_CREDENCE, **)
|
|
14
|
+
belief = network.add_belief(proposition: proposition, domain: domain, credence: credence)
|
|
15
|
+
return { success: false, reason: :limit_reached } unless belief
|
|
16
|
+
|
|
17
|
+
{ success: true, belief_id: belief.id, credence: belief.credence.round(4) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def submit_evidence(belief_id:, evidence_type:, content:, direction: :support,
|
|
21
|
+
weight: EVIDENCE_WEIGHT, source: :unknown, **)
|
|
22
|
+
ev = network.add_evidence(
|
|
23
|
+
belief_id: belief_id, evidence_type: evidence_type, content: content,
|
|
24
|
+
direction: direction, weight: weight, source: source
|
|
25
|
+
)
|
|
26
|
+
return { success: false, reason: :not_found_or_full } unless ev
|
|
27
|
+
|
|
28
|
+
belief = network.beliefs[belief_id]
|
|
29
|
+
{ success: true, evidence_id: ev.id, belief_credence: belief.credence.round(4) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def link_beliefs(from_id:, to_id:, link_type:, **)
|
|
33
|
+
result = network.link_beliefs(from_id: from_id, to_id: to_id, link_type: link_type)
|
|
34
|
+
return { success: false, reason: :invalid_or_limit } unless result
|
|
35
|
+
|
|
36
|
+
{ success: true, from: from_id, to: to_id, link_type: link_type }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def revise_belief(belief_id:, new_credence:, **)
|
|
40
|
+
belief = network.revise_belief(belief_id: belief_id, new_credence: new_credence)
|
|
41
|
+
return { success: false, reason: :not_found } unless belief
|
|
42
|
+
|
|
43
|
+
{ success: true, belief_id: belief_id, credence: belief.credence.round(4), state: belief.state }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def belief_status(belief_id:, **)
|
|
47
|
+
belief = network.beliefs[belief_id]
|
|
48
|
+
return { success: false, reason: :not_found } unless belief
|
|
49
|
+
|
|
50
|
+
{ success: true }.merge(belief.to_h)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def find_contradictions(**)
|
|
54
|
+
pairs = network.contradictions
|
|
55
|
+
{ success: true, contradictions: pairs, count: pairs.size }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def beliefs_in_domain(domain:, **)
|
|
59
|
+
beliefs = network.beliefs_in(domain: domain)
|
|
60
|
+
{ success: true, beliefs: beliefs, count: beliefs.size }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def coherence_report(**)
|
|
64
|
+
{ success: true, coherence: network.coherence_score.round(4),
|
|
65
|
+
believed: network.believed.size, disbelieved: network.disbelieved.size,
|
|
66
|
+
entrenched: network.entrenched.size, contradictions: network.contradictions.size }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def update_belief_revision(**)
|
|
70
|
+
network.decay_all
|
|
71
|
+
{ success: true }.merge(network.to_h)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def belief_revision_stats(**)
|
|
75
|
+
{ success: true }.merge(network.to_h)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def network
|
|
81
|
+
@network ||= Helpers::BeliefNetwork.new
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'belief_revision/version'
|
|
4
|
+
require_relative 'belief_revision/helpers/constants'
|
|
5
|
+
require_relative 'belief_revision/helpers/belief'
|
|
6
|
+
require_relative 'belief_revision/helpers/belief_network'
|
|
7
|
+
require_relative 'belief_revision/helpers/evidence'
|
|
8
|
+
require_relative 'belief_revision/runners/belief_revision'
|
|
9
|
+
require_relative 'belief_revision/client'
|
|
10
|
+
|
|
11
|
+
module Legion
|
|
12
|
+
module Extensions
|
|
13
|
+
module Agentic
|
|
14
|
+
module Inference
|
|
15
|
+
module BeliefRevision
|
|
16
|
+
# Sub-module for belief revision: AGM contraction, expansion, and revision
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/causal_attribution/helpers/attribution'
|
|
4
|
+
require 'legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine'
|
|
5
|
+
require 'legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution'
|
|
6
|
+
|
|
7
|
+
module Legion
|
|
8
|
+
module Extensions
|
|
9
|
+
module Agentic
|
|
10
|
+
module Inference
|
|
11
|
+
module CausalAttribution
|
|
12
|
+
class Client
|
|
13
|
+
include Runners::CausalAttribution
|
|
14
|
+
|
|
15
|
+
def initialize(**)
|
|
16
|
+
@engine = Helpers::AttributionEngine.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
attr_reader :engine
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Inference
|
|
9
|
+
module CausalAttribution
|
|
10
|
+
module Helpers
|
|
11
|
+
class Attribution
|
|
12
|
+
MAX_ATTRIBUTIONS = 200
|
|
13
|
+
MAX_HISTORY = 300
|
|
14
|
+
|
|
15
|
+
LOCUS_VALUES = %i[internal external].freeze
|
|
16
|
+
STABILITY_VALUES = %i[stable unstable].freeze
|
|
17
|
+
CONTROLLABILITY_VALUES = %i[controllable uncontrollable].freeze
|
|
18
|
+
|
|
19
|
+
DEFAULT_CONFIDENCE = 0.5
|
|
20
|
+
CONFIDENCE_FLOOR = 0.0
|
|
21
|
+
CONFIDENCE_CEILING = 1.0
|
|
22
|
+
DECAY_RATE = 0.02
|
|
23
|
+
|
|
24
|
+
ATTRIBUTION_EMOTIONS = {
|
|
25
|
+
%i[internal stable controllable] => :guilt,
|
|
26
|
+
%i[internal stable uncontrollable] => :shame,
|
|
27
|
+
%i[internal unstable controllable] => :regret,
|
|
28
|
+
%i[internal unstable uncontrollable] => :surprise,
|
|
29
|
+
%i[external stable controllable] => :anger,
|
|
30
|
+
%i[external stable uncontrollable] => :helplessness,
|
|
31
|
+
%i[external unstable controllable] => :frustration,
|
|
32
|
+
%i[external unstable uncontrollable] => :relief
|
|
33
|
+
}.freeze
|
|
34
|
+
|
|
35
|
+
attr_reader :id, :event, :outcome, :domain, :locus, :stability, :controllability,
|
|
36
|
+
:confidence, :emotional_response, :created_at
|
|
37
|
+
|
|
38
|
+
def initialize(event:, outcome:, domain:, locus:, stability:, controllability:,
|
|
39
|
+
confidence: DEFAULT_CONFIDENCE)
|
|
40
|
+
@id = SecureRandom.uuid
|
|
41
|
+
@event = event
|
|
42
|
+
@outcome = outcome
|
|
43
|
+
@domain = domain
|
|
44
|
+
@locus = locus
|
|
45
|
+
@stability = stability
|
|
46
|
+
@controllability = controllability
|
|
47
|
+
@confidence = confidence.clamp(CONFIDENCE_FLOOR, CONFIDENCE_CEILING)
|
|
48
|
+
@emotional_response = ATTRIBUTION_EMOTIONS[pattern]
|
|
49
|
+
@created_at = Time.now.utc
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def pattern
|
|
53
|
+
[locus, stability, controllability]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def internal?
|
|
57
|
+
locus == :internal
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def external?
|
|
61
|
+
locus == :external
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def stable?
|
|
65
|
+
stability == :stable
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def controllable?
|
|
69
|
+
controllability == :controllable
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def to_h
|
|
73
|
+
{
|
|
74
|
+
id: id,
|
|
75
|
+
event: event,
|
|
76
|
+
outcome: outcome,
|
|
77
|
+
domain: domain,
|
|
78
|
+
locus: locus,
|
|
79
|
+
stability: stability,
|
|
80
|
+
controllability: controllability,
|
|
81
|
+
confidence: confidence,
|
|
82
|
+
emotional_response: emotional_response,
|
|
83
|
+
created_at: created_at
|
|
84
|
+
}
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|