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,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/affordance/helpers/constants'
|
|
4
|
+
require 'legion/extensions/agentic/inference/affordance/helpers/affordance_item'
|
|
5
|
+
require 'legion/extensions/agentic/inference/affordance/helpers/affordance_field'
|
|
6
|
+
require 'legion/extensions/agentic/inference/affordance/runners/affordance'
|
|
7
|
+
|
|
8
|
+
module Legion
|
|
9
|
+
module Extensions
|
|
10
|
+
module Agentic
|
|
11
|
+
module Inference
|
|
12
|
+
module Affordance
|
|
13
|
+
class Client
|
|
14
|
+
include Runners::Affordance
|
|
15
|
+
|
|
16
|
+
def initialize(field: nil, **)
|
|
17
|
+
@field = field || Helpers::AffordanceField.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
attr_reader :field
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module Affordance
|
|
8
|
+
module Helpers
|
|
9
|
+
class AffordanceField
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :affordances, :capabilities, :environment
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@affordances = {}
|
|
16
|
+
@capabilities = {}
|
|
17
|
+
@environment = {}
|
|
18
|
+
@counter = 0
|
|
19
|
+
@history = []
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def register_capability(name:, domain: :general, level: 1.0)
|
|
23
|
+
return nil if @capabilities.size >= MAX_CAPABILITIES
|
|
24
|
+
|
|
25
|
+
@capabilities[name] = { domain: domain, level: level.to_f.clamp(0.0, 1.0) }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def set_environment(property:, value:, domain: :general)
|
|
29
|
+
return nil if @environment.size >= MAX_ENVIRONMENT_PROPS && !@environment.key?(property)
|
|
30
|
+
|
|
31
|
+
@environment[property] = { value: value, domain: domain, updated_at: Time.now.utc }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def detect_affordance(action:, domain:, affordance_type:, requires: [], relevance: DEFAULT_RELEVANCE)
|
|
35
|
+
return nil unless AFFORDANCE_TYPES.include?(affordance_type)
|
|
36
|
+
return nil if @affordances.size >= MAX_AFFORDANCES
|
|
37
|
+
|
|
38
|
+
@counter += 1
|
|
39
|
+
aff_id = :"aff_#{@counter}"
|
|
40
|
+
aff = AffordanceItem.new(
|
|
41
|
+
id: aff_id, action: action, domain: domain,
|
|
42
|
+
affordance_type: affordance_type, requires: requires, relevance: relevance
|
|
43
|
+
)
|
|
44
|
+
@affordances[aff_id] = aff
|
|
45
|
+
record_detection(aff)
|
|
46
|
+
aff
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def evaluate_action(action:, domain:)
|
|
50
|
+
matching = @affordances.values.select { |a| a.action == action && a.domain == domain }
|
|
51
|
+
return { feasible: false, reason: :no_affordance } if matching.empty?
|
|
52
|
+
|
|
53
|
+
check_blockers(matching) || build_evaluation(matching)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def actionable_affordances
|
|
57
|
+
@affordances.values.select(&:actionable?).sort_by { |a| -a.relevance }.map(&:to_h)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def threats
|
|
61
|
+
@affordances.values.select(&:threatening?).map(&:to_h)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def affordances_in(domain:)
|
|
65
|
+
@affordances.values.select { |a| a.domain == domain }.map(&:to_h)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def decay_all
|
|
69
|
+
@affordances.each_value(&:decay)
|
|
70
|
+
@affordances.reject! { |_, a| a.faded? }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def to_h
|
|
74
|
+
{
|
|
75
|
+
affordance_count: @affordances.size,
|
|
76
|
+
capability_count: @capabilities.size,
|
|
77
|
+
environment_props: @environment.size,
|
|
78
|
+
actionable_count: @affordances.values.count(&:actionable?),
|
|
79
|
+
blocked_count: @affordances.values.count(&:blocked?),
|
|
80
|
+
threat_count: @affordances.values.count(&:threatening?),
|
|
81
|
+
history_size: @history.size
|
|
82
|
+
}
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
private
|
|
86
|
+
|
|
87
|
+
def check_blockers(matching)
|
|
88
|
+
blockers = matching.select(&:blocked?)
|
|
89
|
+
return nil if blockers.empty?
|
|
90
|
+
|
|
91
|
+
{ feasible: false, reason: :blocked, blockers: blockers.map(&:to_h) }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def build_evaluation(matching)
|
|
95
|
+
capabilities_met = check_requirements(matching)
|
|
96
|
+
{
|
|
97
|
+
feasible: capabilities_met,
|
|
98
|
+
reason: capabilities_met ? :capable : :missing_capabilities,
|
|
99
|
+
risks: matching.select(&:risky?).map(&:to_h),
|
|
100
|
+
relevance: matching.map(&:relevance).max,
|
|
101
|
+
affordance_count: matching.size
|
|
102
|
+
}
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def check_requirements(affordances)
|
|
106
|
+
required = affordances.flat_map(&:requires).uniq
|
|
107
|
+
return true if required.empty?
|
|
108
|
+
|
|
109
|
+
required.all? { |r| @capabilities.key?(r) }
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def record_detection(affordance)
|
|
113
|
+
@history << { id: affordance.id, action: affordance.action, type: affordance.affordance_type,
|
|
114
|
+
at: Time.now.utc }
|
|
115
|
+
@history.shift while @history.size > MAX_HISTORY
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module Affordance
|
|
8
|
+
module Helpers
|
|
9
|
+
class AffordanceItem
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :id, :action, :domain, :affordance_type, :requires, :detected_at
|
|
13
|
+
attr_accessor :relevance
|
|
14
|
+
|
|
15
|
+
def initialize(id:, action:, domain:, affordance_type:, requires: [], relevance: DEFAULT_RELEVANCE)
|
|
16
|
+
@id = id
|
|
17
|
+
@action = action
|
|
18
|
+
@domain = domain
|
|
19
|
+
@affordance_type = affordance_type
|
|
20
|
+
@requires = Array(requires)
|
|
21
|
+
@relevance = relevance.to_f.clamp(0.0, 1.0)
|
|
22
|
+
@detected_at = Time.now.utc
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def actionable?
|
|
26
|
+
%i[action_possible resource_available opportunity].include?(@affordance_type) &&
|
|
27
|
+
@relevance >= ACTIONABLE_THRESHOLD
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def blocked?
|
|
31
|
+
@affordance_type == :action_blocked
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def risky?
|
|
35
|
+
@affordance_type == :action_risky
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def threatening?
|
|
39
|
+
@affordance_type == :threat
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def decay
|
|
43
|
+
@relevance = [@relevance - RELEVANCE_DECAY, 0.0].max
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def faded?
|
|
47
|
+
@relevance <= RELEVANCE_FLOOR
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def relevance_label
|
|
51
|
+
RELEVANCE_LABELS.each { |range, lbl| return lbl if range.cover?(@relevance) }
|
|
52
|
+
:negligible
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def to_h
|
|
56
|
+
{
|
|
57
|
+
id: @id,
|
|
58
|
+
action: @action,
|
|
59
|
+
domain: @domain,
|
|
60
|
+
affordance_type: @affordance_type,
|
|
61
|
+
requires: @requires,
|
|
62
|
+
relevance: @relevance.round(4),
|
|
63
|
+
relevance_label: relevance_label,
|
|
64
|
+
actionable: actionable?,
|
|
65
|
+
blocked: blocked?,
|
|
66
|
+
risky: risky?
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module Affordance
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
MAX_AFFORDANCES = 200
|
|
11
|
+
MAX_CAPABILITIES = 50
|
|
12
|
+
MAX_ENVIRONMENT_PROPS = 100
|
|
13
|
+
MAX_HISTORY = 200
|
|
14
|
+
|
|
15
|
+
RELEVANCE_FLOOR = 0.05
|
|
16
|
+
RELEVANCE_DECAY = 0.01
|
|
17
|
+
DEFAULT_RELEVANCE = 0.5
|
|
18
|
+
URGENCY_BOOST = 0.2
|
|
19
|
+
|
|
20
|
+
CAPABILITY_MATCH_THRESHOLD = 0.3
|
|
21
|
+
ACTIONABLE_THRESHOLD = 0.5
|
|
22
|
+
|
|
23
|
+
AFFORDANCE_TYPES = %i[
|
|
24
|
+
action_possible action_blocked action_risky
|
|
25
|
+
resource_available resource_depleted
|
|
26
|
+
opportunity threat neutral
|
|
27
|
+
].freeze
|
|
28
|
+
|
|
29
|
+
RELEVANCE_LABELS = {
|
|
30
|
+
(0.8..) => :critical,
|
|
31
|
+
(0.6...0.8) => :important,
|
|
32
|
+
(0.4...0.6) => :moderate,
|
|
33
|
+
(0.2...0.4) => :minor,
|
|
34
|
+
(..0.2) => :negligible
|
|
35
|
+
}.freeze
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module Affordance
|
|
8
|
+
module Runners
|
|
9
|
+
module Affordance
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
11
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
12
|
+
|
|
13
|
+
def register_capability(name:, domain: :general, level: 1.0, **)
|
|
14
|
+
Legion::Logging.debug "[affordance] capability: #{name} domain=#{domain}"
|
|
15
|
+
cap = field.register_capability(name: name, domain: domain, level: level)
|
|
16
|
+
if cap
|
|
17
|
+
{ success: true, capability: name, capabilities: field.capabilities.size }
|
|
18
|
+
else
|
|
19
|
+
{ success: false, reason: :limit_reached }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def set_environment(property:, value:, domain: :general, **)
|
|
24
|
+
Legion::Logging.debug "[affordance] env: #{property}=#{value}"
|
|
25
|
+
result = field.set_environment(property: property, value: value, domain: domain)
|
|
26
|
+
if result
|
|
27
|
+
{ success: true, property: property }
|
|
28
|
+
else
|
|
29
|
+
{ success: false, reason: :limit_reached }
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def detect_affordance(action:, domain:, affordance_type:, requires: [], relevance: nil, **)
|
|
34
|
+
rel = relevance || Helpers::Constants::DEFAULT_RELEVANCE
|
|
35
|
+
Legion::Logging.debug "[affordance] detect: #{action} type=#{affordance_type}"
|
|
36
|
+
aff = field.detect_affordance(
|
|
37
|
+
action: action, domain: domain, affordance_type: affordance_type.to_sym,
|
|
38
|
+
requires: requires, relevance: rel
|
|
39
|
+
)
|
|
40
|
+
if aff
|
|
41
|
+
{ success: true, affordance: aff.to_h }
|
|
42
|
+
else
|
|
43
|
+
{ success: false, reason: :invalid_or_full }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def evaluate_action(action:, domain:, **)
|
|
48
|
+
result = field.evaluate_action(action: action, domain: domain)
|
|
49
|
+
Legion::Logging.debug "[affordance] evaluate: #{action} feasible=#{result[:feasible]}"
|
|
50
|
+
{ success: true, **result }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def actionable_affordances(**)
|
|
54
|
+
items = field.actionable_affordances
|
|
55
|
+
{ success: true, affordances: items, count: items.size }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def current_threats(**)
|
|
59
|
+
items = field.threats
|
|
60
|
+
{ success: true, threats: items, count: items.size }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def affordances_in_domain(domain:, **)
|
|
64
|
+
items = field.affordances_in(domain: domain)
|
|
65
|
+
{ success: true, affordances: items, count: items.size }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def update_affordances(**)
|
|
69
|
+
Legion::Logging.debug '[affordance] tick'
|
|
70
|
+
field.decay_all
|
|
71
|
+
{ success: true, remaining: field.affordances.size }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def affordance_stats(**)
|
|
75
|
+
Legion::Logging.debug '[affordance] stats'
|
|
76
|
+
{ success: true, stats: field.to_h }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
private
|
|
80
|
+
|
|
81
|
+
def field
|
|
82
|
+
@field ||= Helpers::AffordanceField.new
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/affordance/version'
|
|
4
|
+
require 'legion/extensions/agentic/inference/affordance/helpers/constants'
|
|
5
|
+
require 'legion/extensions/agentic/inference/affordance/helpers/affordance_item'
|
|
6
|
+
require 'legion/extensions/agentic/inference/affordance/helpers/affordance_field'
|
|
7
|
+
require 'legion/extensions/agentic/inference/affordance/runners/affordance'
|
|
8
|
+
require 'legion/extensions/agentic/inference/affordance/client'
|
|
9
|
+
|
|
10
|
+
module Legion
|
|
11
|
+
module Extensions
|
|
12
|
+
module Agentic
|
|
13
|
+
module Inference
|
|
14
|
+
module Affordance
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/analogical/helpers/constants'
|
|
4
|
+
require 'legion/extensions/agentic/inference/analogical/helpers/structure_map'
|
|
5
|
+
require 'legion/extensions/agentic/inference/analogical/helpers/analogy_engine'
|
|
6
|
+
require 'legion/extensions/agentic/inference/analogical/runners/analogical_reasoning'
|
|
7
|
+
|
|
8
|
+
module Legion
|
|
9
|
+
module Extensions
|
|
10
|
+
module Agentic
|
|
11
|
+
module Inference
|
|
12
|
+
module Analogical
|
|
13
|
+
class Client
|
|
14
|
+
include Runners::AnalogicalReasoning
|
|
15
|
+
|
|
16
|
+
def initialize(engine: nil, **)
|
|
17
|
+
@engine = engine || Helpers::AnalogyEngine.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
attr_reader :engine
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module Analogical
|
|
8
|
+
module Helpers
|
|
9
|
+
class AnalogyEngine
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :history
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@analogies = {}
|
|
16
|
+
@domains = Set.new
|
|
17
|
+
@history = []
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create_analogy(source_domain:, target_domain:, mappings:, mapping_type:, strength: nil)
|
|
21
|
+
evict_oldest_analogy if @analogies.size >= Constants::MAX_ANALOGIES
|
|
22
|
+
|
|
23
|
+
analogy = StructureMap.new(
|
|
24
|
+
source_domain: source_domain,
|
|
25
|
+
target_domain: target_domain,
|
|
26
|
+
mappings: mappings,
|
|
27
|
+
mapping_type: mapping_type,
|
|
28
|
+
strength: strength
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
@analogies[analogy.id] = analogy
|
|
32
|
+
register_domain(source_domain)
|
|
33
|
+
register_domain(target_domain)
|
|
34
|
+
record_history(:created, analogy.id)
|
|
35
|
+
|
|
36
|
+
analogy
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def find_analogies(domain:)
|
|
40
|
+
@analogies.values.select do |analogy|
|
|
41
|
+
analogy.source_domain == domain || analogy.target_domain == domain
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def apply_analogy(analogy_id:, source_element:)
|
|
46
|
+
analogy = @analogies[analogy_id]
|
|
47
|
+
return { found: false } unless analogy
|
|
48
|
+
|
|
49
|
+
target_element = analogy.mappings[source_element]
|
|
50
|
+
return { found: true, mapped: false } unless target_element
|
|
51
|
+
|
|
52
|
+
analogy.use!
|
|
53
|
+
record_history(:applied, analogy_id)
|
|
54
|
+
|
|
55
|
+
{
|
|
56
|
+
found: true,
|
|
57
|
+
mapped: true,
|
|
58
|
+
source_element: source_element,
|
|
59
|
+
target_element: target_element,
|
|
60
|
+
confidence: analogy.strength,
|
|
61
|
+
analogy_id: analogy_id
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def evaluate_similarity(source:, target:)
|
|
66
|
+
return 0.0 if source.empty? || target.empty?
|
|
67
|
+
|
|
68
|
+
structural = structural_overlap(source, target)
|
|
69
|
+
surface = surface_overlap(source, target)
|
|
70
|
+
(Constants::STRUCTURAL_WEIGHT * structural) + (Constants::SURFACE_WEIGHT * surface)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def cross_domain_transfer(analogy_id:, source_knowledge:)
|
|
74
|
+
analogy = @analogies[analogy_id]
|
|
75
|
+
return { transferred: false, reason: :not_found } unless analogy
|
|
76
|
+
|
|
77
|
+
transferred = {}
|
|
78
|
+
source_knowledge.each do |key, value|
|
|
79
|
+
mapped_key = analogy.mappings.fetch(key, nil)
|
|
80
|
+
transferred[mapped_key] = value if mapped_key
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
analogy.use!
|
|
84
|
+
record_history(:transferred, analogy_id)
|
|
85
|
+
|
|
86
|
+
{
|
|
87
|
+
transferred: true,
|
|
88
|
+
analogy_id: analogy_id,
|
|
89
|
+
source_domain: analogy.source_domain,
|
|
90
|
+
target_domain: analogy.target_domain,
|
|
91
|
+
result: transferred,
|
|
92
|
+
coverage: coverage_ratio(source_knowledge, transferred)
|
|
93
|
+
}
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def reinforce_analogy(analogy_id:, success:)
|
|
97
|
+
analogy = @analogies[analogy_id]
|
|
98
|
+
return { reinforced: false, reason: :not_found } unless analogy
|
|
99
|
+
|
|
100
|
+
if success
|
|
101
|
+
analogy.reinforce
|
|
102
|
+
record_history(:reinforced, analogy_id)
|
|
103
|
+
else
|
|
104
|
+
analogy.weaken
|
|
105
|
+
record_history(:weakened, analogy_id)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
{ reinforced: true, analogy_id: analogy_id, strength: analogy.strength, state: analogy.state }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def productive_analogies
|
|
112
|
+
@analogies.values.select(&:productive?)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def by_domain(domain:)
|
|
116
|
+
find_analogies(domain: domain)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def by_type(type:)
|
|
120
|
+
@analogies.values.select { |analogy| analogy.mapping_type == type }
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def decay_all
|
|
124
|
+
@analogies.each_value(&:decay)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def prune_stale
|
|
128
|
+
stale_ids = @analogies.select { |_id, analogy| analogy.state == :stale }.keys
|
|
129
|
+
stale_ids.each { |id| @analogies.delete(id) }
|
|
130
|
+
stale_ids.size
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def to_h
|
|
134
|
+
{
|
|
135
|
+
total_analogies: @analogies.size,
|
|
136
|
+
total_domains: @domains.size,
|
|
137
|
+
productive_count: productive_analogies.size,
|
|
138
|
+
history_count: @history.size,
|
|
139
|
+
domains: @domains.to_a,
|
|
140
|
+
analogy_states: state_counts
|
|
141
|
+
}
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
private
|
|
145
|
+
|
|
146
|
+
def register_domain(domain)
|
|
147
|
+
@domains.add(domain)
|
|
148
|
+
evict_oldest_domain if @domains.size > Constants::MAX_DOMAINS
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def evict_oldest_analogy
|
|
152
|
+
oldest_id = @analogies.min_by { |_id, analogy| analogy.last_used_at }&.first
|
|
153
|
+
@analogies.delete(oldest_id) if oldest_id
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def evict_oldest_domain
|
|
157
|
+
@domains.delete(@domains.first)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def record_history(event, analogy_id)
|
|
161
|
+
entry = { event: event, analogy_id: analogy_id, at: Time.now.utc }
|
|
162
|
+
@history << entry
|
|
163
|
+
@history.shift while @history.size > Constants::MAX_HISTORY
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def structural_overlap(source, target)
|
|
167
|
+
source_keys = source.keys.to_set(&:to_s)
|
|
168
|
+
target_keys = target.keys.to_set(&:to_s)
|
|
169
|
+
union = source_keys | target_keys
|
|
170
|
+
return 0.0 if union.empty?
|
|
171
|
+
|
|
172
|
+
(source_keys & target_keys).size.to_f / union.size
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def surface_overlap(source, target)
|
|
176
|
+
common = source.keys.to_set(&:to_s) & target.keys.to_set(&:to_s)
|
|
177
|
+
surface_match_ratio(common, source, target)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def surface_match_ratio(common_keys, source, target)
|
|
181
|
+
return 0.0 if common_keys.empty?
|
|
182
|
+
|
|
183
|
+
matches = common_keys.count do |key|
|
|
184
|
+
sym = key.to_sym
|
|
185
|
+
src_val = source.fetch(sym) { source[key] }
|
|
186
|
+
tgt_val = target.fetch(sym) { target[key] }
|
|
187
|
+
src_val == tgt_val && !src_val.nil?
|
|
188
|
+
end
|
|
189
|
+
matches.to_f / common_keys.size
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def coverage_ratio(source_knowledge, transferred)
|
|
193
|
+
return 0.0 if source_knowledge.empty?
|
|
194
|
+
|
|
195
|
+
transferred.size.to_f / source_knowledge.size
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def state_counts
|
|
199
|
+
@analogies.values.each_with_object(Hash.new(0)) do |analogy, counts|
|
|
200
|
+
counts[analogy.state] += 1
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module Analogical
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
MAX_ANALOGIES = 200
|
|
11
|
+
MAX_DOMAINS = 50
|
|
12
|
+
MAX_HISTORY = 300
|
|
13
|
+
|
|
14
|
+
SIMILARITY_THRESHOLD = 0.4
|
|
15
|
+
STRUCTURAL_WEIGHT = 0.7
|
|
16
|
+
SURFACE_WEIGHT = 0.3
|
|
17
|
+
|
|
18
|
+
DEFAULT_STRENGTH = 0.5
|
|
19
|
+
STRENGTH_FLOOR = 0.05
|
|
20
|
+
STRENGTH_CEILING = 0.95
|
|
21
|
+
|
|
22
|
+
REINFORCEMENT_RATE = 0.1
|
|
23
|
+
DECAY_RATE = 0.01
|
|
24
|
+
|
|
25
|
+
MAPPING_TYPES = %i[attribute relational system].freeze
|
|
26
|
+
ANALOGY_STATES = %i[candidate validated productive stale].freeze
|
|
27
|
+
STATE_THRESHOLDS = {
|
|
28
|
+
productive: 0.75,
|
|
29
|
+
validated: 0.5,
|
|
30
|
+
candidate: 0.25
|
|
31
|
+
}.freeze
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|