lex-agentic-inference 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +13 -0
- data/lex-agentic-inference.gemspec +30 -0
- data/lib/legion/extensions/agentic/inference/abductive/client.rb +25 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/abduction_engine.rb +164 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/constants.rb +39 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/hypothesis.rb +106 -0
- data/lib/legion/extensions/agentic/inference/abductive/helpers/observation.rb +39 -0
- data/lib/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning.rb +129 -0
- data/lib/legion/extensions/agentic/inference/abductive/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/abductive.rb +20 -0
- data/lib/legion/extensions/agentic/inference/affordance/actors/scan.rb +31 -0
- data/lib/legion/extensions/agentic/inference/affordance/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb +123 -0
- data/lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb +75 -0
- data/lib/legion/extensions/agentic/inference/affordance/helpers/constants.rb +42 -0
- data/lib/legion/extensions/agentic/inference/affordance/runners/affordance.rb +90 -0
- data/lib/legion/extensions/agentic/inference/affordance/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/affordance.rb +19 -0
- data/lib/legion/extensions/agentic/inference/analogical/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/analogical/helpers/analogy_engine.rb +209 -0
- data/lib/legion/extensions/agentic/inference/analogical/helpers/constants.rb +38 -0
- data/lib/legion/extensions/agentic/inference/analogical/helpers/structure_map.rb +113 -0
- data/lib/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning.rb +106 -0
- data/lib/legion/extensions/agentic/inference/analogical/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/analogical.rb +19 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb +102 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument_engine.rb +131 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/constants.rb +44 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping.rb +78 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/argument_mapping.rb +19 -0
- data/lib/legion/extensions/agentic/inference/bayesian/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/bayesian/helpers/belief.rb +96 -0
- data/lib/legion/extensions/agentic/inference/bayesian/helpers/belief_network.rb +147 -0
- data/lib/legion/extensions/agentic/inference/bayesian/helpers/constants.rb +36 -0
- data/lib/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief.rb +125 -0
- data/lib/legion/extensions/agentic/inference/bayesian/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/bayesian.rb +19 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/belief.rb +155 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/belief_network.rb +193 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/constants.rb +54 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/helpers/evidence.rb +49 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb +89 -0
- data/lib/legion/extensions/agentic/inference/belief_revision/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/belief_revision.rb +21 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/client.rb +27 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb +92 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine.rb +159 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution.rb +111 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/causal_attribution.rb +18 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/client.rb +24 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_edge.rb +101 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_graph.rb +184 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/constants.rb +40 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning.rb +111 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/causal_reasoning.rb +19 -0
- data/lib/legion/extensions/agentic/inference/coherence/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/coherence/helpers/coherence_engine.rb +170 -0
- data/lib/legion/extensions/agentic/inference/coherence/helpers/constants.rb +35 -0
- data/lib/legion/extensions/agentic/inference/coherence/helpers/proposition.rb +100 -0
- data/lib/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence.rb +123 -0
- data/lib/legion/extensions/agentic/inference/coherence/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/coherence.rb +19 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/helpers/constants.rb +40 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/helpers/counterfactual_engine.rb +157 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb +98 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/runners/counterfactual.rb +106 -0
- data/lib/legion/extensions/agentic/inference/counterfactual/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/counterfactual.rb +19 -0
- data/lib/legion/extensions/agentic/inference/debugging/client.rb +30 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb +51 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/constants.rb +58 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/correction.rb +56 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/debugging_engine.rb +156 -0
- data/lib/legion/extensions/agentic/inference/debugging/helpers/reasoning_error.rb +97 -0
- data/lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb +178 -0
- data/lib/legion/extensions/agentic/inference/debugging/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/debugging.rb +21 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/client.rb +27 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb +120 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop.rb +122 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb +124 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/enactive_cognition.rb +18 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/client.rb +17 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/constants.rb +47 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/expectation.rb +82 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/violation_engine.rb +126 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb +76 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/expectation_violation.rb +19 -0
- data/lib/legion/extensions/agentic/inference/free_energy/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/free_energy/helpers/belief.rb +127 -0
- data/lib/legion/extensions/agentic/inference/free_energy/helpers/constants.rb +58 -0
- data/lib/legion/extensions/agentic/inference/free_energy/helpers/free_energy_engine.rb +156 -0
- data/lib/legion/extensions/agentic/inference/free_energy/runners/free_energy.rb +97 -0
- data/lib/legion/extensions/agentic/inference/free_energy/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/free_energy.rb +19 -0
- data/lib/legion/extensions/agentic/inference/gravity/client.rb +29 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb +77 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/constants.rb +76 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb +164 -0
- data/lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb +64 -0
- data/lib/legion/extensions/agentic/inference/gravity/runners/gravity.rb +132 -0
- data/lib/legion/extensions/agentic/inference/gravity/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/gravity.rb +20 -0
- data/lib/legion/extensions/agentic/inference/horizon/actors/adjust.rb +45 -0
- data/lib/legion/extensions/agentic/inference/horizon/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/horizon/helpers/constants.rb +43 -0
- data/lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb +110 -0
- data/lib/legion/extensions/agentic/inference/horizon/helpers/projection.rb +59 -0
- data/lib/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon.rb +107 -0
- data/lib/legion/extensions/agentic/inference/horizon/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/horizon.rb +19 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/constants.rb +37 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb +83 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine.rb +97 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb +115 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/hypothesis_testing.rb +19 -0
- data/lib/legion/extensions/agentic/inference/intuition/client.rb +19 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/constants.rb +60 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb +66 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb +157 -0
- data/lib/legion/extensions/agentic/inference/intuition/helpers/pattern.rb +105 -0
- data/lib/legion/extensions/agentic/inference/intuition/runners/intuition.rb +87 -0
- data/lib/legion/extensions/agentic/inference/intuition/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/intuition.rb +20 -0
- data/lib/legion/extensions/agentic/inference/magnet/client.rb +29 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/constants.rb +57 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/field.rb +105 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/magnet_engine.rb +179 -0
- data/lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb +80 -0
- data/lib/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet.rb +124 -0
- data/lib/legion/extensions/agentic/inference/magnet/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/magnet.rb +21 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/client.rb +17 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/constants.rb +65 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb +112 -0
- data/lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb +127 -0
- data/lib/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum.rb +101 -0
- data/lib/legion/extensions/agentic/inference/momentum/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/momentum.rb +19 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/constants.rb +34 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field.rb +154 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb +100 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb +120 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/perceptual_inference.rb +19 -0
- data/lib/legion/extensions/agentic/inference/prediction/actors/expire_predictions.rb +45 -0
- data/lib/legion/extensions/agentic/inference/prediction/client.rb +27 -0
- data/lib/legion/extensions/agentic/inference/prediction/helpers/modes.rb +28 -0
- data/lib/legion/extensions/agentic/inference/prediction/helpers/prediction_store.rb +66 -0
- data/lib/legion/extensions/agentic/inference/prediction/runners/prediction.rb +146 -0
- data/lib/legion/extensions/agentic/inference/prediction/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/prediction.rb +18 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/constants.rb +46 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/generative_model.rb +187 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb +59 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding.rb +171 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/predictive_coding.rb +20 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/constants.rb +35 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/generative_model.rb +142 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/predictive_processor.rb +129 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb +104 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/predictive_processing.rb +19 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb +98 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/helpers/constants.rb +41 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine.rb +104 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/runners/reality_testing.rb +94 -0
- data/lib/legion/extensions/agentic/inference/reality_testing/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/reality_testing.rb +19 -0
- data/lib/legion/extensions/agentic/inference/schema/client.rb +26 -0
- data/lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb +70 -0
- data/lib/legion/extensions/agentic/inference/schema/helpers/constants.rb +50 -0
- data/lib/legion/extensions/agentic/inference/schema/helpers/world_model.rb +173 -0
- data/lib/legion/extensions/agentic/inference/schema/runners/schema.rb +101 -0
- data/lib/legion/extensions/agentic/inference/schema/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/schema.rb +19 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/client.rb +28 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/constants.rb +42 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb +66 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/tolerance_engine.rb +139 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb +129 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/version.rb +13 -0
- data/lib/legion/extensions/agentic/inference/uncertainty_tolerance.rb +19 -0
- data/lib/legion/extensions/agentic/inference/version.rb +11 -0
- data/lib/legion/extensions/agentic/inference.rb +44 -0
- data/spec/legion/extensions/agentic/inference/abductive/client_spec.rb +25 -0
- data/spec/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning_spec.rb +349 -0
- data/spec/legion/extensions/agentic/inference/affordance/client_spec.rb +26 -0
- data/spec/legion/extensions/agentic/inference/affordance/helpers/affordance_field_spec.rb +131 -0
- data/spec/legion/extensions/agentic/inference/affordance/helpers/affordance_item_spec.rb +107 -0
- data/spec/legion/extensions/agentic/inference/affordance/runners/affordance_spec.rb +78 -0
- data/spec/legion/extensions/agentic/inference/analogical/client_spec.rb +31 -0
- data/spec/legion/extensions/agentic/inference/analogical/helpers/analogy_engine_spec.rb +276 -0
- data/spec/legion/extensions/agentic/inference/analogical/helpers/structure_map_spec.rb +255 -0
- data/spec/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning_spec.rb +213 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/client_spec.rb +18 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/helpers/argument_engine_spec.rb +218 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/helpers/argument_spec.rb +231 -0
- data/spec/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping_spec.rb +171 -0
- data/spec/legion/extensions/agentic/inference/bayesian/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/inference/bayesian/helpers/belief_network_spec.rb +178 -0
- data/spec/legion/extensions/agentic/inference/bayesian/helpers/belief_spec.rb +137 -0
- data/spec/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief_spec.rb +176 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/client_spec.rb +31 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/helpers/belief_network_spec.rb +176 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/helpers/belief_spec.rb +153 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/helpers/evidence_spec.rb +51 -0
- data/spec/legion/extensions/agentic/inference/belief_revision/runners/belief_revision_spec.rb +106 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/client_spec.rb +24 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine_spec.rb +181 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_spec.rb +108 -0
- data/spec/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution_spec.rb +142 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/client_spec.rb +35 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_edge_spec.rb +158 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_graph_spec.rb +259 -0
- data/spec/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning_spec.rb +161 -0
- data/spec/legion/extensions/agentic/inference/coherence/client_spec.rb +17 -0
- data/spec/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence_spec.rb +267 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/client_spec.rb +48 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/helpers/constants_spec.rb +55 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/helpers/counterfactual_engine_spec.rb +234 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/helpers/scenario_spec.rb +193 -0
- data/spec/legion/extensions/agentic/inference/counterfactual/runners/counterfactual_spec.rb +179 -0
- data/spec/legion/extensions/agentic/inference/debugging/client_spec.rb +46 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/causal_trace_spec.rb +84 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/constants_spec.rb +97 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/correction_spec.rb +98 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/debugging_engine_spec.rb +290 -0
- data/spec/legion/extensions/agentic/inference/debugging/helpers/reasoning_error_spec.rb +164 -0
- data/spec/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging_spec.rb +301 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/client_spec.rb +19 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine_spec.rb +181 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop_spec.rb +184 -0
- data/spec/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition_spec.rb +214 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/expectation_violation_spec.rb +11 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/helpers/expectation_spec.rb +102 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/helpers/violation_engine_spec.rb +121 -0
- data/spec/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation_spec.rb +59 -0
- data/spec/legion/extensions/agentic/inference/free_energy/client_spec.rb +46 -0
- data/spec/legion/extensions/agentic/inference/free_energy/helpers/belief_spec.rb +183 -0
- data/spec/legion/extensions/agentic/inference/free_energy/helpers/free_energy_engine_spec.rb +211 -0
- data/spec/legion/extensions/agentic/inference/free_energy/runners/free_energy_spec.rb +118 -0
- data/spec/legion/extensions/agentic/inference/gravity/client_spec.rb +24 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/attractor_spec.rb +143 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/constants_spec.rb +107 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/gravity_engine_spec.rb +193 -0
- data/spec/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought_spec.rb +103 -0
- data/spec/legion/extensions/agentic/inference/gravity/runners/gravity_spec.rb +159 -0
- data/spec/legion/extensions/agentic/inference/horizon/client_spec.rb +58 -0
- data/spec/legion/extensions/agentic/inference/horizon/helpers/constants_spec.rb +98 -0
- data/spec/legion/extensions/agentic/inference/horizon/helpers/horizon_engine_spec.rb +325 -0
- data/spec/legion/extensions/agentic/inference/horizon/helpers/projection_spec.rb +155 -0
- data/spec/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon_spec.rb +269 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/constants_spec.rb +38 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine_spec.rb +182 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_spec.rb +172 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/hypothesis_testing_spec.rb +16 -0
- data/spec/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing_spec.rb +159 -0
- data/spec/legion/extensions/agentic/inference/intuition/client_spec.rb +33 -0
- data/spec/legion/extensions/agentic/inference/intuition/helpers/heuristic_spec.rb +82 -0
- data/spec/legion/extensions/agentic/inference/intuition/helpers/intuition_engine_spec.rb +163 -0
- data/spec/legion/extensions/agentic/inference/intuition/helpers/pattern_spec.rb +160 -0
- data/spec/legion/extensions/agentic/inference/intuition/runners/intuition_spec.rb +107 -0
- data/spec/legion/extensions/agentic/inference/magnet/client_spec.rb +30 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/constants_spec.rb +120 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/field_spec.rb +193 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/magnet_engine_spec.rb +281 -0
- data/spec/legion/extensions/agentic/inference/magnet/helpers/pole_spec.rb +211 -0
- data/spec/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet_spec.rb +201 -0
- data/spec/legion/extensions/agentic/inference/momentum/cognitive_momentum_spec.rb +11 -0
- data/spec/legion/extensions/agentic/inference/momentum/helpers/idea_spec.rb +152 -0
- data/spec/legion/extensions/agentic/inference/momentum/helpers/momentum_engine_spec.rb +154 -0
- data/spec/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum_spec.rb +97 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/client_spec.rb +39 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/constants_spec.rb +97 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field_spec.rb +270 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis_spec.rb +206 -0
- data/spec/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference_spec.rb +305 -0
- data/spec/legion/extensions/agentic/inference/prediction/actors/expire_predictions_spec.rb +46 -0
- data/spec/legion/extensions/agentic/inference/prediction/client_spec.rb +14 -0
- data/spec/legion/extensions/agentic/inference/prediction/helpers/modes_spec.rb +118 -0
- data/spec/legion/extensions/agentic/inference/prediction/helpers/prediction_store_spec.rb +262 -0
- data/spec/legion/extensions/agentic/inference/prediction/runners/prediction_spec.rb +116 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/client_spec.rb +74 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/helpers/generative_model_spec.rb +194 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error_spec.rb +109 -0
- data/spec/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding_spec.rb +210 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/client_spec.rb +82 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/helpers/generative_model_spec.rb +220 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/helpers/predictive_processor_spec.rb +206 -0
- data/spec/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing_spec.rb +213 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/client_spec.rb +29 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/helpers/belief_spec.rb +197 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/helpers/constants_spec.rb +78 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine_spec.rb +191 -0
- data/spec/legion/extensions/agentic/inference/reality_testing/runners/reality_testing_spec.rb +154 -0
- data/spec/legion/extensions/agentic/inference/schema/client_spec.rb +53 -0
- data/spec/legion/extensions/agentic/inference/schema/helpers/causal_relation_spec.rb +108 -0
- data/spec/legion/extensions/agentic/inference/schema/helpers/constants_spec.rb +54 -0
- data/spec/legion/extensions/agentic/inference/schema/helpers/world_model_spec.rb +179 -0
- data/spec/legion/extensions/agentic/inference/schema/runners/schema_spec.rb +146 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/client_spec.rb +18 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/constants_spec.rb +62 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision_spec.rb +125 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/tolerance_engine_spec.rb +184 -0
- data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance_spec.rb +157 -0
- data/spec/spec_helper.rb +46 -0
- metadata +412 -0
data/lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module PerceptualInference
|
|
8
|
+
module Runners
|
|
9
|
+
module PerceptualInference
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if defined?(Legion::Extensions::Helpers::Lex)
|
|
11
|
+
|
|
12
|
+
def register_percept_hypothesis(content:, modality:, domain: :general, prior: Helpers::DEFAULT_PRIOR, **)
|
|
13
|
+
hypothesis = field.register_hypothesis(content: content, modality: modality, domain: domain, prior: prior)
|
|
14
|
+
Legion::Logging.debug "[perceptual_inference] registered hypothesis modality=#{modality} id=#{hypothesis.id[0..7]}"
|
|
15
|
+
{ success: true, hypothesis_id: hypothesis.id, modality: modality, prior: hypothesis.prior }
|
|
16
|
+
rescue ArgumentError => e
|
|
17
|
+
Legion::Logging.warn "[perceptual_inference] register failed: #{e.message}"
|
|
18
|
+
{ success: false, error: e.message }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def present_perceptual_evidence(modality:, content:, strength: 0.5, **)
|
|
22
|
+
count = field.present_evidence(modality: modality, content: content, strength: strength)
|
|
23
|
+
Legion::Logging.debug "[perceptual_inference] evidence presented modality=#{modality} strength=#{strength} updated=#{count}"
|
|
24
|
+
{ success: true, modality: modality, hypotheses_updated: count, rivalry: field.rivalry?(modality: modality) }
|
|
25
|
+
rescue ArgumentError => e
|
|
26
|
+
Legion::Logging.warn "[perceptual_inference] evidence failed: #{e.message}"
|
|
27
|
+
{ success: false, error: e.message }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def select_percept(modality:, **)
|
|
31
|
+
winner = field.select_percept(modality: modality)
|
|
32
|
+
if winner
|
|
33
|
+
Legion::Logging.info "[perceptual_inference] percept selected modality=#{modality} " \
|
|
34
|
+
"posterior=#{winner.posterior.round(3)} label=#{winner.percept_label}"
|
|
35
|
+
{ success: true, selected: true, hypothesis: winner.to_h }
|
|
36
|
+
else
|
|
37
|
+
rivalry = field.rivalry?(modality: modality)
|
|
38
|
+
Legion::Logging.debug "[perceptual_inference] no percept selected modality=#{modality} rivalry=#{rivalry}"
|
|
39
|
+
{ success: true, selected: false, rivalry: rivalry }
|
|
40
|
+
end
|
|
41
|
+
rescue ArgumentError => e
|
|
42
|
+
{ success: false, error: e.message }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def check_rivalry(modality:, **)
|
|
46
|
+
rival = field.rivalry?(modality: modality)
|
|
47
|
+
candidates = field.hypotheses_for(modality)
|
|
48
|
+
top_two = candidates.select { |h| %i[active selected].include?(h.state) }.max_by(2, &:posterior)
|
|
49
|
+
Legion::Logging.debug "[perceptual_inference] rivalry check modality=#{modality} rival=#{rival}"
|
|
50
|
+
{ success: true, rivalry: rival, modality: modality, top_hypotheses: top_two.map(&:to_h) }
|
|
51
|
+
rescue ArgumentError => e
|
|
52
|
+
{ success: false, error: e.message }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def current_percept(modality:, **)
|
|
56
|
+
percept = field.current_percept(modality: modality)
|
|
57
|
+
if percept
|
|
58
|
+
{ success: true, found: true, modality: modality, percept: percept.to_h }
|
|
59
|
+
else
|
|
60
|
+
{ success: true, found: false, modality: modality }
|
|
61
|
+
end
|
|
62
|
+
rescue ArgumentError => e
|
|
63
|
+
{ success: false, error: e.message }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def adapt_perception(modality:, correct_hypothesis_id:, **)
|
|
67
|
+
field.adapt_priors(modality: modality, correct_hypothesis_id: correct_hypothesis_id)
|
|
68
|
+
Legion::Logging.info "[perceptual_inference] priors adapted modality=#{modality} correct=#{correct_hypothesis_id[0..7]}"
|
|
69
|
+
{ success: true, modality: modality, correct_hypothesis_id: correct_hypothesis_id }
|
|
70
|
+
rescue ArgumentError => e
|
|
71
|
+
{ success: false, error: e.message }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def suppress_percept(hypothesis_id:, **)
|
|
75
|
+
suppressed = field.suppress_hypothesis(hypothesis_id: hypothesis_id)
|
|
76
|
+
Legion::Logging.debug "[perceptual_inference] suppress hypothesis_id=#{hypothesis_id[0..7]} result=#{suppressed}"
|
|
77
|
+
{ success: true, suppressed: suppressed, hypothesis_id: hypothesis_id }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def perceptual_ambiguity(**)
|
|
81
|
+
level = field.ambiguity_level
|
|
82
|
+
label = ambiguity_label(level)
|
|
83
|
+
Legion::Logging.debug "[perceptual_inference] ambiguity=#{level.round(3)} label=#{label}"
|
|
84
|
+
{ success: true, ambiguity_level: level, label: label }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def update_perceptual_inference(**)
|
|
88
|
+
field.decay_all
|
|
89
|
+
Legion::Logging.debug "[perceptual_inference] decay cycle complete remaining=#{field.hypotheses.size}"
|
|
90
|
+
{ success: true, remaining_hypotheses: field.hypotheses.size }
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def perceptual_inference_stats(**)
|
|
94
|
+
{ success: true, stats: field.to_h }
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
private
|
|
98
|
+
|
|
99
|
+
def field
|
|
100
|
+
@field ||= Helpers::PerceptualField.new
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def ambiguity_label(level)
|
|
104
|
+
if level >= 0.75
|
|
105
|
+
:high
|
|
106
|
+
elsif level >= 0.4
|
|
107
|
+
:moderate
|
|
108
|
+
elsif level.positive?
|
|
109
|
+
:low
|
|
110
|
+
else
|
|
111
|
+
:none
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/perceptual_inference/version'
|
|
4
|
+
require 'legion/extensions/agentic/inference/perceptual_inference/helpers/constants'
|
|
5
|
+
require 'legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis'
|
|
6
|
+
require 'legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field'
|
|
7
|
+
require 'legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference'
|
|
8
|
+
require 'legion/extensions/agentic/inference/perceptual_inference/client'
|
|
9
|
+
|
|
10
|
+
module Legion
|
|
11
|
+
module Extensions
|
|
12
|
+
module Agentic
|
|
13
|
+
module Inference
|
|
14
|
+
module PerceptualInference
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/actors/every'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Inference
|
|
9
|
+
module Prediction
|
|
10
|
+
module Actor
|
|
11
|
+
class ExpirePredictions < Legion::Extensions::Actors::Every
|
|
12
|
+
def runner_class
|
|
13
|
+
Legion::Extensions::Agentic::Inference::Prediction::Runners::Prediction
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def runner_function
|
|
17
|
+
'expire_stale_predictions'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def time
|
|
21
|
+
300
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def run_now?
|
|
25
|
+
false
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def use_runner?
|
|
29
|
+
false
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def check_subtask?
|
|
33
|
+
false
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def generate_task?
|
|
37
|
+
false
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/prediction/helpers/modes'
|
|
4
|
+
require 'legion/extensions/agentic/inference/prediction/helpers/prediction_store'
|
|
5
|
+
require 'legion/extensions/agentic/inference/prediction/runners/prediction'
|
|
6
|
+
|
|
7
|
+
module Legion
|
|
8
|
+
module Extensions
|
|
9
|
+
module Agentic
|
|
10
|
+
module Inference
|
|
11
|
+
module Prediction
|
|
12
|
+
class Client
|
|
13
|
+
include Runners::Prediction
|
|
14
|
+
|
|
15
|
+
def initialize(**)
|
|
16
|
+
@prediction_store = Helpers::PredictionStore.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
attr_reader :prediction_store
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module Prediction
|
|
8
|
+
module Helpers
|
|
9
|
+
module Modes
|
|
10
|
+
# Four reasoning modes (spec: prediction-engine-spec.md)
|
|
11
|
+
REASONING_MODES = %i[fault_localization functional_mapping boundary_testing counterfactual].freeze
|
|
12
|
+
|
|
13
|
+
PREDICTION_CONFIDENCE_MIN = 0.65
|
|
14
|
+
MAX_PREDICTIONS_PER_TICK = 5
|
|
15
|
+
PREDICTION_HORIZON = 3600 # 1 hour default lookahead
|
|
16
|
+
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
def valid_mode?(mode)
|
|
20
|
+
REASONING_MODES.include?(mode)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Inference
|
|
9
|
+
module Prediction
|
|
10
|
+
module Helpers
|
|
11
|
+
class PredictionStore
|
|
12
|
+
attr_reader :predictions, :outcomes
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@predictions = {}
|
|
16
|
+
@outcomes = []
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def store(prediction)
|
|
20
|
+
id = prediction[:prediction_id] || SecureRandom.uuid
|
|
21
|
+
prediction[:prediction_id] = id
|
|
22
|
+
prediction[:created_at] ||= Time.now.utc
|
|
23
|
+
prediction[:status] ||= :pending
|
|
24
|
+
@predictions[id] = prediction
|
|
25
|
+
id
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def get(prediction_id)
|
|
29
|
+
@predictions[prediction_id]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def resolve(prediction_id, outcome:, actual: nil)
|
|
33
|
+
pred = @predictions[prediction_id]
|
|
34
|
+
return nil unless pred
|
|
35
|
+
|
|
36
|
+
pred[:status] = outcome # :correct, :incorrect, :partial, :expired
|
|
37
|
+
pred[:resolved_at] = Time.now.utc
|
|
38
|
+
pred[:actual] = actual
|
|
39
|
+
|
|
40
|
+
@outcomes << { prediction_id: prediction_id, outcome: outcome, at: Time.now.utc }
|
|
41
|
+
@outcomes.shift while @outcomes.size > 500
|
|
42
|
+
pred
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def pending
|
|
46
|
+
@predictions.values.select { |p| p[:status] == :pending }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def accuracy(window: 100)
|
|
50
|
+
recent = @outcomes.last(window)
|
|
51
|
+
return 0.0 if recent.empty?
|
|
52
|
+
|
|
53
|
+
correct = recent.count { |o| o[:outcome] == :correct }
|
|
54
|
+
correct.to_f / recent.size
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def count
|
|
58
|
+
@predictions.size
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Inference
|
|
9
|
+
module Prediction
|
|
10
|
+
module Runners
|
|
11
|
+
module Prediction
|
|
12
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
13
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
14
|
+
|
|
15
|
+
def predict(mode:, context: {}, confidence: nil, description: nil, **)
|
|
16
|
+
return { error: :invalid_mode, valid_modes: Helpers::Modes::REASONING_MODES } unless Helpers::Modes.valid_mode?(mode)
|
|
17
|
+
|
|
18
|
+
prediction = {
|
|
19
|
+
prediction_id: SecureRandom.uuid,
|
|
20
|
+
mode: mode,
|
|
21
|
+
context: context,
|
|
22
|
+
confidence: confidence || estimate_confidence(mode, context),
|
|
23
|
+
description: description,
|
|
24
|
+
status: :pending,
|
|
25
|
+
created_at: Time.now.utc,
|
|
26
|
+
horizon: Helpers::Modes::PREDICTION_HORIZON
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
prediction_store.store(prediction)
|
|
30
|
+
|
|
31
|
+
actionable = prediction[:confidence] >= Helpers::Modes::PREDICTION_CONFIDENCE_MIN
|
|
32
|
+
Legion::Logging.debug "[prediction] new: mode=#{mode} confidence=#{prediction[:confidence].round(2)} " \
|
|
33
|
+
"actionable=#{actionable} id=#{prediction[:prediction_id][0..7]}"
|
|
34
|
+
|
|
35
|
+
{
|
|
36
|
+
prediction_id: prediction[:prediction_id],
|
|
37
|
+
mode: mode,
|
|
38
|
+
confidence: prediction[:confidence],
|
|
39
|
+
actionable: actionable
|
|
40
|
+
}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def resolve_prediction(prediction_id:, outcome:, actual: nil, **)
|
|
44
|
+
pred = prediction_store.resolve(prediction_id, outcome: outcome, actual: actual)
|
|
45
|
+
if pred
|
|
46
|
+
Legion::Logging.info "[prediction] resolved #{prediction_id[0..7]} outcome=#{outcome}"
|
|
47
|
+
record_outcome_trace(pred, outcome)
|
|
48
|
+
{ resolved: true, prediction_id: prediction_id, outcome: outcome }
|
|
49
|
+
else
|
|
50
|
+
Legion::Logging.debug "[prediction] resolve failed: #{prediction_id[0..7]} not found"
|
|
51
|
+
{ resolved: false, reason: :not_found }
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def pending_predictions(**)
|
|
56
|
+
preds = prediction_store.pending
|
|
57
|
+
Legion::Logging.debug "[prediction] pending count=#{preds.size}"
|
|
58
|
+
{ predictions: preds, count: preds.size }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def prediction_accuracy(window: 100, **)
|
|
62
|
+
acc = prediction_store.accuracy(window: window)
|
|
63
|
+
total = prediction_store.outcomes.size
|
|
64
|
+
Legion::Logging.debug "[prediction] accuracy=#{acc.round(2)} total_outcomes=#{total}"
|
|
65
|
+
{ accuracy: acc, total_outcomes: total }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def expire_stale_predictions(**)
|
|
69
|
+
expired_count = 0
|
|
70
|
+
|
|
71
|
+
prediction_store.pending.each do |pred|
|
|
72
|
+
age = Time.now.utc - pred[:created_at]
|
|
73
|
+
next unless age > pred[:horizon]
|
|
74
|
+
|
|
75
|
+
prediction_store.resolve(pred[:prediction_id], outcome: :expired, actual: nil)
|
|
76
|
+
expired_count += 1
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
remaining = prediction_store.pending.size
|
|
80
|
+
Legion::Logging.debug "[prediction] expire sweep: expired=#{expired_count} remaining=#{remaining}"
|
|
81
|
+
|
|
82
|
+
{ expired_count: expired_count, remaining_pending: remaining }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def get_prediction(prediction_id:, **)
|
|
86
|
+
pred = prediction_store.get(prediction_id)
|
|
87
|
+
pred ? { found: true, prediction: pred } : { found: false }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private
|
|
91
|
+
|
|
92
|
+
def prediction_store
|
|
93
|
+
@prediction_store ||= Helpers::PredictionStore.new
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def estimate_confidence(mode, context)
|
|
97
|
+
base = case mode
|
|
98
|
+
when :fault_localization then 0.7
|
|
99
|
+
when :functional_mapping then 0.6
|
|
100
|
+
when :counterfactual then 0.4
|
|
101
|
+
else 0.5
|
|
102
|
+
end
|
|
103
|
+
richness_bonus = [context.size * 0.02, 0.2].min
|
|
104
|
+
[base + richness_bonus, 1.0].min
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def record_outcome_trace(prediction, outcome)
|
|
108
|
+
return unless defined?(Legion::Extensions::Memory::Runners::Traces)
|
|
109
|
+
|
|
110
|
+
trace_params = case outcome
|
|
111
|
+
when :correct
|
|
112
|
+
{ type: :semantic, valence: 0.3, intensity: 0.3, unresolved: false }
|
|
113
|
+
when :incorrect
|
|
114
|
+
{ type: :episodic, valence: -0.5, intensity: 0.6, unresolved: true }
|
|
115
|
+
when :partial
|
|
116
|
+
{ type: :episodic, valence: -0.2, intensity: 0.4, unresolved: true }
|
|
117
|
+
else
|
|
118
|
+
return
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
runner = Object.new.extend(Legion::Extensions::Memory::Runners::Traces)
|
|
122
|
+
runner.store_trace(
|
|
123
|
+
type: trace_params[:type],
|
|
124
|
+
content_payload: "prediction #{outcome}: mode=#{prediction[:mode]} confidence=#{prediction[:confidence]}",
|
|
125
|
+
domain_tags: ['prediction', prediction[:mode].to_s],
|
|
126
|
+
origin: :direct_experience,
|
|
127
|
+
emotional_valence: trace_params[:valence],
|
|
128
|
+
emotional_intensity: trace_params[:intensity],
|
|
129
|
+
unresolved: trace_params[:unresolved],
|
|
130
|
+
confidence: prediction[:confidence]
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
store = runner.send(:default_store)
|
|
134
|
+
store.flush if store.respond_to?(:flush)
|
|
135
|
+
|
|
136
|
+
Legion::Logging.debug "[prediction] created #{trace_params[:type]} trace for #{outcome} prediction"
|
|
137
|
+
rescue StandardError => e
|
|
138
|
+
Legion::Logging.warn "[prediction] failed to create outcome trace: #{e.message}"
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/prediction/version'
|
|
4
|
+
require 'legion/extensions/agentic/inference/prediction/helpers/modes'
|
|
5
|
+
require 'legion/extensions/agentic/inference/prediction/helpers/prediction_store'
|
|
6
|
+
require 'legion/extensions/agentic/inference/prediction/runners/prediction'
|
|
7
|
+
require 'legion/extensions/agentic/inference/prediction/client'
|
|
8
|
+
|
|
9
|
+
module Legion
|
|
10
|
+
module Extensions
|
|
11
|
+
module Agentic
|
|
12
|
+
module Inference
|
|
13
|
+
module Prediction
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/actors/every'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Inference
|
|
9
|
+
module PredictiveCoding
|
|
10
|
+
module Actor
|
|
11
|
+
class Decay < Legion::Extensions::Actors::Every
|
|
12
|
+
def runner_class
|
|
13
|
+
Legion::Extensions::Agentic::Inference::PredictiveCoding::Runners::PredictiveCoding
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def runner_function
|
|
17
|
+
'update_predictive_coding'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def time
|
|
21
|
+
60
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def run_now?
|
|
25
|
+
false
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def use_runner?
|
|
29
|
+
false
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def check_subtask?
|
|
33
|
+
false
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def generate_task?
|
|
37
|
+
false
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/inference/predictive_coding/helpers/constants'
|
|
4
|
+
require 'legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error'
|
|
5
|
+
require 'legion/extensions/agentic/inference/predictive_coding/helpers/generative_model'
|
|
6
|
+
require 'legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding'
|
|
7
|
+
|
|
8
|
+
module Legion
|
|
9
|
+
module Extensions
|
|
10
|
+
module Agentic
|
|
11
|
+
module Inference
|
|
12
|
+
module PredictiveCoding
|
|
13
|
+
class Client
|
|
14
|
+
include Runners::PredictiveCoding
|
|
15
|
+
|
|
16
|
+
def initialize(generative_model: nil, **)
|
|
17
|
+
@generative_model = generative_model || Helpers::GenerativeModel.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
attr_reader :generative_model
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Inference
|
|
7
|
+
module PredictiveCoding
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
MAX_PREDICTIONS = 200
|
|
11
|
+
MAX_ERROR_HISTORY = 500
|
|
12
|
+
MAX_MODELS = 20
|
|
13
|
+
DEFAULT_PRECISION = 0.5
|
|
14
|
+
PRECISION_FLOOR = 0.05
|
|
15
|
+
PRECISION_ALPHA = 0.12 # EMA for precision updates
|
|
16
|
+
ERROR_ALPHA = 0.15 # EMA for prediction error smoothing
|
|
17
|
+
MODEL_LEARNING_RATE = 0.1
|
|
18
|
+
FREE_ENERGY_ALPHA = 0.1 # EMA for free energy tracking
|
|
19
|
+
COMPLEXITY_PENALTY = 0.05 # penalizes overly complex models
|
|
20
|
+
PREDICTION_DECAY = 0.01
|
|
21
|
+
PRECISION_DECAY = 0.005
|
|
22
|
+
MAX_ACTIVE_INFERENCES = 50
|
|
23
|
+
SURPRISE_THRESHOLD = 0.7 # above this, prediction error is "surprising"
|
|
24
|
+
|
|
25
|
+
PREDICTION_ERROR_LEVELS = {
|
|
26
|
+
negligible: 0.0..0.1,
|
|
27
|
+
low: 0.1..0.3,
|
|
28
|
+
moderate: 0.3..0.5,
|
|
29
|
+
high: 0.5..0.7,
|
|
30
|
+
surprising: 0.7..1.0
|
|
31
|
+
}.freeze
|
|
32
|
+
|
|
33
|
+
FREE_ENERGY_LEVELS = {
|
|
34
|
+
minimal: 0.0..0.2,
|
|
35
|
+
low: 0.2..0.4,
|
|
36
|
+
moderate: 0.4..0.6,
|
|
37
|
+
elevated: 0.6..0.8,
|
|
38
|
+
critical: 0.8..Float::INFINITY
|
|
39
|
+
}.freeze
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|