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,113 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Inference
|
|
9
|
+
module Analogical
|
|
10
|
+
module Helpers
|
|
11
|
+
class StructureMap
|
|
12
|
+
include Constants
|
|
13
|
+
|
|
14
|
+
attr_reader :id, :source_domain, :target_domain, :mappings, :mapping_type, :times_used, :created_at,
|
|
15
|
+
:last_used_at, :strength
|
|
16
|
+
|
|
17
|
+
def initialize(source_domain:, target_domain:, mappings:, mapping_type:, strength: nil)
|
|
18
|
+
@id = SecureRandom.uuid
|
|
19
|
+
@source_domain = source_domain
|
|
20
|
+
@target_domain = target_domain
|
|
21
|
+
@mappings = mappings
|
|
22
|
+
@mapping_type = mapping_type
|
|
23
|
+
@strength = (strength || Constants::DEFAULT_STRENGTH).clamp(
|
|
24
|
+
Constants::STRENGTH_FLOOR,
|
|
25
|
+
Constants::STRENGTH_CEILING
|
|
26
|
+
)
|
|
27
|
+
@times_used = 0
|
|
28
|
+
@created_at = Time.now.utc
|
|
29
|
+
@last_used_at = Time.now.utc
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def structural_score
|
|
33
|
+
return 0.0 if mappings.empty?
|
|
34
|
+
|
|
35
|
+
relational_count = mappings.count { |_src, tgt| tgt.is_a?(Hash) && tgt[:type] == :relational }
|
|
36
|
+
relational_count.to_f / mappings.size
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def surface_score
|
|
40
|
+
return 0.0 if mappings.empty?
|
|
41
|
+
|
|
42
|
+
attribute_count = mappings.count { |_src, tgt| !(tgt.is_a?(Hash) && tgt[:type] == :relational) }
|
|
43
|
+
attribute_count.to_f / mappings.size
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def similarity_score
|
|
47
|
+
(Constants::STRUCTURAL_WEIGHT * structural_score) +
|
|
48
|
+
(Constants::SURFACE_WEIGHT * surface_score)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def use!
|
|
52
|
+
@times_used += 1
|
|
53
|
+
@last_used_at = Time.now.utc
|
|
54
|
+
reinforce(amount: Constants::REINFORCEMENT_RATE * 0.5)
|
|
55
|
+
self
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def reinforce(amount: Constants::REINFORCEMENT_RATE)
|
|
59
|
+
@strength = (@strength + amount).clamp(Constants::STRENGTH_FLOOR, Constants::STRENGTH_CEILING)
|
|
60
|
+
self
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def weaken(amount: Constants::REINFORCEMENT_RATE)
|
|
64
|
+
@strength = (@strength - amount).clamp(Constants::STRENGTH_FLOOR, Constants::STRENGTH_CEILING)
|
|
65
|
+
self
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def decay
|
|
69
|
+
@strength = (@strength - Constants::DECAY_RATE).clamp(Constants::STRENGTH_FLOOR, Constants::STRENGTH_CEILING)
|
|
70
|
+
self
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def state
|
|
74
|
+
thresholds = Constants::STATE_THRESHOLDS
|
|
75
|
+
if @strength >= thresholds[:productive]
|
|
76
|
+
:productive
|
|
77
|
+
elsif @strength >= thresholds[:validated]
|
|
78
|
+
:validated
|
|
79
|
+
elsif @strength >= thresholds[:candidate]
|
|
80
|
+
:candidate
|
|
81
|
+
else
|
|
82
|
+
:stale
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def productive?
|
|
87
|
+
state == :productive
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def to_h
|
|
91
|
+
{
|
|
92
|
+
id: @id,
|
|
93
|
+
source_domain: @source_domain,
|
|
94
|
+
target_domain: @target_domain,
|
|
95
|
+
mappings: @mappings,
|
|
96
|
+
mapping_type: @mapping_type,
|
|
97
|
+
strength: @strength,
|
|
98
|
+
structural_score: structural_score,
|
|
99
|
+
surface_score: surface_score,
|
|
100
|
+
similarity_score: similarity_score,
|
|
101
|
+
state: state,
|
|
102
|
+
times_used: @times_used,
|
|
103
|
+
created_at: @created_at,
|
|
104
|
+
last_used_at: @last_used_at
|
|
105
|
+
}
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module Analogical
|
|
8
|
+
module Runners
|
|
9
|
+
module AnalogicalReasoning
|
|
10
|
+
def create_analogy(source_domain:, target_domain:, mappings:, mapping_type: :relational, strength: nil, **)
|
|
11
|
+
unless Helpers::Constants::MAPPING_TYPES.include?(mapping_type)
|
|
12
|
+
return { success: false, error: :invalid_mapping_type,
|
|
13
|
+
valid_types: Helpers::Constants::MAPPING_TYPES }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
analogy = engine.create_analogy(
|
|
17
|
+
source_domain: source_domain,
|
|
18
|
+
target_domain: target_domain,
|
|
19
|
+
mappings: mappings,
|
|
20
|
+
mapping_type: mapping_type,
|
|
21
|
+
strength: strength
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
Legion::Logging.debug "[analogical_reasoning] created analogy id=#{analogy.id[0..7]} " \
|
|
25
|
+
"#{source_domain}->#{target_domain} type=#{mapping_type}"
|
|
26
|
+
|
|
27
|
+
{ success: true, analogy_id: analogy.id, source_domain: source_domain,
|
|
28
|
+
target_domain: target_domain, mapping_type: mapping_type,
|
|
29
|
+
strength: analogy.strength, state: analogy.state }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def find_analogies(domain:, **)
|
|
33
|
+
analogies = engine.find_analogies(domain: domain)
|
|
34
|
+
Legion::Logging.debug "[analogical_reasoning] find domain=#{domain} count=#{analogies.size}"
|
|
35
|
+
{ success: true, domain: domain, analogies: analogies.map(&:to_h), count: analogies.size }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def apply_analogy(analogy_id:, source_element:, **)
|
|
39
|
+
result = engine.apply_analogy(analogy_id: analogy_id, source_element: source_element)
|
|
40
|
+
|
|
41
|
+
Legion::Logging.debug "[analogical_reasoning] apply id=#{analogy_id[0..7]} " \
|
|
42
|
+
"element=#{source_element} mapped=#{result[:mapped]}"
|
|
43
|
+
|
|
44
|
+
{ success: true }.merge(result)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def evaluate_similarity(source:, target:, **)
|
|
48
|
+
score = engine.evaluate_similarity(source: source, target: target)
|
|
49
|
+
above_threshold = score >= Helpers::Constants::SIMILARITY_THRESHOLD
|
|
50
|
+
|
|
51
|
+
Legion::Logging.debug "[analogical_reasoning] similarity=#{score.round(3)} " \
|
|
52
|
+
"above_threshold=#{above_threshold}"
|
|
53
|
+
|
|
54
|
+
{ success: true, similarity_score: score, above_threshold: above_threshold,
|
|
55
|
+
threshold: Helpers::Constants::SIMILARITY_THRESHOLD }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def cross_domain_transfer(analogy_id:, source_knowledge:, **)
|
|
59
|
+
result = engine.cross_domain_transfer(analogy_id: analogy_id, source_knowledge: source_knowledge)
|
|
60
|
+
|
|
61
|
+
Legion::Logging.debug "[analogical_reasoning] transfer id=#{analogy_id[0..7]} " \
|
|
62
|
+
"transferred=#{result[:transferred]} coverage=#{result[:coverage]&.round(2)}"
|
|
63
|
+
|
|
64
|
+
{ success: true }.merge(result)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def reinforce_analogy(analogy_id:, success:, **)
|
|
68
|
+
result = engine.reinforce_analogy(analogy_id: analogy_id, success: success)
|
|
69
|
+
|
|
70
|
+
Legion::Logging.debug "[analogical_reasoning] reinforce id=#{analogy_id[0..7]} " \
|
|
71
|
+
"success=#{success} new_state=#{result[:state]}"
|
|
72
|
+
|
|
73
|
+
{ success: true }.merge(result)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def productive_analogies(**)
|
|
77
|
+
analogies = engine.productive_analogies
|
|
78
|
+
Legion::Logging.debug "[analogical_reasoning] productive count=#{analogies.size}"
|
|
79
|
+
{ success: true, analogies: analogies.map(&:to_h), count: analogies.size }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def update_analogical_reasoning(**)
|
|
83
|
+
engine.decay_all
|
|
84
|
+
pruned = engine.prune_stale
|
|
85
|
+
Legion::Logging.debug "[analogical_reasoning] decay+prune pruned=#{pruned}"
|
|
86
|
+
{ success: true, pruned: pruned }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def analogical_reasoning_stats(**)
|
|
90
|
+
stats = engine.to_h
|
|
91
|
+
Legion::Logging.debug "[analogical_reasoning] stats total=#{stats[:total_analogies]}"
|
|
92
|
+
{ success: true }.merge(stats)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
private
|
|
96
|
+
|
|
97
|
+
def engine
|
|
98
|
+
@engine ||= Helpers::AnalogyEngine.new
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/analogical/version'
|
|
4
|
+
require 'legion/extensions/agentic/inference/analogical/helpers/constants'
|
|
5
|
+
require 'legion/extensions/agentic/inference/analogical/helpers/structure_map'
|
|
6
|
+
require 'legion/extensions/agentic/inference/analogical/helpers/analogy_engine'
|
|
7
|
+
require 'legion/extensions/agentic/inference/analogical/runners/analogical_reasoning'
|
|
8
|
+
require 'legion/extensions/agentic/inference/analogical/client'
|
|
9
|
+
|
|
10
|
+
module Legion
|
|
11
|
+
module Extensions
|
|
12
|
+
module Agentic
|
|
13
|
+
module Inference
|
|
14
|
+
module Analogical
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'runners/argument_mapping'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Inference
|
|
9
|
+
module ArgumentMapping
|
|
10
|
+
class Client
|
|
11
|
+
include Runners::ArgumentMapping
|
|
12
|
+
|
|
13
|
+
def initialize(**); end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module ArgumentMapping
|
|
8
|
+
module Helpers
|
|
9
|
+
class Argument
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :id, :claim, :grounds, :warrant, :backing,
|
|
13
|
+
:qualifier, :rebuttals, :created_at, :domain
|
|
14
|
+
|
|
15
|
+
def initialize(id:, claim:, domain: :general, warrant: nil, qualifier: :presumably)
|
|
16
|
+
@id = id
|
|
17
|
+
@claim = claim
|
|
18
|
+
@domain = domain
|
|
19
|
+
@warrant = warrant
|
|
20
|
+
@qualifier = qualifier
|
|
21
|
+
@grounds = []
|
|
22
|
+
@backing = []
|
|
23
|
+
@rebuttals = []
|
|
24
|
+
@created_at = Time.now.utc
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def add_ground(ground:)
|
|
28
|
+
@grounds << ground
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def add_backing(backing:)
|
|
32
|
+
@backing << backing
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def add_rebuttal(content:, impact: 0.5)
|
|
36
|
+
@rebuttals << { content: content, impact: impact.clamp(0.0, 1.0) }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def strength
|
|
40
|
+
raw = (ground_score * GROUND_WEIGHT) +
|
|
41
|
+
(warrant_score * WARRANT_WEIGHT) +
|
|
42
|
+
(backing_score * BACKING_WEIGHT) -
|
|
43
|
+
(rebuttal_score * REBUTTAL_PENALTY)
|
|
44
|
+
raw.clamp(0.0, 1.0)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def strength_label
|
|
48
|
+
ARGUMENT_STRENGTHS.find { |range, _| range.cover?(strength) }&.last
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def sound?
|
|
52
|
+
strength >= 0.6 && !@warrant.nil? && !@grounds.empty?
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def rebutted?
|
|
56
|
+
@rebuttals.any? { |r| r[:impact] > 0.5 }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def to_h
|
|
60
|
+
{
|
|
61
|
+
id: @id,
|
|
62
|
+
claim: @claim,
|
|
63
|
+
domain: @domain,
|
|
64
|
+
grounds: @grounds,
|
|
65
|
+
warrant: @warrant,
|
|
66
|
+
backing: @backing,
|
|
67
|
+
qualifier: @qualifier,
|
|
68
|
+
rebuttals: @rebuttals,
|
|
69
|
+
strength: strength,
|
|
70
|
+
strength_label: strength_label,
|
|
71
|
+
sound: sound?,
|
|
72
|
+
rebutted: rebutted?,
|
|
73
|
+
created_at: @created_at
|
|
74
|
+
}
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
def ground_score
|
|
80
|
+
[@grounds.size / 3.0, 1.0].min
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def warrant_score
|
|
84
|
+
@warrant.nil? ? 0.0 : 0.8
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def backing_score
|
|
88
|
+
[@backing.size / 2.0, 1.0].min
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def rebuttal_score
|
|
92
|
+
return 0.0 if @rebuttals.empty?
|
|
93
|
+
|
|
94
|
+
@rebuttals.sum { |r| r[:impact] } / @rebuttals.size
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module ArgumentMapping
|
|
8
|
+
module Helpers
|
|
9
|
+
class ArgumentEngine
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :arguments, :history
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@arguments = {}
|
|
16
|
+
@history = []
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def create_argument(claim:, domain: :general, warrant: nil, qualifier: :presumably)
|
|
20
|
+
return { success: false, reason: :max_arguments_reached } if @arguments.size >= MAX_ARGUMENTS
|
|
21
|
+
|
|
22
|
+
id = generate_id('arg')
|
|
23
|
+
argument = Argument.new(id: id, claim: claim, domain: domain,
|
|
24
|
+
warrant: warrant, qualifier: qualifier)
|
|
25
|
+
@arguments[id] = argument
|
|
26
|
+
add_history(type: :created, argument_id: id, claim: claim, domain: domain)
|
|
27
|
+
{ success: true, argument: argument.to_h }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def add_ground(argument_id:, ground:)
|
|
31
|
+
argument = @arguments[argument_id]
|
|
32
|
+
return { success: false, reason: :not_found } unless argument
|
|
33
|
+
|
|
34
|
+
argument.add_ground(ground: ground)
|
|
35
|
+
add_history(type: :ground_added, argument_id: argument_id)
|
|
36
|
+
{ success: true, argument: argument.to_h }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def add_backing(argument_id:, backing:)
|
|
40
|
+
argument = @arguments[argument_id]
|
|
41
|
+
return { success: false, reason: :not_found } unless argument
|
|
42
|
+
|
|
43
|
+
argument.add_backing(backing: backing)
|
|
44
|
+
add_history(type: :backing_added, argument_id: argument_id)
|
|
45
|
+
{ success: true, argument: argument.to_h }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def add_rebuttal(argument_id:, content:, impact: 0.5)
|
|
49
|
+
argument = @arguments[argument_id]
|
|
50
|
+
return { success: false, reason: :not_found } unless argument
|
|
51
|
+
|
|
52
|
+
argument.add_rebuttal(content: content, impact: impact)
|
|
53
|
+
add_history(type: :rebuttal_added, argument_id: argument_id, impact: impact)
|
|
54
|
+
{ success: true, argument: argument.to_h }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def assess_argument(argument_id:)
|
|
58
|
+
argument = @arguments[argument_id]
|
|
59
|
+
return { success: false, reason: :not_found } unless argument
|
|
60
|
+
|
|
61
|
+
{
|
|
62
|
+
success: true,
|
|
63
|
+
argument_id: argument_id,
|
|
64
|
+
claim: argument.claim,
|
|
65
|
+
domain: argument.domain,
|
|
66
|
+
strength: argument.strength,
|
|
67
|
+
strength_label: argument.strength_label,
|
|
68
|
+
sound: argument.sound?,
|
|
69
|
+
rebutted: argument.rebutted?,
|
|
70
|
+
ground_count: argument.grounds.size,
|
|
71
|
+
backing_count: argument.backing.size,
|
|
72
|
+
rebuttal_count: argument.rebuttals.size
|
|
73
|
+
}
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def sound_arguments
|
|
77
|
+
@arguments.values.select(&:sound?)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def rebutted_arguments
|
|
81
|
+
@arguments.values.select(&:rebutted?)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def arguments_by_domain(domain:)
|
|
85
|
+
@arguments.values.select { |a| a.domain == domain }
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def strongest_arguments(limit: 5)
|
|
89
|
+
@arguments.values.sort_by { |a| -a.strength }.first(limit)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def weakest_arguments(limit: 5)
|
|
93
|
+
@arguments.values.sort_by(&:strength).first(limit)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def decay_all
|
|
97
|
+
@arguments.each_value do |argument|
|
|
98
|
+
next unless argument.instance_variable_defined?(:@base_strength)
|
|
99
|
+
|
|
100
|
+
current = argument.instance_variable_get(:@base_strength)
|
|
101
|
+
argument.instance_variable_set(:@base_strength, [current - DECAY_RATE, 0.0].max)
|
|
102
|
+
end
|
|
103
|
+
@arguments.size
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def to_h
|
|
107
|
+
{
|
|
108
|
+
total_arguments: @arguments.size,
|
|
109
|
+
sound_arguments: sound_arguments.size,
|
|
110
|
+
rebutted_arguments: rebutted_arguments.size,
|
|
111
|
+
history_entries: @history.size
|
|
112
|
+
}
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private
|
|
116
|
+
|
|
117
|
+
def add_history(entry)
|
|
118
|
+
@history << entry.merge(timestamp: Time.now.utc)
|
|
119
|
+
@history.shift if @history.size > MAX_HISTORY
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def generate_id(prefix)
|
|
123
|
+
"#{prefix}_#{Time.now.utc.to_f}_#{rand(10_000)}"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module ArgumentMapping
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
ARGUMENT_STRENGTHS = {
|
|
11
|
+
(0.8..) => :compelling,
|
|
12
|
+
(0.6...0.8) => :strong,
|
|
13
|
+
(0.4...0.6) => :moderate,
|
|
14
|
+
(0.2...0.4) => :weak,
|
|
15
|
+
(..0.2) => :fallacious
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
QUALIFIER_TYPES = %i[certainly presumably probably possibly apparently].freeze
|
|
19
|
+
|
|
20
|
+
REBUTTAL_IMPACT_LABELS = {
|
|
21
|
+
(0.8..) => :devastating,
|
|
22
|
+
(0.6...0.8) => :significant,
|
|
23
|
+
(0.4...0.6) => :moderate,
|
|
24
|
+
(0.2...0.4) => :minor,
|
|
25
|
+
(..0.2) => :negligible
|
|
26
|
+
}.freeze
|
|
27
|
+
|
|
28
|
+
MAX_ARGUMENTS = 200
|
|
29
|
+
MAX_HISTORY = 500
|
|
30
|
+
|
|
31
|
+
DEFAULT_STRENGTH = 0.5
|
|
32
|
+
GROUND_WEIGHT = 0.3
|
|
33
|
+
WARRANT_WEIGHT = 0.3
|
|
34
|
+
BACKING_WEIGHT = 0.2
|
|
35
|
+
REBUTTAL_PENALTY = 0.2
|
|
36
|
+
|
|
37
|
+
DECAY_RATE = 0.02
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module ArgumentMapping
|
|
8
|
+
module Runners
|
|
9
|
+
module ArgumentMapping
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
11
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
12
|
+
|
|
13
|
+
def create_argument(claim:, domain: :general, warrant: nil, qualifier: :presumably, **)
|
|
14
|
+
Legion::Logging.info "[argument_mapping] create_argument: claim=#{claim} domain=#{domain}"
|
|
15
|
+
engine.create_argument(claim: claim, domain: domain, warrant: warrant, qualifier: qualifier)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_argument_ground(argument_id:, ground:, **)
|
|
19
|
+
Legion::Logging.debug "[argument_mapping] add_ground: id=#{argument_id}"
|
|
20
|
+
engine.add_ground(argument_id: argument_id, ground: ground)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def add_argument_backing(argument_id:, backing:, **)
|
|
24
|
+
Legion::Logging.debug "[argument_mapping] add_backing: id=#{argument_id}"
|
|
25
|
+
engine.add_backing(argument_id: argument_id, backing: backing)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def add_argument_rebuttal(argument_id:, content:, impact: 0.5, **)
|
|
29
|
+
Legion::Logging.info "[argument_mapping] add_rebuttal: id=#{argument_id} impact=#{impact}"
|
|
30
|
+
engine.add_rebuttal(argument_id: argument_id, content: content, impact: impact)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def assess_argument_strength(argument_id:, **)
|
|
34
|
+
Legion::Logging.debug "[argument_mapping] assess: id=#{argument_id}"
|
|
35
|
+
engine.assess_argument(argument_id: argument_id)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def sound_arguments_report(**)
|
|
39
|
+
Legion::Logging.debug '[argument_mapping] sound_arguments_report'
|
|
40
|
+
arguments = engine.sound_arguments
|
|
41
|
+
{ success: true, arguments: arguments.map(&:to_h), count: arguments.size }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def rebutted_arguments_report(**)
|
|
45
|
+
Legion::Logging.debug '[argument_mapping] rebutted_arguments_report'
|
|
46
|
+
arguments = engine.rebutted_arguments
|
|
47
|
+
{ success: true, arguments: arguments.map(&:to_h), count: arguments.size }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def strongest_arguments_report(limit: 5, **)
|
|
51
|
+
Legion::Logging.debug "[argument_mapping] strongest_arguments: limit=#{limit}"
|
|
52
|
+
arguments = engine.strongest_arguments(limit: limit)
|
|
53
|
+
{ success: true, arguments: arguments.map(&:to_h), count: arguments.size }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def update_argument_mapping(**)
|
|
57
|
+
Legion::Logging.debug '[argument_mapping] decay_all'
|
|
58
|
+
decayed = engine.decay_all
|
|
59
|
+
{ success: true, arguments_processed: decayed }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def argument_mapping_stats(**)
|
|
63
|
+
Legion::Logging.debug '[argument_mapping] stats'
|
|
64
|
+
{ success: true }.merge(engine.to_h)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def engine
|
|
70
|
+
@engine ||= Helpers::ArgumentEngine.new
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'argument_mapping/version'
|
|
4
|
+
require_relative 'argument_mapping/helpers/constants'
|
|
5
|
+
require_relative 'argument_mapping/helpers/argument'
|
|
6
|
+
require_relative 'argument_mapping/helpers/argument_engine'
|
|
7
|
+
require_relative 'argument_mapping/runners/argument_mapping'
|
|
8
|
+
require_relative 'argument_mapping/client'
|
|
9
|
+
|
|
10
|
+
module Legion
|
|
11
|
+
module Extensions
|
|
12
|
+
module Agentic
|
|
13
|
+
module Inference
|
|
14
|
+
module ArgumentMapping
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|