@ai.ntellect/core 1.0.0 → 1.1.1
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 +363 -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,78 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { CognitiveHandler, COGNITIVE_NODES } from "../../agent/handlers/cognitive-handler";
|
|
3
|
+
import { AgentLogger } from "../../agent/tools/logger";
|
|
4
|
+
import { AgentContext } from "../../types/agent";
|
|
5
|
+
import sinon from "sinon";
|
|
6
|
+
|
|
7
|
+
describe("CognitiveHandler", () => {
|
|
8
|
+
let llmMock: any;
|
|
9
|
+
let loggerMock: any;
|
|
10
|
+
let handler: CognitiveHandler;
|
|
11
|
+
let context: AgentContext;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
llmMock = {
|
|
15
|
+
generate: sinon.stub()
|
|
16
|
+
};
|
|
17
|
+
loggerMock = {
|
|
18
|
+
log: sinon.stub()
|
|
19
|
+
} as unknown as AgentLogger;
|
|
20
|
+
|
|
21
|
+
context = {
|
|
22
|
+
input: { raw: "test input" },
|
|
23
|
+
actions: [],
|
|
24
|
+
response: "",
|
|
25
|
+
executedActions: [],
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("computeGoal", () => {
|
|
30
|
+
it("should return current goal if dynamicGoal is disabled", async () => {
|
|
31
|
+
handler = new CognitiveHandler(llmMock, loggerMock, { dynamicGoal: false, initialGoal: "static goal" });
|
|
32
|
+
const goal = await handler.computeGoal(context);
|
|
33
|
+
expect(goal).to.equal("static goal");
|
|
34
|
+
expect(llmMock.generate.called).to.be.false;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should call LLM and return dynamic goal if enabled", async () => {
|
|
38
|
+
llmMock.generate.resolves({ object: { goal: "dynamic goal from LLM" } });
|
|
39
|
+
handler = new CognitiveHandler(llmMock, loggerMock, { dynamicGoal: true, initialGoal: "static goal" });
|
|
40
|
+
|
|
41
|
+
const goal = await handler.computeGoal(context);
|
|
42
|
+
|
|
43
|
+
expect(goal).to.equal("dynamic goal from LLM");
|
|
44
|
+
expect(llmMock.generate.calledOnce).to.be.true;
|
|
45
|
+
expect(handler.getCurrentGoal()).to.equal("dynamic goal from LLM");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("computeNext", () => {
|
|
50
|
+
it("should return default next state if dynamicNext is disabled", async () => {
|
|
51
|
+
handler = new CognitiveHandler(llmMock, loggerMock, { dynamicNext: false });
|
|
52
|
+
const next = await handler.computeNext(context, "defineGoal", 1);
|
|
53
|
+
expect(next).to.equal("think");
|
|
54
|
+
expect(llmMock.generate.called).to.be.false;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should call LLM and return next state if enabled", async () => {
|
|
58
|
+
llmMock.generate.resolves({ object: { next: "execute", reason: "testing" } });
|
|
59
|
+
handler = new CognitiveHandler(llmMock, loggerMock, { dynamicNext: true });
|
|
60
|
+
|
|
61
|
+
const next = await handler.computeNext(context, "think", 1);
|
|
62
|
+
|
|
63
|
+
expect(next).to.equal("execute");
|
|
64
|
+
expect(llmMock.generate.calledOnce).to.be.true;
|
|
65
|
+
expect(handler.getCurrentState()).to.equal("execute");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should fallback to 'think' if LLM returns unknown state", async () => {
|
|
69
|
+
// Mocking the Zod transformed output which would return "think"
|
|
70
|
+
llmMock.generate.resolves({ object: { next: "think", reason: "testing fallback" } });
|
|
71
|
+
handler = new CognitiveHandler(llmMock, loggerMock, { dynamicNext: true });
|
|
72
|
+
|
|
73
|
+
const next = await handler.computeNext(context, "think", 1);
|
|
74
|
+
|
|
75
|
+
expect(next).to.equal("think");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { Neo4jEntityStore } from "../../persistence/neo4j/entity-store";
|
|
3
|
+
|
|
4
|
+
class MockSession {
|
|
5
|
+
queries: { query: string; params: any }[] = [];
|
|
6
|
+
records: any[] = [];
|
|
7
|
+
async run(query: string, params?: Record<string, any>): Promise<{ records: any[] }> {
|
|
8
|
+
this.queries.push({ query, params });
|
|
9
|
+
return { records: this.records };
|
|
10
|
+
}
|
|
11
|
+
async close(): Promise<void> {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class MockDriver {
|
|
15
|
+
lastSession?: MockSession;
|
|
16
|
+
session() {
|
|
17
|
+
this.lastSession = new MockSession();
|
|
18
|
+
return this.lastSession;
|
|
19
|
+
}
|
|
20
|
+
async close() {}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("Neo4jEntityStore", () => {
|
|
24
|
+
let driver: MockDriver;
|
|
25
|
+
let store: Neo4jEntityStore;
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
driver = new MockDriver();
|
|
29
|
+
store = new Neo4jEntityStore(driver as any);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should upsert many entities", async () => {
|
|
33
|
+
await store.upsertMany([
|
|
34
|
+
{ id: "e1", category: "file", filename: "test.ts", stem: "test", extension: ".ts", path: "src/test.ts", tokens: ["test"] }
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
expect(driver.lastSession?.queries.length).to.equal(2);
|
|
38
|
+
expect(driver.lastSession?.queries[0].query).to.include("MERGE (e:Entity {id: $id})");
|
|
39
|
+
expect(driver.lastSession?.queries[0].params.id).to.equal("e1");
|
|
40
|
+
expect(driver.lastSession?.queries[0].params.filename).to.equal("test.ts");
|
|
41
|
+
expect(driver.lastSession?.queries[0].params.scope).to.equal("src");
|
|
42
|
+
|
|
43
|
+
expect(driver.lastSession?.queries[1].query).to.include("MERGE (d:Dir {path: $dir})");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should load all entities", async () => {
|
|
47
|
+
const mockSession = new MockSession();
|
|
48
|
+
mockSession.records = [{
|
|
49
|
+
get: (key: string) => {
|
|
50
|
+
if (key === "e") return { properties: { id: "e1", category: "file", filename: "test.ts", stem: "test", extension: ".ts", path: "src/test.ts" } };
|
|
51
|
+
if (key === "tokens") return ["test"];
|
|
52
|
+
}
|
|
53
|
+
}];
|
|
54
|
+
driver.session = () => mockSession;
|
|
55
|
+
|
|
56
|
+
const entities = await store.loadAll();
|
|
57
|
+
|
|
58
|
+
expect(entities.length).to.equal(1);
|
|
59
|
+
expect(entities[0].id).to.equal("e1");
|
|
60
|
+
expect(entities[0].tokens).to.deep.equal(["test"]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should record resolution", async () => {
|
|
64
|
+
await store.recordResolution("e1", "find test", 0.9);
|
|
65
|
+
|
|
66
|
+
expect(driver.lastSession?.queries.length).to.equal(1);
|
|
67
|
+
expect(driver.lastSession?.queries[0].query).to.include("CREATE (r:Resolution");
|
|
68
|
+
expect(driver.lastSession?.queries[0].params.entityId).to.equal("e1");
|
|
69
|
+
expect(driver.lastSession?.queries[0].params.query).to.equal("find test");
|
|
70
|
+
expect(driver.lastSession?.queries[0].params.confidence).to.equal(0.9);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should clear entities", async () => {
|
|
74
|
+
await store.clear("src");
|
|
75
|
+
|
|
76
|
+
expect(driver.lastSession?.queries.length).to.equal(1);
|
|
77
|
+
expect(driver.lastSession?.queries[0].query).to.include("DETACH DELETE e");
|
|
78
|
+
expect(driver.lastSession?.queries[0].params.scope).to.equal("src");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { GraphFlow } from "../../execution/index";
|
|
4
|
+
import { BaseAgent } from "../../agent/base";
|
|
5
|
+
import { GenericExecutor } from "../../agent/generic-executor";
|
|
6
|
+
import { AgentContext } from "../../types/agent";
|
|
7
|
+
|
|
8
|
+
describe("GenericExecutor", () => {
|
|
9
|
+
const llmConfig = {
|
|
10
|
+
provider: "custom" as const,
|
|
11
|
+
model: "mock",
|
|
12
|
+
apiKey: "unused",
|
|
13
|
+
customCall: async () => ({
|
|
14
|
+
object: {
|
|
15
|
+
actions: [] as { name: string; parameters: { name: string; value: unknown }[] }[],
|
|
16
|
+
response: "Done.",
|
|
17
|
+
},
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function createExecutor(
|
|
22
|
+
tools: GraphFlow<any>[] = [],
|
|
23
|
+
customCall?: typeof llmConfig.customCall,
|
|
24
|
+
options?: { dynamicGoal?: boolean; dynamicGoalPrompt?: string }
|
|
25
|
+
) {
|
|
26
|
+
const agent = new BaseAgent({
|
|
27
|
+
role: "Tester",
|
|
28
|
+
goal: "Run tests",
|
|
29
|
+
backstory: "Concise",
|
|
30
|
+
tools,
|
|
31
|
+
llmConfig: customCall
|
|
32
|
+
? { ...llmConfig, customCall }
|
|
33
|
+
: llmConfig,
|
|
34
|
+
});
|
|
35
|
+
return new GenericExecutor(agent, tools, {
|
|
36
|
+
llmConfig: customCall ? { ...llmConfig, customCall } : llmConfig,
|
|
37
|
+
verbose: false,
|
|
38
|
+
}, undefined, options);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
it("makeDecision returns response and actions from customCall", async () => {
|
|
42
|
+
const executor = createExecutor([], async () => ({
|
|
43
|
+
object: {
|
|
44
|
+
actions: [
|
|
45
|
+
{
|
|
46
|
+
name: "noop",
|
|
47
|
+
parameters: [{ name: "x", value: 1 }],
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
response: "Taking action.",
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
const context: AgentContext = {
|
|
55
|
+
input: { raw: "hello" },
|
|
56
|
+
actions: [],
|
|
57
|
+
response: "",
|
|
58
|
+
executedActions: [],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const out = await executor.makeDecision(context);
|
|
62
|
+
expect(out.response).to.equal("Taking action.");
|
|
63
|
+
expect(out.actions).to.have.lengthOf(1);
|
|
64
|
+
expect(out.actions[0].name).to.equal("noop");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("executeActions runs matching GraphFlow tool", async () => {
|
|
68
|
+
const ToolSchema = z.object({
|
|
69
|
+
counter: z.number(),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const toolGraph = new GraphFlow({
|
|
73
|
+
name: "counterTool",
|
|
74
|
+
schema: ToolSchema,
|
|
75
|
+
context: { counter: 0 },
|
|
76
|
+
nodes: [
|
|
77
|
+
{
|
|
78
|
+
name: "bump",
|
|
79
|
+
execute: async (ctx) => {
|
|
80
|
+
ctx.counter = (ctx.counter ?? 0) + 1;
|
|
81
|
+
},
|
|
82
|
+
next: [],
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const executor = createExecutor([toolGraph], async () => ({
|
|
88
|
+
object: {
|
|
89
|
+
actions: [
|
|
90
|
+
{
|
|
91
|
+
name: "counterTool",
|
|
92
|
+
parameters: [{ name: "counter", value: 5 }],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
response: "Incrementing.",
|
|
96
|
+
},
|
|
97
|
+
}));
|
|
98
|
+
|
|
99
|
+
const context: AgentContext = {
|
|
100
|
+
input: { raw: "go" },
|
|
101
|
+
actions: [],
|
|
102
|
+
response: "",
|
|
103
|
+
executedActions: [],
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
await executor.executeActions(
|
|
107
|
+
[
|
|
108
|
+
{
|
|
109
|
+
name: "counterTool",
|
|
110
|
+
parameters: [{ name: "counter", value: 5 }],
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
context
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
expect(context.executedActions).to.have.lengthOf(1);
|
|
117
|
+
expect(context.executedActions[0].name).to.equal("counterTool");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("Dynamic Goal", () => {
|
|
121
|
+
it("should use static goal when dynamicGoal is disabled", async () => {
|
|
122
|
+
const executor = createExecutor([], undefined, { dynamicGoal: false });
|
|
123
|
+
|
|
124
|
+
const context: AgentContext = {
|
|
125
|
+
input: { raw: "test input" },
|
|
126
|
+
actions: [],
|
|
127
|
+
response: "",
|
|
128
|
+
executedActions: [],
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const goal = executor.getCurrentGoal();
|
|
132
|
+
expect(goal).to.equal("Run tests");
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("should update dynamic goal via updateDynamicGoal method", async () => {
|
|
136
|
+
let goalCallCount = 0;
|
|
137
|
+
const goalLlmConfig = {
|
|
138
|
+
provider: "custom" as const,
|
|
139
|
+
model: "mock",
|
|
140
|
+
apiKey: "unused",
|
|
141
|
+
customCall: async () => {
|
|
142
|
+
goalCallCount++;
|
|
143
|
+
return {
|
|
144
|
+
object: {
|
|
145
|
+
goal: goalCallCount === 1 ? "Step 1: Initialize" : "Step 2: Execute",
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const agent = new BaseAgent({
|
|
152
|
+
role: "Tester",
|
|
153
|
+
goal: "Run tests",
|
|
154
|
+
backstory: "Concise",
|
|
155
|
+
tools: [],
|
|
156
|
+
llmConfig: goalLlmConfig,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const executor = new GenericExecutor(agent, [], {
|
|
160
|
+
llmConfig: goalLlmConfig,
|
|
161
|
+
verbose: false,
|
|
162
|
+
}, undefined, { dynamicGoal: true });
|
|
163
|
+
|
|
164
|
+
const context1: AgentContext = {
|
|
165
|
+
input: { raw: "test input" },
|
|
166
|
+
actions: [],
|
|
167
|
+
response: "",
|
|
168
|
+
executedActions: [],
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
await executor.updateDynamicGoal(context1);
|
|
172
|
+
expect(executor.getCurrentGoal()).to.equal("Step 1: Initialize");
|
|
173
|
+
|
|
174
|
+
const context2: AgentContext = {
|
|
175
|
+
input: { raw: "test input" },
|
|
176
|
+
actions: [],
|
|
177
|
+
response: "",
|
|
178
|
+
executedActions: [{ name: "tool1", result: { success: true }, isExecuted: true, timestamp: new Date().toISOString() }],
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
await executor.updateDynamicGoal(context2);
|
|
182
|
+
expect(executor.getCurrentGoal()).to.equal("Step 2: Execute");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("should call LLM when dynamicGoal is enabled", async () => {
|
|
186
|
+
let callCount = 0;
|
|
187
|
+
|
|
188
|
+
const sharedLlmConfig = {
|
|
189
|
+
provider: "custom" as const,
|
|
190
|
+
model: "mock",
|
|
191
|
+
apiKey: "unused",
|
|
192
|
+
customCall: async () => {
|
|
193
|
+
callCount++;
|
|
194
|
+
return {
|
|
195
|
+
object: {
|
|
196
|
+
goal: `Dynamic goal`,
|
|
197
|
+
actions: [],
|
|
198
|
+
response: `Agent response`,
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const agent = new BaseAgent({
|
|
205
|
+
role: "Tester",
|
|
206
|
+
goal: "Run tests",
|
|
207
|
+
backstory: "Concise",
|
|
208
|
+
tools: [],
|
|
209
|
+
llmConfig: sharedLlmConfig,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const executor = new GenericExecutor(agent, [], {
|
|
213
|
+
llmConfig: sharedLlmConfig,
|
|
214
|
+
verbose: false,
|
|
215
|
+
}, undefined, { dynamicGoal: true });
|
|
216
|
+
|
|
217
|
+
const context: AgentContext = {
|
|
218
|
+
input: { raw: "test input" },
|
|
219
|
+
actions: [],
|
|
220
|
+
response: "",
|
|
221
|
+
executedActions: [],
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
await executor.updateDynamicGoal(context);
|
|
225
|
+
await executor.makeDecision(context);
|
|
226
|
+
|
|
227
|
+
expect(callCount).to.equal(2);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { GraphFlow } from "../../execution/index";
|
|
4
|
+
import { Agent } from "../../agent/agent";
|
|
5
|
+
import { AgentRegistry } from "../../agent/registry";
|
|
6
|
+
import { createHandoffTool } from "../../agent/handoff";
|
|
7
|
+
|
|
8
|
+
describe("Handoff Integration", () => {
|
|
9
|
+
let registry: AgentRegistry;
|
|
10
|
+
let specialistAgent: Agent;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
registry = new AgentRegistry();
|
|
14
|
+
|
|
15
|
+
specialistAgent = new Agent({
|
|
16
|
+
role: "Specialist",
|
|
17
|
+
goal: "Handle specific tasks",
|
|
18
|
+
backstory: "I am a specialist agent",
|
|
19
|
+
tools: [],
|
|
20
|
+
verbose: false,
|
|
21
|
+
llmConfig: {
|
|
22
|
+
provider: "custom",
|
|
23
|
+
model: "mock",
|
|
24
|
+
apiKey: "unused",
|
|
25
|
+
customCall: async () => ({
|
|
26
|
+
object: { actions: [], response: "Specialist handled it." },
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
registry.register(
|
|
32
|
+
"code-expert",
|
|
33
|
+
specialistAgent,
|
|
34
|
+
"coder",
|
|
35
|
+
"Expert en TypeScript"
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("handoff tool sets _handoff on context via GraphFlow", async () => {
|
|
40
|
+
const tool = createHandoffTool(registry);
|
|
41
|
+
|
|
42
|
+
const result = await tool.execute("handoff", {
|
|
43
|
+
targetAgent: "code-expert",
|
|
44
|
+
task: "Refactor this function",
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
expect((result as any)._handoff).to.not.be.undefined;
|
|
48
|
+
expect((result as any)._handoff.goto).to.equal("code-expert");
|
|
49
|
+
expect((result as any)._handoff.graph).to.equal("PARENT");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("handoff tool warns for unknown agent (does not throw)", async () => {
|
|
53
|
+
const tool = createHandoffTool(registry);
|
|
54
|
+
|
|
55
|
+
const result = await tool.execute("handoff", {
|
|
56
|
+
targetAgent: "nonexistent",
|
|
57
|
+
task: "Do something",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect((result as any)._handoff).to.be.undefined;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("handoff tool works without registry (no validation)", async () => {
|
|
64
|
+
const tool = createHandoffTool();
|
|
65
|
+
|
|
66
|
+
const result = await tool.execute("handoff", {
|
|
67
|
+
targetAgent: "any-agent",
|
|
68
|
+
task: "Do something",
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect((result as any)._handoff.goto).to.equal("any-agent");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("GraphFlow stops sequential execution after handoff", async () => {
|
|
75
|
+
const flow = new GraphFlow({
|
|
76
|
+
name: "handoff-test",
|
|
77
|
+
schema: z.object({ steps: z.array(z.string()).optional(), _handoff: z.any().optional() }),
|
|
78
|
+
context: { steps: [], _handoff: undefined },
|
|
79
|
+
nodes: [
|
|
80
|
+
{
|
|
81
|
+
name: "start",
|
|
82
|
+
execute: async (ctx: any) => {
|
|
83
|
+
ctx.steps = ["start"];
|
|
84
|
+
},
|
|
85
|
+
next: ["handoff-node", "after-handoff"],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "handoff-node",
|
|
89
|
+
execute: async (ctx: any) => {
|
|
90
|
+
ctx.steps.push("handoff-node");
|
|
91
|
+
ctx._handoff = {
|
|
92
|
+
goto: "specialist",
|
|
93
|
+
graph: "PARENT",
|
|
94
|
+
update: { handoffTask: "test" },
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
next: ["should-not-run"],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "after-handoff",
|
|
101
|
+
execute: async (ctx: any) => {
|
|
102
|
+
ctx.steps.push("after-handoff");
|
|
103
|
+
},
|
|
104
|
+
next: [],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "should-not-run",
|
|
108
|
+
execute: async (_ctx: any) => {
|
|
109
|
+
throw new Error("This node should not be executed after handoff");
|
|
110
|
+
},
|
|
111
|
+
next: [],
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
await flow.execute("start");
|
|
117
|
+
const ctx = flow.getContext() as any;
|
|
118
|
+
|
|
119
|
+
expect(ctx.steps).to.include("start");
|
|
120
|
+
expect(ctx.steps).to.include("handoff-node");
|
|
121
|
+
expect(ctx.steps).to.not.include("should-not-run");
|
|
122
|
+
expect(ctx._handoff.goto).to.equal("specialist");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("handoff in agent workflow stops execution", async () => {
|
|
126
|
+
const handoffTool = createHandoffTool(registry);
|
|
127
|
+
|
|
128
|
+
let callCount = 0;
|
|
129
|
+
const agent = new Agent({
|
|
130
|
+
role: "Router",
|
|
131
|
+
goal: "Route tasks to specialists",
|
|
132
|
+
backstory: "I route tasks",
|
|
133
|
+
tools: [handoffTool],
|
|
134
|
+
verbose: false,
|
|
135
|
+
maxIterations: 3,
|
|
136
|
+
llmConfig: {
|
|
137
|
+
provider: "custom",
|
|
138
|
+
model: "mock",
|
|
139
|
+
apiKey: "unused",
|
|
140
|
+
customCall: async () => {
|
|
141
|
+
callCount++;
|
|
142
|
+
return {
|
|
143
|
+
object: {
|
|
144
|
+
actions: [{
|
|
145
|
+
name: "handoff",
|
|
146
|
+
parameters: { targetAgent: "code-expert", task: "Fix bug" },
|
|
147
|
+
}],
|
|
148
|
+
response: "Handing off to code-expert.",
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const ctx = await agent.process("Fix this bug please");
|
|
156
|
+
expect(ctx.response).to.equal("Handing off to code-expert.");
|
|
157
|
+
|
|
158
|
+
// Le fait que handoff-exists n'ait pas bloqué est déjà un bon signe.
|
|
159
|
+
// Le workflow s'est arrêté après avoir exécuté le handoff tool.
|
|
160
|
+
expect(ctx.executedActions).to.have.length(1);
|
|
161
|
+
expect(ctx.executedActions[0].name).to.equal("handoff");
|
|
162
|
+
});
|
|
163
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { LLMFactory } from "../../agent/llm-factory";
|
|
4
|
+
|
|
5
|
+
describe("LLMFactory", () => {
|
|
6
|
+
it("throws for unsupported provider", () => {
|
|
7
|
+
expect(() =>
|
|
8
|
+
LLMFactory.createLLM({
|
|
9
|
+
provider: "anthropic",
|
|
10
|
+
model: "claude-2",
|
|
11
|
+
apiKey: "x",
|
|
12
|
+
})
|
|
13
|
+
).to.throw("Unsupported LLM provider");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("throws when custom provider has no customCall", () => {
|
|
17
|
+
expect(() =>
|
|
18
|
+
LLMFactory.createLLM({
|
|
19
|
+
provider: "custom",
|
|
20
|
+
model: "mock",
|
|
21
|
+
apiKey: "unused",
|
|
22
|
+
})
|
|
23
|
+
).to.throw("Custom LLM provider requires a customCall function");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("custom provider uses customCall and returns structured object", async () => {
|
|
27
|
+
const schema = z.object({ answer: z.string() });
|
|
28
|
+
const llm = LLMFactory.createLLM({
|
|
29
|
+
provider: "custom",
|
|
30
|
+
model: "mock",
|
|
31
|
+
apiKey: "unused",
|
|
32
|
+
customCall: async (_prompt, _schema) => ({
|
|
33
|
+
object: { answer: "yes" },
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const result = await llm.generate("ignored", schema);
|
|
38
|
+
expect(result.object.answer).to.equal("yes");
|
|
39
|
+
});
|
|
40
|
+
});
|