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.
Files changed (328) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +5 -0
  4. data/LICENSE +21 -0
  5. data/README.md +13 -0
  6. data/lex-agentic-inference.gemspec +30 -0
  7. data/lib/legion/extensions/agentic/inference/abductive/client.rb +25 -0
  8. data/lib/legion/extensions/agentic/inference/abductive/helpers/abduction_engine.rb +164 -0
  9. data/lib/legion/extensions/agentic/inference/abductive/helpers/constants.rb +39 -0
  10. data/lib/legion/extensions/agentic/inference/abductive/helpers/hypothesis.rb +106 -0
  11. data/lib/legion/extensions/agentic/inference/abductive/helpers/observation.rb +39 -0
  12. data/lib/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning.rb +129 -0
  13. data/lib/legion/extensions/agentic/inference/abductive/version.rb +13 -0
  14. data/lib/legion/extensions/agentic/inference/abductive.rb +20 -0
  15. data/lib/legion/extensions/agentic/inference/affordance/actors/scan.rb +31 -0
  16. data/lib/legion/extensions/agentic/inference/affordance/client.rb +28 -0
  17. data/lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb +123 -0
  18. data/lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb +75 -0
  19. data/lib/legion/extensions/agentic/inference/affordance/helpers/constants.rb +42 -0
  20. data/lib/legion/extensions/agentic/inference/affordance/runners/affordance.rb +90 -0
  21. data/lib/legion/extensions/agentic/inference/affordance/version.rb +13 -0
  22. data/lib/legion/extensions/agentic/inference/affordance.rb +19 -0
  23. data/lib/legion/extensions/agentic/inference/analogical/client.rb +28 -0
  24. data/lib/legion/extensions/agentic/inference/analogical/helpers/analogy_engine.rb +209 -0
  25. data/lib/legion/extensions/agentic/inference/analogical/helpers/constants.rb +38 -0
  26. data/lib/legion/extensions/agentic/inference/analogical/helpers/structure_map.rb +113 -0
  27. data/lib/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning.rb +106 -0
  28. data/lib/legion/extensions/agentic/inference/analogical/version.rb +13 -0
  29. data/lib/legion/extensions/agentic/inference/analogical.rb +19 -0
  30. data/lib/legion/extensions/agentic/inference/argument_mapping/client.rb +19 -0
  31. data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb +102 -0
  32. data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument_engine.rb +131 -0
  33. data/lib/legion/extensions/agentic/inference/argument_mapping/helpers/constants.rb +44 -0
  34. data/lib/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping.rb +78 -0
  35. data/lib/legion/extensions/agentic/inference/argument_mapping/version.rb +13 -0
  36. data/lib/legion/extensions/agentic/inference/argument_mapping.rb +19 -0
  37. data/lib/legion/extensions/agentic/inference/bayesian/client.rb +28 -0
  38. data/lib/legion/extensions/agentic/inference/bayesian/helpers/belief.rb +96 -0
  39. data/lib/legion/extensions/agentic/inference/bayesian/helpers/belief_network.rb +147 -0
  40. data/lib/legion/extensions/agentic/inference/bayesian/helpers/constants.rb +36 -0
  41. data/lib/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief.rb +125 -0
  42. data/lib/legion/extensions/agentic/inference/bayesian/version.rb +13 -0
  43. data/lib/legion/extensions/agentic/inference/bayesian.rb +19 -0
  44. data/lib/legion/extensions/agentic/inference/belief_revision/client.rb +19 -0
  45. data/lib/legion/extensions/agentic/inference/belief_revision/helpers/belief.rb +155 -0
  46. data/lib/legion/extensions/agentic/inference/belief_revision/helpers/belief_network.rb +193 -0
  47. data/lib/legion/extensions/agentic/inference/belief_revision/helpers/constants.rb +54 -0
  48. data/lib/legion/extensions/agentic/inference/belief_revision/helpers/evidence.rb +49 -0
  49. data/lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb +89 -0
  50. data/lib/legion/extensions/agentic/inference/belief_revision/version.rb +13 -0
  51. data/lib/legion/extensions/agentic/inference/belief_revision.rb +21 -0
  52. data/lib/legion/extensions/agentic/inference/causal_attribution/client.rb +27 -0
  53. data/lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb +92 -0
  54. data/lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine.rb +159 -0
  55. data/lib/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution.rb +111 -0
  56. data/lib/legion/extensions/agentic/inference/causal_attribution/version.rb +13 -0
  57. data/lib/legion/extensions/agentic/inference/causal_attribution.rb +18 -0
  58. data/lib/legion/extensions/agentic/inference/causal_reasoning/client.rb +24 -0
  59. data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_edge.rb +101 -0
  60. data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_graph.rb +184 -0
  61. data/lib/legion/extensions/agentic/inference/causal_reasoning/helpers/constants.rb +40 -0
  62. data/lib/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning.rb +111 -0
  63. data/lib/legion/extensions/agentic/inference/causal_reasoning/version.rb +13 -0
  64. data/lib/legion/extensions/agentic/inference/causal_reasoning.rb +19 -0
  65. data/lib/legion/extensions/agentic/inference/coherence/client.rb +28 -0
  66. data/lib/legion/extensions/agentic/inference/coherence/helpers/coherence_engine.rb +170 -0
  67. data/lib/legion/extensions/agentic/inference/coherence/helpers/constants.rb +35 -0
  68. data/lib/legion/extensions/agentic/inference/coherence/helpers/proposition.rb +100 -0
  69. data/lib/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence.rb +123 -0
  70. data/lib/legion/extensions/agentic/inference/coherence/version.rb +13 -0
  71. data/lib/legion/extensions/agentic/inference/coherence.rb +19 -0
  72. data/lib/legion/extensions/agentic/inference/counterfactual/client.rb +19 -0
  73. data/lib/legion/extensions/agentic/inference/counterfactual/helpers/constants.rb +40 -0
  74. data/lib/legion/extensions/agentic/inference/counterfactual/helpers/counterfactual_engine.rb +157 -0
  75. data/lib/legion/extensions/agentic/inference/counterfactual/helpers/scenario.rb +98 -0
  76. data/lib/legion/extensions/agentic/inference/counterfactual/runners/counterfactual.rb +106 -0
  77. data/lib/legion/extensions/agentic/inference/counterfactual/version.rb +13 -0
  78. data/lib/legion/extensions/agentic/inference/counterfactual.rb +19 -0
  79. data/lib/legion/extensions/agentic/inference/debugging/client.rb +30 -0
  80. data/lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb +51 -0
  81. data/lib/legion/extensions/agentic/inference/debugging/helpers/constants.rb +58 -0
  82. data/lib/legion/extensions/agentic/inference/debugging/helpers/correction.rb +56 -0
  83. data/lib/legion/extensions/agentic/inference/debugging/helpers/debugging_engine.rb +156 -0
  84. data/lib/legion/extensions/agentic/inference/debugging/helpers/reasoning_error.rb +97 -0
  85. data/lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb +178 -0
  86. data/lib/legion/extensions/agentic/inference/debugging/version.rb +13 -0
  87. data/lib/legion/extensions/agentic/inference/debugging.rb +21 -0
  88. data/lib/legion/extensions/agentic/inference/enactive_cognition/client.rb +27 -0
  89. data/lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb +120 -0
  90. data/lib/legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop.rb +122 -0
  91. data/lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb +124 -0
  92. data/lib/legion/extensions/agentic/inference/enactive_cognition/version.rb +13 -0
  93. data/lib/legion/extensions/agentic/inference/enactive_cognition.rb +18 -0
  94. data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/client.rb +17 -0
  95. data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/constants.rb +47 -0
  96. data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/expectation.rb +82 -0
  97. data/lib/legion/extensions/agentic/inference/expectation_violation/helpers/violation_engine.rb +126 -0
  98. data/lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb +76 -0
  99. data/lib/legion/extensions/agentic/inference/expectation_violation/version.rb +13 -0
  100. data/lib/legion/extensions/agentic/inference/expectation_violation.rb +19 -0
  101. data/lib/legion/extensions/agentic/inference/free_energy/client.rb +19 -0
  102. data/lib/legion/extensions/agentic/inference/free_energy/helpers/belief.rb +127 -0
  103. data/lib/legion/extensions/agentic/inference/free_energy/helpers/constants.rb +58 -0
  104. data/lib/legion/extensions/agentic/inference/free_energy/helpers/free_energy_engine.rb +156 -0
  105. data/lib/legion/extensions/agentic/inference/free_energy/runners/free_energy.rb +97 -0
  106. data/lib/legion/extensions/agentic/inference/free_energy/version.rb +13 -0
  107. data/lib/legion/extensions/agentic/inference/free_energy.rb +19 -0
  108. data/lib/legion/extensions/agentic/inference/gravity/client.rb +29 -0
  109. data/lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb +77 -0
  110. data/lib/legion/extensions/agentic/inference/gravity/helpers/constants.rb +76 -0
  111. data/lib/legion/extensions/agentic/inference/gravity/helpers/gravity_engine.rb +164 -0
  112. data/lib/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought.rb +64 -0
  113. data/lib/legion/extensions/agentic/inference/gravity/runners/gravity.rb +132 -0
  114. data/lib/legion/extensions/agentic/inference/gravity/version.rb +13 -0
  115. data/lib/legion/extensions/agentic/inference/gravity.rb +20 -0
  116. data/lib/legion/extensions/agentic/inference/horizon/actors/adjust.rb +45 -0
  117. data/lib/legion/extensions/agentic/inference/horizon/client.rb +28 -0
  118. data/lib/legion/extensions/agentic/inference/horizon/helpers/constants.rb +43 -0
  119. data/lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb +110 -0
  120. data/lib/legion/extensions/agentic/inference/horizon/helpers/projection.rb +59 -0
  121. data/lib/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon.rb +107 -0
  122. data/lib/legion/extensions/agentic/inference/horizon/version.rb +13 -0
  123. data/lib/legion/extensions/agentic/inference/horizon.rb +19 -0
  124. data/lib/legion/extensions/agentic/inference/hypothesis_testing/client.rb +28 -0
  125. data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/constants.rb +37 -0
  126. data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb +83 -0
  127. data/lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine.rb +97 -0
  128. data/lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb +115 -0
  129. data/lib/legion/extensions/agentic/inference/hypothesis_testing/version.rb +13 -0
  130. data/lib/legion/extensions/agentic/inference/hypothesis_testing.rb +19 -0
  131. data/lib/legion/extensions/agentic/inference/intuition/client.rb +19 -0
  132. data/lib/legion/extensions/agentic/inference/intuition/helpers/constants.rb +60 -0
  133. data/lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb +66 -0
  134. data/lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb +157 -0
  135. data/lib/legion/extensions/agentic/inference/intuition/helpers/pattern.rb +105 -0
  136. data/lib/legion/extensions/agentic/inference/intuition/runners/intuition.rb +87 -0
  137. data/lib/legion/extensions/agentic/inference/intuition/version.rb +13 -0
  138. data/lib/legion/extensions/agentic/inference/intuition.rb +20 -0
  139. data/lib/legion/extensions/agentic/inference/magnet/client.rb +29 -0
  140. data/lib/legion/extensions/agentic/inference/magnet/helpers/constants.rb +57 -0
  141. data/lib/legion/extensions/agentic/inference/magnet/helpers/field.rb +105 -0
  142. data/lib/legion/extensions/agentic/inference/magnet/helpers/magnet_engine.rb +179 -0
  143. data/lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb +80 -0
  144. data/lib/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet.rb +124 -0
  145. data/lib/legion/extensions/agentic/inference/magnet/version.rb +13 -0
  146. data/lib/legion/extensions/agentic/inference/magnet.rb +21 -0
  147. data/lib/legion/extensions/agentic/inference/momentum/helpers/client.rb +17 -0
  148. data/lib/legion/extensions/agentic/inference/momentum/helpers/constants.rb +65 -0
  149. data/lib/legion/extensions/agentic/inference/momentum/helpers/idea.rb +112 -0
  150. data/lib/legion/extensions/agentic/inference/momentum/helpers/momentum_engine.rb +127 -0
  151. data/lib/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum.rb +101 -0
  152. data/lib/legion/extensions/agentic/inference/momentum/version.rb +13 -0
  153. data/lib/legion/extensions/agentic/inference/momentum.rb +19 -0
  154. data/lib/legion/extensions/agentic/inference/perceptual_inference/client.rb +28 -0
  155. data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/constants.rb +34 -0
  156. data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field.rb +154 -0
  157. data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb +100 -0
  158. data/lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb +120 -0
  159. data/lib/legion/extensions/agentic/inference/perceptual_inference/version.rb +13 -0
  160. data/lib/legion/extensions/agentic/inference/perceptual_inference.rb +19 -0
  161. data/lib/legion/extensions/agentic/inference/prediction/actors/expire_predictions.rb +45 -0
  162. data/lib/legion/extensions/agentic/inference/prediction/client.rb +27 -0
  163. data/lib/legion/extensions/agentic/inference/prediction/helpers/modes.rb +28 -0
  164. data/lib/legion/extensions/agentic/inference/prediction/helpers/prediction_store.rb +66 -0
  165. data/lib/legion/extensions/agentic/inference/prediction/runners/prediction.rb +146 -0
  166. data/lib/legion/extensions/agentic/inference/prediction/version.rb +13 -0
  167. data/lib/legion/extensions/agentic/inference/prediction.rb +18 -0
  168. data/lib/legion/extensions/agentic/inference/predictive_coding/actors/decay.rb +45 -0
  169. data/lib/legion/extensions/agentic/inference/predictive_coding/client.rb +28 -0
  170. data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/constants.rb +46 -0
  171. data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/generative_model.rb +187 -0
  172. data/lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb +59 -0
  173. data/lib/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding.rb +171 -0
  174. data/lib/legion/extensions/agentic/inference/predictive_coding/version.rb +13 -0
  175. data/lib/legion/extensions/agentic/inference/predictive_coding.rb +20 -0
  176. data/lib/legion/extensions/agentic/inference/predictive_processing/client.rb +28 -0
  177. data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/constants.rb +35 -0
  178. data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/generative_model.rb +142 -0
  179. data/lib/legion/extensions/agentic/inference/predictive_processing/helpers/predictive_processor.rb +129 -0
  180. data/lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb +104 -0
  181. data/lib/legion/extensions/agentic/inference/predictive_processing/version.rb +13 -0
  182. data/lib/legion/extensions/agentic/inference/predictive_processing.rb +19 -0
  183. data/lib/legion/extensions/agentic/inference/reality_testing/client.rb +28 -0
  184. data/lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb +98 -0
  185. data/lib/legion/extensions/agentic/inference/reality_testing/helpers/constants.rb +41 -0
  186. data/lib/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine.rb +104 -0
  187. data/lib/legion/extensions/agentic/inference/reality_testing/runners/reality_testing.rb +94 -0
  188. data/lib/legion/extensions/agentic/inference/reality_testing/version.rb +13 -0
  189. data/lib/legion/extensions/agentic/inference/reality_testing.rb +19 -0
  190. data/lib/legion/extensions/agentic/inference/schema/client.rb +26 -0
  191. data/lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb +70 -0
  192. data/lib/legion/extensions/agentic/inference/schema/helpers/constants.rb +50 -0
  193. data/lib/legion/extensions/agentic/inference/schema/helpers/world_model.rb +173 -0
  194. data/lib/legion/extensions/agentic/inference/schema/runners/schema.rb +101 -0
  195. data/lib/legion/extensions/agentic/inference/schema/version.rb +13 -0
  196. data/lib/legion/extensions/agentic/inference/schema.rb +19 -0
  197. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/client.rb +28 -0
  198. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/constants.rb +42 -0
  199. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision.rb +66 -0
  200. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/tolerance_engine.rb +139 -0
  201. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb +129 -0
  202. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/version.rb +13 -0
  203. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance.rb +19 -0
  204. data/lib/legion/extensions/agentic/inference/version.rb +11 -0
  205. data/lib/legion/extensions/agentic/inference.rb +44 -0
  206. data/spec/legion/extensions/agentic/inference/abductive/client_spec.rb +25 -0
  207. data/spec/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning_spec.rb +349 -0
  208. data/spec/legion/extensions/agentic/inference/affordance/client_spec.rb +26 -0
  209. data/spec/legion/extensions/agentic/inference/affordance/helpers/affordance_field_spec.rb +131 -0
  210. data/spec/legion/extensions/agentic/inference/affordance/helpers/affordance_item_spec.rb +107 -0
  211. data/spec/legion/extensions/agentic/inference/affordance/runners/affordance_spec.rb +78 -0
  212. data/spec/legion/extensions/agentic/inference/analogical/client_spec.rb +31 -0
  213. data/spec/legion/extensions/agentic/inference/analogical/helpers/analogy_engine_spec.rb +276 -0
  214. data/spec/legion/extensions/agentic/inference/analogical/helpers/structure_map_spec.rb +255 -0
  215. data/spec/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning_spec.rb +213 -0
  216. data/spec/legion/extensions/agentic/inference/argument_mapping/client_spec.rb +18 -0
  217. data/spec/legion/extensions/agentic/inference/argument_mapping/helpers/argument_engine_spec.rb +218 -0
  218. data/spec/legion/extensions/agentic/inference/argument_mapping/helpers/argument_spec.rb +231 -0
  219. data/spec/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping_spec.rb +171 -0
  220. data/spec/legion/extensions/agentic/inference/bayesian/client_spec.rb +20 -0
  221. data/spec/legion/extensions/agentic/inference/bayesian/helpers/belief_network_spec.rb +178 -0
  222. data/spec/legion/extensions/agentic/inference/bayesian/helpers/belief_spec.rb +137 -0
  223. data/spec/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief_spec.rb +176 -0
  224. data/spec/legion/extensions/agentic/inference/belief_revision/client_spec.rb +31 -0
  225. data/spec/legion/extensions/agentic/inference/belief_revision/helpers/belief_network_spec.rb +176 -0
  226. data/spec/legion/extensions/agentic/inference/belief_revision/helpers/belief_spec.rb +153 -0
  227. data/spec/legion/extensions/agentic/inference/belief_revision/helpers/evidence_spec.rb +51 -0
  228. data/spec/legion/extensions/agentic/inference/belief_revision/runners/belief_revision_spec.rb +106 -0
  229. data/spec/legion/extensions/agentic/inference/causal_attribution/client_spec.rb +24 -0
  230. data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_engine_spec.rb +181 -0
  231. data/spec/legion/extensions/agentic/inference/causal_attribution/helpers/attribution_spec.rb +108 -0
  232. data/spec/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution_spec.rb +142 -0
  233. data/spec/legion/extensions/agentic/inference/causal_reasoning/client_spec.rb +35 -0
  234. data/spec/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_edge_spec.rb +158 -0
  235. data/spec/legion/extensions/agentic/inference/causal_reasoning/helpers/causal_graph_spec.rb +259 -0
  236. data/spec/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning_spec.rb +161 -0
  237. data/spec/legion/extensions/agentic/inference/coherence/client_spec.rb +17 -0
  238. data/spec/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence_spec.rb +267 -0
  239. data/spec/legion/extensions/agentic/inference/counterfactual/client_spec.rb +48 -0
  240. data/spec/legion/extensions/agentic/inference/counterfactual/helpers/constants_spec.rb +55 -0
  241. data/spec/legion/extensions/agentic/inference/counterfactual/helpers/counterfactual_engine_spec.rb +234 -0
  242. data/spec/legion/extensions/agentic/inference/counterfactual/helpers/scenario_spec.rb +193 -0
  243. data/spec/legion/extensions/agentic/inference/counterfactual/runners/counterfactual_spec.rb +179 -0
  244. data/spec/legion/extensions/agentic/inference/debugging/client_spec.rb +46 -0
  245. data/spec/legion/extensions/agentic/inference/debugging/helpers/causal_trace_spec.rb +84 -0
  246. data/spec/legion/extensions/agentic/inference/debugging/helpers/constants_spec.rb +97 -0
  247. data/spec/legion/extensions/agentic/inference/debugging/helpers/correction_spec.rb +98 -0
  248. data/spec/legion/extensions/agentic/inference/debugging/helpers/debugging_engine_spec.rb +290 -0
  249. data/spec/legion/extensions/agentic/inference/debugging/helpers/reasoning_error_spec.rb +164 -0
  250. data/spec/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging_spec.rb +301 -0
  251. data/spec/legion/extensions/agentic/inference/enactive_cognition/client_spec.rb +19 -0
  252. data/spec/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine_spec.rb +181 -0
  253. data/spec/legion/extensions/agentic/inference/enactive_cognition/helpers/sensorimotor_loop_spec.rb +184 -0
  254. data/spec/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition_spec.rb +214 -0
  255. data/spec/legion/extensions/agentic/inference/expectation_violation/expectation_violation_spec.rb +11 -0
  256. data/spec/legion/extensions/agentic/inference/expectation_violation/helpers/expectation_spec.rb +102 -0
  257. data/spec/legion/extensions/agentic/inference/expectation_violation/helpers/violation_engine_spec.rb +121 -0
  258. data/spec/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation_spec.rb +59 -0
  259. data/spec/legion/extensions/agentic/inference/free_energy/client_spec.rb +46 -0
  260. data/spec/legion/extensions/agentic/inference/free_energy/helpers/belief_spec.rb +183 -0
  261. data/spec/legion/extensions/agentic/inference/free_energy/helpers/free_energy_engine_spec.rb +211 -0
  262. data/spec/legion/extensions/agentic/inference/free_energy/runners/free_energy_spec.rb +118 -0
  263. data/spec/legion/extensions/agentic/inference/gravity/client_spec.rb +24 -0
  264. data/spec/legion/extensions/agentic/inference/gravity/helpers/attractor_spec.rb +143 -0
  265. data/spec/legion/extensions/agentic/inference/gravity/helpers/constants_spec.rb +107 -0
  266. data/spec/legion/extensions/agentic/inference/gravity/helpers/gravity_engine_spec.rb +193 -0
  267. data/spec/legion/extensions/agentic/inference/gravity/helpers/orbiting_thought_spec.rb +103 -0
  268. data/spec/legion/extensions/agentic/inference/gravity/runners/gravity_spec.rb +159 -0
  269. data/spec/legion/extensions/agentic/inference/horizon/client_spec.rb +58 -0
  270. data/spec/legion/extensions/agentic/inference/horizon/helpers/constants_spec.rb +98 -0
  271. data/spec/legion/extensions/agentic/inference/horizon/helpers/horizon_engine_spec.rb +325 -0
  272. data/spec/legion/extensions/agentic/inference/horizon/helpers/projection_spec.rb +155 -0
  273. data/spec/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon_spec.rb +269 -0
  274. data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/constants_spec.rb +38 -0
  275. data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine_spec.rb +182 -0
  276. data/spec/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_spec.rb +172 -0
  277. data/spec/legion/extensions/agentic/inference/hypothesis_testing/hypothesis_testing_spec.rb +16 -0
  278. data/spec/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing_spec.rb +159 -0
  279. data/spec/legion/extensions/agentic/inference/intuition/client_spec.rb +33 -0
  280. data/spec/legion/extensions/agentic/inference/intuition/helpers/heuristic_spec.rb +82 -0
  281. data/spec/legion/extensions/agentic/inference/intuition/helpers/intuition_engine_spec.rb +163 -0
  282. data/spec/legion/extensions/agentic/inference/intuition/helpers/pattern_spec.rb +160 -0
  283. data/spec/legion/extensions/agentic/inference/intuition/runners/intuition_spec.rb +107 -0
  284. data/spec/legion/extensions/agentic/inference/magnet/client_spec.rb +30 -0
  285. data/spec/legion/extensions/agentic/inference/magnet/helpers/constants_spec.rb +120 -0
  286. data/spec/legion/extensions/agentic/inference/magnet/helpers/field_spec.rb +193 -0
  287. data/spec/legion/extensions/agentic/inference/magnet/helpers/magnet_engine_spec.rb +281 -0
  288. data/spec/legion/extensions/agentic/inference/magnet/helpers/pole_spec.rb +211 -0
  289. data/spec/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet_spec.rb +201 -0
  290. data/spec/legion/extensions/agentic/inference/momentum/cognitive_momentum_spec.rb +11 -0
  291. data/spec/legion/extensions/agentic/inference/momentum/helpers/idea_spec.rb +152 -0
  292. data/spec/legion/extensions/agentic/inference/momentum/helpers/momentum_engine_spec.rb +154 -0
  293. data/spec/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum_spec.rb +97 -0
  294. data/spec/legion/extensions/agentic/inference/perceptual_inference/client_spec.rb +39 -0
  295. data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/constants_spec.rb +97 -0
  296. data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field_spec.rb +270 -0
  297. data/spec/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis_spec.rb +206 -0
  298. data/spec/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference_spec.rb +305 -0
  299. data/spec/legion/extensions/agentic/inference/prediction/actors/expire_predictions_spec.rb +46 -0
  300. data/spec/legion/extensions/agentic/inference/prediction/client_spec.rb +14 -0
  301. data/spec/legion/extensions/agentic/inference/prediction/helpers/modes_spec.rb +118 -0
  302. data/spec/legion/extensions/agentic/inference/prediction/helpers/prediction_store_spec.rb +262 -0
  303. data/spec/legion/extensions/agentic/inference/prediction/runners/prediction_spec.rb +116 -0
  304. data/spec/legion/extensions/agentic/inference/predictive_coding/client_spec.rb +74 -0
  305. data/spec/legion/extensions/agentic/inference/predictive_coding/helpers/generative_model_spec.rb +194 -0
  306. data/spec/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error_spec.rb +109 -0
  307. data/spec/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding_spec.rb +210 -0
  308. data/spec/legion/extensions/agentic/inference/predictive_processing/client_spec.rb +82 -0
  309. data/spec/legion/extensions/agentic/inference/predictive_processing/helpers/generative_model_spec.rb +220 -0
  310. data/spec/legion/extensions/agentic/inference/predictive_processing/helpers/predictive_processor_spec.rb +206 -0
  311. data/spec/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing_spec.rb +213 -0
  312. data/spec/legion/extensions/agentic/inference/reality_testing/client_spec.rb +29 -0
  313. data/spec/legion/extensions/agentic/inference/reality_testing/helpers/belief_spec.rb +197 -0
  314. data/spec/legion/extensions/agentic/inference/reality_testing/helpers/constants_spec.rb +78 -0
  315. data/spec/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine_spec.rb +191 -0
  316. data/spec/legion/extensions/agentic/inference/reality_testing/runners/reality_testing_spec.rb +154 -0
  317. data/spec/legion/extensions/agentic/inference/schema/client_spec.rb +53 -0
  318. data/spec/legion/extensions/agentic/inference/schema/helpers/causal_relation_spec.rb +108 -0
  319. data/spec/legion/extensions/agentic/inference/schema/helpers/constants_spec.rb +54 -0
  320. data/spec/legion/extensions/agentic/inference/schema/helpers/world_model_spec.rb +179 -0
  321. data/spec/legion/extensions/agentic/inference/schema/runners/schema_spec.rb +146 -0
  322. data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/client_spec.rb +18 -0
  323. data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/constants_spec.rb +62 -0
  324. data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/decision_spec.rb +125 -0
  325. data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/helpers/tolerance_engine_spec.rb +184 -0
  326. data/spec/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance_spec.rb +157 -0
  327. data/spec/spec_helper.rb +46 -0
  328. metadata +412 -0
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Agentic
6
+ module Inference
7
+ module Horizon
8
+ module Runners
9
+ module CognitiveHorizon
10
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
11
+ Legion::Extensions::Helpers.const_defined?(:Lex)
12
+
13
+ def get_horizon(**)
14
+ report = horizon_engine.horizon_report
15
+ Legion::Logging.debug "[cognitive_horizon] get_horizon: effective=#{report[:effective_horizon].round(2)} construal=#{report[:construal_label]}"
16
+ { found: true, horizon: report }
17
+ end
18
+
19
+ def expand_horizon(amount: nil, **)
20
+ amt = amount || Helpers::Constants::HORIZON_EXPAND
21
+ before = horizon_engine.current_horizon
22
+ after = horizon_engine.expand_horizon!(amount: amt)
23
+ Legion::Logging.info "[cognitive_horizon] expand: #{before.round(2)} -> #{after.round(2)} (amount=#{amt})"
24
+ { expanded: true, before: before.round(10), after: after.round(10), amount: amt }
25
+ end
26
+
27
+ def contract_horizon(amount: nil, **)
28
+ amt = amount || Helpers::Constants::HORIZON_CONTRACT
29
+ before = horizon_engine.current_horizon
30
+ after = horizon_engine.contract_horizon!(amount: amt)
31
+ Legion::Logging.info "[cognitive_horizon] contract: #{before.round(2)} -> #{after.round(2)} (amount=#{amt})"
32
+ { contracted: true, before: before.round(10), after: after.round(10), amount: amt }
33
+ end
34
+
35
+ def apply_stress(level:, **)
36
+ before = horizon_engine.current_horizon
37
+ after = horizon_engine.apply_stress!(level)
38
+ Legion::Logging.info "[cognitive_horizon] stress applied: level=#{level} horizon #{before.round(2)} -> #{after.round(2)}"
39
+ {
40
+ stress_applied: true,
41
+ stress_level: level,
42
+ before: before.round(10),
43
+ after: after.round(10)
44
+ }
45
+ end
46
+
47
+ def relieve_stress(amount: nil, **)
48
+ amt = amount || 0.1
49
+ before = horizon_engine.stress_level
50
+ horizon_engine.relieve_stress!(amount: amt)
51
+ after = horizon_engine.stress_level
52
+ Legion::Logging.debug "[cognitive_horizon] relieve_stress: #{before.round(2)} -> #{after.round(2)}"
53
+ { relieved: true, before: before.round(10), after: after.round(10), amount: amt }
54
+ end
55
+
56
+ def add_projection(description:, domain: :general, horizon_distance: nil, confidence: 1.0, **)
57
+ proj = horizon_engine.add_projection(
58
+ description: description,
59
+ domain: domain,
60
+ horizon_distance: horizon_distance,
61
+ confidence: confidence
62
+ )
63
+ msg = "[cognitive_horizon] add_projection: id=#{proj.id} distance=#{proj.horizon_distance.round(2)} construal=#{proj.construal_level}"
64
+ Legion::Logging.debug msg
65
+ proj.to_h
66
+ end
67
+
68
+ def projections_within_horizon(**)
69
+ within = horizon_engine.projections_within_horizon
70
+ Legion::Logging.debug "[cognitive_horizon] within_horizon: count=#{within.size} effective=#{horizon_engine.effective_horizon.round(2)}"
71
+ { count: within.size, projections: within.map(&:to_h), effective_horizon: horizon_engine.effective_horizon.round(10) }
72
+ end
73
+
74
+ def beyond_horizon_projections(**)
75
+ beyond = horizon_engine.beyond_horizon_projections
76
+ Legion::Logging.debug "[cognitive_horizon] beyond_horizon: count=#{beyond.size}"
77
+ { count: beyond.size, projections: beyond.map(&:to_h), effective_horizon: horizon_engine.effective_horizon.round(10) }
78
+ end
79
+
80
+ def nearest_projections(count: 5, **)
81
+ projs = horizon_engine.nearest_projections(num: count)
82
+ Legion::Logging.debug "[cognitive_horizon] nearest_projections: count=#{count} returned=#{projs.size}"
83
+ { count: projs.size, projections: projs.map(&:to_h) }
84
+ end
85
+
86
+ def farthest_projections(count: 5, **)
87
+ projs = horizon_engine.farthest_projections(num: count)
88
+ Legion::Logging.debug "[cognitive_horizon] farthest_projections: count=#{count} returned=#{projs.size}"
89
+ { count: projs.size, projections: projs.map(&:to_h) }
90
+ end
91
+
92
+ def horizon_status(**)
93
+ { total_projections: horizon_engine.projections.size, report: horizon_engine.horizon_report }
94
+ end
95
+
96
+ private
97
+
98
+ def horizon_engine
99
+ @horizon_engine ||= Helpers::HorizonEngine.new
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Agentic
6
+ module Inference
7
+ module Horizon
8
+ VERSION = '0.1.0'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/agentic/inference/horizon/version'
4
+ require 'legion/extensions/agentic/inference/horizon/helpers/constants'
5
+ require 'legion/extensions/agentic/inference/horizon/helpers/projection'
6
+ require 'legion/extensions/agentic/inference/horizon/helpers/horizon_engine'
7
+ require 'legion/extensions/agentic/inference/horizon/runners/cognitive_horizon'
8
+ require 'legion/extensions/agentic/inference/horizon/client'
9
+
10
+ module Legion
11
+ module Extensions
12
+ module Agentic
13
+ module Inference
14
+ module Horizon
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/hypothesis_testing/helpers/constants'
4
+ require 'legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis'
5
+ require 'legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine'
6
+ require 'legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing'
7
+
8
+ module Legion
9
+ module Extensions
10
+ module Agentic
11
+ module Inference
12
+ module HypothesisTesting
13
+ class Client
14
+ include Runners::HypothesisTesting
15
+
16
+ def initialize(**)
17
+ @hypothesis_engine = Helpers::HypothesisEngine.new
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :hypothesis_engine
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Agentic
6
+ module Inference
7
+ module HypothesisTesting
8
+ module Helpers
9
+ module Constants
10
+ MAX_HYPOTHESES = 300
11
+ CONFIRMATION_THRESHOLD = 0.8
12
+ DISCONFIRMATION_THRESHOLD = 0.2
13
+ EVIDENCE_WEIGHT = 0.1
14
+ PRIOR_DEFAULT = 0.5
15
+
16
+ STATUS_LABELS = {
17
+ proposed: 'Proposed',
18
+ testing: 'Testing',
19
+ confirmed: 'Confirmed',
20
+ disconfirmed: 'Disconfirmed',
21
+ inconclusive: 'Inconclusive'
22
+ }.freeze
23
+
24
+ CONFIDENCE_LABELS = [
25
+ [0.9..1.0, 'certain'],
26
+ [0.7...0.9, 'confident'],
27
+ [0.5...0.7, 'leaning'],
28
+ [0.3...0.5, 'uncertain'],
29
+ [0.0...0.3, 'agnostic']
30
+ ].freeze
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Agentic
8
+ module Inference
9
+ module HypothesisTesting
10
+ module Helpers
11
+ class Hypothesis
12
+ include Constants
13
+
14
+ attr_reader :id, :description, :domain, :prior, :posterior,
15
+ :evidence_count, :status, :created_at
16
+
17
+ def initialize(description:, domain: 'general', prior: Constants::PRIOR_DEFAULT)
18
+ @id = SecureRandom.uuid
19
+ @description = description
20
+ @domain = domain
21
+ @prior = prior.clamp(0.0, 1.0)
22
+ @posterior = @prior
23
+ @evidence_count = 0
24
+ @status = :proposed
25
+ @created_at = Time.now.utc
26
+ end
27
+
28
+ def update_posterior!(evidence_strength:, supporting: true)
29
+ return self if @status == :confirmed || @status == :disconfirmed
30
+
31
+ @status = :testing
32
+ weight = Constants::EVIDENCE_WEIGHT * evidence_strength.clamp(0.0, 1.0)
33
+
34
+ @posterior = if supporting
35
+ @posterior + (weight * (1.0 - @posterior))
36
+ else
37
+ @posterior - (weight * @posterior)
38
+ end
39
+
40
+ @posterior = @posterior.clamp(0.0, 1.0).round(10)
41
+ @evidence_count += 1
42
+ self
43
+ end
44
+
45
+ def confirm!
46
+ @status = :confirmed
47
+ @posterior = [@posterior, Constants::CONFIRMATION_THRESHOLD].max.round(10)
48
+ self
49
+ end
50
+
51
+ def disconfirm!
52
+ @status = :disconfirmed
53
+ @posterior = [@posterior, Constants::DISCONFIRMATION_THRESHOLD].min.round(10)
54
+ self
55
+ end
56
+
57
+ def confidence_label
58
+ Constants::CONFIDENCE_LABELS.each do |range, label|
59
+ return label if range.cover?(@posterior)
60
+ end
61
+ 'agnostic'
62
+ end
63
+
64
+ def to_h
65
+ {
66
+ id: @id,
67
+ description: @description,
68
+ domain: @domain,
69
+ prior: @prior,
70
+ posterior: @posterior,
71
+ evidence_count: @evidence_count,
72
+ status: @status,
73
+ confidence_label: confidence_label,
74
+ created_at: @created_at
75
+ }
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Agentic
6
+ module Inference
7
+ module HypothesisTesting
8
+ module Helpers
9
+ class HypothesisEngine
10
+ include Constants
11
+
12
+ attr_reader :hypotheses
13
+
14
+ def initialize
15
+ @hypotheses = {}
16
+ end
17
+
18
+ def propose(description:, domain: 'general', prior: Constants::PRIOR_DEFAULT)
19
+ evict_oldest! if @hypotheses.size >= Constants::MAX_HYPOTHESES
20
+
21
+ h = Hypothesis.new(description: description, domain: domain, prior: prior)
22
+ @hypotheses[h.id] = h
23
+ h
24
+ end
25
+
26
+ def test_hypothesis(hypothesis_id:, evidence_strength:, supporting: true)
27
+ h = @hypotheses[hypothesis_id]
28
+ return nil unless h
29
+
30
+ h.update_posterior!(evidence_strength: evidence_strength, supporting: supporting)
31
+ evaluate(hypothesis_id)
32
+ h
33
+ end
34
+
35
+ def evaluate(hypothesis_id)
36
+ h = @hypotheses[hypothesis_id]
37
+ return nil unless h
38
+ return h if %i[confirmed disconfirmed].include?(h.status)
39
+
40
+ if h.posterior >= Constants::CONFIRMATION_THRESHOLD
41
+ h.confirm!
42
+ elsif h.posterior <= Constants::DISCONFIRMATION_THRESHOLD
43
+ h.disconfirm!
44
+ else
45
+ h
46
+ end
47
+ end
48
+
49
+ def competing_hypotheses(domain:)
50
+ @hypotheses.values.select { |h| h.domain == domain }
51
+ end
52
+
53
+ def most_confident(limit: 5)
54
+ @hypotheses.values
55
+ .sort_by { |h| -h.posterior }
56
+ .first(limit)
57
+ end
58
+
59
+ def confirmation_rate
60
+ total = @hypotheses.values.count { |h| %i[confirmed disconfirmed].include?(h.status) }
61
+ return 0.0 if total.zero?
62
+
63
+ confirmed = @hypotheses.values.count { |h| h.status == :confirmed }
64
+ (confirmed.to_f / total).round(10)
65
+ end
66
+
67
+ def hypothesis_report
68
+ by_status = @hypotheses.values.group_by(&:status).transform_values(&:count)
69
+ {
70
+ total: @hypotheses.size,
71
+ by_status: by_status,
72
+ confirmation_rate: confirmation_rate,
73
+ most_confident: most_confident(limit: 3).map(&:to_h)
74
+ }
75
+ end
76
+
77
+ def to_h
78
+ {
79
+ hypotheses: @hypotheses.values.map(&:to_h),
80
+ confirmation_rate: confirmation_rate,
81
+ total: @hypotheses.size
82
+ }
83
+ end
84
+
85
+ private
86
+
87
+ def evict_oldest!
88
+ oldest_key = @hypotheses.min_by { |_, h| h.created_at }&.first
89
+ @hypotheses.delete(oldest_key) if oldest_key
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Agentic
8
+ module Inference
9
+ module HypothesisTesting
10
+ module Runners
11
+ module HypothesisTesting
12
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
13
+ Legion::Extensions::Helpers.const_defined?(:Lex)
14
+
15
+ def propose_hypothesis(description:, domain: 'general', prior: Helpers::Constants::PRIOR_DEFAULT, **)
16
+ h = hypothesis_engine.propose(description: description, domain: domain, prior: prior)
17
+ Legion::Logging.debug "[hypothesis_testing] proposed id=#{h.id[0..7]} domain=#{domain} prior=#{prior}"
18
+ {
19
+ hypothesis_id: h.id,
20
+ description: h.description,
21
+ domain: h.domain,
22
+ prior: h.prior,
23
+ posterior: h.posterior,
24
+ status: h.status,
25
+ confidence_label: h.confidence_label
26
+ }
27
+ end
28
+
29
+ def test_hypothesis(hypothesis_id:, evidence_strength:, supporting: true, **)
30
+ h = hypothesis_engine.test_hypothesis(
31
+ hypothesis_id: hypothesis_id,
32
+ evidence_strength: evidence_strength,
33
+ supporting: supporting
34
+ )
35
+ unless h
36
+ Legion::Logging.debug "[hypothesis_testing] test failed: #{hypothesis_id[0..7]} not found"
37
+ return { tested: false, reason: :not_found }
38
+ end
39
+
40
+ Legion::Logging.info "[hypothesis_testing] tested #{hypothesis_id[0..7]} " \
41
+ "supporting=#{supporting} strength=#{evidence_strength} " \
42
+ "posterior=#{h.posterior.round(4)} status=#{h.status}"
43
+ {
44
+ tested: true,
45
+ hypothesis_id: h.id,
46
+ posterior: h.posterior,
47
+ evidence_count: h.evidence_count,
48
+ status: h.status,
49
+ confidence_label: h.confidence_label
50
+ }
51
+ end
52
+
53
+ def evaluate_hypothesis(hypothesis_id:, **)
54
+ h = hypothesis_engine.evaluate(hypothesis_id)
55
+ unless h
56
+ Legion::Logging.debug "[hypothesis_testing] evaluate failed: #{hypothesis_id[0..7]} not found"
57
+ return { found: false }
58
+ end
59
+
60
+ Legion::Logging.debug "[hypothesis_testing] evaluated #{hypothesis_id[0..7]} status=#{h.status}"
61
+ {
62
+ found: true,
63
+ hypothesis_id: h.id,
64
+ status: h.status,
65
+ posterior: h.posterior,
66
+ confidence_label: h.confidence_label,
67
+ evidence_count: h.evidence_count
68
+ }
69
+ end
70
+
71
+ def competing_hypotheses(domain:, **)
72
+ hypotheses = hypothesis_engine.competing_hypotheses(domain: domain)
73
+ Legion::Logging.debug "[hypothesis_testing] competing count=#{hypotheses.size} domain=#{domain}"
74
+ {
75
+ domain: domain,
76
+ count: hypotheses.size,
77
+ hypotheses: hypotheses.map(&:to_h)
78
+ }
79
+ end
80
+
81
+ def most_confident_hypotheses(limit: 5, **)
82
+ hypotheses = hypothesis_engine.most_confident(limit: limit)
83
+ Legion::Logging.debug "[hypothesis_testing] most_confident count=#{hypotheses.size}"
84
+ {
85
+ count: hypotheses.size,
86
+ hypotheses: hypotheses.map(&:to_h)
87
+ }
88
+ end
89
+
90
+ def hypothesis_report(**)
91
+ report = hypothesis_engine.hypothesis_report
92
+ Legion::Logging.debug "[hypothesis_testing] report total=#{report[:total]} " \
93
+ "confirmation_rate=#{report[:confirmation_rate].round(4)}"
94
+ report
95
+ end
96
+
97
+ def get_hypothesis(hypothesis_id:, **)
98
+ h = hypothesis_engine.hypotheses[hypothesis_id]
99
+ return { found: false } unless h
100
+
101
+ { found: true, hypothesis: h.to_h }
102
+ end
103
+
104
+ private
105
+
106
+ def hypothesis_engine
107
+ @hypothesis_engine ||= Helpers::HypothesisEngine.new
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Agentic
6
+ module Inference
7
+ module HypothesisTesting
8
+ VERSION = '0.1.0'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/agentic/inference/hypothesis_testing/version'
4
+ require 'legion/extensions/agentic/inference/hypothesis_testing/helpers/constants'
5
+ require 'legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis'
6
+ require 'legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis_engine'
7
+ require 'legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing'
8
+ require 'legion/extensions/agentic/inference/hypothesis_testing/client'
9
+
10
+ module Legion
11
+ module Extensions
12
+ module Agentic
13
+ module Inference
14
+ module HypothesisTesting
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Agentic
6
+ module Inference
7
+ module Intuition
8
+ class Client
9
+ include Runners::Intuition
10
+
11
+ def initialize(engine: nil)
12
+ @engine = engine || Helpers::IntuitionEngine.new
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Agentic
6
+ module Inference
7
+ module Intuition
8
+ module Helpers
9
+ module Constants
10
+ MAX_PATTERNS = 200
11
+ MAX_HEURISTICS = 50
12
+ MAX_HISTORY = 300
13
+
14
+ # Recognition threshold: pattern match score needed to trigger recognition
15
+ RECOGNITION_THRESHOLD = 0.6
16
+
17
+ # Confidence: how much the agent trusts its intuitions
18
+ DEFAULT_CONFIDENCE = 0.5
19
+ CONFIDENCE_FLOOR = 0.05
20
+ CONFIDENCE_CEILING = 0.95
21
+
22
+ # Reinforcement: how fast patterns strengthen/weaken
23
+ REINFORCEMENT_RATE = 0.1
24
+ DECAY_RATE = 0.01
25
+
26
+ # Speed advantage: intuition is N times faster than deliberation
27
+ SPEED_MULTIPLIER = 5
28
+
29
+ PATTERN_STATES = %i[nascent developing reliable expert].freeze
30
+
31
+ HEURISTIC_TYPES = %i[
32
+ recognition take_the_best satisficing
33
+ fast_and_frugal anchored gaze
34
+ ].freeze
35
+
36
+ INTUITION_MODES = %i[
37
+ gut_feeling pattern_match heuristic_shortcut
38
+ recognition_primed compiled_expertise
39
+ ].freeze
40
+
41
+ CONFIDENCE_LABELS = {
42
+ (0.8..) => :strong_hunch,
43
+ (0.6...0.8) => :leaning,
44
+ (0.4...0.6) => :uncertain,
45
+ (0.2...0.4) => :weak_signal,
46
+ (..0.2) => :noise
47
+ }.freeze
48
+
49
+ STATE_THRESHOLDS = {
50
+ expert: 0.85,
51
+ reliable: 0.65,
52
+ developing: 0.35
53
+ }.freeze
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Agentic
6
+ module Inference
7
+ module Intuition
8
+ module Helpers
9
+ class Heuristic
10
+ include Constants
11
+
12
+ attr_reader :id, :name, :heuristic_type, :domain, :uses, :successes
13
+
14
+ def initialize(id:, name:, heuristic_type:, domain: :general)
15
+ @id = id
16
+ @name = name
17
+ @heuristic_type = resolve_type(heuristic_type)
18
+ @domain = domain
19
+ @uses = 0
20
+ @successes = 0
21
+ end
22
+
23
+ def apply
24
+ @uses += 1
25
+ end
26
+
27
+ def record_outcome(success:)
28
+ @successes += 1 if success
29
+ end
30
+
31
+ def success_rate
32
+ return 0.0 if @uses.zero?
33
+
34
+ @successes.to_f / @uses
35
+ end
36
+
37
+ def effective?
38
+ @uses >= 3 && success_rate >= 0.6
39
+ end
40
+
41
+ def to_h
42
+ {
43
+ id: @id,
44
+ name: @name,
45
+ heuristic_type: @heuristic_type,
46
+ domain: @domain,
47
+ uses: @uses,
48
+ successes: @successes,
49
+ success_rate: success_rate.round(4),
50
+ effective: effective?
51
+ }
52
+ end
53
+
54
+ private
55
+
56
+ def resolve_type(type)
57
+ sym = type.to_sym
58
+ HEURISTIC_TYPES.include?(sym) ? sym : :fast_and_frugal
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end