@ai.ntellect/core 0.8.3 → 1.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 (460) hide show
  1. package/.mocharc.json +2 -1
  2. package/AGENTS.md +50 -0
  3. package/ARCHITECTURE.md +58 -0
  4. package/BENCHMARK.md +38 -0
  5. package/CHANGELOG.md +224 -0
  6. package/README.md +413 -199
  7. package/agent/agent-workflow.ts +569 -0
  8. package/agent/agent.ts +183 -0
  9. package/{modules/agent → agent}/base/executor.ts +11 -8
  10. package/{modules/agent → agent}/base/index.ts +2 -14
  11. package/agent/entity-resolver/confidence.ts +54 -0
  12. package/agent/entity-resolver/entity-index.ts +241 -0
  13. package/agent/entity-resolver/explore-strategy.ts +82 -0
  14. package/agent/entity-resolver/index.ts +22 -0
  15. package/agent/entity-resolver/resolver.ts +193 -0
  16. package/agent/entity-resolver/scorer.ts +211 -0
  17. package/agent/entity-resolver/types.ts +98 -0
  18. package/agent/generic-executor.ts +713 -0
  19. package/agent/handlers/cognitive-handler.ts +197 -0
  20. package/agent/handlers/index.ts +1 -0
  21. package/agent/handoff.ts +58 -0
  22. package/agent/llm-factory.ts +343 -0
  23. package/agent/orchestrator.ts +45 -0
  24. package/{modules/agent → agent}/prompt-builder.ts +1 -1
  25. package/agent/registry.ts +64 -0
  26. package/agent/tools/file-system.ts +471 -0
  27. package/agent/tools/index.ts +23 -0
  28. package/agent/tools/logger.ts +105 -0
  29. package/agent/tools/tool-resolver.ts +104 -0
  30. package/benchmark/cortexflow-workflow.ts +182 -0
  31. package/benchmark/langgraph-workflow.ts +201 -0
  32. package/benchmark/llm-client.ts +76 -0
  33. package/benchmark/run-benchmark.ts +222 -0
  34. package/cli-dev.ts +419 -0
  35. package/dist/agent/agent-workflow.d.ts +41 -0
  36. package/dist/agent/agent-workflow.d.ts.map +1 -0
  37. package/dist/agent/agent-workflow.js +560 -0
  38. package/dist/agent/agent-workflow.js.map +1 -0
  39. package/dist/agent/agent.d.ts +38 -0
  40. package/dist/agent/agent.d.ts.map +1 -0
  41. package/dist/agent/agent.js +149 -0
  42. package/dist/agent/agent.js.map +1 -0
  43. package/dist/{modules/agent → agent}/base/executor.d.ts +3 -3
  44. package/dist/agent/base/executor.d.ts.map +1 -0
  45. package/dist/{modules/agent → agent}/base/executor.js +8 -5
  46. package/dist/agent/base/executor.js.map +1 -0
  47. package/dist/{modules/agent → agent}/base/index.d.ts +1 -1
  48. package/dist/agent/base/index.d.ts.map +1 -0
  49. package/dist/{modules/agent → agent}/base/index.js +0 -12
  50. package/dist/agent/base/index.js.map +1 -0
  51. package/dist/agent/entity-resolver/confidence.d.ts +4 -0
  52. package/dist/agent/entity-resolver/confidence.d.ts.map +1 -0
  53. package/dist/agent/entity-resolver/confidence.js +47 -0
  54. package/dist/agent/entity-resolver/confidence.js.map +1 -0
  55. package/dist/agent/entity-resolver/entity-index.d.ts +40 -0
  56. package/dist/agent/entity-resolver/entity-index.d.ts.map +1 -0
  57. package/dist/agent/entity-resolver/entity-index.js +244 -0
  58. package/dist/agent/entity-resolver/entity-index.js.map +1 -0
  59. package/dist/agent/entity-resolver/explore-strategy.d.ts +13 -0
  60. package/dist/agent/entity-resolver/explore-strategy.d.ts.map +1 -0
  61. package/dist/agent/entity-resolver/explore-strategy.js +109 -0
  62. package/dist/agent/entity-resolver/explore-strategy.js.map +1 -0
  63. package/dist/agent/entity-resolver/index.d.ts +8 -0
  64. package/dist/agent/entity-resolver/index.d.ts.map +1 -0
  65. package/dist/agent/entity-resolver/index.js +16 -0
  66. package/dist/agent/entity-resolver/index.js.map +1 -0
  67. package/dist/agent/entity-resolver/resolver.d.ts +18 -0
  68. package/dist/agent/entity-resolver/resolver.d.ts.map +1 -0
  69. package/dist/agent/entity-resolver/resolver.js +158 -0
  70. package/dist/agent/entity-resolver/resolver.js.map +1 -0
  71. package/dist/agent/entity-resolver/scorer.d.ts +3 -0
  72. package/dist/agent/entity-resolver/scorer.d.ts.map +1 -0
  73. package/dist/agent/entity-resolver/scorer.js +182 -0
  74. package/dist/agent/entity-resolver/scorer.js.map +1 -0
  75. package/dist/agent/entity-resolver/types.d.ts +89 -0
  76. package/dist/agent/entity-resolver/types.d.ts.map +1 -0
  77. package/dist/agent/entity-resolver/types.js +3 -0
  78. package/dist/agent/entity-resolver/types.js.map +1 -0
  79. package/dist/{modules/agent → agent}/generic-executor.d.ts +37 -27
  80. package/dist/agent/generic-executor.d.ts.map +1 -0
  81. package/dist/agent/generic-executor.js +620 -0
  82. package/dist/agent/generic-executor.js.map +1 -0
  83. package/dist/agent/handlers/cognitive-handler.d.ts +44 -0
  84. package/dist/agent/handlers/cognitive-handler.d.ts.map +1 -0
  85. package/dist/agent/handlers/cognitive-handler.js +172 -0
  86. package/dist/agent/handlers/cognitive-handler.js.map +1 -0
  87. package/dist/agent/handlers/index.d.ts +2 -0
  88. package/dist/agent/handlers/index.d.ts.map +1 -0
  89. package/dist/agent/handlers/index.js +7 -0
  90. package/dist/agent/handlers/index.js.map +1 -0
  91. package/dist/agent/handoff.d.ts +12 -0
  92. package/dist/agent/handoff.d.ts.map +1 -0
  93. package/dist/agent/handoff.js +62 -0
  94. package/dist/agent/handoff.js.map +1 -0
  95. package/dist/agent/llm-factory.d.ts.map +1 -0
  96. package/dist/agent/llm-factory.js +297 -0
  97. package/dist/agent/llm-factory.js.map +1 -0
  98. package/dist/agent/orchestrator.d.ts +18 -0
  99. package/dist/agent/orchestrator.d.ts.map +1 -0
  100. package/dist/agent/orchestrator.js +44 -0
  101. package/dist/agent/orchestrator.js.map +1 -0
  102. package/dist/{modules/agent → agent}/prompt-builder.d.ts +1 -1
  103. package/dist/agent/prompt-builder.d.ts.map +1 -0
  104. package/dist/agent/prompt-builder.js.map +1 -0
  105. package/dist/agent/registry.d.ts +19 -0
  106. package/dist/agent/registry.d.ts.map +1 -0
  107. package/dist/agent/registry.js +48 -0
  108. package/dist/agent/registry.js.map +1 -0
  109. package/dist/agent/tools/file-system.d.ts +11 -0
  110. package/dist/agent/tools/file-system.d.ts.map +1 -0
  111. package/dist/agent/tools/file-system.js +528 -0
  112. package/dist/agent/tools/file-system.js.map +1 -0
  113. package/dist/agent/tools/index.d.ts +4 -0
  114. package/dist/agent/tools/index.d.ts.map +1 -0
  115. package/dist/agent/tools/index.js +20 -0
  116. package/dist/agent/tools/index.js.map +1 -0
  117. package/dist/agent/tools/logger.d.ts +33 -0
  118. package/dist/agent/tools/logger.d.ts.map +1 -0
  119. package/dist/agent/tools/logger.js +86 -0
  120. package/dist/agent/tools/logger.js.map +1 -0
  121. package/dist/agent/tools/tool-resolver.d.ts +7 -0
  122. package/dist/agent/tools/tool-resolver.d.ts.map +1 -0
  123. package/dist/agent/tools/tool-resolver.js +122 -0
  124. package/dist/agent/tools/tool-resolver.js.map +1 -0
  125. package/dist/execution/adapters/in-memory-checkpoint.d.ts +11 -0
  126. package/dist/execution/adapters/in-memory-checkpoint.d.ts.map +1 -0
  127. package/dist/execution/adapters/in-memory-checkpoint.js +54 -0
  128. package/dist/execution/adapters/in-memory-checkpoint.js.map +1 -0
  129. package/dist/execution/compiler.d.ts +8 -0
  130. package/dist/execution/compiler.d.ts.map +1 -0
  131. package/dist/execution/compiler.js +50 -0
  132. package/dist/execution/compiler.js.map +1 -0
  133. package/dist/execution/controller.d.ts.map +1 -0
  134. package/dist/execution/controller.js.map +1 -0
  135. package/dist/execution/event-manager.d.ts +29 -0
  136. package/dist/execution/event-manager.d.ts.map +1 -0
  137. package/dist/{graph → execution}/event-manager.js +4 -114
  138. package/dist/execution/event-manager.js.map +1 -0
  139. package/dist/{graph → execution}/index.d.ts +50 -2
  140. package/dist/execution/index.d.ts.map +1 -0
  141. package/dist/execution/index.js +638 -0
  142. package/dist/execution/index.js.map +1 -0
  143. package/dist/execution/logger.d.ts.map +1 -0
  144. package/dist/execution/logger.js.map +1 -0
  145. package/dist/{graph → execution}/node.d.ts +6 -1
  146. package/dist/execution/node.d.ts.map +1 -0
  147. package/dist/{graph → execution}/node.js +83 -10
  148. package/dist/execution/node.js.map +1 -0
  149. package/dist/execution/observer.d.ts.map +1 -0
  150. package/dist/execution/observer.js.map +1 -0
  151. package/dist/execution/planner.d.ts +14 -0
  152. package/dist/execution/planner.d.ts.map +1 -0
  153. package/dist/execution/planner.js +43 -0
  154. package/dist/execution/planner.js.map +1 -0
  155. package/dist/execution/reducer.d.ts +19 -0
  156. package/dist/execution/reducer.d.ts.map +1 -0
  157. package/dist/execution/reducer.js +61 -0
  158. package/dist/execution/reducer.js.map +1 -0
  159. package/dist/execution/registry.d.ts +38 -0
  160. package/dist/execution/registry.d.ts.map +1 -0
  161. package/dist/execution/registry.js +63 -0
  162. package/dist/execution/registry.js.map +1 -0
  163. package/dist/execution/send-api.d.ts +24 -0
  164. package/dist/execution/send-api.d.ts.map +1 -0
  165. package/dist/execution/send-api.js +52 -0
  166. package/dist/execution/send-api.js.map +1 -0
  167. package/dist/execution/types.parallel.d.ts +61 -0
  168. package/dist/execution/types.parallel.d.ts.map +1 -0
  169. package/dist/execution/types.parallel.js +3 -0
  170. package/dist/execution/types.parallel.js.map +1 -0
  171. package/dist/execution/visualizer.d.ts.map +1 -0
  172. package/dist/execution/visualizer.js.map +1 -0
  173. package/dist/index.d.ts +27 -8
  174. package/dist/index.d.ts.map +1 -1
  175. package/dist/index.js +42 -8
  176. package/dist/index.js.map +1 -1
  177. package/dist/interfaces/index.d.ts +32 -1
  178. package/dist/interfaces/index.d.ts.map +1 -1
  179. package/dist/interfaces/index.js.map +1 -1
  180. package/dist/modules/cli/index.d.ts +13 -0
  181. package/dist/modules/cli/index.d.ts.map +1 -0
  182. package/dist/modules/cli/index.js +672 -0
  183. package/dist/modules/cli/index.js.map +1 -0
  184. package/dist/modules/nlp/engine.d.ts.map +1 -1
  185. package/dist/modules/nlp/engine.js +0 -1
  186. package/dist/modules/nlp/engine.js.map +1 -1
  187. package/dist/persistence/index.d.ts +12 -0
  188. package/dist/persistence/index.d.ts.map +1 -0
  189. package/dist/persistence/index.js +24 -0
  190. package/dist/persistence/index.js.map +1 -0
  191. package/dist/persistence/neo4j/driver.d.ts +26 -0
  192. package/dist/persistence/neo4j/driver.d.ts.map +1 -0
  193. package/dist/persistence/neo4j/driver.js +64 -0
  194. package/dist/persistence/neo4j/driver.js.map +1 -0
  195. package/dist/persistence/neo4j/entity-store.d.ts +15 -0
  196. package/dist/persistence/neo4j/entity-store.d.ts.map +1 -0
  197. package/dist/persistence/neo4j/entity-store.js +136 -0
  198. package/dist/persistence/neo4j/entity-store.js.map +1 -0
  199. package/dist/persistence/neo4j/execution-tracer.d.ts +19 -0
  200. package/dist/persistence/neo4j/execution-tracer.d.ts.map +1 -0
  201. package/dist/persistence/neo4j/execution-tracer.js +166 -0
  202. package/dist/persistence/neo4j/execution-tracer.js.map +1 -0
  203. package/dist/persistence/neo4j/memory-adapter.d.ts +35 -0
  204. package/dist/persistence/neo4j/memory-adapter.d.ts.map +1 -0
  205. package/dist/persistence/neo4j/memory-adapter.js +252 -0
  206. package/dist/persistence/neo4j/memory-adapter.js.map +1 -0
  207. package/dist/persistence/neo4j/petri-checkpoint-adapter.d.ts +22 -0
  208. package/dist/persistence/neo4j/petri-checkpoint-adapter.d.ts.map +1 -0
  209. package/dist/persistence/neo4j/petri-checkpoint-adapter.js +141 -0
  210. package/dist/persistence/neo4j/petri-checkpoint-adapter.js.map +1 -0
  211. package/dist/pipeline/agent-pipeline.d.ts +99 -0
  212. package/dist/pipeline/agent-pipeline.d.ts.map +1 -0
  213. package/dist/pipeline/agent-pipeline.js +356 -0
  214. package/dist/pipeline/agent-pipeline.js.map +1 -0
  215. package/dist/routing/checkpoint-adapter.d.ts +30 -0
  216. package/dist/routing/checkpoint-adapter.d.ts.map +1 -0
  217. package/dist/routing/checkpoint-adapter.js +83 -0
  218. package/dist/routing/checkpoint-adapter.js.map +1 -0
  219. package/dist/routing/documentation-generator.d.ts +47 -0
  220. package/dist/routing/documentation-generator.d.ts.map +1 -0
  221. package/dist/routing/documentation-generator.js +320 -0
  222. package/dist/routing/documentation-generator.js.map +1 -0
  223. package/dist/routing/index.d.ts +38 -0
  224. package/dist/routing/index.d.ts.map +1 -0
  225. package/dist/routing/index.js +375 -0
  226. package/dist/routing/index.js.map +1 -0
  227. package/dist/routing/intent-classifier.d.ts +206 -0
  228. package/dist/routing/intent-classifier.d.ts.map +1 -0
  229. package/dist/routing/intent-classifier.js +267 -0
  230. package/dist/routing/intent-classifier.js.map +1 -0
  231. package/dist/routing/matrix.d.ts +6 -0
  232. package/dist/routing/matrix.d.ts.map +1 -0
  233. package/dist/routing/matrix.js +131 -0
  234. package/dist/routing/matrix.js.map +1 -0
  235. package/dist/routing/orchestrator.d.ts +87 -0
  236. package/dist/routing/orchestrator.d.ts.map +1 -0
  237. package/dist/routing/orchestrator.js +425 -0
  238. package/dist/routing/orchestrator.js.map +1 -0
  239. package/dist/routing/postgres-checkpoint-adapter.d.ts +32 -0
  240. package/dist/routing/postgres-checkpoint-adapter.d.ts.map +1 -0
  241. package/dist/routing/postgres-checkpoint-adapter.js +167 -0
  242. package/dist/routing/postgres-checkpoint-adapter.js.map +1 -0
  243. package/dist/routing/redis-checkpoint-adapter.d.ts +34 -0
  244. package/dist/routing/redis-checkpoint-adapter.d.ts.map +1 -0
  245. package/dist/routing/redis-checkpoint-adapter.js +170 -0
  246. package/dist/routing/redis-checkpoint-adapter.js.map +1 -0
  247. package/dist/routing/types.d.ts +49 -0
  248. package/dist/routing/types.d.ts.map +1 -0
  249. package/dist/routing/types.js +3 -0
  250. package/dist/routing/types.js.map +1 -0
  251. package/dist/types/agent.d.ts +144 -88
  252. package/dist/types/agent.d.ts.map +1 -1
  253. package/dist/types/agent.js +49 -0
  254. package/dist/types/agent.js.map +1 -1
  255. package/dist/types/index.d.ts +46 -4
  256. package/dist/types/index.d.ts.map +1 -1
  257. package/dist/utils/generate-action-schema.d.ts +2 -3
  258. package/dist/utils/generate-action-schema.d.ts.map +1 -1
  259. package/dist/utils/generate-action-schema.js +3 -1
  260. package/dist/utils/generate-action-schema.js.map +1 -1
  261. package/dist/utils/logger.d.ts +27 -0
  262. package/dist/utils/logger.d.ts.map +1 -0
  263. package/dist/utils/logger.js +45 -0
  264. package/dist/utils/logger.js.map +1 -0
  265. package/docs/.gitbook/assets/image (1).png +0 -0
  266. package/docs/.gitbook/assets/image (2).png +0 -0
  267. package/docs/.gitbook/assets/image (3).png +0 -0
  268. package/docs/.gitbook/assets/image (4).png +0 -0
  269. package/docs/.gitbook/assets/image (5).png +0 -0
  270. package/docs/.gitbook/assets/image (6).png +0 -0
  271. package/docs/.gitbook/assets/image.png +0 -0
  272. package/docs/README.md +57 -0
  273. package/docs/SUMMARY.md +34 -0
  274. package/docs/cas-dusages.md +69 -0
  275. package/docs/cli/README.md +65 -0
  276. package/docs/concepts-cles.md +50 -0
  277. package/docs/core/architecture.md +87 -0
  278. package/docs/core/benchmark.md +59 -0
  279. package/docs/core/checkpoint.md +72 -0
  280. package/docs/core/documentation.md +55 -0
  281. package/docs/core/graphcontroller.md +63 -0
  282. package/docs/core/graphflow.md +137 -0
  283. package/docs/core/introduction.md +41 -0
  284. package/docs/core/les-evenements.md +95 -0
  285. package/docs/modules/agenda/README.md +63 -0
  286. package/docs/modules/agenda/interface-iagenda.md +170 -0
  287. package/docs/modules/agenda/les-adaptateurs/README.md +237 -0
  288. package/docs/modules/agenda/les-adaptateurs/nodecronadapter.md +91 -0
  289. package/docs/modules/introduction.md +55 -0
  290. package/docs/modules/les-adaptateurs.md +52 -0
  291. package/docs/modules/memoire/README.md +68 -0
  292. package/docs/modules/memoire/interface-imemory.md +183 -0
  293. package/docs/modules/memoire/les-adaptateurs/README.md +209 -0
  294. package/docs/modules/memoire/les-adaptateurs/inmemoryadapter.md +110 -0
  295. package/docs/modules/memoire/les-adaptateurs/meilisearchadapter.md +147 -0
  296. package/docs/modules/memoire/les-adaptateurs/redisadapter.md +212 -0
  297. package/docs/modules/nlp/README.md +44 -0
  298. package/docs/philosophie.md +51 -0
  299. package/docs/tutoriels/ajouter-des-conditions.md +150 -0
  300. package/docs/tutoriels/branching.md +194 -0
  301. package/docs/tutoriels/checkpoint-usage.md +99 -0
  302. package/docs/tutoriels/creer-agent-onchain.md +1041 -0
  303. package/docs/tutoriels/creer-un-agent.md +108 -0
  304. package/docs/tutoriels/creer-un-graphe-simple.md +92 -0
  305. package/docs/tutoriels/gerer-les-erreurs.md +124 -0
  306. package/docs/tutoriels/pour-commencer.md +73 -0
  307. package/docs/tutoriels/retry.md +166 -0
  308. package/execution/adapters/in-memory-checkpoint.ts +35 -0
  309. package/execution/compiler.ts +47 -0
  310. package/{graph → execution}/event-manager.ts +4 -117
  311. package/{graph → execution}/index.ts +376 -8
  312. package/{graph → execution}/node.ts +116 -12
  313. package/execution/planner.ts +40 -0
  314. package/execution/reducer.ts +73 -0
  315. package/execution/registry.ts +86 -0
  316. package/execution/send-api.ts +58 -0
  317. package/execution/types.parallel.ts +81 -0
  318. package/index.ts +35 -8
  319. package/interfaces/index.ts +37 -0
  320. package/modules/cli/index.ts +580 -0
  321. package/modules/nlp/engine.ts +0 -1
  322. package/package.json +50 -16
  323. package/persistence/index.ts +27 -0
  324. package/persistence/neo4j/driver.ts +34 -0
  325. package/persistence/neo4j/entity-store.ts +141 -0
  326. package/persistence/neo4j/execution-tracer.ts +194 -0
  327. package/persistence/neo4j/memory-adapter.ts +281 -0
  328. package/persistence/neo4j/petri-checkpoint-adapter.ts +153 -0
  329. package/pipeline/agent-pipeline.ts +426 -0
  330. package/routing/checkpoint-adapter.ts +79 -0
  331. package/routing/documentation-generator.ts +358 -0
  332. package/routing/index.ts +459 -0
  333. package/routing/intent-classifier.ts +360 -0
  334. package/routing/matrix.ts +138 -0
  335. package/routing/orchestrator.ts +498 -0
  336. package/routing/patterns/data-extraction.json +79 -0
  337. package/routing/patterns/human-approval.json +64 -0
  338. package/routing/patterns/rag-search.json +68 -0
  339. package/routing/postgres-checkpoint-adapter.ts +172 -0
  340. package/routing/redis-checkpoint-adapter.ts +187 -0
  341. package/routing/types.ts +59 -0
  342. package/routing/web-server.ts +260 -0
  343. package/scripts/generate-petri-docs.ts +70 -0
  344. package/scripts/get-gmail-token.js +65 -0
  345. package/scripts/get-gmail-token.ts +65 -0
  346. package/test/agent/agent.test.ts +92 -0
  347. package/test/agent/clone.test.ts +143 -0
  348. package/test/agent/cognitive-handler.test.ts +78 -0
  349. package/test/agent/entity-store.test.ts +80 -0
  350. package/test/agent/generic-executor.test.ts +230 -0
  351. package/test/agent/handoff.test.ts +163 -0
  352. package/test/agent/llm-factory.test.ts +40 -0
  353. package/test/agent/orchestrator.test.ts +156 -0
  354. package/test/agent/registry.test.ts +97 -0
  355. package/test/agent/tools.test.ts +267 -0
  356. package/test/execution/checkpoint.test.ts +811 -0
  357. package/test/{graph → execution}/controller.test.ts +2 -2
  358. package/test/{graph → execution}/event-manager.test.ts +1 -1
  359. package/test/{graph → execution}/index.test.ts +24 -15
  360. package/test/{graph → execution}/node.test.ts +3 -3
  361. package/test/{graph → execution}/observer.test.ts +2 -2
  362. package/test/execution/parallel.test.ts +135 -0
  363. package/test/execution/plan-llm-integration.test.ts +290 -0
  364. package/test/execution/plan-real-onchain.test.ts +226 -0
  365. package/test/execution/send-api.test.ts +121 -0
  366. package/test/modules/cli/index.test.ts +125 -0
  367. package/test/persistence/neo4j-execution-tracer.test.ts +96 -0
  368. package/test/persistence/neo4j-memory-adapter.test.ts +107 -0
  369. package/test/persistence/neo4j-petri-checkpoint.test.ts +89 -0
  370. package/test/pipeline/agent-pipeline.test.ts +118 -0
  371. package/test/routing/checkpoint-persistence.test.ts +58 -0
  372. package/test/routing/documentation-generator.test.ts +76 -0
  373. package/test/routing/integration.test.ts +261 -0
  374. package/test/routing/intent-classifier.test.ts +102 -0
  375. package/test/routing/petri.test.ts +156 -0
  376. package/test/routing/real-llm.test.ts +260 -0
  377. package/test-petri-features.ts +218 -0
  378. package/test-pipeline-api.ts +163 -0
  379. package/tsconfig.json +5 -2
  380. package/types/agent.ts +126 -4
  381. package/types/index.ts +66 -5
  382. package/utils/generate-action-schema.ts +5 -4
  383. package/utils/logger.ts +40 -0
  384. package/dist/graph/controller.d.ts.map +0 -1
  385. package/dist/graph/controller.js.map +0 -1
  386. package/dist/graph/event-manager.d.ts +0 -101
  387. package/dist/graph/event-manager.d.ts.map +0 -1
  388. package/dist/graph/event-manager.js.map +0 -1
  389. package/dist/graph/index.d.ts.map +0 -1
  390. package/dist/graph/index.js +0 -340
  391. package/dist/graph/index.js.map +0 -1
  392. package/dist/graph/logger.d.ts.map +0 -1
  393. package/dist/graph/logger.js.map +0 -1
  394. package/dist/graph/node.d.ts.map +0 -1
  395. package/dist/graph/node.js.map +0 -1
  396. package/dist/graph/observer.d.ts.map +0 -1
  397. package/dist/graph/observer.js.map +0 -1
  398. package/dist/graph/visualizer.d.ts.map +0 -1
  399. package/dist/graph/visualizer.js.map +0 -1
  400. package/dist/modules/agent/agent.d.ts +0 -35
  401. package/dist/modules/agent/agent.d.ts.map +0 -1
  402. package/dist/modules/agent/agent.js +0 -103
  403. package/dist/modules/agent/agent.js.map +0 -1
  404. package/dist/modules/agent/base/executor.d.ts.map +0 -1
  405. package/dist/modules/agent/base/executor.js.map +0 -1
  406. package/dist/modules/agent/base/index.d.ts.map +0 -1
  407. package/dist/modules/agent/base/index.js.map +0 -1
  408. package/dist/modules/agent/generic-assistant.d.ts +0 -20
  409. package/dist/modules/agent/generic-assistant.d.ts.map +0 -1
  410. package/dist/modules/agent/generic-assistant.js +0 -89
  411. package/dist/modules/agent/generic-assistant.js.map +0 -1
  412. package/dist/modules/agent/generic-executor.d.ts.map +0 -1
  413. package/dist/modules/agent/generic-executor.js +0 -189
  414. package/dist/modules/agent/generic-executor.js.map +0 -1
  415. package/dist/modules/agent/llm-factory.d.ts.map +0 -1
  416. package/dist/modules/agent/llm-factory.js +0 -56
  417. package/dist/modules/agent/llm-factory.js.map +0 -1
  418. package/dist/modules/agent/prompt-builder.d.ts.map +0 -1
  419. package/dist/modules/agent/prompt-builder.js.map +0 -1
  420. package/dist/modules/memory/adapters/in-memory/index.d.ts +0 -120
  421. package/dist/modules/memory/adapters/in-memory/index.d.ts.map +0 -1
  422. package/dist/modules/memory/adapters/in-memory/index.js +0 -212
  423. package/dist/modules/memory/adapters/in-memory/index.js.map +0 -1
  424. package/dist/modules/memory/adapters/meilisearch/index.d.ts +0 -110
  425. package/dist/modules/memory/adapters/meilisearch/index.d.ts.map +0 -1
  426. package/dist/modules/memory/adapters/meilisearch/index.js +0 -324
  427. package/dist/modules/memory/adapters/meilisearch/index.js.map +0 -1
  428. package/dist/modules/memory/adapters/redis/index.d.ts +0 -82
  429. package/dist/modules/memory/adapters/redis/index.d.ts.map +0 -1
  430. package/dist/modules/memory/adapters/redis/index.js +0 -160
  431. package/dist/modules/memory/adapters/redis/index.js.map +0 -1
  432. package/dist/modules/memory/index.d.ts +0 -67
  433. package/dist/modules/memory/index.d.ts.map +0 -1
  434. package/dist/modules/memory/index.js +0 -104
  435. package/dist/modules/memory/index.js.map +0 -1
  436. package/modules/agent/agent.ts +0 -107
  437. package/modules/agent/generic-assistant.ts +0 -92
  438. package/modules/agent/generic-executor.ts +0 -252
  439. package/modules/agent/llm-factory.ts +0 -47
  440. package/modules/memory/adapters/in-memory/index.ts +0 -208
  441. package/modules/memory/adapters/meilisearch/index.ts +0 -364
  442. package/modules/memory/adapters/redis/index.ts +0 -165
  443. package/modules/memory/index.ts +0 -93
  444. package/test/modules/memory/adapters/in-memory.test.ts +0 -153
  445. package/test/modules/memory/adapters/meilisearch.test.ts +0 -287
  446. package/test/modules/memory/base.test.ts +0 -230
  447. /package/dist/{modules/agent → agent}/llm-factory.d.ts +0 -0
  448. /package/dist/{modules/agent → agent}/prompt-builder.js +0 -0
  449. /package/dist/{graph → execution}/controller.d.ts +0 -0
  450. /package/dist/{graph → execution}/controller.js +0 -0
  451. /package/dist/{graph → execution}/logger.d.ts +0 -0
  452. /package/dist/{graph → execution}/logger.js +0 -0
  453. /package/dist/{graph → execution}/observer.d.ts +0 -0
  454. /package/dist/{graph → execution}/observer.js +0 -0
  455. /package/dist/{graph → execution}/visualizer.d.ts +0 -0
  456. /package/dist/{graph → execution}/visualizer.js +0 -0
  457. /package/{graph → execution}/controller.ts +0 -0
  458. /package/{graph → execution}/logger.ts +0 -0
  459. /package/{graph → execution}/observer.ts +0 -0
  460. /package/{graph → execution}/visualizer.ts +0 -0
