@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.
- package/.mocharc.json +2 -1
- package/AGENTS.md +50 -0
- package/ARCHITECTURE.md +58 -0
- package/BENCHMARK.md +38 -0
- package/CHANGELOG.md +224 -0
- package/README.md +413 -199
- package/agent/agent-workflow.ts +569 -0
- package/agent/agent.ts +183 -0
- package/{modules/agent → agent}/base/executor.ts +11 -8
- package/{modules/agent → agent}/base/index.ts +2 -14
- package/agent/entity-resolver/confidence.ts +54 -0
- package/agent/entity-resolver/entity-index.ts +241 -0
- package/agent/entity-resolver/explore-strategy.ts +82 -0
- package/agent/entity-resolver/index.ts +22 -0
- package/agent/entity-resolver/resolver.ts +193 -0
- package/agent/entity-resolver/scorer.ts +211 -0
- package/agent/entity-resolver/types.ts +98 -0
- package/agent/generic-executor.ts +713 -0
- package/agent/handlers/cognitive-handler.ts +197 -0
- package/agent/handlers/index.ts +1 -0
- package/agent/handoff.ts +58 -0
- package/agent/llm-factory.ts +343 -0
- package/agent/orchestrator.ts +45 -0
- package/{modules/agent → agent}/prompt-builder.ts +1 -1
- package/agent/registry.ts +64 -0
- package/agent/tools/file-system.ts +471 -0
- package/agent/tools/index.ts +23 -0
- package/agent/tools/logger.ts +105 -0
- package/agent/tools/tool-resolver.ts +104 -0
- package/benchmark/cortexflow-workflow.ts +182 -0
- package/benchmark/langgraph-workflow.ts +201 -0
- package/benchmark/llm-client.ts +76 -0
- package/benchmark/run-benchmark.ts +222 -0
- package/cli-dev.ts +419 -0
- package/dist/agent/agent-workflow.d.ts +41 -0
- package/dist/agent/agent-workflow.d.ts.map +1 -0
- package/dist/agent/agent-workflow.js +560 -0
- package/dist/agent/agent-workflow.js.map +1 -0
- package/dist/agent/agent.d.ts +38 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +149 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/{modules/agent → agent}/base/executor.d.ts +3 -3
- package/dist/agent/base/executor.d.ts.map +1 -0
- package/dist/{modules/agent → agent}/base/executor.js +8 -5
- package/dist/agent/base/executor.js.map +1 -0
- package/dist/{modules/agent → agent}/base/index.d.ts +1 -1
- package/dist/agent/base/index.d.ts.map +1 -0
- package/dist/{modules/agent → agent}/base/index.js +0 -12
- package/dist/agent/base/index.js.map +1 -0
- package/dist/agent/entity-resolver/confidence.d.ts +4 -0
- package/dist/agent/entity-resolver/confidence.d.ts.map +1 -0
- package/dist/agent/entity-resolver/confidence.js +47 -0
- package/dist/agent/entity-resolver/confidence.js.map +1 -0
- package/dist/agent/entity-resolver/entity-index.d.ts +40 -0
- package/dist/agent/entity-resolver/entity-index.d.ts.map +1 -0
- package/dist/agent/entity-resolver/entity-index.js +244 -0
- package/dist/agent/entity-resolver/entity-index.js.map +1 -0
- package/dist/agent/entity-resolver/explore-strategy.d.ts +13 -0
- package/dist/agent/entity-resolver/explore-strategy.d.ts.map +1 -0
- package/dist/agent/entity-resolver/explore-strategy.js +109 -0
- package/dist/agent/entity-resolver/explore-strategy.js.map +1 -0
- package/dist/agent/entity-resolver/index.d.ts +8 -0
- package/dist/agent/entity-resolver/index.d.ts.map +1 -0
- package/dist/agent/entity-resolver/index.js +16 -0
- package/dist/agent/entity-resolver/index.js.map +1 -0
- package/dist/agent/entity-resolver/resolver.d.ts +18 -0
- package/dist/agent/entity-resolver/resolver.d.ts.map +1 -0
- package/dist/agent/entity-resolver/resolver.js +158 -0
- package/dist/agent/entity-resolver/resolver.js.map +1 -0
- package/dist/agent/entity-resolver/scorer.d.ts +3 -0
- package/dist/agent/entity-resolver/scorer.d.ts.map +1 -0
- package/dist/agent/entity-resolver/scorer.js +182 -0
- package/dist/agent/entity-resolver/scorer.js.map +1 -0
- package/dist/agent/entity-resolver/types.d.ts +89 -0
- package/dist/agent/entity-resolver/types.d.ts.map +1 -0
- package/dist/agent/entity-resolver/types.js +3 -0
- package/dist/agent/entity-resolver/types.js.map +1 -0
- package/dist/{modules/agent → agent}/generic-executor.d.ts +37 -27
- package/dist/agent/generic-executor.d.ts.map +1 -0
- package/dist/agent/generic-executor.js +620 -0
- package/dist/agent/generic-executor.js.map +1 -0
- package/dist/agent/handlers/cognitive-handler.d.ts +44 -0
- package/dist/agent/handlers/cognitive-handler.d.ts.map +1 -0
- package/dist/agent/handlers/cognitive-handler.js +172 -0
- package/dist/agent/handlers/cognitive-handler.js.map +1 -0
- package/dist/agent/handlers/index.d.ts +2 -0
- package/dist/agent/handlers/index.d.ts.map +1 -0
- package/dist/agent/handlers/index.js +7 -0
- package/dist/agent/handlers/index.js.map +1 -0
- package/dist/agent/handoff.d.ts +12 -0
- package/dist/agent/handoff.d.ts.map +1 -0
- package/dist/agent/handoff.js +62 -0
- package/dist/agent/handoff.js.map +1 -0
- package/dist/agent/llm-factory.d.ts.map +1 -0
- package/dist/agent/llm-factory.js +297 -0
- package/dist/agent/llm-factory.js.map +1 -0
- package/dist/agent/orchestrator.d.ts +18 -0
- package/dist/agent/orchestrator.d.ts.map +1 -0
- package/dist/agent/orchestrator.js +44 -0
- package/dist/agent/orchestrator.js.map +1 -0
- package/dist/{modules/agent → agent}/prompt-builder.d.ts +1 -1
- package/dist/agent/prompt-builder.d.ts.map +1 -0
- package/dist/agent/prompt-builder.js.map +1 -0
- package/dist/agent/registry.d.ts +19 -0
- package/dist/agent/registry.d.ts.map +1 -0
- package/dist/agent/registry.js +48 -0
- package/dist/agent/registry.js.map +1 -0
- package/dist/agent/tools/file-system.d.ts +11 -0
- package/dist/agent/tools/file-system.d.ts.map +1 -0
- package/dist/agent/tools/file-system.js +528 -0
- package/dist/agent/tools/file-system.js.map +1 -0
- package/dist/agent/tools/index.d.ts +4 -0
- package/dist/agent/tools/index.d.ts.map +1 -0
- package/dist/agent/tools/index.js +20 -0
- package/dist/agent/tools/index.js.map +1 -0
- package/dist/agent/tools/logger.d.ts +33 -0
- package/dist/agent/tools/logger.d.ts.map +1 -0
- package/dist/agent/tools/logger.js +86 -0
- package/dist/agent/tools/logger.js.map +1 -0
- package/dist/agent/tools/tool-resolver.d.ts +7 -0
- package/dist/agent/tools/tool-resolver.d.ts.map +1 -0
- package/dist/agent/tools/tool-resolver.js +122 -0
- package/dist/agent/tools/tool-resolver.js.map +1 -0
- package/dist/execution/adapters/in-memory-checkpoint.d.ts +11 -0
- package/dist/execution/adapters/in-memory-checkpoint.d.ts.map +1 -0
- package/dist/execution/adapters/in-memory-checkpoint.js +54 -0
- package/dist/execution/adapters/in-memory-checkpoint.js.map +1 -0
- package/dist/execution/compiler.d.ts +8 -0
- package/dist/execution/compiler.d.ts.map +1 -0
- package/dist/execution/compiler.js +50 -0
- package/dist/execution/compiler.js.map +1 -0
- package/dist/execution/controller.d.ts.map +1 -0
- package/dist/execution/controller.js.map +1 -0
- package/dist/execution/event-manager.d.ts +29 -0
- package/dist/execution/event-manager.d.ts.map +1 -0
- package/dist/{graph → execution}/event-manager.js +4 -114
- package/dist/execution/event-manager.js.map +1 -0
- package/dist/{graph → execution}/index.d.ts +50 -2
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +638 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/logger.d.ts.map +1 -0
- package/dist/execution/logger.js.map +1 -0
- package/dist/{graph → execution}/node.d.ts +6 -1
- package/dist/execution/node.d.ts.map +1 -0
- package/dist/{graph → execution}/node.js +83 -10
- package/dist/execution/node.js.map +1 -0
- package/dist/execution/observer.d.ts.map +1 -0
- package/dist/execution/observer.js.map +1 -0
- package/dist/execution/planner.d.ts +14 -0
- package/dist/execution/planner.d.ts.map +1 -0
- package/dist/execution/planner.js +43 -0
- package/dist/execution/planner.js.map +1 -0
- package/dist/execution/reducer.d.ts +19 -0
- package/dist/execution/reducer.d.ts.map +1 -0
- package/dist/execution/reducer.js +61 -0
- package/dist/execution/reducer.js.map +1 -0
- package/dist/execution/registry.d.ts +38 -0
- package/dist/execution/registry.d.ts.map +1 -0
- package/dist/execution/registry.js +63 -0
- package/dist/execution/registry.js.map +1 -0
- package/dist/execution/send-api.d.ts +24 -0
- package/dist/execution/send-api.d.ts.map +1 -0
- package/dist/execution/send-api.js +52 -0
- package/dist/execution/send-api.js.map +1 -0
- package/dist/execution/types.parallel.d.ts +61 -0
- package/dist/execution/types.parallel.d.ts.map +1 -0
- package/dist/execution/types.parallel.js +3 -0
- package/dist/execution/types.parallel.js.map +1 -0
- package/dist/execution/visualizer.d.ts.map +1 -0
- package/dist/execution/visualizer.js.map +1 -0
- package/dist/index.d.ts +27 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -8
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +32 -1
- package/dist/interfaces/index.d.ts.map +1 -1
- package/dist/interfaces/index.js.map +1 -1
- package/dist/modules/cli/index.d.ts +13 -0
- package/dist/modules/cli/index.d.ts.map +1 -0
- package/dist/modules/cli/index.js +672 -0
- package/dist/modules/cli/index.js.map +1 -0
- package/dist/modules/nlp/engine.d.ts.map +1 -1
- package/dist/modules/nlp/engine.js +0 -1
- package/dist/modules/nlp/engine.js.map +1 -1
- package/dist/persistence/index.d.ts +12 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +24 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/neo4j/driver.d.ts +26 -0
- package/dist/persistence/neo4j/driver.d.ts.map +1 -0
- package/dist/persistence/neo4j/driver.js +64 -0
- package/dist/persistence/neo4j/driver.js.map +1 -0
- package/dist/persistence/neo4j/entity-store.d.ts +15 -0
- package/dist/persistence/neo4j/entity-store.d.ts.map +1 -0
- package/dist/persistence/neo4j/entity-store.js +136 -0
- package/dist/persistence/neo4j/entity-store.js.map +1 -0
- package/dist/persistence/neo4j/execution-tracer.d.ts +19 -0
- package/dist/persistence/neo4j/execution-tracer.d.ts.map +1 -0
- package/dist/persistence/neo4j/execution-tracer.js +166 -0
- package/dist/persistence/neo4j/execution-tracer.js.map +1 -0
- package/dist/persistence/neo4j/memory-adapter.d.ts +35 -0
- package/dist/persistence/neo4j/memory-adapter.d.ts.map +1 -0
- package/dist/persistence/neo4j/memory-adapter.js +252 -0
- package/dist/persistence/neo4j/memory-adapter.js.map +1 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.d.ts +22 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.d.ts.map +1 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.js +141 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.js.map +1 -0
- package/dist/pipeline/agent-pipeline.d.ts +99 -0
- package/dist/pipeline/agent-pipeline.d.ts.map +1 -0
- package/dist/pipeline/agent-pipeline.js +356 -0
- package/dist/pipeline/agent-pipeline.js.map +1 -0
- package/dist/routing/checkpoint-adapter.d.ts +30 -0
- package/dist/routing/checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/checkpoint-adapter.js +83 -0
- package/dist/routing/checkpoint-adapter.js.map +1 -0
- package/dist/routing/documentation-generator.d.ts +47 -0
- package/dist/routing/documentation-generator.d.ts.map +1 -0
- package/dist/routing/documentation-generator.js +320 -0
- package/dist/routing/documentation-generator.js.map +1 -0
- package/dist/routing/index.d.ts +38 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +375 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/routing/intent-classifier.d.ts +206 -0
- package/dist/routing/intent-classifier.d.ts.map +1 -0
- package/dist/routing/intent-classifier.js +267 -0
- package/dist/routing/intent-classifier.js.map +1 -0
- package/dist/routing/matrix.d.ts +6 -0
- package/dist/routing/matrix.d.ts.map +1 -0
- package/dist/routing/matrix.js +131 -0
- package/dist/routing/matrix.js.map +1 -0
- package/dist/routing/orchestrator.d.ts +87 -0
- package/dist/routing/orchestrator.d.ts.map +1 -0
- package/dist/routing/orchestrator.js +425 -0
- package/dist/routing/orchestrator.js.map +1 -0
- package/dist/routing/postgres-checkpoint-adapter.d.ts +32 -0
- package/dist/routing/postgres-checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/postgres-checkpoint-adapter.js +167 -0
- package/dist/routing/postgres-checkpoint-adapter.js.map +1 -0
- package/dist/routing/redis-checkpoint-adapter.d.ts +34 -0
- package/dist/routing/redis-checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/redis-checkpoint-adapter.js +170 -0
- package/dist/routing/redis-checkpoint-adapter.js.map +1 -0
- package/dist/routing/types.d.ts +49 -0
- package/dist/routing/types.d.ts.map +1 -0
- package/dist/routing/types.js +3 -0
- package/dist/routing/types.js.map +1 -0
- package/dist/types/agent.d.ts +144 -88
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/agent.js +49 -0
- package/dist/types/agent.js.map +1 -1
- package/dist/types/index.d.ts +46 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/generate-action-schema.d.ts +2 -3
- package/dist/utils/generate-action-schema.d.ts.map +1 -1
- package/dist/utils/generate-action-schema.js +3 -1
- package/dist/utils/generate-action-schema.js.map +1 -1
- package/dist/utils/logger.d.ts +27 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +45 -0
- package/dist/utils/logger.js.map +1 -0
- package/docs/.gitbook/assets/image (1).png +0 -0
- package/docs/.gitbook/assets/image (2).png +0 -0
- package/docs/.gitbook/assets/image (3).png +0 -0
- package/docs/.gitbook/assets/image (4).png +0 -0
- package/docs/.gitbook/assets/image (5).png +0 -0
- package/docs/.gitbook/assets/image (6).png +0 -0
- package/docs/.gitbook/assets/image.png +0 -0
- package/docs/README.md +57 -0
- package/docs/SUMMARY.md +34 -0
- package/docs/cas-dusages.md +69 -0
- package/docs/cli/README.md +65 -0
- package/docs/concepts-cles.md +50 -0
- package/docs/core/architecture.md +87 -0
- package/docs/core/benchmark.md +59 -0
- package/docs/core/checkpoint.md +72 -0
- package/docs/core/documentation.md +55 -0
- package/docs/core/graphcontroller.md +63 -0
- package/docs/core/graphflow.md +137 -0
- package/docs/core/introduction.md +41 -0
- package/docs/core/les-evenements.md +95 -0
- package/docs/modules/agenda/README.md +63 -0
- package/docs/modules/agenda/interface-iagenda.md +170 -0
- package/docs/modules/agenda/les-adaptateurs/README.md +237 -0
- package/docs/modules/agenda/les-adaptateurs/nodecronadapter.md +91 -0
- package/docs/modules/introduction.md +55 -0
- package/docs/modules/les-adaptateurs.md +52 -0
- package/docs/modules/memoire/README.md +68 -0
- package/docs/modules/memoire/interface-imemory.md +183 -0
- package/docs/modules/memoire/les-adaptateurs/README.md +209 -0
- package/docs/modules/memoire/les-adaptateurs/inmemoryadapter.md +110 -0
- package/docs/modules/memoire/les-adaptateurs/meilisearchadapter.md +147 -0
- package/docs/modules/memoire/les-adaptateurs/redisadapter.md +212 -0
- package/docs/modules/nlp/README.md +44 -0
- package/docs/philosophie.md +51 -0
- package/docs/tutoriels/ajouter-des-conditions.md +150 -0
- package/docs/tutoriels/branching.md +194 -0
- package/docs/tutoriels/checkpoint-usage.md +99 -0
- package/docs/tutoriels/creer-agent-onchain.md +1041 -0
- package/docs/tutoriels/creer-un-agent.md +108 -0
- package/docs/tutoriels/creer-un-graphe-simple.md +92 -0
- package/docs/tutoriels/gerer-les-erreurs.md +124 -0
- package/docs/tutoriels/pour-commencer.md +73 -0
- package/docs/tutoriels/retry.md +166 -0
- package/execution/adapters/in-memory-checkpoint.ts +35 -0
- package/execution/compiler.ts +47 -0
- package/{graph → execution}/event-manager.ts +4 -117
- package/{graph → execution}/index.ts +376 -8
- package/{graph → execution}/node.ts +116 -12
- package/execution/planner.ts +40 -0
- package/execution/reducer.ts +73 -0
- package/execution/registry.ts +86 -0
- package/execution/send-api.ts +58 -0
- package/execution/types.parallel.ts +81 -0
- package/index.ts +35 -8
- package/interfaces/index.ts +37 -0
- package/modules/cli/index.ts +580 -0
- package/modules/nlp/engine.ts +0 -1
- package/package.json +50 -16
- package/persistence/index.ts +27 -0
- package/persistence/neo4j/driver.ts +34 -0
- package/persistence/neo4j/entity-store.ts +141 -0
- package/persistence/neo4j/execution-tracer.ts +194 -0
- package/persistence/neo4j/memory-adapter.ts +281 -0
- package/persistence/neo4j/petri-checkpoint-adapter.ts +153 -0
- package/pipeline/agent-pipeline.ts +426 -0
- package/routing/checkpoint-adapter.ts +79 -0
- package/routing/documentation-generator.ts +358 -0
- package/routing/index.ts +459 -0
- package/routing/intent-classifier.ts +360 -0
- package/routing/matrix.ts +138 -0
- package/routing/orchestrator.ts +498 -0
- package/routing/patterns/data-extraction.json +79 -0
- package/routing/patterns/human-approval.json +64 -0
- package/routing/patterns/rag-search.json +68 -0
- package/routing/postgres-checkpoint-adapter.ts +172 -0
- package/routing/redis-checkpoint-adapter.ts +187 -0
- package/routing/types.ts +59 -0
- package/routing/web-server.ts +260 -0
- package/scripts/generate-petri-docs.ts +70 -0
- package/scripts/get-gmail-token.js +65 -0
- package/scripts/get-gmail-token.ts +65 -0
- package/test/agent/agent.test.ts +92 -0
- package/test/agent/clone.test.ts +143 -0
- package/test/agent/cognitive-handler.test.ts +78 -0
- package/test/agent/entity-store.test.ts +80 -0
- package/test/agent/generic-executor.test.ts +230 -0
- package/test/agent/handoff.test.ts +163 -0
- package/test/agent/llm-factory.test.ts +40 -0
- package/test/agent/orchestrator.test.ts +156 -0
- package/test/agent/registry.test.ts +97 -0
- package/test/agent/tools.test.ts +267 -0
- package/test/execution/checkpoint.test.ts +811 -0
- package/test/{graph → execution}/controller.test.ts +2 -2
- package/test/{graph → execution}/event-manager.test.ts +1 -1
- package/test/{graph → execution}/index.test.ts +24 -15
- package/test/{graph → execution}/node.test.ts +3 -3
- package/test/{graph → execution}/observer.test.ts +2 -2
- package/test/execution/parallel.test.ts +135 -0
- package/test/execution/plan-llm-integration.test.ts +290 -0
- package/test/execution/plan-real-onchain.test.ts +226 -0
- package/test/execution/send-api.test.ts +121 -0
- package/test/modules/cli/index.test.ts +125 -0
- package/test/persistence/neo4j-execution-tracer.test.ts +96 -0
- package/test/persistence/neo4j-memory-adapter.test.ts +107 -0
- package/test/persistence/neo4j-petri-checkpoint.test.ts +89 -0
- package/test/pipeline/agent-pipeline.test.ts +118 -0
- package/test/routing/checkpoint-persistence.test.ts +58 -0
- package/test/routing/documentation-generator.test.ts +76 -0
- package/test/routing/integration.test.ts +261 -0
- package/test/routing/intent-classifier.test.ts +102 -0
- package/test/routing/petri.test.ts +156 -0
- package/test/routing/real-llm.test.ts +260 -0
- package/test-petri-features.ts +218 -0
- package/test-pipeline-api.ts +163 -0
- package/tsconfig.json +5 -2
- package/types/agent.ts +126 -4
- package/types/index.ts +66 -5
- package/utils/generate-action-schema.ts +5 -4
- package/utils/logger.ts +40 -0
- package/dist/graph/controller.d.ts.map +0 -1
- package/dist/graph/controller.js.map +0 -1
- package/dist/graph/event-manager.d.ts +0 -101
- package/dist/graph/event-manager.d.ts.map +0 -1
- package/dist/graph/event-manager.js.map +0 -1
- package/dist/graph/index.d.ts.map +0 -1
- package/dist/graph/index.js +0 -340
- package/dist/graph/index.js.map +0 -1
- package/dist/graph/logger.d.ts.map +0 -1
- package/dist/graph/logger.js.map +0 -1
- package/dist/graph/node.d.ts.map +0 -1
- package/dist/graph/node.js.map +0 -1
- package/dist/graph/observer.d.ts.map +0 -1
- package/dist/graph/observer.js.map +0 -1
- package/dist/graph/visualizer.d.ts.map +0 -1
- package/dist/graph/visualizer.js.map +0 -1
- package/dist/modules/agent/agent.d.ts +0 -35
- package/dist/modules/agent/agent.d.ts.map +0 -1
- package/dist/modules/agent/agent.js +0 -103
- package/dist/modules/agent/agent.js.map +0 -1
- package/dist/modules/agent/base/executor.d.ts.map +0 -1
- package/dist/modules/agent/base/executor.js.map +0 -1
- package/dist/modules/agent/base/index.d.ts.map +0 -1
- package/dist/modules/agent/base/index.js.map +0 -1
- package/dist/modules/agent/generic-assistant.d.ts +0 -20
- package/dist/modules/agent/generic-assistant.d.ts.map +0 -1
- package/dist/modules/agent/generic-assistant.js +0 -89
- package/dist/modules/agent/generic-assistant.js.map +0 -1
- package/dist/modules/agent/generic-executor.d.ts.map +0 -1
- package/dist/modules/agent/generic-executor.js +0 -189
- package/dist/modules/agent/generic-executor.js.map +0 -1
- package/dist/modules/agent/llm-factory.d.ts.map +0 -1
- package/dist/modules/agent/llm-factory.js +0 -56
- package/dist/modules/agent/llm-factory.js.map +0 -1
- package/dist/modules/agent/prompt-builder.d.ts.map +0 -1
- package/dist/modules/agent/prompt-builder.js.map +0 -1
- package/dist/modules/memory/adapters/in-memory/index.d.ts +0 -120
- package/dist/modules/memory/adapters/in-memory/index.d.ts.map +0 -1
- package/dist/modules/memory/adapters/in-memory/index.js +0 -212
- package/dist/modules/memory/adapters/in-memory/index.js.map +0 -1
- package/dist/modules/memory/adapters/meilisearch/index.d.ts +0 -110
- package/dist/modules/memory/adapters/meilisearch/index.d.ts.map +0 -1
- package/dist/modules/memory/adapters/meilisearch/index.js +0 -324
- package/dist/modules/memory/adapters/meilisearch/index.js.map +0 -1
- package/dist/modules/memory/adapters/redis/index.d.ts +0 -82
- package/dist/modules/memory/adapters/redis/index.d.ts.map +0 -1
- package/dist/modules/memory/adapters/redis/index.js +0 -160
- package/dist/modules/memory/adapters/redis/index.js.map +0 -1
- package/dist/modules/memory/index.d.ts +0 -67
- package/dist/modules/memory/index.d.ts.map +0 -1
- package/dist/modules/memory/index.js +0 -104
- package/dist/modules/memory/index.js.map +0 -1
- package/modules/agent/agent.ts +0 -107
- package/modules/agent/generic-assistant.ts +0 -92
- package/modules/agent/generic-executor.ts +0 -252
- package/modules/agent/llm-factory.ts +0 -47
- package/modules/memory/adapters/in-memory/index.ts +0 -208
- package/modules/memory/adapters/meilisearch/index.ts +0 -364
- package/modules/memory/adapters/redis/index.ts +0 -165
- package/modules/memory/index.ts +0 -93
- package/test/modules/memory/adapters/in-memory.test.ts +0 -153
- package/test/modules/memory/adapters/meilisearch.test.ts +0 -287
- package/test/modules/memory/base.test.ts +0 -230
- /package/dist/{modules/agent → agent}/llm-factory.d.ts +0 -0
- /package/dist/{modules/agent → agent}/prompt-builder.js +0 -0
- /package/dist/{graph → execution}/controller.d.ts +0 -0
- /package/dist/{graph → execution}/controller.js +0 -0
- /package/dist/{graph → execution}/logger.d.ts +0 -0
- /package/dist/{graph → execution}/logger.js +0 -0
- /package/dist/{graph → execution}/observer.d.ts +0 -0
- /package/dist/{graph → execution}/observer.js +0 -0
- /package/dist/{graph → execution}/visualizer.d.ts +0 -0
- /package/dist/{graph → execution}/visualizer.js +0 -0
- /package/{graph → execution}/controller.ts +0 -0
- /package/{graph → execution}/logger.ts +0 -0
- /package/{graph → execution}/observer.ts +0 -0
- /package/{graph → execution}/visualizer.ts +0 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: >-
|
|
3
|
+
L’adaptateur Redis utilise une base de données clé-valeur en mémoire, idéale
|
|
4
|
+
pour des stockages rapides et temporaires.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# RedisAdapter
|
|
8
|
+
|
|
9
|
+
`RedisAdapter` intègre **Redis** comme moteur de stockage pour la mémoire des systèmes. 
|
|
10
|
+
|
|
11
|
+
Redis permet un **accès instantané** aux données grâce à un modèle **clé-valeur**, tout en offrant des fonctionnalités avancées comme **la persistance**, **le TTL (Time-To-Live)** et **la réplication distribuée**.
|
|
12
|
+
|
|
13
|
+
Ce type d’adaptateur est particulièrement adapté aux agents qui nécessitent **des accès ultra-rapides** et une **gestion fine du cycle de vie des mémoires**.
|
|
14
|
+
|
|
15
|
+
***
|
|
16
|
+
|
|
17
|
+
### **Spécificités techniques du RedisAdapter**
|
|
18
|
+
|
|
19
|
+
#### **Stockage sous forme de clés structurées**
|
|
20
|
+
|
|
21
|
+
Chaque mémoire est stockée dans Redis avec une clé formée comme suit :
|
|
22
|
+
|
|
23
|
+
```plaintext
|
|
24
|
+
<memory_prefix>:<room_id>:<memory_id>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Cela permet de **segmenter les mémoires** par `roomId` et d’éviter les collisions.
|
|
28
|
+
|
|
29
|
+
Exemple de stockage d’une mémoire :
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const key = `${this.cachePrefix}${memory.roomId}:${memory.id}`;
|
|
33
|
+
await this.redis.set(key, JSON.stringify(memory), { EX: this.cacheTTL });
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
L’option `{ EX: this.cacheTTL }` définit **une expiration automatique** après un temps défini, évitant ainsi l’accumulation de données obsolètes.
|
|
37
|
+
|
|
38
|
+
***
|
|
39
|
+
|
|
40
|
+
#### **Initialisation et connexion au serveur Redis**
|
|
41
|
+
|
|
42
|
+
L’adaptateur doit établir une connexion avec un serveur Redis, qui peut être **local, distant ou géré via un service cloud**.
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
constructor(
|
|
46
|
+
private readonly redisUrl: string,
|
|
47
|
+
options: { cachePrefix?: string; cacheTTL?: number }
|
|
48
|
+
) {
|
|
49
|
+
this.cachePrefix = options.cachePrefix || "memory:";
|
|
50
|
+
this.cacheTTL = options.cacheTTL || 3600;
|
|
51
|
+
this.redis = createClient({ url: redisUrl });
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
* `cachePrefix` permet de **différencier plusieurs types de données** stockées dans Redis.
|
|
56
|
+
* `cacheTTL` définit **le temps de rétention** des mémoires (en secondes).
|
|
57
|
+
|
|
58
|
+
**Avantage :** Un système utilisant Redis peut fonctionner sans base de données persistante, en exploitant uniquement la mémoire vive du serveur.
|
|
59
|
+
|
|
60
|
+
***
|
|
61
|
+
|
|
62
|
+
#### **Création et récupération des mémoires**
|
|
63
|
+
|
|
64
|
+
**Stockage d’une nouvelle mémoire**
|
|
65
|
+
|
|
66
|
+
Chaque entrée est **convertie en JSON** et stockée sous une clé unique dans Redis.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
async createMemory(input: CreateMemoryInput & { embedding?: number[] }): Promise<BaseMemoryType | undefined> {
|
|
70
|
+
const memory: BaseMemoryType = {
|
|
71
|
+
id: input.id || crypto.randomUUID(),
|
|
72
|
+
data: input.data,
|
|
73
|
+
embedding: input.embedding,
|
|
74
|
+
roomId: input.roomId,
|
|
75
|
+
createdAt: new Date(),
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const key = `${this.cachePrefix}${memory.roomId}:${memory.id}`;
|
|
79
|
+
await this.redis.set(key, JSON.stringify(memory), { EX: this.cacheTTL });
|
|
80
|
+
|
|
81
|
+
return memory;
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
💡 **Optimisation :** Redis étant une base en RAM, **éviter de stocker des objets volumineux** pour limiter l’impact sur la mémoire.
|
|
86
|
+
|
|
87
|
+
***
|
|
88
|
+
|
|
89
|
+
**Récupération d’une mémoire**
|
|
90
|
+
|
|
91
|
+
Les entrées sont récupérées en **temps constant** grâce à l’accès clé-valeur.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
async getMemoryById(id: string, roomId: string): Promise<BaseMemoryType | null> {
|
|
95
|
+
const key = `${this.cachePrefix}${roomId}:${id}`;
|
|
96
|
+
const data = await this.redis.get(key);
|
|
97
|
+
return data ? JSON.parse(data) : null;
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Temps d’accès :** \~ **1 ms**, bien plus rapide qu’une base de données traditionnelle.
|
|
102
|
+
|
|
103
|
+
***
|
|
104
|
+
|
|
105
|
+
#### **Recherche et indexation dans Redis**
|
|
106
|
+
|
|
107
|
+
Redis ne supporte pas nativement **les recherches full-text**, mais il est possible de **simuler une indexation** en utilisant **les clés et SCAN MATCH**.
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
async getMemoryByIndex(query: string, options: { roomId: string; limit?: number }): Promise<BaseMemoryType[]> {
|
|
111
|
+
const pattern = `${this.cachePrefix}${options.roomId}:*`;
|
|
112
|
+
const keys = await this.redis.keys(pattern);
|
|
113
|
+
|
|
114
|
+
const memories = await Promise.all(
|
|
115
|
+
keys.map(async (key) => {
|
|
116
|
+
const data = await this.redis.get(key);
|
|
117
|
+
return data ? JSON.parse(data) : null;
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
return memories.filter(Boolean).slice(0, options.limit || 10);
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Limite :** Redis ne propose pas de scoring de pertinence comme Meilisearch. Les recherches sont basées sur **des correspondances exactes** ou **un filtrage par clé**.
|
|
126
|
+
|
|
127
|
+
***
|
|
128
|
+
|
|
129
|
+
#### **Suppression et nettoyage de la mémoire**
|
|
130
|
+
|
|
131
|
+
Redis permet une suppression instantanée d’une mémoire spécifique ou d’un ensemble de mémoires.
|
|
132
|
+
|
|
133
|
+
**Suppression d’une mémoire individuelle**
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
async clearMemoryById(id: string, roomId: string): Promise<void> {
|
|
137
|
+
const key = `${this.cachePrefix}${roomId}:${id}`;
|
|
138
|
+
await this.redis.del(key);
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Suppression de toutes les mémoires d’un agent**
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
async clearAllMemories(): Promise<void> {
|
|
146
|
+
const keys = await this.redis.keys(`${this.cachePrefix}*`);
|
|
147
|
+
if (keys.length > 0) {
|
|
148
|
+
await this.redis.del(keys);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Attention :** Cette opération peut être coûteuse si le volume de données est important.
|
|
154
|
+
|
|
155
|
+
***
|
|
156
|
+
|
|
157
|
+
### **Limitations et considérations**
|
|
158
|
+
|
|
159
|
+
#### **Dépendance à un service en mémoire volatile**
|
|
160
|
+
|
|
161
|
+
Redis fonctionne en **RAM**, ce qui signifie que **sans mécanisme de persistance activé**, les mémoires stockées peuvent être **perdues en cas de redémarrage**. Par défaut, Redis offre **deux modes de persistance** :
|
|
162
|
+
|
|
163
|
+
* **RDB (Redis Database Snapshot)** : Sauvegarde périodique en dur.
|
|
164
|
+
* **AOF (Append-Only File)** : Journalisation des opérations pour rejouer l’état en cas de crash.\
|
|
165
|
+
Si la mémoire de l’agent doit être **persistante sur le long terme**, il est recommandé d’associer Redis avec **une base durable** comme PostgreSQL ou Meilisearch.
|
|
166
|
+
|
|
167
|
+
#### **Latence ultra-faible mais dépendance au réseau**
|
|
168
|
+
|
|
169
|
+
Redis est **extrêmement rapide** (accès en **O(1)**), mais cette rapidité dépend de **l’emplacement du serveur**.
|
|
170
|
+
|
|
171
|
+
* Un **Redis local** offre **des performances optimales**.
|
|
172
|
+
* Un **Redis distant** introduit une **latence liée au réseau**.\
|
|
173
|
+
Si l’agent est déployé dans un environnement distribué, il est préférable d’**héberger Redis proche de l’instance exécutant l’agent**.
|
|
174
|
+
|
|
175
|
+
#### **Consommation mémoire et TTL obligatoire**
|
|
176
|
+
|
|
177
|
+
Redis stocke **tout en RAM**, ce qui peut poser un problème si un système génère un **grand volume de données**.
|
|
178
|
+
|
|
179
|
+
⚠ **Sans expiration (TTL), les mémoires s’accumulent et saturent Redis**.
|
|
180
|
+
|
|
181
|
+
Il est **recommandé de fixer une politique d’expiration** (exemple : **stockage des mémoires pour X heures**).
|
|
182
|
+
|
|
183
|
+
Exemple de gestion du TTL :
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
await this.redis.set(key, JSON.stringify(memory), { EX: 3600 }); // Expire après 1h
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Si l’agent doit **conserver son historique sur le long terme**, une solution **persistante (Meilisearch, SQL, stockage objet)** est plus adaptée.
|
|
190
|
+
|
|
191
|
+
#### **Absence de moteur de recherche avancé**
|
|
192
|
+
|
|
193
|
+
Redis **ne supporte pas nativement les recherches full-text ou vectorielles**.
|
|
194
|
+
|
|
195
|
+
* Pour **des recherches sémantiques**, il est préférable d’utiliser **Meilisearch**.
|
|
196
|
+
* Pour **des recherches par similarité**, Redis **peut stocker des embeddings**, mais un moteur spécialisé comme **FAISS ou Weaviate** est plus efficace.
|
|
197
|
+
|
|
198
|
+
#### **Non adapté aux grosses bases historiques**
|
|
199
|
+
|
|
200
|
+
Si le système doit **retrouver des informations sur plusieurs mois/années**, Redis n’est pas une solution idéale.\
|
|
201
|
+
**Recommandation** : Utiliser Redis pour **le stockage temporaire** et exporter les anciennes données vers une **base durable** (Meilisearch/PostgreSQL).
|
|
202
|
+
|
|
203
|
+
***
|
|
204
|
+
|
|
205
|
+
### **Cas d’usage adaptés**
|
|
206
|
+
|
|
207
|
+
**`RedisAdapter`** est particulièrement utile pour : 
|
|
208
|
+
|
|
209
|
+
* **Le caching des réponses d’un agent** pour réduire les appels aux LLMs.
|
|
210
|
+
* **Les sessions temporaires**, où l’état mémoire doit expirer après une période définie.
|
|
211
|
+
* **Les interactions en temps réel**, nécessitant des accès ultra-rapides.
|
|
212
|
+
* **Le stockage intermédiaire** avant synchronisation avec une base plus durable.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Module NLP
|
|
2
|
+
|
|
3
|
+
Le module NLP enveloppe `@nlpjs/basic` comme nœuds de graphe pour le traitement du langage naturel.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Le module est inclus dans le package principal:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { NLPEngine } from "@ai.ntellect/core";
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Utilisation de base
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { NLPEngine } from "@ai.ntellect/core";
|
|
17
|
+
|
|
18
|
+
const nlp = new NLPEngine();
|
|
19
|
+
|
|
20
|
+
// Entraîner le moteur
|
|
21
|
+
await nlp.train([
|
|
22
|
+
{ intent: "greeting", utterances: ["hello", "hi", "hey"], answer: "Hello! How can I help?" },
|
|
23
|
+
{ intent: "goodbye", utterances: ["bye", "see you"], answer: "Goodbye!" },
|
|
24
|
+
]);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Utilisation comme nœud de graphe
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
{
|
|
31
|
+
name: "process_input",
|
|
32
|
+
execute: async (ctx) => {
|
|
33
|
+
const result = await nlp.process(ctx.userInput);
|
|
34
|
+
ctx.intent = result.intent;
|
|
35
|
+
ctx.answer = result.answer;
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Cas d'usage
|
|
41
|
+
|
|
42
|
+
- **Chatbots** — Détection d'intention sur les entrées utilisateur
|
|
43
|
+
- **Classification** — Catégoriser du texte
|
|
44
|
+
- **Réponses automatiques** — Réponses basées sur des règles simples
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# The Philosophy of Deterministic Control
|
|
2
|
+
|
|
3
|
+
In the current AI landscape, there is a fundamental tension between **autonomy** and **reliability**.
|
|
4
|
+
|
|
5
|
+
## The Problem: The "LLM-as-Brain" Fallacy
|
|
6
|
+
|
|
7
|
+
Most modern agent frameworks are built on the assumption that the LLM should act as the central controller. In this model, the LLM:
|
|
8
|
+
1. Analyzes the state.
|
|
9
|
+
2. Decides which tool to call.
|
|
10
|
+
3. Evaluates the result.
|
|
11
|
+
4. Decides the next step.
|
|
12
|
+
|
|
13
|
+
This is "Autonomous Reasoning." It works beautifully in demos, but it fails in production. Why? Because **probabilistic models are fundamentally unsuitable for control flow.**
|
|
14
|
+
|
|
15
|
+
When an LLM manages routing, you introduce **non-deterministic drift**. A slight change in prompt or a random seed shift can lead the agent to skip a critical validation step or enter an infinite loop.
|
|
16
|
+
|
|
17
|
+
## Our Solution: The Classifier-Controller Split
|
|
18
|
+
|
|
19
|
+
We believe that for an AI agent to be production-ready, it must be **verifiable**. To achieve this, `@ai.ntellect/core` implements a strict separation of concerns:
|
|
20
|
+
|
|
21
|
+
### 1. The LLM as the Classifier (The "What")
|
|
22
|
+
We use the LLM for what it is best at: **high-dimensional pattern matching**.
|
|
23
|
+
Instead of asking the LLM "What should I do next?", we ask "Which known intent does this user request match?". The LLM provides a classification, not a command.
|
|
24
|
+
|
|
25
|
+
### 2. The System as the Controller (The "How")
|
|
26
|
+
Once the intent is identified, the LLM is removed from the routing logic. The flow is handed over to a **verified Petri Net**.
|
|
27
|
+
The Petri Net defines the legal transitions of the system. It doesn't "guess" the next step; it executes a mathematically proven path.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## The Three Pillars of Our Approach
|
|
32
|
+
|
|
33
|
+
### 🛡️ Determinism over Autonomy
|
|
34
|
+
We prioritize **predictability** over "magic." We believe that a developer should be able to look at a graph and know exactly how the system will behave, regardless of the LLM's temperature.
|
|
35
|
+
|
|
36
|
+
### 🔍 Verifiability over Trust
|
|
37
|
+
"Trusting" an LLM to follow instructions is a risk. **Verifying** a Petri Net for deadlocks or reachability is a guarantee. By using formal methods, we move from "It usually works" to "It is mathematically impossible for this to deadlock."
|
|
38
|
+
|
|
39
|
+
### 🏗️ Transparency over Opacity
|
|
40
|
+
We reject "Black Box" orchestration. Every transition, every state change, and every checkpoint in `@ai.ntellect/core` is observable and traceable. You don't debug a prompt; you debug a state machine.
|
|
41
|
+
|
|
42
|
+
## Alignment with d/acc (Defensive Accelerationism)
|
|
43
|
+
|
|
44
|
+
This technical philosophy is a practical application of **Defensive Accelerationism**. We accelerate the capabilities of AI, but we do so by building **defensive infrastructures**.
|
|
45
|
+
|
|
46
|
+
By wrapping probabilistic AI in deterministic controllers, we create systems that are:
|
|
47
|
+
- **Resilient**: They don't break when the LLM hallucinates.
|
|
48
|
+
- **Sovereign**: The developer, not the model provider, maintains total control over the logic.
|
|
49
|
+
- **Transparent**: The execution path is a visible graph, not a hidden chain of thought.
|
|
50
|
+
|
|
51
|
+
**We don't want agents that "try their best." We want agents that execute precisely.**
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: >-
|
|
3
|
+
Ajoutez des conditions pour orienter l'exécution en fonction des données du
|
|
4
|
+
contexte. Créez des branches conditionnelles pour adapter le parcours.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Ajouter des conditions
|
|
8
|
+
|
|
9
|
+
Dans ce tutoriel, nous allons apprendre **comment prendre des décisions dynamiques** dans un **GraphFlow**. Nous allons modifier notre graphe pour **choisir un chemin d'exécution** en fonction des données du contexte.
|
|
10
|
+
|
|
11
|
+
Cela permet de :
|
|
12
|
+
|
|
13
|
+
* **Modifier le flux d'exécution** en fonction des entrées.
|
|
14
|
+
* **Créer des branches conditionnelles** (ex : Si `x > 10`, alors `A`, sinon `B`).
|
|
15
|
+
* **Améliorer la flexibilité du graphe** en lui permettant de s'adapter aux données.
|
|
16
|
+
|
|
17
|
+
***
|
|
18
|
+
|
|
19
|
+
### **Ajouter des conditions à un graphe**
|
|
20
|
+
|
|
21
|
+
Nous allons **ajouter une logique conditionnelle** qui :
|
|
22
|
+
|
|
23
|
+
1. **Convert text to uppercase**.
|
|
24
|
+
2. **Check text length**.
|
|
25
|
+
3. **If text length > 10**, mark as **"LONG"**.
|
|
26
|
+
4. **Else**, mark as **"SHORT"**.
|
|
27
|
+
|
|
28
|
+
Nous utiliserons **une fonction `next` dynamique** qui **choisit** la prochaine étape en fonction des données.
|
|
29
|
+
|
|
30
|
+
***
|
|
31
|
+
|
|
32
|
+
### **Implémentation du graphe avec logique conditionnelle**
|
|
33
|
+
|
|
34
|
+
Nous allons modifier **notre précédent GraphFlow** pour ajouter **deux branches conditionnelles**.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { GraphFlow, GraphNodeConfig } from "@ai.ntellect/core";
|
|
38
|
+
import { z } from "zod";
|
|
39
|
+
|
|
40
|
+
// Définition du schéma du contexte
|
|
41
|
+
const schema = z.object({
|
|
42
|
+
input: z.string(),
|
|
43
|
+
processed: z.string().optional(),
|
|
44
|
+
result: z.string().optional(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Node 1: Convert text to uppercase
|
|
48
|
+
const processText: GraphNodeConfig<typeof schema> = {
|
|
49
|
+
name: "processText",
|
|
50
|
+
execute: async (context) => {
|
|
51
|
+
context.processed = context.input.toUpperCase();
|
|
52
|
+
console.log("Text transformed:", context.processed);
|
|
53
|
+
},
|
|
54
|
+
next: (context) => {
|
|
55
|
+
return (context.processed?.length ?? 0) > 10
|
|
56
|
+
? ["longTextHandler"]
|
|
57
|
+
: ["shortTextHandler"];
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Node 2A: Handle long text
|
|
62
|
+
const longTextHandler: GraphNodeConfig<typeof schema> = {
|
|
63
|
+
name: "longTextHandler",
|
|
64
|
+
execute: async (context) => {
|
|
65
|
+
context.result = `LONG: ${context.processed}`;
|
|
66
|
+
console.log("Long text:", context.result);
|
|
67
|
+
},
|
|
68
|
+
next: ["logResult"],
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Node 2B: Handle short text
|
|
72
|
+
const shortTextHandler: GraphNodeConfig<typeof schema> = {
|
|
73
|
+
name: "shortTextHandler",
|
|
74
|
+
execute: async (context) => {
|
|
75
|
+
context.result = `COURT: ${context.processed}`;
|
|
76
|
+
console.log("Short text:", context.result);
|
|
77
|
+
},
|
|
78
|
+
next: ["logResult"],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Final node: Display result
|
|
82
|
+
const logResult: GraphNodeConfig<typeof schema> = {
|
|
83
|
+
name: "logResult",
|
|
84
|
+
execute: async (context) => {
|
|
85
|
+
console.log("Final result:", context.result);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// Création du graphe
|
|
90
|
+
const graph = new GraphFlow("GraphWithDecision", {
|
|
91
|
+
name: "GraphWithDecision",
|
|
92
|
+
nodes: [processText, longTextHandler, shortTextHandler, logResult],
|
|
93
|
+
context: { input: "" },
|
|
94
|
+
schema,
|
|
95
|
+
entryNode: "processText",
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Exécution du graphe avec différents inputs
|
|
99
|
+
(async () => {
|
|
100
|
+
console.log("Execution with short text");
|
|
101
|
+
// ...
|
|
102
|
+
console.log("Execution with long text");
|
|
103
|
+
await graph.execute("processText", { input: "Hello GraphFlow!" });
|
|
104
|
+
})();
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
***
|
|
108
|
+
|
|
109
|
+
### **Explication du code**
|
|
110
|
+
|
|
111
|
+
#### **Ajout d’un `next` dynamique**
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
next: (context) => {
|
|
115
|
+
return (context.processed?.length ?? 0) > 10
|
|
116
|
+
? ["longTextHandler"]
|
|
117
|
+
: ["shortTextHandler"];
|
|
118
|
+
},
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
* **Si le texte est long** (`> 10 caractères`), on va vers **`longTextHandler`**.
|
|
122
|
+
* **Sinon**, on va vers **`shortTextHandler`**.
|
|
123
|
+
|
|
124
|
+
#### **Affichage du résultat final**
|
|
125
|
+
|
|
126
|
+
* `longTextHandler` marque le texte comme **"LONG"**.
|
|
127
|
+
* `shortTextHandler` marque le texte comme **"SHORT"**.
|
|
128
|
+
* Le `logResult` affiche le **résultat final**.
|
|
129
|
+
|
|
130
|
+
***
|
|
131
|
+
|
|
132
|
+
### **Résultat attendu**
|
|
133
|
+
|
|
134
|
+
#### Cas 1 : **Texte court**
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
Execution with short text
|
|
138
|
+
Text transformed: HELLO
|
|
139
|
+
Short text: COURT: HELLO
|
|
140
|
+
Final result: COURT: HELLO
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### Cas 2 : **Long text**
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
Execution with long text
|
|
147
|
+
Text transformed: HELLO GRAPHFLOW!
|
|
148
|
+
Long text: LONG: HELLO GRAPHFLOW!
|
|
149
|
+
Final result: LONG: HELLO GRAPHFLOW!
|
|
150
|
+
```
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Branching
|
|
2
|
+
|
|
3
|
+
Le branching permet de créer des chemins d'exécution multiples dans votre graphe, que ce soit par condition, en parallèle, ou via un fan-out dynamique.
|
|
4
|
+
|
|
5
|
+
## Branching conditionnel
|
|
6
|
+
|
|
7
|
+
Utilisez `next` avec une condition pour diriger le flux vers différents nœuds :
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { GraphFlow } from "@ai.ntellect/core";
|
|
11
|
+
|
|
12
|
+
const workflow = new GraphFlow({
|
|
13
|
+
name: "order-process",
|
|
14
|
+
context: { amount: 0, status: "" },
|
|
15
|
+
nodes: [
|
|
16
|
+
{
|
|
17
|
+
name: "check_amount",
|
|
18
|
+
execute: async (ctx) => {
|
|
19
|
+
ctx.status = ctx.amount > 1000 ? "high" : "normal";
|
|
20
|
+
},
|
|
21
|
+
next: [
|
|
22
|
+
{ when: (ctx) => ctx.status === "high", to: "manager_approval" },
|
|
23
|
+
{ when: (ctx) => ctx.status === "normal", to: "auto_approve" },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "manager_approval",
|
|
28
|
+
execute: async (ctx) => { ctx.approved = true; },
|
|
29
|
+
next: "notify",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "auto_approve",
|
|
33
|
+
execute: async (ctx) => { ctx.approved = true; },
|
|
34
|
+
next: "notify",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "notify",
|
|
38
|
+
execute: async (ctx) => { console.log("Commande approuvée"); },
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
await workflow.execute("check_amount", { amount: 1500 });
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Parallélisation (Fork-Join)
|
|
47
|
+
|
|
48
|
+
Activez `parallel: { enabled: true }` sur un nœud pour exécuter plusieurs branches simultanément. Utilisez `joinNode` pour spécifier où les branches se rejoignent.
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const workflow = new GraphFlow({
|
|
52
|
+
name: "parallel-processing",
|
|
53
|
+
context: { results: [], data: "test" },
|
|
54
|
+
nodes: [
|
|
55
|
+
{
|
|
56
|
+
name: "split",
|
|
57
|
+
execute: async (ctx) => { ctx.results = []; },
|
|
58
|
+
parallel: { enabled: true },
|
|
59
|
+
next: [
|
|
60
|
+
{ to: "process_a", branchId: "a" },
|
|
61
|
+
{ to: "process_b", branchId: "b" },
|
|
62
|
+
{ to: "process_c", branchId: "c" },
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "process_a",
|
|
67
|
+
execute: async (ctx) => { ctx.results.push("A"); },
|
|
68
|
+
joinNode: "merge",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "process_b",
|
|
72
|
+
execute: async (ctx) => { ctx.results.push("B"); },
|
|
73
|
+
joinNode: "merge",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "process_c",
|
|
77
|
+
execute: async (ctx) => { ctx.results.push("C"); },
|
|
78
|
+
joinNode: "merge",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "merge",
|
|
82
|
+
execute: async (ctx) => {
|
|
83
|
+
console.log("Résultats:", ctx.results); // ["A", "B", "C"]
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
await workflow.execute("split");
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Chaque branche reçoit une copie isolée du contexte (`structuredClone`). Les résultats sont fusionnés selon les règles de réduction définies.
|
|
93
|
+
|
|
94
|
+
## Reducers (fusion des résultats)
|
|
95
|
+
|
|
96
|
+
Contrôlez comment les résultats des branches parallèles sont fusionnés avec des reducers :
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { Reducers } from "@ai.ntellect/core";
|
|
100
|
+
|
|
101
|
+
{
|
|
102
|
+
name: "split",
|
|
103
|
+
execute: async (ctx) => { ctx.results = []; },
|
|
104
|
+
parallel: { enabled: true },
|
|
105
|
+
reducers: [
|
|
106
|
+
{ key: "results", reducer: Reducers.append }, // concatène les tableaux
|
|
107
|
+
],
|
|
108
|
+
next: [
|
|
109
|
+
{ to: "branch_a", branchId: "a" },
|
|
110
|
+
{ to: "branch_b", branchId: "b" },
|
|
111
|
+
],
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Reducers intégrés :
|
|
116
|
+
- `Reducers.append` — concatène les tableaux
|
|
117
|
+
- `Reducers.deepMerge` — fusion profonde (défaut)
|
|
118
|
+
- `Reducers.lastWins` — garde la dernière valeur
|
|
119
|
+
- `Reducers.sum` — additionne les nombres
|
|
120
|
+
|
|
121
|
+
## Send API (fan-out dynamique)
|
|
122
|
+
|
|
123
|
+
Le `send` API permet de créer dynamiquement des branches au runtime :
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { SendAPI } from "@ai.ntellect/core";
|
|
127
|
+
|
|
128
|
+
{
|
|
129
|
+
name: "distribute",
|
|
130
|
+
execute: async (ctx) => { ctx.processed = 0; },
|
|
131
|
+
send: (ctx) => {
|
|
132
|
+
const items = ctx.items || ["a", "b", "c"];
|
|
133
|
+
return SendAPI.map(items, (item, i) => ({
|
|
134
|
+
to: "process_item",
|
|
135
|
+
input: { item, index: i },
|
|
136
|
+
branchId: `item_${i}`,
|
|
137
|
+
}));
|
|
138
|
+
},
|
|
139
|
+
reducers: [
|
|
140
|
+
{ key: "processed", reducer: (acc, val) => acc + val },
|
|
141
|
+
],
|
|
142
|
+
joinNode: "done",
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "process_item",
|
|
146
|
+
execute: async (ctx) => {
|
|
147
|
+
console.log("Traitement:", ctx.item);
|
|
148
|
+
return 1; // sera additionné par le reducer
|
|
149
|
+
},
|
|
150
|
+
joinNode: "done",
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: "done",
|
|
154
|
+
execute: async (ctx) => {
|
|
155
|
+
console.log("Total traité:", ctx.processed); // 3
|
|
156
|
+
},
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Subgraphs (branches complexes)
|
|
161
|
+
|
|
162
|
+
Une branche peut être un graphe complet enregistré via `SubgraphManager` :
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { SubgraphManager } from "@ai.ntellect/core";
|
|
166
|
+
|
|
167
|
+
const subgraph = new GraphFlow({
|
|
168
|
+
name: "subtask",
|
|
169
|
+
context: { result: "" },
|
|
170
|
+
nodes: [{
|
|
171
|
+
name: "run",
|
|
172
|
+
execute: async (ctx) => { ctx.result = "done"; },
|
|
173
|
+
}],
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const manager = new SubgraphManager();
|
|
177
|
+
manager.register("subtask", subgraph);
|
|
178
|
+
|
|
179
|
+
// Utilisable comme branche parallèle
|
|
180
|
+
{
|
|
181
|
+
name: "run_subgraph",
|
|
182
|
+
execute: async (ctx) => {},
|
|
183
|
+
parallel: { enabled: true },
|
|
184
|
+
next: [{ to: "subtask", subgraph: "subtask" }],
|
|
185
|
+
joinNode: "next",
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Cas d'usage
|
|
190
|
+
|
|
191
|
+
- **Validation parallèle** : Vérifier plusieurs conditions simultanément
|
|
192
|
+
- **Pipeline de données** : Traiter des éléments indépendants en parallèle
|
|
193
|
+
- **Fan-out dynamique** : Distribuer du travail selon la taille d'un tableau
|
|
194
|
+
- **Subgraphs** : Décomposer un workflow complexe en composants réutilisables
|