lex-agentic-inference 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +13 -0
- data/lex-agentic-inference.gemspec +30 -0
- data/lib/legion/extensions/agentic/inference/abductive/client.rb +25 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/abduction_engine.rb +164 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/constants.rb +39 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/hypothesis.rb +106 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/observation.rb +39 -0
- data/lib/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning.rb +129 -0
- data/lib/legion/extensions/agentic/inference/abductive/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/abductive.rb +20 -0
- data/lib/legion/extensions/agentic/inference/affordance/actors/scan.rb +31 -0
- data/lib/legion/extensions/agentic/inference/affordance/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb +123 -0
- data/lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb +75 -0
- data/lib/legion/extensions/agentic/inference/affordance/helpers/constants.rb +42 -0
- data/lib/legion/extensions/agentic/inference/affordance/runners/affordance.rb +90 -0
- data/lib/legion/extensions/agentic/inference/affordance/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/affordance.rb +19 -0
- data/lib/legion/extensions/agentic/inference/analogical/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/analogical/helpers/analogy_engine.rb +209 -0
- data/lib/legion/extensions/agentic/inference/analogical/helpers/constants.rb +38 -0
- data/lib/legion/extensions/agentic/inference/analogical/helpers/structure_map.rb +113 -0
- data/lib/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning.rb +106 -0
- data/lib/legion/extensions/agentic/inference/analogical/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/analogical.rb +19 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb +102 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument_engine.rb +131 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/constants.rb +44 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping.rb +78 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping.rb +19 -0
- data/lib/legion/extensions/agentic/inference/bayesian/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/bayesian/helpers/belief.rb +96 -0
- data/lib/legion/extensions/agentic/inference/bayesian/helpers/belief_network.rb +147 -0
- data/lib/legion/extensions/agentic/inference/bayesian/helpers/constants.rb +36 -0
- data/lib/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief.rb +125 -0
- data/lib/legion/extensions/agentic/inference/bayesian/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/bayesian.rb +19 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/belief.rb +155 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/belief_network.rb +193 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/constants.rb +54 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/evidence.rb +49 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb +89 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/belief_revision.rb +21 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/client.rb +27 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb +92 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine.rb +159 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution.rb +111 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution.rb +18 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/client.rb +24 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_edge.rb +101 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_graph.rb +184 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/constants.rb +40 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning.rb +111 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning.rb +19 -0
- data/lib/legion/extensions/agentic/inference/coherence/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/coherence/helpers/coherence_engine.rb +170 -0
- data/lib/legion/extensions/agentic/inference/coherence/helpers/constants.rb +35 -0
- data/lib/legion/extensions/agentic/inference/coherence/helpers/proposition.rb +100 -0
- data/lib/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence.rb +123 -0
- data/lib/legion/extensions/agentic/inference/coherence/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/coherence.rb +19 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/helpers/constants.rb +40 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/helpers/counterfactual_engine.rb +157 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb +98 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/runners/counterfactual.rb +106 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/counterfactual.rb +19 -0
- data/lib/legion/extensions/agentic/inference/debugging/client.rb +30 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb +51 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/constants.rb +58 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/correction.rb +56 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/debugging_engine.rb +156 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/reasoning_error.rb +97 -0
- data/lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb +178 -0
- data/lib/legion/extensions/agentic/inference/debugging/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/debugging.rb +21 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/client.rb +27 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb +120 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop.rb +122 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb +124 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition.rb +18 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/client.rb +17 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/constants.rb +47 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/expectation.rb +82 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/violation_engine.rb +126 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb +76 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation.rb +19 -0
- data/lib/legion/extensions/agentic/inference/free_energy/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/free_energy/helpers/belief.rb +127 -0
- data/lib/legion/extensions/agentic/inference/free_energy/helpers/constants.rb +58 -0
- data/lib/legion/extensions/agentic/inference/free_energy/helpers/free_energy_engine.rb +156 -0
- data/lib/legion/extensions/agentic/inference/free_energy/runners/free_energy.rb +97 -0
- data/lib/legion/extensions/agentic/inference/free_energy/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/free_energy.rb +19 -0
- data/lib/legion/extensions/agentic/inference/gravity/client.rb +29 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb +77 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/constants.rb +76 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb +164 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb +64 -0
- data/lib/legion/extensions/agentic/inference/gravity/runners/gravity.rb +132 -0
- data/lib/legion/extensions/agentic/inference/gravity/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/gravity.rb +20 -0
- data/lib/legion/extensions/agentic/inference/horizon/actors/adjust.rb +45 -0
- data/lib/legion/extensions/agentic/inference/horizon/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/horizon/helpers/constants.rb +43 -0
- data/lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb +110 -0
- data/lib/legion/extensions/agentic/inference/horizon/helpers/projection.rb +59 -0
- data/lib/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon.rb +107 -0
- data/lib/legion/extensions/agentic/inference/horizon/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/horizon.rb +19 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/constants.rb +37 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb +83 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine.rb +97 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb +115 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing.rb +19 -0
- data/lib/legion/extensions/agentic/inference/intuition/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/constants.rb +60 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb +66 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb +157 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/pattern.rb +105 -0
- data/lib/legion/extensions/agentic/inference/intuition/runners/intuition.rb +87 -0
- data/lib/legion/extensions/agentic/inference/intuition/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/intuition.rb +20 -0
- data/lib/legion/extensions/agentic/inference/magnet/client.rb +29 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/constants.rb +57 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/field.rb +105 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/magnet_engine.rb +179 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb +80 -0
- data/lib/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet.rb +124 -0
- data/lib/legion/extensions/agentic/inference/magnet/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/magnet.rb +21 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/client.rb +17 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/constants.rb +65 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb +112 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb +127 -0
- data/lib/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum.rb +101 -0
- data/lib/legion/extensions/agentic/inference/momentum/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/momentum.rb +19 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/constants.rb +34 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field.rb +154 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb +100 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb +120 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference.rb +19 -0
- data/lib/legion/extensions/agentic/inference/prediction/actors/expire_predictions.rb +45 -0
- data/lib/legion/extensions/agentic/inference/prediction/client.rb +27 -0
- data/lib/legion/extensions/agentic/inference/prediction/helpers/modes.rb +28 -0
- data/lib/legion/extensions/agentic/inference/prediction/helpers/prediction_store.rb +66 -0
- data/lib/legion/extensions/agentic/inference/prediction/runners/prediction.rb +146 -0
- data/lib/legion/extensions/agentic/inference/prediction/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/prediction.rb +18 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/constants.rb +46 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/generative_model.rb +187 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb +59 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding.rb +171 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding.rb +20 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/constants.rb +35 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/generative_model.rb +142 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/predictive_processor.rb +129 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb +104 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing.rb +19 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb +98 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/helpers/constants.rb +41 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine.rb +104 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/runners/reality_testing.rb +94 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/reality_testing.rb +19 -0
- data/lib/legion/extensions/agentic/inference/schema/client.rb +26 -0
- data/lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb +70 -0
- data/lib/legion/extensions/agentic/inference/schema/helpers/constants.rb +50 -0
- data/lib/legion/extensions/agentic/inference/schema/helpers/world_model.rb +173 -0
- data/lib/legion/extensions/agentic/inference/schema/runners/schema.rb +101 -0
- data/lib/legion/extensions/agentic/inference/schema/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/schema.rb +19 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/constants.rb +42 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb +66 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/tolerance_engine.rb +139 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb +129 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance.rb +19 -0
- data/lib/legion/extensions/agentic/inference/version.rb +11 -0
- data/lib/legion/extensions/agentic/inference.rb +44 -0
- data/spec/legion/extensions/agentic/inference/abductive/client_spec.rb +25 -0
- data/spec/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning_spec.rb +349 -0
- data/spec/legion/extensions/agentic/inference/affordance/client_spec.rb +26 -0
- data/spec/legion/extensions/agentic/inference/affordance/helpers/affordance_field_spec.rb +131 -0
- data/spec/legion/extensions/agentic/inference/affordance/helpers/affordance_item_spec.rb +107 -0
- data/spec/legion/extensions/agentic/inference/affordance/runners/affordance_spec.rb +78 -0
- data/spec/legion/extensions/agentic/inference/analogical/client_spec.rb +31 -0
- data/spec/legion/extensions/agentic/inference/analogical/helpers/analogy_engine_spec.rb +276 -0
- data/spec/legion/extensions/agentic/inference/analogical/helpers/structure_map_spec.rb +255 -0
- data/spec/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning_spec.rb +213 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/client_spec.rb +18 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/helpers/argument_engine_spec.rb +218 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/helpers/argument_spec.rb +231 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping_spec.rb +171 -0
- data/spec/legion/extensions/agentic/inference/bayesian/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/inference/bayesian/helpers/belief_network_spec.rb +178 -0
- data/spec/legion/extensions/agentic/inference/bayesian/helpers/belief_spec.rb +137 -0
- data/spec/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief_spec.rb +176 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/client_spec.rb +31 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/helpers/belief_network_spec.rb +176 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/helpers/belief_spec.rb +153 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/helpers/evidence_spec.rb +51 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/runners/belief_revision_spec.rb +106 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/client_spec.rb +24 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine_spec.rb +181 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_spec.rb +108 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution_spec.rb +142 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/client_spec.rb +35 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_edge_spec.rb +158 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_graph_spec.rb +259 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning_spec.rb +161 -0
- data/spec/legion/extensions/agentic/inference/coherence/client_spec.rb +17 -0
- data/spec/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence_spec.rb +267 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/client_spec.rb +48 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/helpers/constants_spec.rb +55 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/helpers/counterfactual_engine_spec.rb +234 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/helpers/scenario_spec.rb +193 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/runners/counterfactual_spec.rb +179 -0
- data/spec/legion/extensions/agentic/inference/debugging/client_spec.rb +46 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/causal_trace_spec.rb +84 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/constants_spec.rb +97 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/correction_spec.rb +98 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/debugging_engine_spec.rb +290 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/reasoning_error_spec.rb +164 -0
- data/spec/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging_spec.rb +301 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/client_spec.rb +19 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine_spec.rb +181 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop_spec.rb +184 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition_spec.rb +214 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/expectation_violation_spec.rb +11 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/helpers/expectation_spec.rb +102 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/helpers/violation_engine_spec.rb +121 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation_spec.rb +59 -0
- data/spec/legion/extensions/agentic/inference/free_energy/client_spec.rb +46 -0
- data/spec/legion/extensions/agentic/inference/free_energy/helpers/belief_spec.rb +183 -0
- data/spec/legion/extensions/agentic/inference/free_energy/helpers/free_energy_engine_spec.rb +211 -0
- data/spec/legion/extensions/agentic/inference/free_energy/runners/free_energy_spec.rb +118 -0
- data/spec/legion/extensions/agentic/inference/gravity/client_spec.rb +24 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/attractor_spec.rb +143 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/constants_spec.rb +107 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/gravity_engine_spec.rb +193 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought_spec.rb +103 -0
- data/spec/legion/extensions/agentic/inference/gravity/runners/gravity_spec.rb +159 -0
- data/spec/legion/extensions/agentic/inference/horizon/client_spec.rb +58 -0
- data/spec/legion/extensions/agentic/inference/horizon/helpers/constants_spec.rb +98 -0
- data/spec/legion/extensions/agentic/inference/horizon/helpers/horizon_engine_spec.rb +325 -0
- data/spec/legion/extensions/agentic/inference/horizon/helpers/projection_spec.rb +155 -0
- data/spec/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon_spec.rb +269 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/constants_spec.rb +38 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine_spec.rb +182 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_spec.rb +172 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/hypothesis_testing_spec.rb +16 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing_spec.rb +159 -0
- data/spec/legion/extensions/agentic/inference/intuition/client_spec.rb +33 -0
- data/spec/legion/extensions/agentic/inference/intuition/helpers/heuristic_spec.rb +82 -0
- data/spec/legion/extensions/agentic/inference/intuition/helpers/intuition_engine_spec.rb +163 -0
- data/spec/legion/extensions/agentic/inference/intuition/helpers/pattern_spec.rb +160 -0
- data/spec/legion/extensions/agentic/inference/intuition/runners/intuition_spec.rb +107 -0
- data/spec/legion/extensions/agentic/inference/magnet/client_spec.rb +30 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/constants_spec.rb +120 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/field_spec.rb +193 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/magnet_engine_spec.rb +281 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/pole_spec.rb +211 -0
- data/spec/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet_spec.rb +201 -0
- data/spec/legion/extensions/agentic/inference/momentum/cognitive_momentum_spec.rb +11 -0
- data/spec/legion/extensions/agentic/inference/momentum/helpers/idea_spec.rb +152 -0
- data/spec/legion/extensions/agentic/inference/momentum/helpers/momentum_engine_spec.rb +154 -0
- data/spec/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum_spec.rb +97 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/client_spec.rb +39 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/constants_spec.rb +97 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field_spec.rb +270 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis_spec.rb +206 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference_spec.rb +305 -0
- data/spec/legion/extensions/agentic/inference/prediction/actors/expire_predictions_spec.rb +46 -0
- data/spec/legion/extensions/agentic/inference/prediction/client_spec.rb +14 -0
- data/spec/legion/extensions/agentic/inference/prediction/helpers/modes_spec.rb +118 -0
- data/spec/legion/extensions/agentic/inference/prediction/helpers/prediction_store_spec.rb +262 -0
- data/spec/legion/extensions/agentic/inference/prediction/runners/prediction_spec.rb +116 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/client_spec.rb +74 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/helpers/generative_model_spec.rb +194 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error_spec.rb +109 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding_spec.rb +210 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/client_spec.rb +82 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/helpers/generative_model_spec.rb +220 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/helpers/predictive_processor_spec.rb +206 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing_spec.rb +213 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/client_spec.rb +29 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/helpers/belief_spec.rb +197 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/helpers/constants_spec.rb +78 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine_spec.rb +191 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/runners/reality_testing_spec.rb +154 -0
- data/spec/legion/extensions/agentic/inference/schema/client_spec.rb +53 -0
- data/spec/legion/extensions/agentic/inference/schema/helpers/causal_relation_spec.rb +108 -0
- data/spec/legion/extensions/agentic/inference/schema/helpers/constants_spec.rb +54 -0
- data/spec/legion/extensions/agentic/inference/schema/helpers/world_model_spec.rb +179 -0
- data/spec/legion/extensions/agentic/inference/schema/runners/schema_spec.rb +146 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/client_spec.rb +18 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/constants_spec.rb +62 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision_spec.rb +125 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/tolerance_engine_spec.rb +184 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance_spec.rb +157 -0
- data/spec/spec_helper.rb +46 -0
- metadata +412 -0
data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine_spec.rb
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::CausalAttribution::Helpers::AttributionEngine do
|
|
4
|
+
subject(:engine) { described_class.new }
|
|
5
|
+
|
|
6
|
+
let(:basic_args) do
|
|
7
|
+
{
|
|
8
|
+
event: 'task completed',
|
|
9
|
+
outcome: :success,
|
|
10
|
+
domain: :work,
|
|
11
|
+
locus: :internal,
|
|
12
|
+
stability: :stable,
|
|
13
|
+
controllability: :controllable
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe '#create_attribution' do
|
|
18
|
+
it 'returns an Attribution object' do
|
|
19
|
+
result = engine.create_attribution(**basic_args)
|
|
20
|
+
expect(result).to be_a(Legion::Extensions::Agentic::Inference::CausalAttribution::Helpers::Attribution)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'stores the attribution' do
|
|
24
|
+
engine.create_attribution(**basic_args)
|
|
25
|
+
expect(engine.count).to eq(1)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'accepts optional confidence' do
|
|
29
|
+
attr = engine.create_attribution(**basic_args, confidence: 0.9)
|
|
30
|
+
expect(attr.confidence).to eq(0.9)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe '#reattribute' do
|
|
35
|
+
let!(:attr) { engine.create_attribution(**basic_args) }
|
|
36
|
+
|
|
37
|
+
it 'updates locus when provided' do
|
|
38
|
+
result = engine.reattribute(attribution_id: attr.id, locus: :external)
|
|
39
|
+
expect(result.locus).to eq(:external)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'preserves unchanged dimensions' do
|
|
43
|
+
result = engine.reattribute(attribution_id: attr.id, locus: :external)
|
|
44
|
+
expect(result.stability).to eq(:stable)
|
|
45
|
+
expect(result.controllability).to eq(:controllable)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'updates the emotional_response after reattribution' do
|
|
49
|
+
result = engine.reattribute(attribution_id: attr.id, locus: :external)
|
|
50
|
+
expect(result.emotional_response).to eq(:anger)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'returns not found hash for unknown id' do
|
|
54
|
+
result = engine.reattribute(attribution_id: 'nonexistent')
|
|
55
|
+
expect(result[:found]).to be false
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe '#by_pattern' do
|
|
60
|
+
before do
|
|
61
|
+
engine.create_attribution(**basic_args)
|
|
62
|
+
engine.create_attribution(**basic_args, locus: :external)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'filters by locus' do
|
|
66
|
+
results = engine.by_pattern(locus: :internal)
|
|
67
|
+
expect(results.size).to eq(1)
|
|
68
|
+
expect(results.first.locus).to eq(:internal)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'returns all when no filter given' do
|
|
72
|
+
expect(engine.by_pattern.size).to eq(2)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe '#by_domain' do
|
|
77
|
+
before do
|
|
78
|
+
engine.create_attribution(**basic_args)
|
|
79
|
+
engine.create_attribution(**basic_args, domain: :personal)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'returns only matching domain' do
|
|
83
|
+
results = engine.by_domain(domain: :work)
|
|
84
|
+
expect(results.size).to eq(1)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe '#by_outcome' do
|
|
89
|
+
before do
|
|
90
|
+
engine.create_attribution(**basic_args)
|
|
91
|
+
engine.create_attribution(**basic_args, outcome: :failure)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'returns only matching outcome' do
|
|
95
|
+
results = engine.by_outcome(outcome: :failure)
|
|
96
|
+
expect(results.size).to eq(1)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe '#attribution_bias' do
|
|
101
|
+
it 'returns bias hash with detection key' do
|
|
102
|
+
engine.create_attribution(**basic_args)
|
|
103
|
+
result = engine.attribution_bias
|
|
104
|
+
expect(result).to have_key(:self_serving_bias_detected)
|
|
105
|
+
expect(result).to have_key(:external_failure_ratio)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'detects self-serving bias when failures are mostly external' do
|
|
109
|
+
3.times do
|
|
110
|
+
engine.create_attribution(**basic_args, outcome: :failure, locus: :external, stability: :unstable, controllability: :controllable)
|
|
111
|
+
end
|
|
112
|
+
result = engine.attribution_bias
|
|
113
|
+
expect(result[:self_serving_bias_detected]).to be true
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'returns no attributions message when empty' do
|
|
117
|
+
result = engine.attribution_bias
|
|
118
|
+
expect(result[:bias]).to eq(:none)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
describe '#emotional_profile' do
|
|
123
|
+
before do
|
|
124
|
+
engine.create_attribution(**basic_args)
|
|
125
|
+
engine.create_attribution(**basic_args, locus: :external, stability: :unstable)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it 'returns distribution and dominant' do
|
|
129
|
+
result = engine.emotional_profile
|
|
130
|
+
expect(result).to have_key(:distribution)
|
|
131
|
+
expect(result).to have_key(:dominant)
|
|
132
|
+
expect(result[:total]).to eq(2)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe '#most_common_pattern' do
|
|
137
|
+
before do
|
|
138
|
+
2.times { engine.create_attribution(**basic_args) }
|
|
139
|
+
engine.create_attribution(**basic_args, locus: :external)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'returns the most frequent pattern' do
|
|
143
|
+
result = engine.most_common_pattern
|
|
144
|
+
expect(result[:pattern]).to eq(%i[internal stable controllable])
|
|
145
|
+
expect(result[:count]).to eq(2)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it 'returns nil pattern when empty' do
|
|
149
|
+
expect(described_class.new.most_common_pattern[:pattern]).to be_nil
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
describe '#decay_all' do
|
|
154
|
+
it 'reduces confidence on all attributions' do
|
|
155
|
+
engine.create_attribution(**basic_args, confidence: 0.8)
|
|
156
|
+
engine.decay_all
|
|
157
|
+
expect(engine.by_pattern.first.confidence).to be < 0.8
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it 'returns count of decayed entries' do
|
|
161
|
+
2.times { engine.create_attribution(**basic_args) }
|
|
162
|
+
expect(engine.decay_all).to eq(2)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it 'floors at CONFIDENCE_FLOOR' do
|
|
166
|
+
attr = engine.create_attribution(**basic_args, confidence: 0.001)
|
|
167
|
+
engine.decay_all
|
|
168
|
+
expect(attr.confidence).to be >= Legion::Extensions::Agentic::Inference::CausalAttribution::Helpers::Attribution::CONFIDENCE_FLOOR
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
describe '#to_h' do
|
|
173
|
+
it 'includes stats keys' do
|
|
174
|
+
engine.create_attribution(**basic_args)
|
|
175
|
+
h = engine.to_h
|
|
176
|
+
expect(h).to have_key(:total_attributions)
|
|
177
|
+
expect(h).to have_key(:outcome_counts)
|
|
178
|
+
expect(h).to have_key(:locus_counts)
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::CausalAttribution::Helpers::Attribution do
|
|
4
|
+
subject(:attr) do
|
|
5
|
+
described_class.new(
|
|
6
|
+
event: 'task failed',
|
|
7
|
+
outcome: :failure,
|
|
8
|
+
domain: :work,
|
|
9
|
+
locus: :internal,
|
|
10
|
+
stability: :stable,
|
|
11
|
+
controllability: :controllable
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe '#initialize' do
|
|
16
|
+
it 'assigns an id' do
|
|
17
|
+
expect(attr.id).to match(/\A[0-9a-f-]{36}\z/)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'stores all dimensions' do
|
|
21
|
+
expect(attr.locus).to eq(:internal)
|
|
22
|
+
expect(attr.stability).to eq(:stable)
|
|
23
|
+
expect(attr.controllability).to eq(:controllable)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'derives emotional_response from ATTRIBUTION_EMOTIONS' do
|
|
27
|
+
expect(attr.emotional_response).to eq(:guilt)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'uses DEFAULT_CONFIDENCE when none given' do
|
|
31
|
+
expect(attr.confidence).to eq(described_class::DEFAULT_CONFIDENCE)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'clamps confidence to ceiling' do
|
|
35
|
+
high = described_class.new(
|
|
36
|
+
event: 'x', outcome: :success, domain: :test,
|
|
37
|
+
locus: :external, stability: :unstable, controllability: :uncontrollable,
|
|
38
|
+
confidence: 5.0
|
|
39
|
+
)
|
|
40
|
+
expect(high.confidence).to eq(1.0)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'clamps confidence to floor' do
|
|
44
|
+
low = described_class.new(
|
|
45
|
+
event: 'x', outcome: :success, domain: :test,
|
|
46
|
+
locus: :external, stability: :unstable, controllability: :uncontrollable,
|
|
47
|
+
confidence: -1.0
|
|
48
|
+
)
|
|
49
|
+
expect(low.confidence).to eq(0.0)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'records created_at' do
|
|
53
|
+
expect(attr.created_at).to be_a(Time)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe '#pattern' do
|
|
58
|
+
it 'returns [locus, stability, controllability] tuple' do
|
|
59
|
+
expect(attr.pattern).to eq(%i[internal stable controllable])
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe 'predicates' do
|
|
64
|
+
it 'internal? returns true for internal locus' do
|
|
65
|
+
expect(attr.internal?).to be true
|
|
66
|
+
expect(attr.external?).to be false
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'stable? returns true for stable stability' do
|
|
70
|
+
expect(attr.stable?).to be true
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'controllable? returns true for controllable controllability' do
|
|
74
|
+
expect(attr.controllable?).to be true
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe 'ATTRIBUTION_EMOTIONS mapping' do
|
|
79
|
+
{
|
|
80
|
+
%i[internal stable controllable] => :guilt,
|
|
81
|
+
%i[internal stable uncontrollable] => :shame,
|
|
82
|
+
%i[internal unstable controllable] => :regret,
|
|
83
|
+
%i[internal unstable uncontrollable] => :surprise,
|
|
84
|
+
%i[external stable controllable] => :anger,
|
|
85
|
+
%i[external stable uncontrollable] => :helplessness,
|
|
86
|
+
%i[external unstable controllable] => :frustration,
|
|
87
|
+
%i[external unstable uncontrollable] => :relief
|
|
88
|
+
}.each do |pattern, emotion|
|
|
89
|
+
it "maps #{pattern.inspect} to #{emotion}" do
|
|
90
|
+
a = described_class.new(
|
|
91
|
+
event: 'e', outcome: :neutral, domain: :test,
|
|
92
|
+
locus: pattern[0], stability: pattern[1], controllability: pattern[2]
|
|
93
|
+
)
|
|
94
|
+
expect(a.emotional_response).to eq(emotion)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe '#to_h' do
|
|
100
|
+
it 'includes all required keys' do
|
|
101
|
+
h = attr.to_h
|
|
102
|
+
%i[id event outcome domain locus stability controllability
|
|
103
|
+
confidence emotional_response created_at].each do |key|
|
|
104
|
+
expect(h).to have_key(key)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
data/spec/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution_spec.rb
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/causal_attribution/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::CausalAttribution::Runners::CausalAttribution do
|
|
6
|
+
let(:client) { Legion::Extensions::Agentic::Inference::CausalAttribution::Client.new }
|
|
7
|
+
|
|
8
|
+
let(:base_args) do
|
|
9
|
+
{
|
|
10
|
+
event: 'missed deadline',
|
|
11
|
+
outcome: :failure,
|
|
12
|
+
domain: :work,
|
|
13
|
+
locus: :internal,
|
|
14
|
+
stability: :stable,
|
|
15
|
+
controllability: :controllable
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe '#create_causal_attribution' do
|
|
20
|
+
it 'returns success true' do
|
|
21
|
+
result = client.create_causal_attribution(**base_args)
|
|
22
|
+
expect(result[:success]).to be true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'includes attribution hash' do
|
|
26
|
+
result = client.create_causal_attribution(**base_args)
|
|
27
|
+
expect(result[:attribution]).to have_key(:id)
|
|
28
|
+
expect(result[:attribution][:emotional_response]).to eq(:guilt)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'accepts string locus and coerces to symbol' do
|
|
32
|
+
result = client.create_causal_attribution(**base_args, locus: 'external')
|
|
33
|
+
expect(result[:attribution][:locus]).to eq(:external)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe '#reattribute_cause' do
|
|
38
|
+
let!(:id) { client.create_causal_attribution(**base_args)[:attribution][:id] }
|
|
39
|
+
|
|
40
|
+
it 'updates the attribution' do
|
|
41
|
+
result = client.reattribute_cause(attribution_id: id, locus: :external)
|
|
42
|
+
expect(result[:success]).to be true
|
|
43
|
+
expect(result[:attribution][:locus]).to eq(:external)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'returns success false for unknown id' do
|
|
47
|
+
result = client.reattribute_cause(attribution_id: 'bad-id')
|
|
48
|
+
expect(result[:success]).to be false
|
|
49
|
+
expect(result[:found]).to be false
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe '#attributions_by_pattern' do
|
|
54
|
+
before do
|
|
55
|
+
client.create_causal_attribution(**base_args)
|
|
56
|
+
client.create_causal_attribution(**base_args, locus: :external)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'filters by locus' do
|
|
60
|
+
result = client.attributions_by_pattern(locus: :internal)
|
|
61
|
+
expect(result[:count]).to eq(1)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'returns all when no filter given' do
|
|
65
|
+
result = client.attributions_by_pattern
|
|
66
|
+
expect(result[:count]).to eq(2)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe '#domain_attributions' do
|
|
71
|
+
before { client.create_causal_attribution(**base_args) }
|
|
72
|
+
|
|
73
|
+
it 'returns attributions for domain' do
|
|
74
|
+
result = client.domain_attributions(domain: :work)
|
|
75
|
+
expect(result[:count]).to be >= 1
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe '#outcome_attributions' do
|
|
80
|
+
before do
|
|
81
|
+
client.create_causal_attribution(**base_args)
|
|
82
|
+
client.create_causal_attribution(**base_args, outcome: :success)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'returns attributions by outcome' do
|
|
86
|
+
result = client.outcome_attributions(outcome: :failure)
|
|
87
|
+
expect(result[:count]).to eq(1)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe '#attribution_bias_assessment' do
|
|
92
|
+
before { client.create_causal_attribution(**base_args) }
|
|
93
|
+
|
|
94
|
+
it 'returns bias structure' do
|
|
95
|
+
result = client.attribution_bias_assessment
|
|
96
|
+
expect(result[:success]).to be true
|
|
97
|
+
expect(result[:bias]).to have_key(:self_serving_bias_detected)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe '#emotional_attribution_profile' do
|
|
102
|
+
before { client.create_causal_attribution(**base_args) }
|
|
103
|
+
|
|
104
|
+
it 'returns profile with dominant emotion' do
|
|
105
|
+
result = client.emotional_attribution_profile
|
|
106
|
+
expect(result[:success]).to be true
|
|
107
|
+
expect(result[:profile]).to have_key(:dominant)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
describe '#most_common_attribution' do
|
|
112
|
+
before do
|
|
113
|
+
2.times { client.create_causal_attribution(**base_args) }
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'returns the most frequent pattern' do
|
|
117
|
+
result = client.most_common_attribution
|
|
118
|
+
expect(result[:success]).to be true
|
|
119
|
+
expect(result[:count]).to eq(2)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
describe '#update_causal_attribution' do
|
|
124
|
+
before { client.create_causal_attribution(**base_args, confidence: 0.8) }
|
|
125
|
+
|
|
126
|
+
it 'decays confidence and reports count' do
|
|
127
|
+
result = client.update_causal_attribution
|
|
128
|
+
expect(result[:success]).to be true
|
|
129
|
+
expect(result[:decayed]).to eq(1)
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
describe '#causal_attribution_stats' do
|
|
134
|
+
before { client.create_causal_attribution(**base_args) }
|
|
135
|
+
|
|
136
|
+
it 'returns stats hash' do
|
|
137
|
+
result = client.causal_attribution_stats
|
|
138
|
+
expect(result[:success]).to be true
|
|
139
|
+
expect(result[:stats][:total_attributions]).to eq(1)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/causal_reasoning/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::CausalReasoning::Client do
|
|
6
|
+
let(:client) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'responds to all runner methods' do
|
|
9
|
+
expect(client).to respond_to(:add_causal_variable)
|
|
10
|
+
expect(client).to respond_to(:add_causal_edge)
|
|
11
|
+
expect(client).to respond_to(:find_causes)
|
|
12
|
+
expect(client).to respond_to(:find_effects)
|
|
13
|
+
expect(client).to respond_to(:trace_causal_chain)
|
|
14
|
+
expect(client).to respond_to(:causal_intervention)
|
|
15
|
+
expect(client).to respond_to(:find_confounders)
|
|
16
|
+
expect(client).to respond_to(:add_causal_evidence)
|
|
17
|
+
expect(client).to respond_to(:update_causal_reasoning)
|
|
18
|
+
expect(client).to respond_to(:causal_reasoning_stats)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'accepts an injected graph' do
|
|
22
|
+
injected_graph = Legion::Extensions::Agentic::Inference::CausalReasoning::Helpers::CausalGraph.new
|
|
23
|
+
injected_graph.add_edge(cause: :a, effect: :b, edge_type: :causes)
|
|
24
|
+
client_with_graph = described_class.new(graph: injected_graph)
|
|
25
|
+
result = client_with_graph.causal_reasoning_stats
|
|
26
|
+
expect(result[:edges]).to eq(1)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'maintains isolated state between instances' do
|
|
30
|
+
c1 = described_class.new
|
|
31
|
+
c2 = described_class.new
|
|
32
|
+
c1.add_causal_edge(cause: :a, effect: :b, edge_type: :causes)
|
|
33
|
+
expect(c2.causal_reasoning_stats[:edges]).to eq(0)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/causal_reasoning/client'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Inference::CausalReasoning::Helpers::CausalEdge do
|
|
6
|
+
subject(:edge) do
|
|
7
|
+
described_class.new(cause: :rain, effect: :wet_grass, edge_type: :causes, domain: :weather)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe '#initialize' do
|
|
11
|
+
it 'sets cause and effect' do
|
|
12
|
+
expect(edge.cause).to eq(:rain)
|
|
13
|
+
expect(edge.effect).to eq(:wet_grass)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'sets edge_type and domain' do
|
|
17
|
+
expect(edge.edge_type).to eq(:causes)
|
|
18
|
+
expect(edge.domain).to eq(:weather)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'clamps strength to STRENGTH_FLOOR..STRENGTH_CEILING' do
|
|
22
|
+
over = described_class.new(cause: :a, effect: :b, edge_type: :causes, strength: 2.0)
|
|
23
|
+
under = described_class.new(cause: :a, effect: :b, edge_type: :causes, strength: 0.0)
|
|
24
|
+
expect(over.strength).to eq(Legion::Extensions::Agentic::Inference::CausalReasoning::Helpers::Constants::STRENGTH_CEILING)
|
|
25
|
+
expect(under.strength).to eq(Legion::Extensions::Agentic::Inference::CausalReasoning::Helpers::Constants::STRENGTH_FLOOR)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'starts with evidence_count of zero' do
|
|
29
|
+
expect(edge.evidence_count).to eq(0)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'assigns a unique id' do
|
|
33
|
+
other = described_class.new(cause: :rain, effect: :wet_grass, edge_type: :causes)
|
|
34
|
+
expect(edge.id).not_to eq(other.id)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe '#add_evidence' do
|
|
39
|
+
it 'increments evidence_count' do
|
|
40
|
+
edge.add_evidence
|
|
41
|
+
expect(edge.evidence_count).to eq(1)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'increases strength' do
|
|
45
|
+
before = edge.strength
|
|
46
|
+
edge.add_evidence
|
|
47
|
+
expect(edge.strength).to be > before
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'returns self' do
|
|
51
|
+
expect(edge.add_evidence).to be(edge)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'does not exceed STRENGTH_CEILING' do
|
|
55
|
+
100.times { edge.add_evidence }
|
|
56
|
+
expect(edge.strength).to eq(Legion::Extensions::Agentic::Inference::CausalReasoning::Helpers::Constants::STRENGTH_CEILING)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe '#remove_evidence' do
|
|
61
|
+
it 'decrements evidence_count but not below zero' do
|
|
62
|
+
edge.remove_evidence
|
|
63
|
+
expect(edge.evidence_count).to eq(0)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'decreases strength' do
|
|
67
|
+
before = edge.strength
|
|
68
|
+
edge.remove_evidence
|
|
69
|
+
expect(edge.strength).to be < before
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'does not go below STRENGTH_FLOOR' do
|
|
73
|
+
100.times { edge.remove_evidence }
|
|
74
|
+
expect(edge.strength).to eq(Legion::Extensions::Agentic::Inference::CausalReasoning::Helpers::Constants::STRENGTH_FLOOR)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe '#reinforce' do
|
|
79
|
+
it 'increases strength by given amount' do
|
|
80
|
+
before = edge.strength
|
|
81
|
+
edge.reinforce(amount: 0.2)
|
|
82
|
+
expect(edge.strength).to be_within(0.001).of(before + 0.2)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'clamps at STRENGTH_CEILING' do
|
|
86
|
+
edge.reinforce(amount: 1.0)
|
|
87
|
+
expect(edge.strength).to eq(Legion::Extensions::Agentic::Inference::CausalReasoning::Helpers::Constants::STRENGTH_CEILING)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe '#weaken' do
|
|
92
|
+
it 'decreases strength by given amount' do
|
|
93
|
+
before = edge.strength
|
|
94
|
+
edge.weaken(amount: 0.1)
|
|
95
|
+
expect(edge.strength).to be_within(0.001).of(before - 0.1)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'clamps at STRENGTH_FLOOR' do
|
|
99
|
+
edge.weaken(amount: 1.0)
|
|
100
|
+
expect(edge.strength).to eq(Legion::Extensions::Agentic::Inference::CausalReasoning::Helpers::Constants::STRENGTH_FLOOR)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe '#decay' do
|
|
105
|
+
it 'reduces strength by DECAY_RATE' do
|
|
106
|
+
before = edge.strength
|
|
107
|
+
edge.decay
|
|
108
|
+
expect(edge.strength).to be_within(0.001).of(before - Legion::Extensions::Agentic::Inference::CausalReasoning::Helpers::Constants::DECAY_RATE)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'does not go below STRENGTH_FLOOR' do
|
|
112
|
+
100.times { edge.decay }
|
|
113
|
+
expect(edge.strength).to eq(Legion::Extensions::Agentic::Inference::CausalReasoning::Helpers::Constants::STRENGTH_FLOOR)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe '#confident?' do
|
|
118
|
+
it 'returns false when evidence_count is below EVIDENCE_THRESHOLD' do
|
|
119
|
+
expect(edge.confident?).to be false
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'returns true when both strength and evidence_count meet thresholds' do
|
|
123
|
+
3.times { edge.add_evidence }
|
|
124
|
+
edge.reinforce(amount: 0.2)
|
|
125
|
+
expect(edge.confident?).to be true
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
describe '#confidence_label' do
|
|
130
|
+
it 'returns :speculative for low strength' do
|
|
131
|
+
edge.weaken(amount: 1.0)
|
|
132
|
+
expect(edge.confidence_label).to eq(:speculative)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it 'returns :moderate for strength around 0.7' do
|
|
136
|
+
strong_edge = described_class.new(cause: :a, effect: :b, edge_type: :causes, strength: 0.7)
|
|
137
|
+
expect(strong_edge.confidence_label).to eq(:moderate)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'returns :strong for strength >= 0.8' do
|
|
141
|
+
strong_edge = described_class.new(cause: :a, effect: :b, edge_type: :causes, strength: 0.9)
|
|
142
|
+
expect(strong_edge.confidence_label).to eq(:strong)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
describe '#to_h' do
|
|
147
|
+
it 'includes all key fields' do
|
|
148
|
+
hash = edge.to_h
|
|
149
|
+
expect(hash).to include(:id, :cause, :effect, :edge_type, :domain,
|
|
150
|
+
:strength, :evidence_count, :confident, :label,
|
|
151
|
+
:created_at, :updated_at)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it 'reflects confident? state' do
|
|
155
|
+
expect(edge.to_h[:confident]).to be false
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|