@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
@@ -1,104 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Memory = void 0;
13
- const interfaces_1 = require("../../interfaces");
14
- /**
15
- * @module Memory
16
- * @description A module for managing memory storage and retrieval operations.
17
- * Implements the BaseMemory abstract class and provides concrete implementations
18
- * for memory-related operations using the provided adapter.
19
- * @extends {BaseMemory}
20
- */
21
- class Memory extends interfaces_1.BaseMemory {
22
- /**
23
- * Creates an instance of Memory
24
- * @param {IMemoryAdapter} adapter - The memory adapter implementation to use
25
- */
26
- constructor(adapter) {
27
- super(adapter);
28
- }
29
- /**
30
- * Initializes the memory module with default room
31
- * @returns {Promise<void>}
32
- */
33
- init() {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- yield this.adapter.init("default");
36
- });
37
- }
38
- /**
39
- * Creates a new memory entry
40
- * @param {CreateMemoryInput & { embedding?: number[] }} input - Memory data with optional embedding
41
- * @returns {Promise<BaseMemoryType | undefined>} Created memory or undefined
42
- */
43
- createMemory(input) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- return this.adapter.createMemory(input);
46
- });
47
- }
48
- /**
49
- * Retrieves a memory by ID and room ID
50
- * @param {string} id - Memory identifier
51
- * @param {string} roomId - Room identifier
52
- * @returns {Promise<BaseMemoryType | null>} Memory entry or null if not found
53
- */
54
- getMemoryById(id, roomId) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- return this.adapter.getMemoryById(id, roomId);
57
- });
58
- }
59
- /**
60
- * Searches for memories based on query and options
61
- * @param {string} query - Search query
62
- * @param {Object} options - Search options
63
- * @param {string} options.roomId - Room identifier
64
- * @param {number} [options.limit] - Maximum number of results to return
65
- * @returns {Promise<BaseMemoryType[]>} Array of matching memories
66
- */
67
- getMemoryByIndex(query, options) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- return this.adapter.getMemoryByIndex(query, options);
70
- });
71
- }
72
- /**
73
- * Retrieves all memories for a specific room
74
- * @param {string} roomId - Room identifier
75
- * @returns {Promise<BaseMemoryType[]>} Array of all memories in the room
76
- */
77
- getAllMemories(roomId) {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- return this.adapter.getAllMemories(roomId);
80
- });
81
- }
82
- /**
83
- * Deletes a specific memory
84
- * @param {string} id - Memory identifier
85
- * @param {string} roomId - Room identifier
86
- * @returns {Promise<void>}
87
- */
88
- clearMemoryById(id, roomId) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- yield this.adapter.clearMemoryById(id, roomId);
91
- });
92
- }
93
- /**
94
- * Clears all memories across all rooms
95
- * @returns {Promise<void>}
96
- */
97
- clearAllMemories() {
98
- return __awaiter(this, void 0, void 0, function* () {
99
- yield this.adapter.clearAllMemories();
100
- });
101
- }
102
- }
103
- exports.Memory = Memory;
104
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../modules/memory/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA8D;AAG9D;;;;;;GAMG;AACH,MAAa,MAAO,SAAQ,uBAAU;IACpC;;;OAGG;IACH,YAAY,OAAuB;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED;;;OAGG;IACG,IAAI;;YACR,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACrC,CAAC;KAAA;IAED;;;;OAIG;IACG,YAAY,CAChB,KAAmD;;YAEnD,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;KAAA;IAED;;;;;OAKG;IACG,aAAa,CACjB,EAAU,EACV,MAAc;;YAEd,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAChD,CAAC;KAAA;IAED;;;;;;;OAOG;IACG,gBAAgB,CACpB,KAAa,EACb,OAA2C;;YAE3C,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACvD,CAAC;KAAA;IAED;;;;OAIG;IACG,cAAc,CAAC,MAAc;;YACjC,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC7C,CAAC;KAAA;IAED;;;;;OAKG;IACG,eAAe,CAAC,EAAU,EAAE,MAAc;;YAC9C,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC;KAAA;IAED;;;OAGG;IACG,gBAAgB;;YACpB,MAAM,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;QACxC,CAAC;KAAA;CACF;AAlFD,wBAkFC"}
@@ -1,107 +0,0 @@
1
- import { GraphContext } from "@/types";
2
- import { GraphFlow } from "../../graph/index";
3
- import {
4
- AgentConfig,
5
- AgentContext,
6
- AgentContextSchema,
7
- } from "../../types/agent";
8
- import { BaseAgent } from "./base";
9
- import { GenericExecutor } from "./generic-executor";
10
-
11
- /**
12
- * A generic assistant that can be configured with different roles, goals, and personalities
13
- * @class Agent
14
- * @example
15
- * const assistant = new Agent({
16
- * role: "Email Assistant",
17
- * goal: "Help users send emails efficiently",
18
- * backstory: "I am a professional and friendly assistant who specializes in email communication",
19
- * llmConfig: { provider: "openai", model: "gpt-4" }
20
- * tools: []
21
- * });
22
- */
23
- export class Agent {
24
- private executor: GenericExecutor;
25
- private workflow: GraphFlow<typeof AgentContextSchema>;
26
-
27
- /**
28
- * Creates an instance of Agent
29
- * @param {AgentConfig} config - Configuration for the agent
30
- */
31
- constructor(config: AgentConfig) {
32
- const agent = new BaseAgent({
33
- role: config.role,
34
- goal: config.goal,
35
- backstory: config.backstory,
36
- tools: config.tools,
37
- memory: config.memory,
38
- llmConfig: config.llmConfig,
39
- });
40
-
41
- this.executor = new GenericExecutor(agent, config.tools, {
42
- llmConfig: config.llmConfig,
43
- verbose: config.verbose,
44
- });
45
-
46
- this.workflow = this.setupWorkflow();
47
- }
48
-
49
- /**
50
- * Sets up the workflow for processing inputs and executing actions
51
- * @private
52
- * @returns {GraphFlow<typeof AgentContextSchema>} The configured workflow
53
- */
54
- private setupWorkflow(): GraphFlow<typeof AgentContextSchema> {
55
- return new GraphFlow({
56
- name: "assistant",
57
- schema: AgentContextSchema,
58
- context: {
59
- input: { raw: "" },
60
- actions: [],
61
- response: "",
62
- },
63
- nodes: [
64
- {
65
- name: "process",
66
- execute: async (context: GraphContext<typeof AgentContextSchema>) => {
67
- const agentContext = context as unknown as AgentContext;
68
- const decision = await this.executor.makeDecision(agentContext);
69
- context.actions = decision.actions;
70
- context.response = decision.response;
71
- },
72
- next: (context: GraphContext<typeof AgentContextSchema>) =>
73
- context.actions.length > 0 ? ["execute"] : [],
74
- },
75
- {
76
- name: "execute",
77
- execute: async (context: GraphContext<typeof AgentContextSchema>) => {
78
- const timestamp = new Date().toISOString();
79
- context.knowledge = `Date: ${timestamp}\n${JSON.stringify(
80
- context.actions
81
- )}`;
82
- await this.executor.executeActions(
83
- context.actions,
84
- context as unknown as AgentContext
85
- );
86
- },
87
- next: ["process"],
88
- },
89
- ],
90
- });
91
- }
92
-
93
- /**
94
- * Processes an input string through the agent's workflow
95
- * @param {string} input - The input string to process
96
- * @returns {Promise<AgentContext>} The resulting context after processing
97
- */
98
- public async process(input: string): Promise<AgentContext> {
99
- await this.workflow.execute("process", {
100
- input: { raw: input },
101
- actions: [],
102
- response: "",
103
- });
104
-
105
- return this.workflow.getContext() as unknown as AgentContext;
106
- }
107
- }
@@ -1,92 +0,0 @@
1
- import { GraphContext } from "@/types";
2
- import { GraphFlow } from "../../graph/index";
3
- import {
4
- AgentConfig,
5
- AgentContext,
6
- AgentContextSchema,
7
- } from "../../types/agent";
8
- import { BaseAgent } from "./base";
9
- import { GenericExecutor } from "./generic-executor";
10
-
11
- /**
12
- * A generic assistant that can be configured with different roles, goals, and personalities
13
- * @class Agent
14
- * @example
15
- * const assistant = new Agent({
16
- * role: "Email Assistant",
17
- * goal: "Help users send emails efficiently",
18
- * backstory: "I am a professional and friendly assistant who specializes in email communication",
19
- * llmConfig: { provider: "openai", model: "gpt-4" }
20
- * });
21
- */
22
- export class Agent {
23
- private executor: GenericExecutor;
24
- private workflow: GraphFlow<typeof AgentContextSchema>;
25
-
26
- constructor(config: AgentConfig) {
27
- const agent = new BaseAgent({
28
- role: config.role,
29
- goal: config.goal,
30
- backstory: config.backstory,
31
- tools: config.tools,
32
- memory: config.memory,
33
- llmConfig: config.llmConfig,
34
- });
35
-
36
- this.executor = new GenericExecutor(agent, config.tools, {
37
- llmConfig: config.llmConfig,
38
- verbose: config.verbose,
39
- });
40
-
41
- this.workflow = this.setupWorkflow();
42
- }
43
-
44
- private setupWorkflow(): GraphFlow<typeof AgentContextSchema> {
45
- return new GraphFlow({
46
- name: "assistant",
47
- schema: AgentContextSchema,
48
- context: {
49
- input: { raw: "" },
50
- actions: [],
51
- response: "",
52
- executedActions: [],
53
- },
54
- nodes: [
55
- {
56
- name: "process",
57
- execute: async (context: GraphContext<typeof AgentContextSchema>) => {
58
- const agentContext = context as unknown as AgentContext;
59
- const decision = await this.executor.makeDecision(agentContext);
60
- context.actions = decision.actions;
61
- context.response = decision.response;
62
- },
63
- next: (context: GraphContext<typeof AgentContextSchema>) =>
64
- context.actions.length > 0 ? ["execute"] : [],
65
- },
66
- {
67
- name: "execute",
68
- execute: async (context: GraphContext<typeof AgentContextSchema>) => {
69
- console.log(`Executing actions:`);
70
- console.log(context.actions);
71
-
72
- await this.executor.executeActions(
73
- context.actions,
74
- context as unknown as AgentContext
75
- );
76
- },
77
- next: ["process"],
78
- },
79
- ],
80
- });
81
- }
82
-
83
- public async process(input: string): Promise<AgentContext> {
84
- await this.workflow.execute("process", {
85
- input: { raw: input },
86
- actions: [],
87
- response: "",
88
- });
89
-
90
- return this.workflow.getContext() as unknown as AgentContext;
91
- }
92
- }
@@ -1,252 +0,0 @@
1
- import chalk from "chalk";
2
- import { z } from "zod";
3
- import { GraphFlow } from "../../graph/index";
4
- import {
5
- ActionSchema,
6
- AgentContext,
7
- DecisionOutput,
8
- ExecutorConfig,
9
- } from "../../types/agent";
10
- import { BaseAgent } from "./base";
11
- import { AgentExecutor } from "./base/executor";
12
- import { LLMFactory } from "./llm-factory";
13
- import { PromptBuilder } from "./prompt-builder";
14
-
15
- /**
16
- * Generic executor that handles the interaction between the agent and LLM
17
- * Uses a structured prompt format:
18
- * - ROLE: The function/job the agent performs
19
- * - GOAL: The specific objective to achieve
20
- * - BACKSTORY: The personality and behavior traits
21
- * - CONTEXT: Current knowledge and state
22
- * - AVAILABLE ACTIONS: What the agent can do
23
- * - INSTRUCTIONS: How to process and respond
24
- * @class GenericExecutor
25
- * @extends {AgentExecutor}
26
- */
27
- export class GenericExecutor extends AgentExecutor {
28
- private verbose: boolean;
29
- private llm: ReturnType<typeof LLMFactory.createLLM>;
30
-
31
- /**
32
- * Creates an instance of GenericExecutor
33
- * @param {BaseAgent} agent - The agent instance this executor is tied to
34
- * @param {GraphFlow<any>[]} graphs - Array of available graph flows
35
- * @param {ExecutorConfig} config - Configuration for the executor
36
- */
37
- constructor(
38
- agent: BaseAgent,
39
- graphs: GraphFlow<any>[],
40
- config: ExecutorConfig
41
- ) {
42
- super(agent, graphs);
43
- this.verbose = config.verbose ?? true;
44
- this.llm = LLMFactory.createLLM(config.llmConfig);
45
- }
46
-
47
- /**
48
- * Logs a message with a specific type if verbose mode is enabled
49
- * @private
50
- * @param {"info" | "success" | "warning" | "error" | "thinking"} type - The type of log message
51
- * @param {string} message - The message to log
52
- */
53
- private log(
54
- type: "info" | "success" | "warning" | "error" | "thinking",
55
- message: string
56
- ) {
57
- if (!this.verbose) return;
58
-
59
- const prefix = {
60
- info: chalk.blue("ℹ"),
61
- success: chalk.green("✓"),
62
- warning: chalk.yellow("⚠"),
63
- error: chalk.red("✖"),
64
- thinking: chalk.magenta("🤔"),
65
- }[type];
66
-
67
- console.log(`${prefix} ${message}`);
68
- }
69
-
70
- /**
71
- * Generates a string representation of the available action schemas
72
- * @private
73
- * @returns {string} Formatted string containing all available actions and their parameters
74
- */
75
- protected generateActionSchema(): string {
76
- return Array.from(this.availableGraphs.values())
77
- .map((graph) => {
78
- const schema = graph.getSchema();
79
- const schemaDescription = Object.entries(schema.shape)
80
- .map(([key, value]) => {
81
- const zodValue = value as z.ZodTypeAny;
82
- return ` - ${key}: ${
83
- zodValue.description || zodValue._def.typeName
84
- }`;
85
- })
86
- .join("\n");
87
-
88
- return `${graph.name}:
89
- Parameters:
90
- ${schemaDescription}
91
- Available Operations:
92
- ${graph
93
- .getNodes()
94
- .map((n) => ` - ${n.name}`)
95
- .join("\n")}`;
96
- })
97
- .join("\n\n");
98
- }
99
-
100
- private async buildSystemPrompt(context: AgentContext): Promise<string> {
101
- return new PromptBuilder()
102
- .addSection("ROLE", this.agent.getRole())
103
- .addSection("GOAL", this.agent.getGoal())
104
- .addSection("BACKSTORY", this.agent.getBackstory())
105
- .addSection(
106
- "RECENT ACTIONS (check this before deciding what to do)",
107
- context.knowledge || "None"
108
- )
109
- .addSection(
110
- "AVAILABLE ACTIONS (only if you need)",
111
- this.generateActionSchema()
112
- )
113
- .addSection(
114
- "INSTRUCTIONS",
115
- `
116
- - Never take actions if an recent action matches the user's input
117
- - If you need to take actions, structure parameters according to the action's schema
118
- - If goal is achieved, explain that you achieved for examples:
119
- - "I have achieved the goal"
120
- - "I have done what I needed to do"
121
- - "I have completed the task"
122
- `
123
- )
124
- .build(context);
125
- }
126
-
127
- /**
128
- * Makes a decision based on the current context using the LLM
129
- * @param {AgentContext} context - The context to base the decision on
130
- * @returns {Promise<DecisionOutput>} The decision output containing actions and response
131
- */
132
- async makeDecision(context: AgentContext): Promise<DecisionOutput> {
133
- this.log(
134
- "thinking",
135
- chalk.dim("Analyzing context and available actions...")
136
- );
137
-
138
- const systemPrompt = await this.buildSystemPrompt(context);
139
-
140
- console.log({ systemPrompt });
141
- this.log("info", chalk.dim("Generating response..."));
142
-
143
- const result = await this.llm.generate(
144
- {
145
- system: systemPrompt,
146
- user: `User sent you this message at ${new Date().toISOString()}\n${
147
- context.input.raw
148
- }`,
149
- },
150
- z.object({
151
- actions: z.array(
152
- z.object({
153
- name: z.string(),
154
- parameters: z.array(
155
- z.object({
156
- name: z.string(),
157
- value: z.any(),
158
- })
159
- ),
160
- })
161
- ),
162
- response: z.string(),
163
- })
164
- );
165
- if (result.object.actions.length > 0) {
166
- this.log("success", chalk.green("Decided to take actions:"));
167
- result.object.actions.forEach(
168
- (action: {
169
- name: string;
170
- parameters: Array<{ name: string; value: any }>;
171
- }) => {
172
- this.log("info", chalk.cyan(`Action: ${action.name}`));
173
- action.parameters.forEach((param: { name: string; value: any }) => {
174
- this.log(
175
- "info",
176
- chalk.dim(` - ${param.name}: ${JSON.stringify(param.value)}`)
177
- );
178
- });
179
- }
180
- );
181
- } else {
182
- this.log("info", chalk.yellow("No actions needed"));
183
- }
184
-
185
- this.log("success", chalk.green(`Response: ${result.object.response}`));
186
-
187
- return {
188
- actions: result.object.actions as unknown as ActionSchema[],
189
- response: result.object.response,
190
- };
191
- }
192
-
193
- /**
194
- * Executes multiple workflows with their respective inputs
195
- * @protected
196
- * @param {GraphFlow<any>[]} workflows - Array of workflows to execute
197
- * @param {string[]} startNodes - Array of starting node names for each workflow
198
- * @param {any[]} inputs - Array of inputs for each workflow
199
- * @param {AgentContext} context - The context in which to execute the workflows
200
- * @returns {Promise<void>}
201
- */
202
- protected async executeWorkflows(
203
- workflows: GraphFlow<any>[],
204
- startNodes: string[],
205
- inputs: any[],
206
- context: AgentContext
207
- ): Promise<void> {
208
- this.log("info", chalk.cyan("Executing workflows:"));
209
-
210
- for (let i = 0; i < workflows.length; i++) {
211
- const workflow = workflows[i];
212
- const startNode = startNodes[i];
213
- const input = inputs[i];
214
-
215
- this.log(
216
- "info",
217
- chalk.dim(
218
- `Executing workflow ${workflow.name} starting at node ${startNode}`
219
- )
220
- );
221
- this.log(
222
- "info",
223
- chalk.dim(`Input parameters: ${JSON.stringify(input, null, 2)}`)
224
- );
225
-
226
- // Initialize workflow context with input
227
- const workflowContext = {
228
- ...workflow.getContext(),
229
- ...input,
230
- };
231
-
232
- // Execute with merged context
233
- const result = await workflow.execute(
234
- startNode,
235
-
236
- workflowContext
237
- );
238
-
239
- this.log("success", chalk.green(`Workflow ${workflow.name} completed`));
240
- this.log("info", chalk.dim(`Result: ${JSON.stringify(result, null, 2)}`));
241
-
242
- if (context.executedActions) {
243
- context.executedActions.push({
244
- name: workflow.name,
245
- result: result,
246
- timestamp: new Date().toISOString(),
247
- isExecuted: true,
248
- });
249
- }
250
- }
251
- }
252
- }
@@ -1,47 +0,0 @@
1
- import { LLMConfig, PromptInput } from "@/types/agent";
2
- import { openai } from "@ai-sdk/openai";
3
- import { generateObject } from "ai";
4
- import { z } from "zod";
5
-
6
- /**
7
- * Factory class for creating Language Model instances based on configuration
8
- * @class LLMFactory
9
- */
10
- export class LLMFactory {
11
- /**
12
- * Creates an LLM instance based on the provided configuration
13
- * @static
14
- * @param {LLMConfig} config - Configuration for the LLM
15
- * @returns {Object} An object with a generate method for interacting with the LLM
16
- * @throws {Error} When an unsupported provider is specified or custom provider lacks required function
17
- */
18
- static createLLM(config: LLMConfig) {
19
- switch (config.provider) {
20
- case "openai":
21
- return {
22
- generate: async (
23
- prompt: string | PromptInput,
24
- schema: z.ZodType<any>
25
- ) => {
26
- return generateObject({
27
- model: openai(config.model),
28
- temperature: config.temperature ?? 0.7,
29
- maxTokens: config.maxTokens,
30
- prompt: typeof prompt === "string" ? prompt : prompt.user,
31
- system: typeof prompt === "string" ? undefined : prompt.system,
32
- schema,
33
- });
34
- },
35
- };
36
- case "custom":
37
- if (!config.customCall) {
38
- throw new Error("Custom LLM provider requires a customCall function");
39
- }
40
- return {
41
- generate: config.customCall,
42
- };
43
- default:
44
- throw new Error(`Unsupported LLM provider: ${config.provider}`);
45
- }
46
- }
47
- }