@ai.ntellect/core 1.0.0 → 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 +6 -0
- package/AGENTS.md +50 -0
- package/ARCHITECTURE.md +58 -0
- package/BENCHMARK.md +38 -0
- package/CHANGELOG.md +224 -0
- package/README.md +411 -142
- package/agent/agent-workflow.ts +569 -0
- package/agent/agent.ts +183 -0
- package/agent/base/executor.ts +103 -0
- package/agent/base/index.ts +87 -0
- 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/agent/prompt-builder.ts +78 -0
- 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/agent/base/executor.d.ts +51 -0
- package/dist/agent/base/executor.d.ts.map +1 -0
- package/dist/agent/base/executor.js +69 -0
- package/dist/agent/base/executor.js.map +1 -0
- package/dist/agent/base/index.d.ts +30 -0
- package/dist/agent/base/index.d.ts.map +1 -0
- package/dist/agent/base/index.js +88 -0
- 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/agent/generic-executor.d.ts +68 -0
- 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 +19 -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/agent/prompt-builder.d.ts +35 -0
- package/dist/agent/prompt-builder.d.ts.map +1 -0
- package/dist/agent/prompt-builder.js +76 -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 +30 -0
- package/dist/execution/controller.d.ts.map +1 -0
- package/dist/execution/controller.js +80 -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/execution/event-manager.js +264 -0
- package/dist/execution/event-manager.js.map +1 -0
- package/dist/execution/index.d.ts +221 -0
- 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 +46 -0
- package/dist/execution/logger.d.ts.map +1 -0
- package/dist/execution/logger.js +69 -0
- package/dist/execution/logger.js.map +1 -0
- package/dist/execution/node.d.ts +65 -0
- package/dist/execution/node.d.ts.map +1 -0
- package/dist/execution/node.js +250 -0
- package/dist/execution/node.js.map +1 -0
- package/dist/execution/observer.d.ts +38 -0
- package/dist/execution/observer.d.ts.map +1 -0
- package/dist/execution/observer.js +111 -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 +35 -0
- package/dist/execution/visualizer.d.ts.map +1 -0
- package/dist/execution/visualizer.js +131 -0
- package/dist/execution/visualizer.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +487 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +75 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/modules/agenda/adapters/node-cron/index.d.ts +17 -0
- package/dist/modules/agenda/adapters/node-cron/index.d.ts.map +1 -0
- package/dist/modules/agenda/adapters/node-cron/index.js +30 -0
- package/dist/modules/agenda/adapters/node-cron/index.js.map +1 -0
- package/dist/modules/agenda/index.d.ts +63 -0
- package/dist/modules/agenda/index.d.ts.map +1 -0
- package/dist/modules/agenda/index.js +141 -0
- package/dist/modules/agenda/index.js.map +1 -0
- 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/embedding/adapters/ai/index.d.ts +29 -0
- package/dist/modules/embedding/adapters/ai/index.d.ts.map +1 -0
- package/dist/modules/embedding/adapters/ai/index.js +58 -0
- package/dist/modules/embedding/adapters/ai/index.js.map +1 -0
- package/dist/modules/embedding/index.d.ts +36 -0
- package/dist/modules/embedding/index.d.ts.map +1 -0
- package/dist/modules/embedding/index.js +60 -0
- package/dist/modules/embedding/index.js.map +1 -0
- package/dist/modules/nlp/engine.d.ts +126 -0
- package/dist/modules/nlp/engine.d.ts.map +1 -0
- package/dist/modules/nlp/engine.js +299 -0
- package/dist/modules/nlp/engine.js.map +1 -0
- package/dist/modules/nlp/index.d.ts +27 -0
- package/dist/modules/nlp/index.d.ts.map +1 -0
- package/dist/modules/nlp/index.js +56 -0
- package/dist/modules/nlp/index.js.map +1 -0
- 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 +289 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +78 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/index.d.ts +343 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/generate-action-schema.d.ts +4 -0
- package/dist/utils/generate-action-schema.d.ts.map +1 -0
- package/dist/utils/generate-action-schema.js +46 -0
- package/dist/utils/generate-action-schema.js.map +1 -0
- package/dist/utils/header-builder.d.ts +12 -0
- package/dist/utils/header-builder.d.ts.map +1 -0
- package/dist/utils/header-builder.js +35 -0
- package/dist/utils/header-builder.js.map +1 -0
- 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/execution/controller.ts +84 -0
- package/execution/event-manager.ts +331 -0
- package/execution/index.ts +800 -0
- package/execution/logger.ts +70 -0
- package/execution/node.ts +315 -0
- package/execution/observer.ts +192 -0
- 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/execution/visualizer.ts +158 -0
- package/index.ts +55 -465
- package/interfaces/index.ts +597 -0
- package/modules/agenda/adapters/node-cron/index.ts +25 -0
- package/modules/agenda/index.ts +146 -0
- package/modules/cli/index.ts +580 -0
- package/modules/embedding/adapters/ai/index.ts +42 -0
- package/modules/embedding/index.ts +45 -0
- package/modules/nlp/engine.ts +324 -0
- package/modules/nlp/index.ts +45 -0
- package/package.json +81 -9
- 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/execution/controller.test.ts +236 -0
- package/test/execution/event-manager.test.ts +118 -0
- package/test/execution/index.test.ts +690 -0
- package/test/execution/node.test.ts +464 -0
- package/test/execution/observer.test.ts +393 -0
- 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/agenda/node-cron.test.ts +307 -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 +30 -108
- package/types/agent.ts +296 -0
- package/types/index.ts +387 -0
- package/utils/generate-action-schema.ts +47 -0
- package/utils/header-builder.ts +40 -0
- package/utils/logger.ts +40 -0
- package/package copy.json +0 -21
- package/types.ts +0 -62
- package/utils/executor.ts +0 -42
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Building Tool-Using Agents
|
|
2
|
+
|
|
3
|
+
An **Agent** is a high-level entity that combines an LLM's reasoning with GraphFlow's deterministic execution.
|
|
4
|
+
|
|
5
|
+
Instead of letting the LLM "guess" how to solve a problem, we give it a set of **Tools** (which are just GraphFlows) and let it decide which one to use.
|
|
6
|
+
|
|
7
|
+
## 🛠️ Step 1: Create the Tools
|
|
8
|
+
|
|
9
|
+
A tool is simply a `GraphFlow`. The LLM uses the `name` and the `Zod schema` to understand what the tool does and what parameters it needs.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { GraphFlow } from "@ai.ntellect/core";
|
|
14
|
+
|
|
15
|
+
// Tool 1: A simple calculator
|
|
16
|
+
const calculator = new GraphFlow({
|
|
17
|
+
name: "calculator",
|
|
18
|
+
schema: z.object({
|
|
19
|
+
a: z.number(),
|
|
20
|
+
b: z.number(),
|
|
21
|
+
operation: z.enum(["add", "subtract", "multiply", "divide"]),
|
|
22
|
+
result: z.number().optional(),
|
|
23
|
+
}),
|
|
24
|
+
context: { a: 0, b: 0, operation: "add" },
|
|
25
|
+
nodes: [{
|
|
26
|
+
name: "calc",
|
|
27
|
+
execute: async (ctx) => {
|
|
28
|
+
if (ctx.operation === "add") ctx.result = ctx.a + ctx.b;
|
|
29
|
+
// ... other operations
|
|
30
|
+
}
|
|
31
|
+
}],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Tool 2: A web search tool
|
|
35
|
+
const webSearch = new GraphFlow({
|
|
36
|
+
name: "web_search",
|
|
37
|
+
schema: z.object({
|
|
38
|
+
query: z.string(),
|
|
39
|
+
results: z.array(z.string()).optional(),
|
|
40
|
+
}),
|
|
41
|
+
context: { query: "", results: [] },
|
|
42
|
+
nodes: [{
|
|
43
|
+
name: "search",
|
|
44
|
+
execute: async (ctx) => {
|
|
45
|
+
const res = await fetch(`https://api.example.com/search?q=${ctx.query}`);
|
|
46
|
+
ctx.results = await res.json();
|
|
47
|
+
}
|
|
48
|
+
}],
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 🤖 Step 2: Initialize the Agent
|
|
53
|
+
|
|
54
|
+
The `Agent` class handles the "Cognitive Loop": **Think $\rightarrow$ Execute $\rightarrow$ Reply**.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { Agent } from "@ai.ntellect/core";
|
|
58
|
+
|
|
59
|
+
const agent = new Agent({
|
|
60
|
+
role: "Research Assistant",
|
|
61
|
+
goal: "Provide accurate data and calculations",
|
|
62
|
+
tools: [calculator, webSearch],
|
|
63
|
+
llmConfig: {
|
|
64
|
+
provider: "ollama",
|
|
65
|
+
model: "llama3"
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 🚀 Step 3: Process a Request
|
|
71
|
+
|
|
72
|
+
When you call `agent.process()`, the following happens:
|
|
73
|
+
1. **Analyze**: The LLM looks at the user request and the available tools.
|
|
74
|
+
2. **Select**: The LLM chooses the best tool and extracts the parameters.
|
|
75
|
+
3. **Execute**: The framework runs the selected `GraphFlow` deterministically.
|
|
76
|
+
4. **Synthesize**: The LLM takes the tool result and formulates a final answer.
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
const response = await agent.process("Search for the current price of Bitcoin and multiply it by 2");
|
|
80
|
+
|
|
81
|
+
// The agent will:
|
|
82
|
+
// 1. Call 'web_search' with { query: "current price of Bitcoin" }
|
|
83
|
+
// 2. Take the result and call 'calculator' with { a: price, b: 2, operation: "multiply" }
|
|
84
|
+
// 3. Return: "The current price is X, so double that is Y."
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 🧠 Pro Tip: Adding Memory
|
|
90
|
+
|
|
91
|
+
By default, an agent might forget what it just did. Enable `memory: true` to allow the agent to track its own history and avoid repeating the same mistake.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const smartAgent = new Agent({
|
|
95
|
+
// ... other config
|
|
96
|
+
memory: true,
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## ⚖️ Agent vs. CortexFlow
|
|
101
|
+
|
|
102
|
+
| Agent (Standard) | CortexFlow (Deterministic) |
|
|
103
|
+
| :--- | :--- |
|
|
104
|
+
| LLM chooses tools in a loop | LLM classifies intent once |
|
|
105
|
+
| High flexibility, higher drift | Low drift, total predictability |
|
|
106
|
+
| Best for open-ended exploration | Best for business-critical workflows |
|
|
107
|
+
|
|
108
|
+
**Rule of thumb**: Use the `Agent` module for "Assistant" behavior, and `CortexFlow` for "Workflow" behavior.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Building Your First Workflow
|
|
2
|
+
|
|
3
|
+
In this guide, we'll move from a single node to a **complete pipeline**. We will build a data processing workflow that retrieves, transforms, and logs information.
|
|
4
|
+
|
|
5
|
+
## 🏗️ The Blueprint
|
|
6
|
+
|
|
7
|
+
We want to create a three-step process:
|
|
8
|
+
`Retrieve Data` $\rightarrow$ `Transform to Uppercase` $\rightarrow$ `Log Result`
|
|
9
|
+
|
|
10
|
+
### 1. Define the State (Schema)
|
|
11
|
+
The **Schema** is the most important part of a GraphFlow. It acts as a contract. If a node tries to set a value that doesn't match the schema, the workflow will throw an error immediately.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
|
|
16
|
+
const DataSchema = z.object({
|
|
17
|
+
rawInput: z.string(),
|
|
18
|
+
processedData: z.string().optional(),
|
|
19
|
+
finalResult: z.string().optional(),
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 2. Define the Nodes
|
|
24
|
+
Each node is a discrete unit of logic. We use the `next` property to define the path.
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
const retrieveNode = {
|
|
28
|
+
name: "retrieve",
|
|
29
|
+
execute: async (ctx) => {
|
|
30
|
+
ctx.rawInput = "deterministic orchestration is powerful";
|
|
31
|
+
},
|
|
32
|
+
next: "transform", // Go to 'transform' next
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const transformNode = {
|
|
36
|
+
name: "transform",
|
|
37
|
+
execute: async (ctx) => {
|
|
38
|
+
ctx.processedData = ctx.rawInput.toUpperCase();
|
|
39
|
+
},
|
|
40
|
+
next: "log", // Go to 'log' next
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const logNode = {
|
|
44
|
+
name: "log",
|
|
45
|
+
execute: async (ctx) => {
|
|
46
|
+
ctx.finalResult = `SUCCESS: ${ctx.processedData}`;
|
|
47
|
+
console.log(ctx.finalResult);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 3. Assemble the GraphFlow
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { GraphFlow } from "@ai.ntellect/core";
|
|
56
|
+
|
|
57
|
+
const workflow = new GraphFlow({
|
|
58
|
+
name: "DataPipeline",
|
|
59
|
+
schema: DataSchema,
|
|
60
|
+
context: { rawInput: "", processedData: "", finalResult: "" },
|
|
61
|
+
nodes: [retrieveNode, transformNode, logNode],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
await workflow.execute("retrieve");
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## ⚡ Advanced Routing: Dynamic Branching
|
|
70
|
+
|
|
71
|
+
In the real world, workflows aren't always linear. You can make the `next` property a **function** to create conditional logic.
|
|
72
|
+
|
|
73
|
+
**Example: High-Value Path**
|
|
74
|
+
```typescript
|
|
75
|
+
const checkAmount = {
|
|
76
|
+
name: "checkAmount",
|
|
77
|
+
execute: async (ctx) => {
|
|
78
|
+
ctx.amount = 150;
|
|
79
|
+
},
|
|
80
|
+
next: (ctx) => {
|
|
81
|
+
return ctx.amount > 100 ? ["premium_flow"] : ["standard_flow"];
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Now the workflow splits based on the value of 'amount'
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 🚀 Summary
|
|
89
|
+
You've just built a deterministic pipeline. Unlike a standard script, this workflow is:
|
|
90
|
+
1. **Observable**: You can track exactly which node is running.
|
|
91
|
+
2. **Type-Safe**: Zod ensures your data is always correct.
|
|
92
|
+
3. **Extensible**: You can add a "Retry" or "Checkpoint" to any node without rewriting the whole logic.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: >-
|
|
3
|
+
Implémentez des stratégies de gestion d'erreurs, définissez des tentatives de
|
|
4
|
+
reprise et assurez-vous que votre graphe réagit aux échecs de manière
|
|
5
|
+
contrôlée.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Gérer les erreurs
|
|
9
|
+
|
|
10
|
+
Dans ce tutoriel, nous allons voir **comment gérer les erreurs et les retries** dans un graphe **GraphFlow**.
|
|
11
|
+
|
|
12
|
+
L'objectif est de :
|
|
13
|
+
|
|
14
|
+
* **Détecter une erreur** et l'afficher.
|
|
15
|
+
* **Mettre en place un retry automatique** en cas d'échec d'un nœud.
|
|
16
|
+
* **Continuer l'exécution même après un échec** si nécessaire.
|
|
17
|
+
|
|
18
|
+
***
|
|
19
|
+
|
|
20
|
+
### **Ajouter une gestion des erreurs et retries**
|
|
21
|
+
|
|
22
|
+
Nous allons **modifier le nœud `retrieveData`** pour qu'il **puisse échouer** et **être retenté automatiquement**.
|
|
23
|
+
|
|
24
|
+
#### **Modification :**
|
|
25
|
+
|
|
26
|
+
* On ajoute une **erreur simulée** dans `retrieveData`.
|
|
27
|
+
* On active un **retry** avec `maxAttempts: 2` et un délai de 2 secondes.
|
|
28
|
+
* Si le retry échoue, on affiche un message et on continue l'exécution.
|
|
29
|
+
|
|
30
|
+
Voici **le code complet avec cette nouvelle gestion** :
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { GraphFlow, GraphNodeConfig } from "@ai.ntellect/core";
|
|
34
|
+
import { z } from "zod";
|
|
35
|
+
|
|
36
|
+
// Définition du contexte
|
|
37
|
+
const schema = z.object({
|
|
38
|
+
input: z.string(),
|
|
39
|
+
processed: z.string().optional(),
|
|
40
|
+
result: z.string().optional(),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Step 1: Retrieve data (with simulated error)
|
|
44
|
+
const retrieveData: GraphNodeConfig<typeof schema> = {
|
|
45
|
+
name: "retrieveData",
|
|
46
|
+
execute: async (context) => {
|
|
47
|
+
console.log("Attempting to retrieve data...");
|
|
48
|
+
if (Math.random() < 0.7) {
|
|
49
|
+
throw new Error("Simulated error during data retrieval!");
|
|
50
|
+
}
|
|
51
|
+
context.input = "Hello, GraphFlow!";
|
|
52
|
+
console.log("Data retrieved:", context.input);
|
|
53
|
+
},
|
|
54
|
+
retry: {
|
|
55
|
+
maxAttempts: 2, // On tente 2 fois avant d'abandonner
|
|
56
|
+
delay: 2000, // 2 secondes d'attente entre chaque tentative
|
|
57
|
+
onRetryFailed: async (error) => {
|
|
58
|
+
console.log("❌ Retry failed:", error.message);
|
|
59
|
+
},
|
|
60
|
+
continueOnFailed: true, // On continue l'exécution même en cas d'échec
|
|
61
|
+
},
|
|
62
|
+
next: ["processData"],
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Step 2: Transform data
|
|
66
|
+
const processData: GraphNodeConfig<typeof schema> = {
|
|
67
|
+
name: "processData",
|
|
68
|
+
execute: async (context) => {
|
|
69
|
+
if (!context.input) {
|
|
70
|
+
console.log("No data retrieved, cannot transform.");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
context.processed = context.input.toUpperCase();
|
|
74
|
+
console.log("Data transformed:", context.processed);
|
|
75
|
+
},
|
|
76
|
+
next: ["logResult"],
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Step 3: Display result
|
|
80
|
+
const logResult: GraphNodeConfig<typeof schema> = {
|
|
81
|
+
name: "logResult",
|
|
82
|
+
execute: async (context) => {
|
|
83
|
+
if (!context.processed) {
|
|
84
|
+
console.log("No result to display.");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
console.log("Final Result:", context.result);
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Construction du graphe
|
|
92
|
+
const graphDefinition = {
|
|
93
|
+
name: "SimpleGraph",
|
|
94
|
+
nodes: [retrieveData, processData, logResult],
|
|
95
|
+
context: { input: "" },
|
|
96
|
+
schema,
|
|
97
|
+
entryNode: "retrieveData",
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// Exécution du graphe
|
|
101
|
+
const graph = new GraphFlow("SimpleGraph", graphDefinition);
|
|
102
|
+
|
|
103
|
+
(async () => {
|
|
104
|
+
try {
|
|
105
|
+
console.log("Executing graph...");
|
|
106
|
+
await graph.execute("retrieveData");
|
|
107
|
+
console.log("Graph completed!");
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error("Error:", error);
|
|
110
|
+
}
|
|
111
|
+
})();
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
***
|
|
115
|
+
|
|
116
|
+
### **Explication des changements**
|
|
117
|
+
|
|
118
|
+
1. **Simulated error in `retrieveData`** : 70% chance of failure.
|
|
119
|
+
2. **Automatic retry** : Up to 2 attempts with **2 second delay**.
|
|
120
|
+
3. **If retry fails**, a message is displayed (`onRetryFailed`).
|
|
121
|
+
4. **Continue execution** even if `retrieveData` fails (`continueOnFailed: true`).
|
|
122
|
+
5. **If data retrieval completely fails**, `processData` and `logResult` execute but display a warning.
|
|
123
|
+
|
|
124
|
+
**Important** : Le graphe peut avoir **différents comportements** en fonction de si l'erreur est résolue ou non après les retries.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Quick Start Guide
|
|
2
|
+
|
|
3
|
+
Welcome to **@ai.ntellect/core**. This guide will take you from zero to your first deterministic workflow in less than 5 minutes.
|
|
4
|
+
|
|
5
|
+
## 1. Installation
|
|
6
|
+
|
|
7
|
+
Install the core package and Zod (used for state validation):
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @ai.ntellect/core zod
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 2. Your First Workflow: "Hello World"
|
|
14
|
+
|
|
15
|
+
The basic unit of execution in this framework is the `GraphFlow`. Create a file named `index.ts`:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
import { GraphFlow } from "@ai.ntellect/core";
|
|
20
|
+
|
|
21
|
+
// 1. Define the state shape (This ensures your agent never crashes due to missing data)
|
|
22
|
+
const Schema = z.object({
|
|
23
|
+
message: z.string(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// 2. Define the workflow
|
|
27
|
+
const workflow = new GraphFlow({
|
|
28
|
+
name: "hello-world",
|
|
29
|
+
schema: Schema,
|
|
30
|
+
context: { message: "" },
|
|
31
|
+
nodes: [
|
|
32
|
+
{
|
|
33
|
+
name: "greet",
|
|
34
|
+
execute: async (ctx) => {
|
|
35
|
+
ctx.message = "Hello from @ai.ntellect/core!";
|
|
36
|
+
console.log("Node 'greet' executed.");
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// 3. Run it
|
|
43
|
+
async function run() {
|
|
44
|
+
await workflow.execute("greet");
|
|
45
|
+
console.log("Final State:", workflow.getContext().message);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
run();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 3. Running the code
|
|
52
|
+
|
|
53
|
+
Use `ts-node` to execute your TypeScript file directly:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
pnpm ts-node index.ts
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Expected Output:**
|
|
60
|
+
```text
|
|
61
|
+
Node 'greet' executed.
|
|
62
|
+
Final State: Hello from @ai.ntellect/core!
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 🧭 What's Next?
|
|
68
|
+
|
|
69
|
+
Now that you've run a simple node, it's time to explore the real power of the framework:
|
|
70
|
+
|
|
71
|
+
- **Want to chain multiple steps?** $\rightarrow$ [Build a Simple Graph](./creer-un-graphe-simple.md)
|
|
72
|
+
- **Want to add an LLM?** $\rightarrow$ [Create a Tool-Using Agent](./creer-un-agent.md)
|
|
73
|
+
- **Want to handle real-world events?** $\rightarrow$ [Explore Event-Driven Nodes](../core/les-evenements.md)
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Retry
|
|
2
|
+
|
|
3
|
+
Le retry permet de gérer les échecs temporaires en réessayant l'exécution d'un nœud avec une stratégie de délai configurable.
|
|
4
|
+
|
|
5
|
+
## Configuration de base
|
|
6
|
+
|
|
7
|
+
Ajoutez une configuration `retry` sur n'importe quel nœud :
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { GraphFlow } from "@ai.ntellect/core";
|
|
11
|
+
|
|
12
|
+
const workflow = new GraphFlow({
|
|
13
|
+
name: "api-fetch",
|
|
14
|
+
context: { data: null, attempts: 0 },
|
|
15
|
+
nodes: [
|
|
16
|
+
{
|
|
17
|
+
name: "fetch_api",
|
|
18
|
+
execute: async (ctx) => {
|
|
19
|
+
ctx.attempts++;
|
|
20
|
+
const response = await fetch("https://api.example.com/data");
|
|
21
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
22
|
+
ctx.data = await response.json();
|
|
23
|
+
},
|
|
24
|
+
retry: {
|
|
25
|
+
maxAttempts: 3,
|
|
26
|
+
backoff: "exponential",
|
|
27
|
+
delay: 1000, // délai initial en ms
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await workflow.execute("fetch_api");
|
|
34
|
+
console.log(`Récupéré après ${workflow.getContext().attempts} tentative(s)`);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Stratégies de backoff
|
|
38
|
+
|
|
39
|
+
### Fixed (fixe)
|
|
40
|
+
|
|
41
|
+
Délai constant entre chaque tentative :
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
retry: {
|
|
45
|
+
maxAttempts: 3,
|
|
46
|
+
backoff: "fixed",
|
|
47
|
+
delay: 1000, // 1 seconde à chaque fois
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Linear (linéaire)
|
|
52
|
+
|
|
53
|
+
Délai qui augmente linéairement (`delay * attempt`) :
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
retry: {
|
|
57
|
+
maxAttempts: 3,
|
|
58
|
+
backoff: "linear",
|
|
59
|
+
delay: 1000, // 1s, 2s, 3s...
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Exponential (exponentiel)
|
|
64
|
+
|
|
65
|
+
Délai qui double à chaque tentative (`delay * 2^(attempt-1)`) :
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
retry: {
|
|
69
|
+
maxAttempts: 3,
|
|
70
|
+
backoff: "exponential",
|
|
71
|
+
delay: 1000, // 1s, 2s, 4s...
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Exemple complet avec gestion d'erreur
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const workflow = new GraphFlow({
|
|
79
|
+
name: "robust-fetch",
|
|
80
|
+
context: { data: null, error: null, attempts: 0 },
|
|
81
|
+
nodes: [
|
|
82
|
+
{
|
|
83
|
+
name: "fetch_with_retry",
|
|
84
|
+
execute: async (ctx) => {
|
|
85
|
+
ctx.attempts++;
|
|
86
|
+
const controller = new AbortController();
|
|
87
|
+
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const response = await fetch("https://api.example.com/data", {
|
|
91
|
+
signal: controller.signal,
|
|
92
|
+
});
|
|
93
|
+
clearTimeout(timeout);
|
|
94
|
+
|
|
95
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
96
|
+
ctx.data = await response.json();
|
|
97
|
+
} catch (err) {
|
|
98
|
+
if (ctx.attempts >= 3) {
|
|
99
|
+
ctx.error = err.message;
|
|
100
|
+
throw err; // Propager après le dernier essai
|
|
101
|
+
}
|
|
102
|
+
throw err; // Déclenche le retry
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
retry: {
|
|
106
|
+
maxAttempts: 3,
|
|
107
|
+
backoff: "exponential",
|
|
108
|
+
delay: 1000,
|
|
109
|
+
},
|
|
110
|
+
next: [
|
|
111
|
+
{ when: (ctx) => !ctx.error, to: "success" },
|
|
112
|
+
{ when: (ctx) => ctx.error, to: "handle_error" },
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: "success",
|
|
117
|
+
execute: async (ctx) => {
|
|
118
|
+
console.log("Success:", ctx.data);
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "handle_error",
|
|
123
|
+
execute: async (ctx) => {
|
|
124
|
+
console.error("Failure after", ctx.attempts, "attempts:", ctx.error);
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Retry avec état persistant
|
|
132
|
+
|
|
133
|
+
Combinez le retry avec le système de checkpoints pour survivre à un redémarrage :
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { InMemoryCheckpointAdapter } from "@ai.ntellect/core";
|
|
137
|
+
|
|
138
|
+
const adapter = new InMemoryCheckpointAdapter();
|
|
139
|
+
|
|
140
|
+
const workflow = new GraphFlow({
|
|
141
|
+
name: "resilient-task",
|
|
142
|
+
context: { attempts: 0 },
|
|
143
|
+
nodes: [
|
|
144
|
+
{
|
|
145
|
+
name: "unstable_task",
|
|
146
|
+
execute: async (ctx) => {
|
|
147
|
+
ctx.attempts++;
|
|
148
|
+
if (Math.random() < 0.7) throw new Error("Aleatory failure");
|
|
149
|
+
ctx.done = true;
|
|
150
|
+
},
|
|
151
|
+
retry: { maxAttempts: 5, backoff: "exponential", delay: 500 },
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Avec checkpoint, l'état des tentatives est préservé
|
|
157
|
+
await workflow.executeWithCheckpoint("unstable_task", {}, adapter);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Cas d'usage
|
|
161
|
+
|
|
162
|
+
- **Appels API instables** : Réessayer en cas d'erreurs réseau (429, 500, 503)
|
|
163
|
+
- **Opérations de base de données** : Gérer les verrous temporaires ou timeouts
|
|
164
|
+
- **Services tiers** : Tolérance aux pannes transientes
|
|
165
|
+
- **Webhooks** : Garantir la livraison malgré les erreurs temporaires
|
|
166
|
+
- **LLM calls** : Gérer les rate limits des API d'IA
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ICheckpointAdapter } from "../../interfaces";
|
|
2
|
+
import { Checkpoint } from "../../types";
|
|
3
|
+
|
|
4
|
+
export class InMemoryCheckpointAdapter implements ICheckpointAdapter {
|
|
5
|
+
private storage = new Map<string, Checkpoint>();
|
|
6
|
+
|
|
7
|
+
async save(checkpoint: Checkpoint): Promise<void> {
|
|
8
|
+
this.storage.set(checkpoint.id, structuredClone(checkpoint));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async load(id: string): Promise<Checkpoint | null> {
|
|
12
|
+
const cp = this.storage.get(id);
|
|
13
|
+
return cp ? structuredClone(cp) : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async list(graphName: string): Promise<Checkpoint[]> {
|
|
17
|
+
return Array.from(this.storage.values())
|
|
18
|
+
.filter((cp) => cp.graphName === graphName)
|
|
19
|
+
.sort((a, b) => b.metadata.createdAt - a.metadata.createdAt);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async delete(id: string): Promise<void> {
|
|
23
|
+
this.storage.delete(id);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async clear(graphName?: string): Promise<void> {
|
|
27
|
+
if (!graphName) {
|
|
28
|
+
this.storage.clear();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
for (const [id, cp] of this.storage) {
|
|
32
|
+
if (cp.graphName === graphName) this.storage.delete(id);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { GraphFlow } from './index';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { Plan } from './planner';
|
|
4
|
+
import { ToolRegistry } from './registry';
|
|
5
|
+
|
|
6
|
+
export function compilePlan(plan: Plan, registry: ToolRegistry): { graph: GraphFlow<any>; startNode: string } {
|
|
7
|
+
const graph = new GraphFlow<any>({
|
|
8
|
+
name: 'compiled-plan',
|
|
9
|
+
context: {},
|
|
10
|
+
schema: z.object({}).passthrough(),
|
|
11
|
+
nodes: [],
|
|
12
|
+
entryNode: '',
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
plan.steps.forEach((step, index) => {
|
|
16
|
+
const tool = registry.get(step.node);
|
|
17
|
+
if (!tool) {
|
|
18
|
+
throw new Error(`Unknown tool: ${step.node}`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const nodeName = `step_${index}_${step.node}`;
|
|
22
|
+
const nextNode = index < plan.steps.length - 1
|
|
23
|
+
? `step_${index + 1}_${plan.steps[index + 1].node}`
|
|
24
|
+
: undefined;
|
|
25
|
+
|
|
26
|
+
graph.addNode({
|
|
27
|
+
name: nodeName,
|
|
28
|
+
execute: async (ctx: any) => {
|
|
29
|
+
// Merge accumulated context with step params
|
|
30
|
+
const toolCtx = { ...ctx, ...step.params };
|
|
31
|
+
console.log(` [${nodeName}] Executing ${step.node} with:`, toolCtx);
|
|
32
|
+
|
|
33
|
+
// Execute the tool's graph
|
|
34
|
+
const resultCtx = await tool.graph.execute(tool.startNode, toolCtx);
|
|
35
|
+
|
|
36
|
+
// Merge tool result back into ctx (which is the graph's context)
|
|
37
|
+
Object.assign(ctx, resultCtx, { _lastStep: step.node });
|
|
38
|
+
console.log(` [${nodeName}] Updated context:`, ctx);
|
|
39
|
+
},
|
|
40
|
+
next: nextNode,
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const startNode = plan.steps.length > 0 ? `step_0_${plan.steps[0].node}` : '';
|
|
45
|
+
|
|
46
|
+
return { graph, startNode };
|
|
47
|
+
}
|