@@ -0,0 +1,87 @@
1
+ # System Architecture
2
+
3
+ `@ai.ntellect/core` is designed as a layered system that separates **Intent**, **Routing**, and **Execution**. This architecture ensures that as your AI agent becomes more complex, it remains maintainable and verifiable.
4
+
5
+ ---
6
+
7
+ ## 📐 The Three-Layer Model
8
+
9
+ ### Layer 1: The Intent Layer (Probabilistic)
10
+ This is the only place where "uncertainty" is allowed. We use an LLM to classify user input.
11
+ - **Component**: `IntentClassifier`
12
+ - **Responsibility**: Map `String` $\rightarrow$ `IntentID`.
13
+ - **Guardrail**: Confidence thresholds. If the LLM is unsure, the system triggers a clarification request rather than guessing.
14
+
15
+ ### Layer 2: The Routing Layer (Deterministic)
16
+ Once the intent is known, the system enters the **CortexFlow** layer. Routing is handled by a **Petri Net**.
17
+ - **Component**: `CortexFlowOrchestrator`
18
+ - **Responsibility**: Map `IntentID` $\rightarrow$ `WorkflowPath`.
19
+ - **Guardrail**: Formal Verification. Because Petri Nets are mathematical objects, we use incidence matrices to detect deadlocks and bounded states at build-time.
20
+
21
+ ### Layer 3: The Execution Layer (Typed)
22
+ The final layer is the **GraphFlow** engine, which executes the specific steps of the chosen path.
23
+ - **Component**: `GraphFlow` / `GraphNode`
24
+ - **Responsibility**: Execute business logic and update state.
25
+ - **Guardrail**: Zod Validation. Every state transition is validated against a schema to ensure data integrity.
26
+
27
+ ---
28
+
29
+ ## 🔄 Data Flow & State Management
30
+
31
+ ### The Shared Context
32
+ Every workflow instance has a **Context**. This is a single source of truth that is passed from node to node.
33
+ - **Immutable-ish**: Nodes modify the context, but these modifications are tracked.
34
+ - **Validated**: The context is validated against the `GraphFlow` schema at every node transition.
35
+
36
+ ### Checkpointing & Persistence
37
+ To support long-running workflows (e.g., waiting for an event for 3 days), the architecture uses **Checkpoint Adapters**.
38
+ - After every node execution, the current context and the "marking" (current position in the Petri Net) are snapshotted.
39
+ - This allows the system to be completely stateless; a workflow can be resumed on a different server just by loading its `checkpointId` from Redis or PostgreSQL.
40
+
41
+ ---
42
+
43
+ ## 🧩 Modularity & Adapters
44
+
45
+ The framework follows the **Dependency Inversion Principle**. Core logic does not depend on specific technologies.
46
+
47
+ ### Pluggable Modules
48
+ We provide interfaces for common agent needs:
49
+ - `IMemoryAdapter`: For long-term memory (InMemory $\rightarrow$ Redis $\rightarrow$ Meilisearch).
50
+ - `ICheckpointAdapter`: For state persistence (InMemory $\rightarrow$ Postgres).
51
+ - `IEventEmitter`: For event handling (Node.js EventEmitter $\rightarrow$ RabbitMQ $\rightarrow$ Kafka).
52
+
53
+ ### The GraphController
54
+ For complex systems, a single graph isn't enough. The `GraphController` allows you to treat `GraphFlows` as building blocks, orchestrating them in parallel or sequence to build "Super-Graphs."
55
+
56
+ ---
57
+
58
+ ---
59
+
60
+ ## 📁 Source Code Structure (Bounded Contexts)
61
+
62
+ The framework source is organized into **Bounded Contexts** that mirror the three-layer model:
63
+
64
+ ```
65
+ execution/ → Layer 3: GraphFlow engine (typed nodes, events, planner, compiler)
66
+ routing/ → Layer 2: PetriNet, CortexFlowOrchestrator, IntentClassifier
67
+ agent/ → Cognitive loop: Agent, GenericExecutor, handlers, tools
68
+ persistence/ → Barrel: Memory + checkpoint adapters
69
+ pipeline/ → AgentPipeline (trigger → stages → gate)
70
+ modules/ → Plugins: agenda, cli, embedding, memory, nlp
71
+ interfaces/ → Contract interfaces
72
+ types/ → Zod schemas
73
+ ```
74
+
75
+ This structure ensures that each concern (routing, execution, agent loop) lives in its own directory with clear boundaries and no circular dependencies.
76
+
77
+ ---
78
+
79
+ ## 🚀 Summary of the Architectural Edge
80
+
81
+ | Feature | Traditional AI Frameworks | @ai.ntellect/core |
82
+ | :--- | :--- | :--- |
83
+ | **Control Flow** | LLM-driven (Probabilistic) | Petri Net-driven (Deterministic) |
84
+ | **State** | Loose / Prompt-based | Strongly Typed (Zod) |
85
+ | **Verification** | Trial and Error | Mathematical Proof (Deadlock detection) |
86
+ | **Persistence** | Session-based | Checkpoint-based (Time-travel) |
87
+ | **Latency** | Multiple LLM calls for routing | Single LLM call for classification |
@@ -0,0 +1,59 @@
1
+ # Benchmark: CortexFlow vs. LangGraph
2
+
3
+ To validate our thesis that **deterministic routing is superior to probabilistic routing**, we conducted a rigorous benchmark comparing `CortexFlow` against a standard `LangGraph` implementation.
4
+
5
+ ## 🧪 The Test Scenario
6
+
7
+ **The Task**: An AI Agent must process an inbox of 5 emails. It must:
8
+ 1. Fetch emails $\rightarrow$ 2. Classify urgency $\rightarrow$ 3. Draft responses for urgent ones $\rightarrow$ 4. Archive non-urgent ones.
9
+
10
+ This is a classic "routing" task where an agent must decide between different paths based on input.
11
+
12
+ ---
13
+
14
+ ## 📊 The Results
15
+
16
+ ### Test 1: Local Execution (Ollama — llama3:latest)
17
+ *Observation: Local LLM calls have high latency (~2s per call), making the number of calls the primary bottleneck.*
18
+
19
+ | Metric | CortexFlow | LangGraph (Naive) | LangGraph (Optimized) |
20
+ | :--- | :--- | :--- | :--- |
21
+ | **LLM Calls** | **1** | 7 | 2 |
22
+ | **Total Time** | **13.4s** | 3.7s | 4.2s |
23
+ | **Reliability** | 100% (Deterministic) | ~85% (Occasional Drift) | ~95% (Manual Batching) |
24
+
25
+ **Analysis**: CortexFlow is slower in local mode because it performs **Formal Verification** (deadlock/boundedness checks) at the start. However, it reduces LLM calls by **86%**.
26
+
27
+ ### Test 2: Cloud Execution (Groq API — llama-3.1-8b-instant)
28
+ *Observation: Cloud LLMs have extremely low latency, shifting the bottleneck to the orchestration overhead.*
29
+
30
+ | Metric | CortexFlow | LangGraph (Naive) | LangGraph (Optimized) |
31
+ | :--- | :--- | :--- | :--- |
32
+ | **LLM Calls** | **1** | 7 | 2 |
33
+ | **Total Time** | **1,650 ms** | 2,192 ms | 1,668 ms |
34
+ | **Performance** | **1.33x Faster** | Baseline | 1.31x Faster |
35
+
36
+ **Analysis**: In a production environment (low-latency LLM), **CortexFlow is the fastest**. By eliminating the "routing loops," it removes multiple network round-trips.
37
+
38
+ ---
39
+
40
+ ## 📉 The "LLM Call" Tax
41
+
42
+ The biggest find from this benchmark is the **LLM Call Tax**.
43
+ In traditional frameworks, every decision is a call:
44
+ `User` $\rightarrow$ `Call 1 (Route)` $\rightarrow$ `Call 2 (Validate)` $\rightarrow$ `Call 3 (Act)` $\rightarrow$ `Call 4 (Summarize)`.
45
+
46
+ In CortexFlow, we pay the tax **once**:
47
+ `User` $\rightarrow$ `Call 1 (Classify Intent)` $\rightarrow$ `System (Deterministic Route)` $\rightarrow$ `Done`.
48
+
49
+ ---
50
+
51
+ ## 🏆 Final Verdict: Why Choose CortexFlow?
52
+
53
+ The benchmark proves that the gain is not just about milliseconds—it's about **Reliability**.
54
+
55
+ 1. **Zero Routing Hallucinations**: Because the routing is in a Petri Net, the agent *cannot* decide to go to a node that doesn't exist or skip a mandatory step.
56
+ 2. **Constant Complexity**: Whether the conversation is 2 turns or 200 turns, the routing cost remains **1 LLM call**.
57
+ 3. **Formal Guarantees**: You get a mathematical proof that your agent will never deadlock, regardless of what the LLM outputs.
58
+
59
+ **LangGraph is a great tool for autonomous exploration. CortexFlow is the tool for production systems.**
@@ -0,0 +1,72 @@
1
+ # Resilience & Checkpoints
2
+
3
+ In production, workflows fail. Servers crash, APIs timeout, and humans take days to approve requests. The **Checkpoint System** is what makes `@ai.ntellect/core` production-grade.
4
+
5
+ ## 📌 What is a Checkpoint?
6
+
7
+ A checkpoint is a **serialized snapshot** of a workflow's entire state at a specific point in time. It includes:
8
+ 1. The current **Context** (the data).
9
+ 2. The current **Node/Position** (where we are).
10
+ 3. The **Run ID** (which execution this belongs to).
11
+ 4. **Metadata** (timestamps, error states, approval status).
12
+
13
+ ---
14
+
15
+ ## 🛠️ Core Functionalities
16
+
17
+ ### 1. Automatic State Persistence
18
+ By using `executeWithCheckpoint`, the engine automatically saves the state after every single node execution. If the process crashes, you don't lose progress; you simply resume from the last successful node.
19
+
20
+ ### 2. Breakpoints (Human-in-the-Loop)
21
+ Breakpoints allow you to intentionally pause a workflow *before* a critical node executes.
22
+ ```typescript
23
+ await workflow.executeWithCheckpoint("start", adapter, {
24
+ breakpoints: ["execute_payment"],
25
+ });
26
+ ```
27
+ The workflow will stop exactly before `execute_payment`. It stays in a `awaiting_approval` state until an external command calls `resumeFromCheckpoint`.
28
+
29
+ ### 3. Time-Travel Debugging
30
+ This is the most powerful tool for developers. You can resume a workflow from *any* previous checkpoint in its history, and you can even **modify the state** before resuming.
31
+
32
+ ```typescript
33
+ // "What would have happened if the user had entered 'USD' instead of 'EUR'?"
34
+ await workflow.resumeFromCheckpoint(cpId, adapter, {
35
+ contextModifications: { currency: "USD" },
36
+ });
37
+ ```
38
+
39
+ ---
40
+
41
+ ## 🔌 Adapters
42
+
43
+ You can choose where your checkpoints are stored based on your needs:
44
+
45
+ | Adapter | Best For | Persistence |
46
+ | :--- | :--- | :--- |
47
+ | `InMemoryCheckpointAdapter` | Local dev, unit tests | Volatile (Lost on restart) |
48
+ | `RedisPetriCheckpointAdapter` | High-performance production | Persistent / Distributed |
49
+ | `PostgresPetriCheckpointAdapter` | Audit-heavy, relational data | Persistent / ACID |
50
+
51
+ ---
52
+
53
+ ## 🧠 Petri Net Checkpoints
54
+
55
+ For **CortexFlow** workflows, checkpoints are even more critical. We save the **Petri Net Marking** (the distribution of tokens across places).
56
+
57
+ This means you can:
58
+ - Pause a complex orchestration.
59
+ - Restore the exact state of the Petri Net.
60
+ - See exactly which transitions were enabled at the moment of the pause.
61
+
62
+ ---
63
+
64
+ ## ⚠️ Error Handling & Recovery
65
+
66
+ When a node fails, the system creates an **Error Checkpoint**.
67
+ Instead of the whole system crashing, the workflow enters a `failed` state. A developer or an automated process can then:
68
+ 1. Analyze the error in the checkpoint metadata.
69
+ 2. Fix the underlying issue (or modify the context).
70
+ 3. Resume the workflow from the failed node.
71
+
72
+ **This eliminates the need to restart long-running workflows from scratch.**
@@ -0,0 +1,55 @@
1
+ # Living Documentation: Visualizing Your Agents
2
+
3
+ One of the biggest challenges in AI orchestration is the "Black Box" problem: you don't know why an agent took a certain path. `@ai.ntellect/core` solves this by treating **documentation as code**.
4
+
5
+ CortexFlow can automatically generate visual and textual documentation directly from your Petri Net definitions.
6
+
7
+ ---
8
+
9
+ ## 🛠️ Generation Tools
10
+
11
+ ### 1. CLI Generation
12
+ You can generate documentation for any JSON-defined Petri Net using the provided script:
13
+
14
+ ```bash
15
+ npx ts-node scripts/generate-petri-docs.ts <petri-net.json> [output-dir]
16
+ ```
17
+
18
+ **What you get:**
19
+ - **Markdown (`.md`)**: A human-readable explanation of all places, transitions, and the intended flow.
20
+ - **Mermaid Diagram (`.mmd`)**: A visual graph that can be rendered in GitHub, Notion, or Obsidian.
21
+ - **Interactive HTML (`.html`)**: A standalone page with an embedded render of the workflow.
22
+
23
+ ### 2. Programmatic Generation
24
+ You can integrate documentation generation into your CI/CD pipeline or your own admin dashboard:
25
+
26
+ ```typescript
27
+ import { PetriDocumentationGenerator } from "@ai.ntellect/core/routing/documentation-generator";
28
+
29
+ const generator = new PetriDocumentationGenerator();
30
+ await generator.generateForPetri(net, {
31
+ outputDir: "./docs/petri",
32
+ format: "all",
33
+ });
34
+ ```
35
+
36
+ ---
37
+
38
+ ## 🔍 Session-Based Documentation (The "Audit Trail")
39
+
40
+ Unlike static documentation, **Session Documentation** captures the *actual* execution of a specific request.
41
+
42
+ When you generate documentation for a session:
43
+ 1. **State Highlighting**: The resulting diagram highlights exactly where the tokens were located at the time of the snapshot.
44
+ 2. **Transition History**: The Markdown report lists every transition that was fired, in order, with its associated `traceId`.
45
+ 3. **Enabled Analysis**: The report shows which transitions were "enabled" (ready to fire) but were not chosen.
46
+
47
+ **This turns your documentation into a forensic tool for debugging production agents.**
48
+
49
+ ---
50
+
51
+ ## 📈 Why "Living" Docs?
52
+
53
+ - **Zero Drift**: Since the docs are generated from the `PetriNet` object, they can never be out of sync with the code.
54
+ - **Accessibility**: Non-technical stakeholders (Product Managers, Compliance Officers) can review the Mermaid diagrams to verify the business logic.
55
+ - **Fast Onboarding**: New developers can visualize the entire agent's decision tree without reading thousands of lines of code.
@@ -0,0 +1,63 @@
1
+ # GraphController: Multi-Graph Orchestration
2
+
3
+ While a `GraphFlow` is powerful for a single workflow, real-world applications often require the coordination of multiple independent workflows. The `GraphController` is the orchestrator that manages these relationships.
4
+
5
+ ## 🎯 Purpose
6
+
7
+ The `GraphController` allows you to treat individual `GraphFlows` as modular components. Instead of building one giant, monolithic graph, you can build small, testable graphs and compose them into complex pipelines.
8
+
9
+ ---
10
+
11
+ ## 🚀 Execution Modes
12
+
13
+ ### 1. Sequential Execution
14
+ Use `executeSequential` when Workflow B depends on the successful completion of Workflow A.
15
+
16
+ ```typescript
17
+ const controller = new GraphController();
18
+
19
+ await controller.executeSequential([
20
+ { graph: userValidationGraph, startNode: "start" },
21
+ { graph: paymentProcessingGraph, startNode: "init" },
22
+ { graph: notificationGraph, startNode: "send" },
23
+ ]);
24
+ ```
25
+ If any graph in the sequence fails, the chain stops, and the error is propagated, preventing inconsistent states.
26
+
27
+ ### 2. Parallel Execution
28
+ Use `executeParallel` to trigger multiple independent workflows simultaneously, reducing overall latency.
29
+
30
+ ```typescript
31
+ const results = await controller.executeParallel([
32
+ { graph: fetchStockGraph, startNode: "start" },
33
+ { graph: fetchPriceGraph, startNode: "start" },
34
+ { graph: checkComplianceGraph, startNode: "start" },
35
+ ]);
36
+ ```
37
+ The `GraphController` manages the `Promise.all` logic internally and returns an array of results once all graphs have completed.
38
+
39
+ ---
40
+
41
+ ## 🛠️ Advanced Patterns
42
+
43
+ ### The "Super-Graph" Pattern
44
+ You can use a `GraphController` inside a `GraphNode` of another `GraphFlow`. This allows you to create hierarchical workflows:
45
+ - **Parent Graph**: Handles high-level business logic.
46
+ - **Child Graphs (via Controller)**: Handle specific technical implementations.
47
+
48
+ ### Cross-Graph Event Communication
49
+ Graphs managed by a controller can communicate via the event system.
50
+ 1. `Graph A` emits an event `data.ready`.
51
+ 2. `Graph B` has a node waiting for `data.ready`.
52
+ 3. `Graph B` wakes up and processes the data produced by `Graph A`.
53
+
54
+ ---
55
+
56
+ ## ⚖️ When to use GraphController vs. Parallel Nodes?
57
+
58
+ | Feature | Parallel Nodes (within GraphFlow) | GraphController (across GraphFlows) |
59
+ | :--- | :--- | :--- |
60
+ | **Scope** | Intra-graph (Internal) | Inter-graph (External) |
61
+ | **State** | Shares the same `Context` | Each graph has its own `Context` |
62
+ | **Coupling** | Tightly coupled | Loosely coupled (Modular) |
63
+ | **Use Case** | Splitting a single task into sub-tasks | Orchestrating different business modules |
@@ -0,0 +1,137 @@
1
+ # GraphFlow: The Execution Engine
2
+
3
+ `GraphFlow` is the primary primitive for defining a workflow in `@ai.ntellect/core`. Think of it as a **typed state machine** where each transition is a validated step.
4
+
5
+ ## 🏗️ Creating a Workflow
6
+
7
+ A GraphFlow consists of a **Schema** (Zod), an initial **Context**, and a set of **Nodes**.
8
+
9
+ ```typescript
10
+ import { z } from "zod";
11
+ import { GraphFlow } from "@ai.ntellect/core";
12
+
13
+ // 1. Define the state shape (MANDATORY for validation)
14
+ const OrderSchema = z.object({
15
+ orderId: z.string(),
16
+ status: z.string(),
17
+ amount: z.number(),
18
+ });
19
+
20
+ // 2. Define the workflow
21
+ const orderWorkflow = new GraphFlow({
22
+ name: "OrderProcessing",
23
+ schema: OrderSchema,
24
+ context: { orderId: "", status: "pending", amount: 0 },
25
+ nodes: [
26
+ {
27
+ name: "validate_order",
28
+ execute: async (ctx) => {
29
+ if (ctx.amount <= 0) throw new Error("Invalid amount");
30
+ ctx.status = "validated";
31
+ },
32
+ next: "process_payment",
33
+ },
34
+ {
35
+ name: "process_payment",
36
+ execute: async (ctx) => {
37
+ // Payment logic here
38
+ ctx.status = "paid";
39
+ },
40
+ },
41
+ ],
42
+ });
43
+
44
+ await orderWorkflow.execute("validate_order");
45
+ ```
46
+
47
+ ---
48
+
49
+ ## 🛣️ Routing Logic
50
+
51
+ ### Sequential & Conditional Execution
52
+ Nodes move to the next step via the `next` property. This can be:
53
+ - **Static**: `next: "nextNodeName"`
54
+ - **Dynamic**: `next: (ctx) => ctx.amount > 100 ? "high_value_flow" : "standard_flow"`
55
+
56
+ ### Parallel Execution (Fork-Join Model)
57
+ You can execute multiple branches concurrently to reduce latency.
58
+ ```typescript
59
+ {
60
+ name: "start",
61
+ parallel: { enabled: true, joinNode: "merge" },
62
+ next: ["fetch_user", "fetch_inventory", "check_credit"],
63
+ }
64
+ ```
65
+ The engine clones the context for each branch, executes them via `Promise.all`, and merges the results into the `joinNode` using a **Reducer**.
66
+
67
+ ### Dynamic Fan-Out (The Send API)
68
+ When the number of parallel branches is determined at runtime (e.g., processing a list of items), use the `send` API:
69
+ ```typescript
70
+ {
71
+ name: "distribute",
72
+ send: (ctx) => ctx.items.map(item => ({
73
+ to: "processItem",
74
+ input: { item },
75
+ })),
76
+ parallel: { enabled: true, joinNode: "complete" },
77
+ }
78
+ ```
79
+
80
+ ---
81
+
82
+ ## ⚡ Event-Driven Nodes
83
+
84
+ A node can pause execution and wait for an external signal. This is critical for **Human-in-the-Loop** or **Asynchronous Integrations**.
85
+
86
+ ```typescript
87
+ {
88
+ name: "await_approval",
89
+ when: {
90
+ events: ["manager.approved"],
91
+ timeout: 86400000, // 24 hours
92
+ strategy: { type: "single" },
93
+ },
94
+ execute: async (ctx, _, event) => {
95
+ ctx.approvedBy = event.payload.managerId;
96
+ ctx.status = "approved";
97
+ },
98
+ }
99
+ ```
100
+
101
+ ### Event Strategies
102
+ - **`single`**: Fires on the first matching event.
103
+ - **`all`**: Fires only after *every* listed event has arrived.
104
+ - **`correlate`**: Fires when events arrive that match a custom correlation function (e.g., matching `orderId`).
105
+
106
+ ---
107
+
108
+ ## 🔍 Observability & State
109
+
110
+ Because GraphFlow is deterministic, it is fully observable.
111
+
112
+ ### Reactive State Tracking
113
+ You can subscribe to context changes in real-time:
114
+ ```typescript
115
+ workflow.observe().property("status").subscribe(s => console.log(`Status: ${s}`));
116
+ ```
117
+
118
+ ### Formal Validation
119
+ The Zod schema isn't just for TypeScript types; it's a **runtime guard**. If a node attempts to set the context to an invalid state, the GraphFlow throws an error immediately, preventing corrupted state from propagating.
120
+
121
+ ---
122
+
123
+ ## 📖 API Reference
124
+
125
+ ### `GraphFlow` Methods
126
+ - `execute(nodeName, initialContext)`: Starts the workflow.
127
+ - `emit(event, payload)`: Triggers event-driven nodes.
128
+ - `getContext()`: Returns the current validated state.
129
+ - `observe()`: Returns an observer for state and event tracking.
130
+
131
+ ### `GraphNodeConfig` Properties
132
+ - `name`: Unique identifier.
133
+ - `execute`: The core logic function.
134
+ - `next`: Routing logic (string or function).
135
+ - `when`: Event-wait configuration.
136
+ - `parallel`: Fork-Join configuration.
137
+ - `retry`: Backoff and attempt configuration.
@@ -0,0 +1,41 @@
1
+ # Introduction
2
+
3
+ Welcome to the core of **@ai.ntellect/core**. This framework is built on the principle that **AI agents in production must be deterministic**.
4
+
5
+ While most frameworks focus on "autonomy" (letting the LLM decide everything), we focus on **Orchestration**. We provide the tools to wrap probabilistic AI in a deterministic shell, ensuring your agent doesn't drift, hallucinate its routing, or enter infinite loops.
6
+
7
+ ---
8
+
9
+ ## 🛠️ The Three Pillars of the Core
10
+
11
+ ### 1. Graph-Based Execution (GraphFlow)
12
+ At the lowest level, we use **GraphFlow**. A GraphFlow is a typed directed graph where each node is a discrete unit of logic.
13
+ - **Modular**: Each node is an independent action.
14
+ - **Typed**: Every transition is validated via Zod, preventing runtime type errors.
15
+ - **Dynamic**: Nodes can execute sequentially, in parallel (Fork-Join), or based on conditional logic.
16
+
17
+ ### 2. Event-Driven Reactivity
18
+ Our engine doesn't just run from start to finish; it lives in a state of reactivity.
19
+ - **External Triggers**: Nodes can pause and wait for webhooks, blockchain events, or user actions.
20
+ - **Asynchronousity**: The system can handle thousands of paused workflows, resuming them only when the required event arrives.
21
+ - **Interoperability**: By using an `IEventEmitter` interface, the framework integrates seamlessly with any event-driven architecture.
22
+
23
+ ### 3. Deterministic Orchestration (CortexFlow)
24
+ This is where the "Intelligence" meets "Control." CortexFlow implements the **Classifier-Controller Split**:
25
+ - **The LLM as the Classifier**: It identifies the *Intent* of the user request.
26
+ - **The Petri Net as the Controller**: It routes that intent through a mathematically verified path.
27
+
28
+ By moving the routing logic out of the LLM and into a Petri Net, we achieve **formal verification**. We can prove, before a single line of code runs, that your workflow is free of deadlocks and that all states are reachable.
29
+
30
+ ---
31
+
32
+ ## 🚀 Why this matters for Production
33
+
34
+ | The "Autonomous" Approach | The "@ai.ntellect/core" Approach |
35
+ | :--- | :--- |
36
+ | LLM decides the next step at every turn | LLM decides the *intent* once |
37
+ | Hallucinations lead to routing errors | Routing is deterministic and verified |
38
+ | Prompt engineering is used to "fix" flow | Graph structure defines the flow |
39
+ | Debugging involves "guessing" LLM state | Debugging involves tracing a state machine |
40
+
41
+ **In short: We move AI from "guessing" to "executing."**
@@ -0,0 +1,95 @@
1
+ # Event-Driven Workflows
2
+
3
+ In most traditional code, a function starts and runs until it returns. In `@ai.ntellect/core`, a workflow can **pause and wait for the world to change**.
4
+
5
+ This is achieved through **Event-Driven Nodes**.
6
+
7
+ ## ⚙️ How it Works
8
+
9
+ An event-driven node uses the `when` property to define its trigger conditions. When the engine reaches such a node, it does not execute the `execute` function immediately. Instead, it:
10
+ 1. Saves the current state (Checkpoint).
11
+ 2. Registers a listener for the specified events.
12
+ 3. Pauses execution.
13
+
14
+ Once the event arrives via `workflow.emit()`, the engine wakes up, validates the event, and executes the node logic.
15
+
16
+ ---
17
+
18
+ ## 🛠️ Configuration & Strategies
19
+
20
+ ### 1. The `single` Strategy
21
+ The simplest form of reactivity. The node fires as soon as any one of the listed events occurs.
22
+ ```typescript
23
+ when: {
24
+ events: ["payment.received", "payment.manual_override"],
25
+ strategy: { type: "single" },
26
+ }
27
+ ```
28
+
29
+ ### 2. The `all` Strategy
30
+ Used for synchronization. The node only executes after *all* required events have been received.
31
+ ```typescript
32
+ when: {
33
+ events: ["identity.verified", "credit.checked"],
34
+ strategy: { type: "all" },
35
+ }
36
+ ```
37
+
38
+ ### 3. The `correlate` Strategy (Advanced)
39
+ In a multi-user system, you receive thousands of events. You need to ensure the event you receive belongs to the **current workflow instance**.
40
+
41
+ The `correlate` strategy allows you to provide a function that matches event payloads to the workflow context.
42
+ ```typescript
43
+ when: {
44
+ events: ["order.shipped"],
45
+ strategy: {
46
+ type: "correlate",
47
+ correlation: (events) =>
48
+ events[0].payload.orderId === ctx.orderId,
49
+ },
50
+ }
51
+ ```
52
+
53
+ ---
54
+
55
+ ## 📡 Emitting Events
56
+
57
+ Events can be emitted from anywhere in your application—an API endpoint, a webhook handler, or even another GraphFlow.
58
+
59
+ ```typescript
60
+ // Trigger a waiting node in a specific workflow instance
61
+ await workflow.emit("payment.received", {
62
+ orderId: "order_123",
63
+ amount: 49.99,
64
+ timestamp: Date.now(),
65
+ });
66
+ ```
67
+
68
+ ---
69
+
70
+ ## ⏱️ Timeouts & Resilience
71
+
72
+ What happens if the event never arrives? To prevent "zombie" workflows, you can define a `timeout`.
73
+
74
+ ```typescript
75
+ when: {
76
+ events: ["user.approval"],
77
+ timeout: 3600000, // 1 hour
78
+ strategy: { type: "single" },
79
+ }
80
+ ```
81
+ If the timeout is reached, the workflow can either:
82
+ 1. Throw a timeout error.
83
+ 2. Move to a fallback node (via the `next` logic).
84
+
85
+ ## 📈 Use Case: The "Human-in-the-Loop" Pattern
86
+
87
+ Event-driven nodes are the foundation of **Human-in-the-Loop (HITL)**.
88
+
89
+ 1. **Workflow reaches a sensitive node** (e.g., `execute_large_transfer`).
90
+ 2. **Workflow pauses** using a `when` node waiting for `admin.approved`.
91
+ 3. **Admin receives an email** with a link.
92
+ 4. **Admin clicks "Approve"**, which triggers an API call to `workflow.emit("admin.approved", { ... })`.
93
+ 5. **Workflow resumes** and completes the transfer.
94
+
95
+ This turns a risky autonomous action into a secure, audited business process.
@@ -0,0 +1,63 @@
1
+ # Module Agenda
2
+
3
+ Planification de tâches récurrentes avec expressions cron. L'agenda s'exécute en processus — quand le cron correspond, votre fonction de tâche s'exécute.
4
+
5
+ ## Installation
6
+
7
+ Le module est inclus dans le package principal:
8
+
9
+ ```typescript
10
+ import { Agenda } from "@ai.ntellect/core";
11
+ ```
12
+
13
+ ## Utilisation de base
14
+
15
+ ```typescript
16
+ import { Agenda, NodeCronAdapter } from "@ai.ntellect/core";
17
+
18
+ const agenda = new Agenda(new NodeCronAdapter());
19
+
20
+ // Toutes les heures
21
+ agenda.schedule("0 * * * *", async () => {
22
+ console.log("Tâche horaire en cours");
23
+ });
24
+
25
+ // Tâche nommée pour annulation
26
+ agenda.schedule("daily_cleanup", "0 0 * * *", async () => {
27
+ console.log("Nettoyage quotidien");
28
+ });
29
+ ```
30
+
31
+ ## Syntaxe cron
32
+
33
+ Utilise `node-cron` en arrière-plan. La syntaxe suit les conventions cron standard:
34
+
35
+ ```
36
+ * * * * * *
37
+ │ │ │ │ │ │
38
+ │ │ │ │ │ └── Jour de la semaine (0-7, 0 et 7 = dimanche)
39
+ │ │ │ │ └──── Mois (1-12)
40
+ │ │ │ └────── Jour du mois (1-31)
41
+ │ │ └──────── Heure (0-23)
42
+ │ └────────── Minute (0-59)
43
+ └──────────── Seconde (0-59, optionnel)
44
+ ```
45
+
46
+ ## API
47
+
48
+ - `schedule(cronExpression: string, task: Function): void`
49
+ - `schedule(name: string, cronExpression: string, task: Function): void`
50
+ - `cancel(name: string): void`
51
+
52
+ ## Intégration avec l'Agent
53
+
54
+ L'agent peut utiliser l'agenda pour planifier des réveils:
55
+
56
+ ```typescript
57
+ const agent = new Agent({
58
+ role: "Assistant",
59
+ enableSchedule: true,
60
+ agenda: agenda,
61
+ // ...
62
+ });
63
+ ```