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