@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,620 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.GenericExecutor = void 0;
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const zod_1 = require("zod");
|
|
18
|
+
const executor_1 = require("./base/executor");
|
|
19
|
+
const llm_factory_1 = require("./llm-factory");
|
|
20
|
+
const prompt_builder_1 = require("./prompt-builder");
|
|
21
|
+
const logger_1 = require("./tools/logger");
|
|
22
|
+
const handlers_1 = require("./handlers");
|
|
23
|
+
class GenericExecutor extends executor_1.AgentExecutor {
|
|
24
|
+
constructor(agent, graphs, config, logger, options) {
|
|
25
|
+
var _a, _b, _c;
|
|
26
|
+
super(agent, graphs);
|
|
27
|
+
this.entityIndex = null;
|
|
28
|
+
this.verbose = (_a = config.verbose) !== null && _a !== void 0 ? _a : true;
|
|
29
|
+
this.llm = llm_factory_1.LLMFactory.createLLM(config.llmConfig);
|
|
30
|
+
this.logger = logger || new logger_1.AgentLogger(this.verbose);
|
|
31
|
+
this.cognitiveHandler = new handlers_1.CognitiveHandler(this.llm, this.logger, {
|
|
32
|
+
dynamicGoal: options === null || options === void 0 ? void 0 : options.dynamicGoal,
|
|
33
|
+
goalPrompt: options === null || options === void 0 ? void 0 : options.dynamicGoalPrompt,
|
|
34
|
+
initialGoal: agent.getGoal(),
|
|
35
|
+
dynamicNext: options === null || options === void 0 ? void 0 : options.dynamicNext,
|
|
36
|
+
nextPrompt: options === null || options === void 0 ? void 0 : options.dynamicNextPrompt,
|
|
37
|
+
});
|
|
38
|
+
this.enableSchedule = (_b = options === null || options === void 0 ? void 0 : options.enableSchedule) !== null && _b !== void 0 ? _b : false;
|
|
39
|
+
this.enableReflection = (_c = options === null || options === void 0 ? void 0 : options.enableReflection) !== null && _c !== void 0 ? _c : false;
|
|
40
|
+
this.agenda = options === null || options === void 0 ? void 0 : options.agenda;
|
|
41
|
+
}
|
|
42
|
+
setDynamicGoal(enabled, customPrompt) {
|
|
43
|
+
this.cognitiveHandler.setEnabled({ dynamicGoal: enabled, dynamicNext: undefined });
|
|
44
|
+
if (customPrompt) {
|
|
45
|
+
this.cognitiveHandler.goalPromptTemplate = customPrompt;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
getCurrentGoal() {
|
|
49
|
+
return this.cognitiveHandler.getCurrentGoal();
|
|
50
|
+
}
|
|
51
|
+
getCurrentState() {
|
|
52
|
+
return this.cognitiveHandler.getCurrentState();
|
|
53
|
+
}
|
|
54
|
+
setCurrentState(state) {
|
|
55
|
+
this.cognitiveHandler.setCurrentState(state);
|
|
56
|
+
}
|
|
57
|
+
getAvailableNodes() {
|
|
58
|
+
return this.cognitiveHandler.getAvailableNodes();
|
|
59
|
+
}
|
|
60
|
+
setLogger(logger) {
|
|
61
|
+
this.logger = logger;
|
|
62
|
+
}
|
|
63
|
+
setEntityIndex(index) {
|
|
64
|
+
this.entityIndex = index;
|
|
65
|
+
}
|
|
66
|
+
computeNextState(context, currentState, iteration) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return this.cognitiveHandler.computeNext(context, currentState, iteration);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
scheduleTask(cronExpression, request) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
if (!this.enableSchedule || !this.agenda) {
|
|
74
|
+
this.log("warning", chalk_1.default.yellow("Schedule not enabled or Agenda not configured"));
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const id = yield this.agenda.scheduleRequest({
|
|
79
|
+
originalRequest: request,
|
|
80
|
+
cronExpression,
|
|
81
|
+
});
|
|
82
|
+
this.log("success", chalk_1.default.green(`Scheduled task: ${id} (${cronExpression})`));
|
|
83
|
+
return id;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
this.log("error", chalk_1.default.red(`Failed to schedule task: ${error}`));
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
log(type, message) {
|
|
92
|
+
if (!this.verbose)
|
|
93
|
+
return;
|
|
94
|
+
const levelMap = {
|
|
95
|
+
info: "info",
|
|
96
|
+
success: "info",
|
|
97
|
+
warning: "warn",
|
|
98
|
+
error: "error",
|
|
99
|
+
thinking: "info",
|
|
100
|
+
};
|
|
101
|
+
this.logger.log(levelMap[type], "executor", message);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Generates a string representation of the available action schemas
|
|
105
|
+
* @private
|
|
106
|
+
* @returns {string} Formatted string containing all available actions and their parameters
|
|
107
|
+
*/
|
|
108
|
+
generateActionSchema() {
|
|
109
|
+
const HIDDEN_FIELDS = new Set([
|
|
110
|
+
"path", "success", "entries",
|
|
111
|
+
"stdout", "stderr", "exitCode", "isolationMethod",
|
|
112
|
+
"result", "error",
|
|
113
|
+
]);
|
|
114
|
+
return Array.from(this.availableGraphs.values())
|
|
115
|
+
.map((graph) => {
|
|
116
|
+
const schema = graph.getSchema();
|
|
117
|
+
const schemaDescription = Object.entries(schema.shape)
|
|
118
|
+
.filter(([key, value]) => {
|
|
119
|
+
const zodValue = value;
|
|
120
|
+
return !key.endsWith("_result") && !key.includes("Result") && !HIDDEN_FIELDS.has(key);
|
|
121
|
+
})
|
|
122
|
+
.map(([key, value]) => {
|
|
123
|
+
var _a, _b, _c, _d;
|
|
124
|
+
const zodValue = value;
|
|
125
|
+
let desc = zodValue.description || "";
|
|
126
|
+
if (zodValue instanceof zod_1.z.ZodEnum) {
|
|
127
|
+
const options = (_a = zodValue.options) !== null && _a !== void 0 ? _a : [];
|
|
128
|
+
desc = desc ? `${desc} (Options: ${options.join(", ")})` : `Options: ${options.join(", ")}`;
|
|
129
|
+
}
|
|
130
|
+
const typeName = (_d = (_c = (_b = zodValue._def) === null || _b === void 0 ? void 0 : _b.typeName) !== null && _c !== void 0 ? _c : zodValue.constructor.name) !== null && _d !== void 0 ? _d : "unknown";
|
|
131
|
+
return ` - ${key}: ${desc || typeName}`;
|
|
132
|
+
})
|
|
133
|
+
.join("\n");
|
|
134
|
+
return `${graph.name}:
|
|
135
|
+
Parameters (INPUT only):
|
|
136
|
+
${schemaDescription}
|
|
137
|
+
Output: stored as \$${graph.name}_result`;
|
|
138
|
+
})
|
|
139
|
+
.join("\n\n");
|
|
140
|
+
}
|
|
141
|
+
buildSystemPrompt(context) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
var _a, _b;
|
|
144
|
+
const executedTools = context.executedActions.map(a => a.name);
|
|
145
|
+
const alreadyExecuted = executedTools.length > 0
|
|
146
|
+
? `ALREADY DONE (DO NOT RE-EXECUTE THESE): ${executedTools.join(", ")}`
|
|
147
|
+
: "No tools executed yet.";
|
|
148
|
+
const availableToolNames = Array.from(this.availableGraphs.keys()).join(", ");
|
|
149
|
+
const cwd = context.cwd || process.cwd();
|
|
150
|
+
let variables = "";
|
|
151
|
+
if (executedTools.length > 0) {
|
|
152
|
+
variables = "IMPORTANT - Use these exact variable names for READ-ONLY reference:\n";
|
|
153
|
+
for (const action of context.executedActions) {
|
|
154
|
+
const resultVal = typeof action.result === 'object' && action.result !== null
|
|
155
|
+
? JSON.stringify(action.result)
|
|
156
|
+
: String(action.result);
|
|
157
|
+
variables += ` \$${action.name}_result = ${resultVal}\n`;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
variables = "No variables yet. Execute a tool first.";
|
|
162
|
+
}
|
|
163
|
+
let conversationHistory = "";
|
|
164
|
+
const msgs = context.messages || [];
|
|
165
|
+
if (msgs.length > 0) {
|
|
166
|
+
conversationHistory = "CONVERSATION HISTORY (most recent first):\n";
|
|
167
|
+
const recent = msgs.slice(-6).reverse();
|
|
168
|
+
for (const msg of recent) {
|
|
169
|
+
conversationHistory += ` [${msg.role === "user" ? "USER" : "YOU"}]: ${msg.content}\n`;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
conversationHistory = "No previous conversation.";
|
|
174
|
+
}
|
|
175
|
+
let scratchpadSection = "No prior reasoning recorded.";
|
|
176
|
+
const pad = context.scratchpad || [];
|
|
177
|
+
if (pad.length > 0) {
|
|
178
|
+
scratchpadSection = "YOUR REASONING JOURNAL (most recent first):\n";
|
|
179
|
+
const recent = pad.slice(-4).reverse();
|
|
180
|
+
for (const entry of recent) {
|
|
181
|
+
scratchpadSection += ` [Turn ${entry.turn}] Thought: ${entry.thought}\n → Action: ${entry.action}\n → Observation: ${entry.observation}\n`;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
let memoriesSection = "No relevant past memories.";
|
|
185
|
+
const mems = context.memories || [];
|
|
186
|
+
if (mems.length > 0) {
|
|
187
|
+
memoriesSection = "RECOLLECTED MEMORIES FROM PAST INTERACTIONS:\n";
|
|
188
|
+
for (const m of mems.slice(-5)) {
|
|
189
|
+
memoriesSection += ` - ${(_a = m.content) === null || _a === void 0 ? void 0 : _a.substring(0, 300)}\n`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
let entitySection = "";
|
|
193
|
+
const es = context.entityState;
|
|
194
|
+
const cs = context.conversationState;
|
|
195
|
+
const handles = es === null || es === void 0 ? void 0 : es.handles;
|
|
196
|
+
if (handles && Object.keys(handles).length > 0) {
|
|
197
|
+
entitySection = "AVAILABLE ENTITY HANDLES (use entityId in tool calls):\n";
|
|
198
|
+
for (const [eid, h] of Object.entries(handles)) {
|
|
199
|
+
entitySection += ` [${eid}] ${h.label} (${h.category})\n`;
|
|
200
|
+
}
|
|
201
|
+
entitySection += "\nIMPORTANT: Use ONLY the entityId from the list above. Do NOT write paths or filenames directly.\n";
|
|
202
|
+
entitySection += "Example: file_reader({ entityId: \"ent_0\" })\n";
|
|
203
|
+
const stillAmbiguous = ((_b = es.pendingResolutions) === null || _b === void 0 ? void 0 : _b.length) > 0 &&
|
|
204
|
+
es.pendingResolutions.some((r) => { var _a; return r.resolved === null && ((_a = r.candidates) === null || _a === void 0 ? void 0 : _a.length) > 0; });
|
|
205
|
+
if (stillAmbiguous) {
|
|
206
|
+
entitySection += "\nSome references are still ambiguous. Choose the entityId that best matches the user's intent.\n";
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
let pendingSection = "";
|
|
210
|
+
if ((cs === null || cs === void 0 ? void 0 : cs.pendingIntent) && cs.pendingIntent.failed) {
|
|
211
|
+
pendingSection = `PENDING INTENT (carried over from previous turn):\n`;
|
|
212
|
+
pendingSection += ` Original request: "${cs.pendingIntent.originalInput}"\n`;
|
|
213
|
+
if (cs.pendingIntent.unresolvedEntity) {
|
|
214
|
+
pendingSection += ` Unresolved entity: "${cs.pendingIntent.unresolvedEntity}"\n`;
|
|
215
|
+
}
|
|
216
|
+
pendingSection += ` This intent was NOT satisfied. Address it if the user continues the topic.\n`;
|
|
217
|
+
}
|
|
218
|
+
return new prompt_builder_1.PromptBuilder()
|
|
219
|
+
.addSection("ROLE", this.agent.getRole())
|
|
220
|
+
.addSection("GOAL", this.getCurrentGoal())
|
|
221
|
+
.addSection("BACKSTORY", this.agent.getBackstory())
|
|
222
|
+
.addSection("ENVIRONMENT", `Current directory: ${cwd}`)
|
|
223
|
+
.addSection("CONVERSATION", conversationHistory)
|
|
224
|
+
.addSection("MEMORIES", memoriesSection)
|
|
225
|
+
.addSection("SCRATCHPAD", scratchpadSection)
|
|
226
|
+
.addSection("TOOLS", availableToolNames)
|
|
227
|
+
.addSection("SCHEMAS", this.generateActionSchema())
|
|
228
|
+
.addSection("VARIABLES", variables)
|
|
229
|
+
.addSection("STATUS", alreadyExecuted)
|
|
230
|
+
.addSection("ENTITY_REFERENCES", entitySection || "No entity references detected.")
|
|
231
|
+
.addSection("PENDING_INTENT", pendingSection || "No pending intent from previous turns.")
|
|
232
|
+
.addSection("RULES", `JSON format EXACT: {"thought":"your reasoning","actions":[{"name":"TOOL_NAME","parameters":{"param1":"value1"}}],"response":"votre réponse"}
|
|
233
|
+
|
|
234
|
+
RÈGLES STRICTES - Sortie JSON uniquement, pas de texte avant/après:
|
|
235
|
+
- **"actions"**: tableau d'actions à exécuter. []
|
|
236
|
+
si aucune action **non déjà exécutée** n'est nécessaire.
|
|
237
|
+
- **"response"**: réponse directe et naturelle à l'utilisateur (1-2 phrases, dans la langue de l'utilisateur).
|
|
238
|
+
- **NE JAMAIS remettre une action déjà listée dans ALREADY DONE**. Les outils exécutés ont déjà produit un résultat.
|
|
239
|
+
- **RÈGLE CRITIQUE**: Ta réponse dans le champ "response" est lue AVANT l'exécution des outils.
|
|
240
|
+
Ne JAMAIS annoncer un résultat ("Voici...", "Le fichier contient...").
|
|
241
|
+
Dis seulement ton INTENTION ("Je vais lister...", "Je vérifie...").
|
|
242
|
+
Le vrai résultat sera généré APRÈS exécution dans un second appel.
|
|
243
|
+
- **QUAND DES OUTILS ONT DÉJÀ ÉTÉ EXÉCUTÉS** (ALREADY DONE non vide): ta réponse DOIT inclure les RÉSULTATS basés sur les VARIABLES.
|
|
244
|
+
Ne dis PAS ce que tu vas faire — dis ce que tu as trouvé.
|
|
245
|
+
- **QUAND L'UTILISATEUR CORRIGE** ("non", "pas ça"): annule l'intention précédente et réanalyse.
|
|
246
|
+
- **ENTITY IDs**: Utilise UNIQUEMENT les entityId listés dans ENTITY_REFERENCES. Ne JAMAIS écrire de path ou filename directement.
|
|
247
|
+
Exemple correct: file_reader({ entityId: "ent_0" })
|
|
248
|
+
Exemple INCORRECT: file_reader({ path: "agent" }) ou file_reader({ target: "agent" })
|
|
249
|
+
- **QUAND ENTITY_REFERENCES EST DISPONIBLE**: ignore toute connaissance antérieure des chemins. Utilise UNIQUEMENT les entityId fournis.
|
|
250
|
+
- **SANS ENTITY_REFERENCES**: utilise path avec parcimonie. Préfère lister d'abord pour découvrir les entités.
|
|
251
|
+
- **ENCODING**: utilise TOUJOURS "utf-8" (avec le tiret). Jamais "utf8", "utf-8".
|
|
252
|
+
|
|
253
|
+
EXEMPLE appel initial (aucun outil exécuté):
|
|
254
|
+
Input: "hello"
|
|
255
|
+
Output: {"actions":[],"response":"Bonjour ! Comment puis-je vous aider aujourd'hui ?"}
|
|
256
|
+
|
|
257
|
+
Input: "liste les fichiers"
|
|
258
|
+
Output: {"actions":[{"name":"directory_lister","parameters":{"path":"."}}],"response":"Je liste le dossier..."}
|
|
259
|
+
|
|
260
|
+
EXEMPLE après exécution d'un outil (ALREADY DONE contient directory_lister):
|
|
261
|
+
Input: "liste les fichiers"
|
|
262
|
+
Output: {"actions":[],"response":"Voici les fichiers : fichier1.txt, dossier/ (36 entrées)"}
|
|
263
|
+
|
|
264
|
+
EXEMPLE correction utilisateur:
|
|
265
|
+
User: "liste les fichiers"
|
|
266
|
+
→ directory_lister(".")
|
|
267
|
+
User: "non, lis AGENTS.md"
|
|
268
|
+
→ file_reader(path="AGENTS.md")
|
|
269
|
+
|
|
270
|
+
NE PAS inclure de reasoning, pas de texte hors JSON.`)
|
|
271
|
+
.build(context);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
updateDynamicGoal(context) {
|
|
275
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
+
return this.cognitiveHandler.computeGoal(context);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
reflect(context) {
|
|
280
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
281
|
+
var _a, _b;
|
|
282
|
+
if (!this.enableReflection) {
|
|
283
|
+
return { learning: "Reflection disabled." };
|
|
284
|
+
}
|
|
285
|
+
this.log("thinking", chalk_1.default.dim("Reflecting on last action..."));
|
|
286
|
+
const lastActions = (context.executedActions || []).slice(-3);
|
|
287
|
+
const prompt = `Analyze the just-completed action(s):
|
|
288
|
+
|
|
289
|
+
Actions executed:
|
|
290
|
+
${JSON.stringify(lastActions.map(a => ({ name: a.name, parameters: a.parameters, result: a.result })), null, 2)}
|
|
291
|
+
|
|
292
|
+
Current goal: ${this.getCurrentGoal()}
|
|
293
|
+
|
|
294
|
+
Answer in JSON only:
|
|
295
|
+
{
|
|
296
|
+
"learning": "What did you learn? What insight helps future steps?",
|
|
297
|
+
"adjustedGoal": "(optional) improved goal if the original needs refinement"
|
|
298
|
+
}`;
|
|
299
|
+
const schema = zod_1.z.object({
|
|
300
|
+
learning: zod_1.z.string(),
|
|
301
|
+
adjustedGoal: zod_1.z.string().optional(),
|
|
302
|
+
});
|
|
303
|
+
try {
|
|
304
|
+
const result = yield this.llm.generate({ system: "You reflect on actions to extract learnings.", user: prompt }, schema);
|
|
305
|
+
const learning = ((_a = result.object) === null || _a === void 0 ? void 0 : _a.learning) || "No specific learning extracted.";
|
|
306
|
+
const adjustedGoal = (_b = result.object) === null || _b === void 0 ? void 0 : _b.adjustedGoal;
|
|
307
|
+
if (adjustedGoal) {
|
|
308
|
+
this.cognitiveHandler.setGoal(adjustedGoal);
|
|
309
|
+
}
|
|
310
|
+
this.log("info", chalk_1.default.cyan(`Reflection: ${learning.substring(0, 100)}...`));
|
|
311
|
+
return { learning, adjustedGoal };
|
|
312
|
+
}
|
|
313
|
+
catch (_c) {
|
|
314
|
+
this.log("warning", chalk_1.default.yellow("Reflection LLM call failed"));
|
|
315
|
+
return { learning: "Reflection unavailable." };
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Makes a decision based on the current context using the LLM
|
|
321
|
+
* @param {AgentContext} context - The context to base the decision on
|
|
322
|
+
* @returns {Promise<DecisionOutput>} The decision output containing actions and response
|
|
323
|
+
*/
|
|
324
|
+
makeDecision(context) {
|
|
325
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
326
|
+
var _a, _b, _c, _d;
|
|
327
|
+
var _e;
|
|
328
|
+
this.log("thinking", chalk_1.default.dim("Analyzing context and available actions..."));
|
|
329
|
+
const systemPrompt = yield this.buildSystemPrompt(context);
|
|
330
|
+
this.log("info", chalk_1.default.dim("Generating response..."));
|
|
331
|
+
const t0 = performance.now();
|
|
332
|
+
const result = yield this.llm.generate({
|
|
333
|
+
system: systemPrompt,
|
|
334
|
+
user: `User message: ${context.input.raw}`,
|
|
335
|
+
}, zod_1.z.object({
|
|
336
|
+
thought: zod_1.z.string().catch("").default(""),
|
|
337
|
+
actions: zod_1.z.array(zod_1.z.object({
|
|
338
|
+
name: zod_1.z.string().optional().catch(() => ""),
|
|
339
|
+
parameters: zod_1.z.union([
|
|
340
|
+
zod_1.z.array(zod_1.z.object({
|
|
341
|
+
name: zod_1.z.string(),
|
|
342
|
+
value: zod_1.z.any(),
|
|
343
|
+
})),
|
|
344
|
+
zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
|
|
345
|
+
]).optional().catch(() => ({})),
|
|
346
|
+
}).passthrough().catch(() => ({ name: "", parameters: {} }))).default([]),
|
|
347
|
+
response: zod_1.z.string().catch("D'accord, compris.").default("D'accord, compris."),
|
|
348
|
+
}));
|
|
349
|
+
const llmDuration = performance.now() - t0;
|
|
350
|
+
const llmCalls = ((_e = context).llmCalls || (_e.llmCalls = []));
|
|
351
|
+
llmCalls.push({
|
|
352
|
+
promptTokens: (_b = (_a = result.usage) === null || _a === void 0 ? void 0 : _a.promptTokens) !== null && _b !== void 0 ? _b : 0,
|
|
353
|
+
completionTokens: (_d = (_c = result.usage) === null || _c === void 0 ? void 0 : _c.completionTokens) !== null && _d !== void 0 ? _d : 0,
|
|
354
|
+
duration: llmDuration,
|
|
355
|
+
timestamp: new Date().toISOString(),
|
|
356
|
+
});
|
|
357
|
+
const validActions = result.object.actions
|
|
358
|
+
.filter((a) => a && a.name && typeof a.name === 'string' && a.name.length > 0)
|
|
359
|
+
.map((action) => {
|
|
360
|
+
const p = action.parameters || {};
|
|
361
|
+
if (!Array.isArray(p)) {
|
|
362
|
+
action.parameters = Object.entries(p).map(([name, value]) => ({
|
|
363
|
+
name,
|
|
364
|
+
value,
|
|
365
|
+
}));
|
|
366
|
+
}
|
|
367
|
+
return action;
|
|
368
|
+
});
|
|
369
|
+
if (validActions.length > 0) {
|
|
370
|
+
this.log("success", chalk_1.default.green("Decided to take actions:"));
|
|
371
|
+
validActions.forEach((action) => {
|
|
372
|
+
const params = action.parameters || {};
|
|
373
|
+
if (Array.isArray(params)) {
|
|
374
|
+
params.forEach((param) => {
|
|
375
|
+
this.log("info", chalk_1.default.cyan(` → ${action.name}(${param.name}=${JSON.stringify(param.value)})`));
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
380
|
+
this.log("info", chalk_1.default.cyan(` → ${action.name}(${key}=${JSON.stringify(value)})`));
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
this.log("info", chalk_1.default.yellow("No actions needed"));
|
|
387
|
+
}
|
|
388
|
+
this.log("info", chalk_1.default.dim(`LLM Response: ${result.object.response}`));
|
|
389
|
+
if (this.verbose) {
|
|
390
|
+
this.logger.log("info", "executor", `Raw LLM result: ${JSON.stringify(result.object)}`);
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
actions: validActions,
|
|
394
|
+
response: result.object.response,
|
|
395
|
+
thought: result.object.thought || "",
|
|
396
|
+
};
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
decomposeTask(actions, context) {
|
|
400
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
401
|
+
var _a;
|
|
402
|
+
if (actions.length <= 1) {
|
|
403
|
+
return { groups: [actions], response: "Single action, no decomposition needed." };
|
|
404
|
+
}
|
|
405
|
+
const toolNames = actions.map(a => a.name).join(", ");
|
|
406
|
+
const prompt = `Analyze these ${actions.length} tool calls and group them for PARALLEL execution.
|
|
407
|
+
Actions: ${JSON.stringify(actions.map(a => ({ name: a.name, params: a.parameters })))}
|
|
408
|
+
Rules:
|
|
409
|
+
- Group actions that are INDEPENDENT (no data dependency between them)
|
|
410
|
+
- Each group runs sequentially within itself
|
|
411
|
+
- Groups run in parallel with each other
|
|
412
|
+
- Return the minimal number of groups
|
|
413
|
+
Respond with JSON: { "groups": [[action1, action2], [action3]], "reasoning": "..." }`;
|
|
414
|
+
const schema = zod_1.z.object({
|
|
415
|
+
groups: zod_1.z.array(zod_1.z.array(zod_1.z.object({
|
|
416
|
+
name: zod_1.z.string(),
|
|
417
|
+
parameters: zod_1.z.array(zod_1.z.object({ name: zod_1.z.string(), value: zod_1.z.any() })).optional(),
|
|
418
|
+
}).passthrough())),
|
|
419
|
+
reasoning: zod_1.z.string().optional(),
|
|
420
|
+
});
|
|
421
|
+
let result;
|
|
422
|
+
try {
|
|
423
|
+
result = yield this.llm.generate({ system: "You are a task decomposition expert. Group actions for optimal parallel execution.", user: prompt }, schema);
|
|
424
|
+
}
|
|
425
|
+
catch (_b) {
|
|
426
|
+
this.log("warning", chalk_1.default.yellow("Decomposition LLM call failed, running sequentially"));
|
|
427
|
+
return { groups: [actions], response: "Sequential fallback." };
|
|
428
|
+
}
|
|
429
|
+
const groups = ((_a = result.object) === null || _a === void 0 ? void 0 : _a.groups) || [actions];
|
|
430
|
+
if (!Array.isArray(groups) || groups.length === 0) {
|
|
431
|
+
return { groups: [actions], response: "No parallelization possible." };
|
|
432
|
+
}
|
|
433
|
+
const validGroups = groups.filter((g) => Array.isArray(g) && g.length > 0);
|
|
434
|
+
if (validGroups.length === 0) {
|
|
435
|
+
return { groups: [actions], response: "No parallelization possible." };
|
|
436
|
+
}
|
|
437
|
+
this.log("info", chalk_1.default.cyan(`Decomposed into ${validGroups.length} parallel groups: ${validGroups.map((g) => g.map((a) => a.name).join(", ")).join(" | ")}`));
|
|
438
|
+
return { groups: validGroups, response: `Split into ${validGroups.length} groups` };
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Executes multiple workflows with their respective inputs
|
|
443
|
+
* @protected
|
|
444
|
+
* @param {GraphFlow<any>[]} workflows - Array of workflows to execute
|
|
445
|
+
* @param {string[]} startNodes - Array of starting node names for each workflow
|
|
446
|
+
* @param {any[]} inputs - Array of inputs for each workflow
|
|
447
|
+
* @param {AgentContext} context - The context in which to execute the workflows
|
|
448
|
+
* @returns {Promise<void>}
|
|
449
|
+
*/
|
|
450
|
+
executeWorkflows(workflows, startNodes, inputs, context) {
|
|
451
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
452
|
+
var _a, _b, _c;
|
|
453
|
+
this.log("info", chalk_1.default.cyan("Executing workflows:"));
|
|
454
|
+
for (let i = 0; i < workflows.length; i++) {
|
|
455
|
+
const workflow = workflows[i];
|
|
456
|
+
const startNode = startNodes[i];
|
|
457
|
+
const input = inputs[i];
|
|
458
|
+
this.log("info", chalk_1.default.dim(`Executing workflow ${workflow.name} starting at node ${startNode}`));
|
|
459
|
+
if (input.entityId && !input.path) {
|
|
460
|
+
const handles = (_a = context === null || context === void 0 ? void 0 : context.entityState) === null || _a === void 0 ? void 0 : _a.handles;
|
|
461
|
+
const handle = handles === null || handles === void 0 ? void 0 : handles[input.entityId];
|
|
462
|
+
if (handle) {
|
|
463
|
+
this.log("info", chalk_1.default.dim(`Resolved entityId "${input.entityId}" → ${handle.label}`));
|
|
464
|
+
input.path = handle.path;
|
|
465
|
+
delete input.entityId;
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
throw new Error(`entityId "${input.entityId}" not found in available handles. ` +
|
|
469
|
+
`Available: ${handles ? Object.keys(handles).join(", ") : "none"}`);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (input.entityId && !input.path) {
|
|
473
|
+
throw new Error(`Tool "${workflow.name}" called with entityId="${input.entityId}" but no path resolved. ` +
|
|
474
|
+
`Provide a valid entityId from ENTITY REFERENCES.`);
|
|
475
|
+
}
|
|
476
|
+
if (input.target && !input.path && this.entityIndex) {
|
|
477
|
+
const index = this.entityIndex;
|
|
478
|
+
const resolved = index.resolveByTarget ? index.resolveByTarget(input.target) : null;
|
|
479
|
+
if (resolved) {
|
|
480
|
+
this.log("info", chalk_1.default.dim(`Resolved target "${input.target}" → ${resolved.filename}`));
|
|
481
|
+
input.path = resolved.path;
|
|
482
|
+
input.entityId = resolved.id;
|
|
483
|
+
}
|
|
484
|
+
delete input.target;
|
|
485
|
+
}
|
|
486
|
+
const resolvedInput = {};
|
|
487
|
+
for (const [key, value] of Object.entries(input)) {
|
|
488
|
+
if (typeof value === 'string' && value.startsWith('$')) {
|
|
489
|
+
let varPath = value.substring(1);
|
|
490
|
+
let varValue = undefined;
|
|
491
|
+
if (varPath.includes('.')) {
|
|
492
|
+
const [varName, ...rest] = varPath.split('.');
|
|
493
|
+
varValue = context[varName];
|
|
494
|
+
if (varValue !== undefined) {
|
|
495
|
+
for (const prop of rest) {
|
|
496
|
+
varValue = varValue === null || varValue === void 0 ? void 0 : varValue[prop];
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
const fallback = context.executedActions.find(a => `${a.name}_result` === varName);
|
|
501
|
+
if (fallback) {
|
|
502
|
+
varValue = fallback.result;
|
|
503
|
+
for (const prop of rest) {
|
|
504
|
+
varValue = varValue === null || varValue === void 0 ? void 0 : varValue[prop];
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
varValue = context[varPath];
|
|
511
|
+
if (varValue === undefined) {
|
|
512
|
+
const fallback = context.executedActions.find(a => `${a.name}_result` === varPath);
|
|
513
|
+
if (fallback)
|
|
514
|
+
varValue = fallback.result;
|
|
515
|
+
}
|
|
516
|
+
if (varValue === undefined) {
|
|
517
|
+
const lastResult = (_b = context.executedActions[context.executedActions.length - 1]) === null || _b === void 0 ? void 0 : _b.result;
|
|
518
|
+
if (lastResult !== undefined)
|
|
519
|
+
varValue = lastResult;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if (varValue !== undefined) {
|
|
523
|
+
const extracted = typeof varValue === 'object' && (varValue === null || varValue === void 0 ? void 0 : varValue.result) !== undefined && !varPath.includes('.result')
|
|
524
|
+
? varValue.result
|
|
525
|
+
: varValue;
|
|
526
|
+
this.log("info", chalk_1.default.dim(` Resolved \$${varPath} = ${JSON.stringify(extracted)}`));
|
|
527
|
+
resolvedInput[key] = extracted;
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
resolvedInput[key] = value;
|
|
532
|
+
}
|
|
533
|
+
this.log("info", chalk_1.default.dim(`Input parameters: ${JSON.stringify(resolvedInput, null, 2)}`));
|
|
534
|
+
const coercedInput = {};
|
|
535
|
+
const schema = workflow.getSchema();
|
|
536
|
+
for (const [key, value] of Object.entries(resolvedInput)) {
|
|
537
|
+
const fieldSchema = schema.shape[key];
|
|
538
|
+
if (fieldSchema) {
|
|
539
|
+
const typeName = fieldSchema._def.typeName;
|
|
540
|
+
if (typeName === 'ZodOptional') {
|
|
541
|
+
const inner = fieldSchema._def.innerType;
|
|
542
|
+
const innerType = (_c = inner === null || inner === void 0 ? void 0 : inner._def) === null || _c === void 0 ? void 0 : _c.typeName;
|
|
543
|
+
if (innerType === 'ZodNumber') {
|
|
544
|
+
coercedInput[key] = typeof value === 'string' ? parseFloat(value) : value;
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
if (innerType === 'ZodString') {
|
|
548
|
+
if (typeof value === 'object' && value !== null) {
|
|
549
|
+
coercedInput[key] = JSON.stringify(value);
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
coercedInput[key] = String(value);
|
|
553
|
+
}
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
if (innerType === 'ZodEnum') {
|
|
557
|
+
const options = inner._def.values || [];
|
|
558
|
+
const lowerOptions = options.map((o) => o.toLowerCase());
|
|
559
|
+
const matchIdx = lowerOptions.indexOf(String(value).toLowerCase());
|
|
560
|
+
coercedInput[key] = matchIdx >= 0 ? options[matchIdx] : value;
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (typeName === 'ZodNumber') {
|
|
565
|
+
coercedInput[key] = typeof value === 'string' ? parseFloat(value) : value;
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
if (typeName === 'ZodString') {
|
|
569
|
+
if (typeof value === 'object' && value !== null) {
|
|
570
|
+
coercedInput[key] = JSON.stringify(value);
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
coercedInput[key] = String(value);
|
|
574
|
+
}
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
if (typeName === 'ZodBoolean') {
|
|
578
|
+
if (typeof value === 'string') {
|
|
579
|
+
coercedInput[key] = value.toLowerCase() === 'true' || value === '1' || value === 'yes';
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
coercedInput[key] = Boolean(value) && value !== null && value !== undefined;
|
|
583
|
+
}
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
if (typeName === 'ZodEnum') {
|
|
587
|
+
const options = fieldSchema._def.values || [];
|
|
588
|
+
const lowerOptions = options.map((o) => o.toLowerCase());
|
|
589
|
+
const matchIdx = lowerOptions.indexOf(String(value).toLowerCase());
|
|
590
|
+
coercedInput[key] = matchIdx >= 0 ? options[matchIdx] : value;
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
coercedInput[key] = value;
|
|
595
|
+
}
|
|
596
|
+
const workflowContext = Object.assign(Object.assign({}, workflow.getContext()), coercedInput);
|
|
597
|
+
// Execute with merged context
|
|
598
|
+
const result = yield workflow.execute(startNode, workflowContext);
|
|
599
|
+
this.log("success", chalk_1.default.green(`Workflow ${workflow.name} completed`));
|
|
600
|
+
this.log("info", chalk_1.default.dim(`Result: ${JSON.stringify(result, null, 2)}`));
|
|
601
|
+
if (context.executedActions) {
|
|
602
|
+
context.executedActions.push({
|
|
603
|
+
name: workflow.name,
|
|
604
|
+
parameters: resolvedInput,
|
|
605
|
+
result: result,
|
|
606
|
+
timestamp: new Date().toISOString(),
|
|
607
|
+
isExecuted: true,
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
const resultVarName = `${workflow.name}_result`;
|
|
611
|
+
context[resultVarName] = result;
|
|
612
|
+
if (result && typeof result === 'object' && result._handoff) {
|
|
613
|
+
context._handoff = result._handoff;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
exports.GenericExecutor = GenericExecutor;
|
|
620
|
+
//# sourceMappingURL=generic-executor.js.map
|