@falai/agent 1.2.7 → 2.0.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/README.md +40 -886
- package/dist/adapters/MemoryAdapter.js +2 -2
- package/dist/adapters/MemoryAdapter.js.map +1 -1
- package/dist/adapters/MongoAdapter.js +2 -2
- package/dist/adapters/MongoAdapter.js.map +1 -1
- package/dist/adapters/OpenSearchAdapter.d.ts.map +1 -1
- package/dist/adapters/OpenSearchAdapter.js +9 -7
- package/dist/adapters/OpenSearchAdapter.js.map +1 -1
- package/dist/adapters/PostgreSQLAdapter.d.ts +14 -0
- package/dist/adapters/PostgreSQLAdapter.d.ts.map +1 -1
- package/dist/adapters/PostgreSQLAdapter.js +25 -9
- package/dist/adapters/PostgreSQLAdapter.js.map +1 -1
- package/dist/adapters/PrismaAdapter.js +5 -5
- package/dist/adapters/PrismaAdapter.js.map +1 -1
- package/dist/adapters/RedisAdapter.js +2 -2
- package/dist/adapters/RedisAdapter.js.map +1 -1
- package/dist/adapters/SQLiteAdapter.d.ts +17 -0
- package/dist/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/dist/adapters/SQLiteAdapter.js +30 -11
- package/dist/adapters/SQLiteAdapter.js.map +1 -1
- package/dist/cjs/adapters/MemoryAdapter.js +2 -2
- package/dist/cjs/adapters/MemoryAdapter.js.map +1 -1
- package/dist/cjs/adapters/MongoAdapter.js +2 -2
- package/dist/cjs/adapters/MongoAdapter.js.map +1 -1
- package/dist/cjs/adapters/OpenSearchAdapter.d.ts.map +1 -1
- package/dist/cjs/adapters/OpenSearchAdapter.js +9 -7
- package/dist/cjs/adapters/OpenSearchAdapter.js.map +1 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.d.ts +14 -0
- package/dist/cjs/adapters/PostgreSQLAdapter.d.ts.map +1 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.js +25 -9
- package/dist/cjs/adapters/PostgreSQLAdapter.js.map +1 -1
- package/dist/cjs/adapters/PrismaAdapter.js +5 -5
- package/dist/cjs/adapters/PrismaAdapter.js.map +1 -1
- package/dist/cjs/adapters/RedisAdapter.js +2 -2
- package/dist/cjs/adapters/RedisAdapter.js.map +1 -1
- package/dist/cjs/adapters/SQLiteAdapter.d.ts +17 -0
- package/dist/cjs/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/dist/cjs/adapters/SQLiteAdapter.js +30 -11
- package/dist/cjs/adapters/SQLiteAdapter.js.map +1 -1
- package/dist/cjs/constants/index.d.ts +0 -9
- package/dist/cjs/constants/index.d.ts.map +1 -1
- package/dist/cjs/constants/index.js +2 -11
- package/dist/cjs/constants/index.js.map +1 -1
- package/dist/cjs/core/Agent.d.ts +119 -153
- package/dist/cjs/core/Agent.d.ts.map +1 -1
- package/dist/cjs/core/Agent.js +471 -324
- package/dist/cjs/core/Agent.js.map +1 -1
- package/dist/cjs/core/AutoChainExecutor.d.ts +107 -0
- package/dist/cjs/core/AutoChainExecutor.d.ts.map +1 -0
- package/dist/cjs/core/AutoChainExecutor.js +297 -0
- package/dist/cjs/core/AutoChainExecutor.js.map +1 -0
- package/dist/cjs/core/BranchEvaluator.d.ts +54 -0
- package/dist/cjs/core/BranchEvaluator.d.ts.map +1 -0
- package/dist/cjs/core/BranchEvaluator.js +130 -0
- package/dist/cjs/core/BranchEvaluator.js.map +1 -0
- package/dist/cjs/core/DirectiveBus.d.ts +88 -0
- package/dist/cjs/core/DirectiveBus.d.ts.map +1 -0
- package/dist/cjs/core/DirectiveBus.js +196 -0
- package/dist/cjs/core/DirectiveBus.js.map +1 -0
- package/dist/cjs/core/DirectiveChainTracker.d.ts +49 -0
- package/dist/cjs/core/DirectiveChainTracker.d.ts.map +1 -0
- package/dist/cjs/core/DirectiveChainTracker.js +121 -0
- package/dist/cjs/core/DirectiveChainTracker.js.map +1 -0
- package/dist/cjs/core/Flow.d.ts +186 -0
- package/dist/cjs/core/Flow.d.ts.map +1 -0
- package/dist/cjs/core/Flow.js +550 -0
- package/dist/cjs/core/Flow.js.map +1 -0
- package/dist/cjs/core/FlowRouter.d.ts +182 -0
- package/dist/cjs/core/FlowRouter.d.ts.map +1 -0
- package/dist/cjs/core/{RoutingEngine.js → FlowRouter.js} +323 -306
- package/dist/cjs/core/FlowRouter.js.map +1 -0
- package/dist/cjs/core/PersistenceManager.d.ts +2 -2
- package/dist/cjs/core/PersistenceManager.d.ts.map +1 -1
- package/dist/cjs/core/PersistenceManager.js +7 -7
- package/dist/cjs/core/PersistenceManager.js.map +1 -1
- package/dist/cjs/core/PromptComposer.d.ts +21 -8
- package/dist/cjs/core/PromptComposer.d.ts.map +1 -1
- package/dist/cjs/core/PromptComposer.js +182 -105
- package/dist/cjs/core/PromptComposer.js.map +1 -1
- package/dist/cjs/core/PromptSectionCache.d.ts +1 -1
- package/dist/cjs/core/PromptSectionCache.js +1 -1
- package/dist/cjs/core/ResponseEngine.d.ts +18 -8
- package/dist/cjs/core/ResponseEngine.d.ts.map +1 -1
- package/dist/cjs/core/ResponseEngine.js +38 -36
- package/dist/cjs/core/ResponseEngine.js.map +1 -1
- package/dist/cjs/core/ResponseModal.d.ts +73 -56
- package/dist/cjs/core/ResponseModal.d.ts.map +1 -1
- package/dist/cjs/core/ResponseModal.js +1196 -1015
- package/dist/cjs/core/ResponseModal.js.map +1 -1
- package/dist/cjs/core/ResponsePipeline.d.ts +124 -26
- package/dist/cjs/core/ResponsePipeline.d.ts.map +1 -1
- package/dist/cjs/core/ResponsePipeline.js +524 -134
- package/dist/cjs/core/ResponsePipeline.js.map +1 -1
- package/dist/cjs/core/SignalEvaluator.d.ts +86 -0
- package/dist/cjs/core/SignalEvaluator.d.ts.map +1 -0
- package/dist/cjs/core/SignalEvaluator.js +333 -0
- package/dist/cjs/core/SignalEvaluator.js.map +1 -0
- package/dist/cjs/core/SignalProcessor.d.ts +152 -0
- package/dist/cjs/core/SignalProcessor.d.ts.map +1 -0
- package/dist/cjs/core/SignalProcessor.js +562 -0
- package/dist/cjs/core/SignalProcessor.js.map +1 -0
- package/dist/cjs/core/Step.d.ts +43 -32
- package/dist/cjs/core/Step.d.ts.map +1 -1
- package/dist/cjs/core/Step.js +221 -126
- package/dist/cjs/core/Step.js.map +1 -1
- package/dist/cjs/core/StreamingToolExecutor.d.ts +2 -2
- package/dist/cjs/core/StreamingToolExecutor.d.ts.map +1 -1
- package/dist/cjs/core/StreamingToolExecutor.js.map +1 -1
- package/dist/cjs/core/ToolManager.d.ts +44 -13
- package/dist/cjs/core/ToolManager.d.ts.map +1 -1
- package/dist/cjs/core/ToolManager.js +174 -91
- package/dist/cjs/core/ToolManager.js.map +1 -1
- package/dist/cjs/core/createAgent.d.ts +35 -0
- package/dist/cjs/core/createAgent.d.ts.map +1 -0
- package/dist/cjs/core/createAgent.js +39 -0
- package/dist/cjs/core/createAgent.js.map +1 -0
- package/dist/cjs/core/flow-namespace.d.ts +49 -0
- package/dist/cjs/core/flow-namespace.d.ts.map +1 -0
- package/dist/cjs/core/flow-namespace.js +171 -0
- package/dist/cjs/core/flow-namespace.js.map +1 -0
- package/dist/cjs/index.d.ts +11 -14
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +18 -22
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/providers/GeminiProvider.d.ts +3 -3
- package/dist/cjs/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/cjs/providers/GeminiProvider.js +16 -14
- package/dist/cjs/providers/GeminiProvider.js.map +1 -1
- package/dist/cjs/types/agent.d.ts +183 -54
- package/dist/cjs/types/agent.d.ts.map +1 -1
- package/dist/cjs/types/agent.js +0 -6
- package/dist/cjs/types/agent.js.map +1 -1
- package/dist/cjs/types/ai.d.ts +3 -3
- package/dist/cjs/types/ai.d.ts.map +1 -1
- package/dist/cjs/types/errors.d.ts +15 -0
- package/dist/cjs/types/errors.d.ts.map +1 -0
- package/dist/cjs/types/errors.js +22 -0
- package/dist/cjs/types/errors.js.map +1 -0
- package/dist/cjs/types/flow.d.ts +513 -0
- package/dist/cjs/types/flow.d.ts.map +1 -0
- package/dist/cjs/types/{route.js → flow.js} +2 -2
- package/dist/cjs/types/flow.js.map +1 -0
- package/dist/cjs/types/index.d.ts +7 -6
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +6 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/persistence.d.ts +11 -7
- package/dist/cjs/types/persistence.d.ts.map +1 -1
- package/dist/cjs/types/routing.d.ts +1 -1
- package/dist/cjs/types/routing.d.ts.map +1 -1
- package/dist/cjs/types/session.d.ts +24 -23
- package/dist/cjs/types/session.d.ts.map +1 -1
- package/dist/cjs/types/signals.d.ts +248 -0
- package/dist/cjs/types/signals.d.ts.map +1 -0
- package/dist/cjs/types/signals.js +11 -0
- package/dist/cjs/types/signals.js.map +1 -0
- package/dist/cjs/types/template.d.ts +2 -8
- package/dist/cjs/types/template.d.ts.map +1 -1
- package/dist/cjs/types/tool.d.ts +36 -29
- package/dist/cjs/types/tool.d.ts.map +1 -1
- package/dist/cjs/types/tool.js +1 -1
- package/dist/cjs/types/tool.js.map +1 -1
- package/dist/cjs/utils/condition.d.ts +7 -1
- package/dist/cjs/utils/condition.d.ts.map +1 -1
- package/dist/cjs/utils/condition.js.map +1 -1
- package/dist/cjs/utils/id.d.ts +13 -5
- package/dist/cjs/utils/id.d.ts.map +1 -1
- package/dist/cjs/utils/id.js +24 -10
- package/dist/cjs/utils/id.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +2 -2
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +7 -3
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/session.d.ts +44 -5
- package/dist/cjs/utils/session.d.ts.map +1 -1
- package/dist/cjs/utils/session.js +197 -38
- package/dist/cjs/utils/session.js.map +1 -1
- package/dist/constants/index.d.ts +0 -9
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +3 -9
- package/dist/constants/index.js.map +1 -1
- package/dist/core/Agent.d.ts +119 -153
- package/dist/core/Agent.d.ts.map +1 -1
- package/dist/core/Agent.js +472 -325
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/AutoChainExecutor.d.ts +107 -0
- package/dist/core/AutoChainExecutor.d.ts.map +1 -0
- package/dist/core/AutoChainExecutor.js +293 -0
- package/dist/core/AutoChainExecutor.js.map +1 -0
- package/dist/core/BranchEvaluator.d.ts +54 -0
- package/dist/core/BranchEvaluator.d.ts.map +1 -0
- package/dist/core/BranchEvaluator.js +126 -0
- package/dist/core/BranchEvaluator.js.map +1 -0
- package/dist/core/DirectiveBus.d.ts +88 -0
- package/dist/core/DirectiveBus.d.ts.map +1 -0
- package/dist/core/DirectiveBus.js +192 -0
- package/dist/core/DirectiveBus.js.map +1 -0
- package/dist/core/DirectiveChainTracker.d.ts +49 -0
- package/dist/core/DirectiveChainTracker.d.ts.map +1 -0
- package/dist/core/DirectiveChainTracker.js +117 -0
- package/dist/core/DirectiveChainTracker.js.map +1 -0
- package/dist/core/Flow.d.ts +186 -0
- package/dist/core/Flow.d.ts.map +1 -0
- package/dist/core/Flow.js +546 -0
- package/dist/core/Flow.js.map +1 -0
- package/dist/core/FlowRouter.d.ts +182 -0
- package/dist/core/FlowRouter.d.ts.map +1 -0
- package/dist/core/{RoutingEngine.js → FlowRouter.js} +322 -305
- package/dist/core/FlowRouter.js.map +1 -0
- package/dist/core/PersistenceManager.d.ts +2 -2
- package/dist/core/PersistenceManager.d.ts.map +1 -1
- package/dist/core/PersistenceManager.js +7 -7
- package/dist/core/PersistenceManager.js.map +1 -1
- package/dist/core/PromptComposer.d.ts +21 -8
- package/dist/core/PromptComposer.d.ts.map +1 -1
- package/dist/core/PromptComposer.js +183 -106
- package/dist/core/PromptComposer.js.map +1 -1
- package/dist/core/PromptSectionCache.d.ts +1 -1
- package/dist/core/PromptSectionCache.js +1 -1
- package/dist/core/ResponseEngine.d.ts +18 -8
- package/dist/core/ResponseEngine.d.ts.map +1 -1
- package/dist/core/ResponseEngine.js +38 -36
- package/dist/core/ResponseEngine.js.map +1 -1
- package/dist/core/ResponseModal.d.ts +73 -56
- package/dist/core/ResponseModal.d.ts.map +1 -1
- package/dist/core/ResponseModal.js +1198 -1017
- package/dist/core/ResponseModal.js.map +1 -1
- package/dist/core/ResponsePipeline.d.ts +124 -26
- package/dist/core/ResponsePipeline.d.ts.map +1 -1
- package/dist/core/ResponsePipeline.js +524 -135
- package/dist/core/ResponsePipeline.js.map +1 -1
- package/dist/core/SignalEvaluator.d.ts +86 -0
- package/dist/core/SignalEvaluator.d.ts.map +1 -0
- package/dist/core/SignalEvaluator.js +326 -0
- package/dist/core/SignalEvaluator.js.map +1 -0
- package/dist/core/SignalProcessor.d.ts +152 -0
- package/dist/core/SignalProcessor.d.ts.map +1 -0
- package/dist/core/SignalProcessor.js +555 -0
- package/dist/core/SignalProcessor.js.map +1 -0
- package/dist/core/Step.d.ts +43 -32
- package/dist/core/Step.d.ts.map +1 -1
- package/dist/core/Step.js +220 -126
- package/dist/core/Step.js.map +1 -1
- package/dist/core/StreamingToolExecutor.d.ts +2 -2
- package/dist/core/StreamingToolExecutor.d.ts.map +1 -1
- package/dist/core/StreamingToolExecutor.js.map +1 -1
- package/dist/core/ToolManager.d.ts +44 -13
- package/dist/core/ToolManager.d.ts.map +1 -1
- package/dist/core/ToolManager.js +174 -91
- package/dist/core/ToolManager.js.map +1 -1
- package/dist/core/createAgent.d.ts +35 -0
- package/dist/core/createAgent.d.ts.map +1 -0
- package/dist/core/createAgent.js +36 -0
- package/dist/core/createAgent.js.map +1 -0
- package/dist/core/flow-namespace.d.ts +49 -0
- package/dist/core/flow-namespace.d.ts.map +1 -0
- package/dist/core/flow-namespace.js +168 -0
- package/dist/core/flow-namespace.js.map +1 -0
- package/dist/index.d.ts +11 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -12
- package/dist/index.js.map +1 -1
- package/dist/providers/GeminiProvider.d.ts +3 -3
- package/dist/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/GeminiProvider.js +16 -14
- package/dist/providers/GeminiProvider.js.map +1 -1
- package/dist/types/agent.d.ts +183 -54
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/agent.js +0 -6
- package/dist/types/agent.js.map +1 -1
- package/dist/types/ai.d.ts +3 -3
- package/dist/types/ai.d.ts.map +1 -1
- package/dist/types/errors.d.ts +15 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +18 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/flow.d.ts +513 -0
- package/dist/types/flow.d.ts.map +1 -0
- package/dist/types/flow.js +5 -0
- package/dist/types/flow.js.map +1 -0
- package/dist/types/index.d.ts +7 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +4 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/persistence.d.ts +11 -7
- package/dist/types/persistence.d.ts.map +1 -1
- package/dist/types/routing.d.ts +1 -1
- package/dist/types/routing.d.ts.map +1 -1
- package/dist/types/session.d.ts +24 -23
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types/signals.d.ts +248 -0
- package/dist/types/signals.d.ts.map +1 -0
- package/dist/types/signals.js +10 -0
- package/dist/types/signals.js.map +1 -0
- package/dist/types/template.d.ts +2 -8
- package/dist/types/template.d.ts.map +1 -1
- package/dist/types/tool.d.ts +36 -29
- package/dist/types/tool.d.ts.map +1 -1
- package/dist/types/tool.js +1 -1
- package/dist/types/tool.js.map +1 -1
- package/dist/utils/condition.d.ts +7 -1
- package/dist/utils/condition.d.ts.map +1 -1
- package/dist/utils/condition.js.map +1 -1
- package/dist/utils/id.d.ts +13 -5
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +22 -9
- package/dist/utils/id.js.map +1 -1
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/session.d.ts +44 -5
- package/dist/utils/session.d.ts.map +1 -1
- package/dist/utils/session.js +193 -37
- package/dist/utils/session.js.map +1 -1
- package/docs/README.md +15 -202
- package/docs/concepts/architecture.md +281 -0
- package/docs/concepts/directives.md +400 -0
- package/docs/concepts/pipeline.md +399 -0
- package/docs/guides/branching.md +263 -0
- package/docs/guides/compaction.md +163 -0
- package/docs/guides/conditions.md +167 -0
- package/docs/guides/error-handling.md +176 -0
- package/docs/guides/flow-control.md +409 -0
- package/docs/guides/instructions.md +210 -0
- package/docs/guides/persistence.md +182 -0
- package/docs/guides/streaming.md +137 -0
- package/docs/migration/README.md +15 -0
- package/docs/migration/route-to-flow.md +560 -0
- package/docs/migration/v1-to-v2.md +909 -0
- package/docs/reference/adapters.md +481 -0
- package/docs/reference/branches.md +241 -0
- package/docs/reference/create-agent.md +186 -0
- package/docs/reference/directive.md +243 -0
- package/docs/reference/errors.md +122 -0
- package/docs/reference/flow.md +238 -0
- package/docs/reference/instruction.md +177 -0
- package/docs/reference/pre-directive.md +131 -0
- package/docs/reference/providers.md +227 -0
- package/docs/reference/signals.md +356 -0
- package/docs/reference/step.md +339 -0
- package/docs/reference/tool.md +269 -0
- package/docs/start/01-install.md +81 -0
- package/docs/start/02-first-agent.md +196 -0
- package/docs/start/03-collect-data.md +222 -0
- package/docs/start/04-add-tools.md +276 -0
- package/docs/start/05-go-to-production.md +216 -0
- package/examples/01-quickstart.ts +20 -0
- package/examples/02-data-extraction.ts +90 -0
- package/examples/03-tools.ts +136 -0
- package/examples/04-instructions.ts +100 -0
- package/examples/05-branching.ts +140 -0
- package/examples/06-flow-control.ts +103 -0
- package/examples/07-streaming.ts +69 -0
- package/examples/08-persistence.ts +98 -0
- package/examples/09-signals.ts +144 -0
- package/examples/tsconfig.json +30 -0
- package/package.json +2 -1
- package/src/adapters/MemoryAdapter.ts +3 -3
- package/src/adapters/MongoAdapter.ts +3 -3
- package/src/adapters/OpenSearchAdapter.ts +10 -8
- package/src/adapters/PostgreSQLAdapter.ts +26 -10
- package/src/adapters/PrismaAdapter.ts +6 -6
- package/src/adapters/RedisAdapter.ts +3 -3
- package/src/adapters/SQLiteAdapter.ts +31 -12
- package/src/constants/index.ts +2 -10
- package/src/core/Agent.ts +585 -374
- package/src/core/AutoChainExecutor.ts +440 -0
- package/src/core/BranchEvaluator.ts +167 -0
- package/src/core/DirectiveBus.ts +248 -0
- package/src/core/DirectiveChainTracker.ts +144 -0
- package/src/core/Flow.ts +666 -0
- package/src/core/{RoutingEngine.ts → FlowRouter.ts} +385 -365
- package/src/core/PersistenceManager.ts +8 -8
- package/src/core/PromptComposer.ts +209 -140
- package/src/core/PromptSectionCache.ts +1 -1
- package/src/core/ResponseEngine.ts +61 -46
- package/src/core/ResponseModal.ts +1458 -1241
- package/src/core/ResponsePipeline.ts +675 -173
- package/src/core/SignalEvaluator.ts +420 -0
- package/src/core/SignalProcessor.ts +723 -0
- package/src/core/Step.ts +279 -176
- package/src/core/StreamingToolExecutor.ts +4 -4
- package/src/core/ToolManager.ts +200 -97
- package/src/core/createAgent.ts +40 -0
- package/src/core/flow-namespace.ts +219 -0
- package/src/index.ts +42 -36
- package/src/providers/GeminiProvider.ts +17 -15
- package/src/types/agent.ts +182 -53
- package/src/types/ai.ts +3 -3
- package/src/types/errors.ts +18 -0
- package/src/types/flow.ts +590 -0
- package/src/types/index.ts +43 -16
- package/src/types/persistence.ts +12 -8
- package/src/types/routing.ts +1 -1
- package/src/types/session.ts +26 -23
- package/src/types/signals.ts +321 -0
- package/src/types/template.ts +3 -11
- package/src/types/tool.ts +50 -42
- package/src/utils/condition.ts +13 -4
- package/src/utils/id.ts +27 -9
- package/src/utils/index.ts +6 -2
- package/src/utils/session.ts +238 -42
- package/dist/cjs/core/BatchExecutor.d.ts +0 -359
- package/dist/cjs/core/BatchExecutor.d.ts.map +0 -1
- package/dist/cjs/core/BatchExecutor.js +0 -861
- package/dist/cjs/core/BatchExecutor.js.map +0 -1
- package/dist/cjs/core/BatchPromptBuilder.d.ts +0 -89
- package/dist/cjs/core/BatchPromptBuilder.d.ts.map +0 -1
- package/dist/cjs/core/BatchPromptBuilder.js +0 -223
- package/dist/cjs/core/BatchPromptBuilder.js.map +0 -1
- package/dist/cjs/core/Route.d.ts +0 -180
- package/dist/cjs/core/Route.d.ts.map +0 -1
- package/dist/cjs/core/Route.js +0 -542
- package/dist/cjs/core/Route.js.map +0 -1
- package/dist/cjs/core/RoutingEngine.d.ts +0 -185
- package/dist/cjs/core/RoutingEngine.d.ts.map +0 -1
- package/dist/cjs/core/RoutingEngine.js.map +0 -1
- package/dist/cjs/types/route.d.ts +0 -336
- package/dist/cjs/types/route.d.ts.map +0 -1
- package/dist/cjs/types/route.js.map +0 -1
- package/dist/core/BatchExecutor.d.ts +0 -359
- package/dist/core/BatchExecutor.d.ts.map +0 -1
- package/dist/core/BatchExecutor.js +0 -856
- package/dist/core/BatchExecutor.js.map +0 -1
- package/dist/core/BatchPromptBuilder.d.ts +0 -89
- package/dist/core/BatchPromptBuilder.d.ts.map +0 -1
- package/dist/core/BatchPromptBuilder.js +0 -219
- package/dist/core/BatchPromptBuilder.js.map +0 -1
- package/dist/core/Route.d.ts +0 -180
- package/dist/core/Route.d.ts.map +0 -1
- package/dist/core/Route.js +0 -538
- package/dist/core/Route.js.map +0 -1
- package/dist/core/RoutingEngine.d.ts +0 -185
- package/dist/core/RoutingEngine.d.ts.map +0 -1
- package/dist/core/RoutingEngine.js.map +0 -1
- package/dist/types/route.d.ts +0 -336
- package/dist/types/route.d.ts.map +0 -1
- package/dist/types/route.js +0 -5
- package/dist/types/route.js.map +0 -1
- package/docs/CONTRIBUTING.md +0 -521
- package/docs/api/README.md +0 -3299
- package/docs/api/overview.md +0 -1410
- package/docs/architecture/data-extraction-flow.md +0 -360
- package/docs/architecture/multi-step-execution.md +0 -277
- package/docs/core/agent/README.md +0 -938
- package/docs/core/agent/context-management.md +0 -796
- package/docs/core/agent/rules-and-prohibitions.md +0 -113
- package/docs/core/agent/session-management.md +0 -693
- package/docs/core/ai-integration/prompt-composition.md +0 -355
- package/docs/core/ai-integration/providers.md +0 -515
- package/docs/core/ai-integration/response-processing.md +0 -433
- package/docs/core/conversation-flows/data-collection.md +0 -772
- package/docs/core/conversation-flows/route-dsl.md +0 -509
- package/docs/core/conversation-flows/routes.md +0 -249
- package/docs/core/conversation-flows/step-transitions.md +0 -731
- package/docs/core/conversation-flows/steps.md +0 -268
- package/docs/core/error-handling.md +0 -830
- package/docs/core/persistence/adapters.md +0 -255
- package/docs/core/persistence/session-storage.md +0 -656
- package/docs/core/routing/intelligent-routing.md +0 -470
- package/docs/core/tools/enhanced-tool.md +0 -186
- package/docs/core/tools/streaming-execution.md +0 -161
- package/docs/core/tools/tool-definition.md +0 -970
- package/docs/core/tools/tool-scoping.md +0 -819
- package/docs/guides/advanced-patterns/publishing.md +0 -186
- package/docs/guides/context-compaction.md +0 -96
- package/docs/guides/error-handling-patterns.md +0 -578
- package/docs/guides/getting-started/README.md +0 -795
- package/docs/guides/migration/README.md +0 -101
- package/docs/guides/migration/flexible-routing-conditions.md +0 -375
- package/docs/guides/migration/multi-step-execution.md +0 -393
- package/docs/guides/migration/response-modal-refactor.md +0 -518
- package/docs/guides/prompt-optimization.md +0 -164
- package/examples/advanced-patterns/context-compaction.ts +0 -223
- package/examples/advanced-patterns/knowledge-based-agent.ts +0 -735
- package/examples/advanced-patterns/persistent-onboarding.ts +0 -728
- package/examples/advanced-patterns/route-lifecycle-hooks.ts +0 -556
- package/examples/advanced-patterns/streaming-responses.ts +0 -656
- package/examples/ai-providers/anthropic-integration.ts +0 -388
- package/examples/ai-providers/openai-integration.ts +0 -228
- package/examples/condition-patterns/function-only-conditions.ts +0 -365
- package/examples/condition-patterns/mixed-array-conditions.ts +0 -477
- package/examples/condition-patterns/route-skipif-patterns.ts +0 -468
- package/examples/condition-patterns/step-skipif-patterns.ts +0 -0
- package/examples/condition-patterns/string-only-conditions.ts +0 -296
- package/examples/conversation-flows/completion-transitions.ts +0 -318
- package/examples/core-concepts/basic-agent.ts +0 -503
- package/examples/core-concepts/modern-streaming-api.ts +0 -309
- package/examples/core-concepts/schema-driven-extraction.ts +0 -332
- package/examples/core-concepts/session-management.ts +0 -494
- package/examples/integrations/database-integration.ts +0 -631
- package/examples/integrations/healthcare-integration.ts +0 -595
- package/examples/integrations/search-integration.ts +0 -530
- package/examples/integrations/server-session-management.ts +0 -307
- package/examples/persistence/custom-adapter.ts +0 -526
- package/examples/persistence/database-persistence.ts +0 -583
- package/examples/persistence/memory-sessions.ts +0 -495
- package/examples/persistence/prisma-schema.example.prisma +0 -74
- package/examples/persistence/redis-persistence.ts +0 -488
- package/examples/tools/basic-tools.ts +0 -765
- package/examples/tools/data-enrichment-tools.ts +0 -593
- package/examples/tools/enhanced-tool-metadata.ts +0 -268
- package/examples/tools/streaming-tool-execution.ts +0 -283
- package/src/core/BatchExecutor.ts +0 -1187
- package/src/core/BatchPromptBuilder.ts +0 -299
- package/src/core/Route.ts +0 -678
- package/src/types/route.ts +0 -392
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
# Data Extraction Flow Architecture
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
@falai/agent uses an **intelligent pre-extraction system** that captures data from user messages BEFORE entering conversation steps. This eliminates repetitive questions and creates efficient, natural conversations.
|
|
6
|
-
|
|
7
|
-
## The Problem with Traditional Approaches
|
|
8
|
-
|
|
9
|
-
Traditional conversational AI follows a rigid step-by-step approach:
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
User: "I want to book the Grand Hotel for 2 people next Friday"
|
|
13
|
-
|
|
14
|
-
Traditional Flow:
|
|
15
|
-
Step 1: "Which hotel?" → User already said this!
|
|
16
|
-
Step 2: "How many guests?" → User already said this!
|
|
17
|
-
Step 3: "What date?" → User already said this!
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
This wastes user time and creates frustration.
|
|
21
|
-
|
|
22
|
-
## Our Solution: Pre-Extraction + Smart Step Selection
|
|
23
|
-
|
|
24
|
-
### Phase 1: Route Selection & Pre-Extraction
|
|
25
|
-
|
|
26
|
-
When a user message arrives:
|
|
27
|
-
|
|
28
|
-
1. **Route Evaluation** - AI scores all routes based on user intent
|
|
29
|
-
2. **Route Selection** - Best matching route is selected
|
|
30
|
-
3. **Pre-Extraction** - If entering a NEW route that collects data:
|
|
31
|
-
- AI extracts ALL relevant data from the message
|
|
32
|
-
- Data is validated against the agent schema
|
|
33
|
-
- Collected data is merged into session
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
// User: "I want to book the Grand Hotel for 2 people next Friday"
|
|
37
|
-
|
|
38
|
-
// Pre-extraction automatically captures:
|
|
39
|
-
{
|
|
40
|
-
hotelName: "Grand Hotel",
|
|
41
|
-
guests: 2,
|
|
42
|
-
date: "next Friday"
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### Phase 2: Step Skipping
|
|
47
|
-
|
|
48
|
-
After pre-extraction, the system evaluates the route's steps:
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
// Route defines required fields
|
|
52
|
-
agent.createRoute({
|
|
53
|
-
title: "Book Hotel",
|
|
54
|
-
requiredFields: ["hotelName", "guests", "date"],
|
|
55
|
-
// ...
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// After pre-extraction, all required fields are present.
|
|
59
|
-
// The data is now in the session, which allows steps to be evaluated.
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
**Key Insight:** Routes complete by naturally reaching the `END_ROUTE` step. If all required data is pre-extracted, the system will rapidly skip through the data-collection steps and naturally reach the end of the route.
|
|
63
|
-
|
|
64
|
-
### Phase 3: Smart Step Selection
|
|
65
|
-
|
|
66
|
-
If route is NOT complete, determine which step to start at:
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
// Steps with skipIf conditions
|
|
70
|
-
steps: [
|
|
71
|
-
{
|
|
72
|
-
id: "ask_hotel",
|
|
73
|
-
collect: ["hotelName"],
|
|
74
|
-
skipIf: (data) => !!data.hotelName // ✅ SKIP - already have it
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
id: "ask_guests",
|
|
78
|
-
collect: ["guests"],
|
|
79
|
-
skipIf: (data) => data.guests !== undefined // ✅ SKIP - already have it
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
id: "ask_date",
|
|
83
|
-
collect: ["date"],
|
|
84
|
-
skipIf: (data) => !!data.date // ✅ SKIP - already have it
|
|
85
|
-
}
|
|
86
|
-
]
|
|
87
|
-
|
|
88
|
-
// Result: All steps skipped → Route complete
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Phase 4: Response Generation
|
|
92
|
-
|
|
93
|
-
**If route is complete:**
|
|
94
|
-
- Generate completion message
|
|
95
|
-
- Mark step as END_ROUTE
|
|
96
|
-
- Exclude route from future selection
|
|
97
|
-
|
|
98
|
-
**If route is NOT complete:**
|
|
99
|
-
- Enter the first non-skipped step
|
|
100
|
-
- Generate response asking for missing data
|
|
101
|
-
- Continue conversation
|
|
102
|
-
|
|
103
|
-
## Complete Flow Example
|
|
104
|
-
|
|
105
|
-
### Scenario: User provides all data at once
|
|
106
|
-
|
|
107
|
-
```typescript
|
|
108
|
-
// Turn 1
|
|
109
|
-
User: "I want to book the Grand Hotel for 2 people next Friday"
|
|
110
|
-
|
|
111
|
-
System:
|
|
112
|
-
1. Routes to "Book Hotel" (AI scoring)
|
|
113
|
-
2. Pre-extracts: { hotelName: "Grand Hotel", guests: 2, date: "next Friday" }
|
|
114
|
-
3. Evaluates steps: All collection steps are skipped (data already present)
|
|
115
|
-
4. Reaches END_ROUTE and generates completion message
|
|
116
|
-
5. Marks route as complete
|
|
117
|
-
|
|
118
|
-
AI: "Perfect! Booking confirmed for 2 guests at Grand Hotel on Friday!"
|
|
119
|
-
|
|
120
|
-
// Turn 2
|
|
121
|
-
User: "I'm feeling anxious about my visit"
|
|
122
|
-
|
|
123
|
-
System:
|
|
124
|
-
1. Evaluates routes
|
|
125
|
-
2. Excludes "Book Hotel" (already complete)
|
|
126
|
-
3. Routes to "General Healthcare Questions"
|
|
127
|
-
4. Generates response
|
|
128
|
-
|
|
129
|
-
AI: "I understand you're feeling anxious. How can I help?"
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Scenario: User provides partial data
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
// Turn 1
|
|
136
|
-
User: "I want to book the Grand Hotel"
|
|
137
|
-
|
|
138
|
-
System:
|
|
139
|
-
1. Routes to "Book Hotel"
|
|
140
|
-
2. Pre-extracts: { hotelName: "Grand Hotel" }
|
|
141
|
-
3. Checks completion: Missing guests and date ✗
|
|
142
|
-
4. Evaluates steps:
|
|
143
|
-
- ask_hotel: SKIP (have hotelName)
|
|
144
|
-
- ask_guests: ENTER (need guests)
|
|
145
|
-
5. Enters ask_guests step
|
|
146
|
-
|
|
147
|
-
AI: "How many guests will be staying?"
|
|
148
|
-
|
|
149
|
-
// Turn 2
|
|
150
|
-
User: "2 people next Friday"
|
|
151
|
-
|
|
152
|
-
System:
|
|
153
|
-
1. Already in "Book Hotel" route
|
|
154
|
-
2. Pre-extracts: { guests: 2, date: "next Friday" }
|
|
155
|
-
3. Evaluates steps: All collection steps are skipped (data already present)
|
|
156
|
-
4. Reaches END_ROUTE and generates completion message
|
|
157
|
-
|
|
158
|
-
AI: "Booking confirmed for 2 guests at Grand Hotel on Friday!"
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
## Key Design Decisions
|
|
162
|
-
|
|
163
|
-
### 1. Pre-Extraction Triggers
|
|
164
|
-
|
|
165
|
-
Pre-extraction only happens when:
|
|
166
|
-
- Entering a NEW route (not already in it)
|
|
167
|
-
- Route has `requiredFields`, `optionalFields`, OR steps with `collect` arrays
|
|
168
|
-
|
|
169
|
-
This minimizes unnecessary AI calls for purely conversational routes.
|
|
170
|
-
|
|
171
|
-
### 2. Route Completion Logic
|
|
172
|
-
|
|
173
|
-
A route is complete when:
|
|
174
|
-
- **It reaches the END_ROUTE marker in its step flow**
|
|
175
|
-
|
|
176
|
-
`requiredFields` act as a validation gate. While they must be collected, simply collecting them doesn't instantly end the route; the conversation naturally progresses through any remaining steps (or skips them) until it finishes.
|
|
177
|
-
|
|
178
|
-
### 3. Completed Route Exclusion
|
|
179
|
-
|
|
180
|
-
Once a route is 100% complete:
|
|
181
|
-
- It's excluded from future route selection
|
|
182
|
-
- Users won't be forced back into finished tasks
|
|
183
|
-
- System falls back to other routes or general conversation
|
|
184
|
-
|
|
185
|
-
### 4. Step Skipping Logic
|
|
186
|
-
|
|
187
|
-
Steps are skipped when:
|
|
188
|
-
- `skipIf` condition evaluates to true
|
|
189
|
-
- `requires` fields are not yet collected
|
|
190
|
-
- Data for `collect` fields is already present
|
|
191
|
-
|
|
192
|
-
## Configuration
|
|
193
|
-
|
|
194
|
-
### Enable Pre-Extraction
|
|
195
|
-
|
|
196
|
-
Pre-extraction is automatic when you define:
|
|
197
|
-
|
|
198
|
-
```typescript
|
|
199
|
-
// Option 1: Route-level required fields
|
|
200
|
-
agent.createRoute({
|
|
201
|
-
title: "Booking",
|
|
202
|
-
requiredFields: ["hotel", "date", "guests"],
|
|
203
|
-
// Pre-extraction enabled automatically
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// Option 2: Route-level optional fields
|
|
207
|
-
agent.createRoute({
|
|
208
|
-
title: "Booking",
|
|
209
|
-
optionalFields: ["specialRequests"],
|
|
210
|
-
// Pre-extraction enabled automatically
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
// Option 3: Steps with collect arrays
|
|
214
|
-
agent.createRoute({
|
|
215
|
-
title: "Booking",
|
|
216
|
-
steps: [
|
|
217
|
-
{
|
|
218
|
-
id: "ask_hotel",
|
|
219
|
-
collect: ["hotel"], // Pre-extraction enabled automatically
|
|
220
|
-
}
|
|
221
|
-
]
|
|
222
|
-
});
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### Disable Pre-Extraction
|
|
226
|
-
|
|
227
|
-
For purely conversational routes (no data collection):
|
|
228
|
-
|
|
229
|
-
```typescript
|
|
230
|
-
agent.createRoute({
|
|
231
|
-
title: "General Chat",
|
|
232
|
-
// No requiredFields, optionalFields, or collect arrays
|
|
233
|
-
// Pre-extraction skipped automatically
|
|
234
|
-
steps: [
|
|
235
|
-
{
|
|
236
|
-
id: "chat",
|
|
237
|
-
prompt: "Have a friendly conversation"
|
|
238
|
-
// No collect array
|
|
239
|
-
}
|
|
240
|
-
]
|
|
241
|
-
});
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
## Performance Considerations
|
|
245
|
-
|
|
246
|
-
### AI Call Optimization
|
|
247
|
-
|
|
248
|
-
Pre-extraction adds ONE additional AI call when entering a new data-collecting route:
|
|
249
|
-
|
|
250
|
-
```
|
|
251
|
-
Traditional: N calls (one per step)
|
|
252
|
-
With Pre-Extraction: 1 + M calls (pre-extract + remaining steps)
|
|
253
|
-
|
|
254
|
-
Where M ≤ N (often M = 0 if all data extracted)
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
**Net Result:** Usually FEWER total AI calls due to step skipping.
|
|
258
|
-
|
|
259
|
-
### When to Use Pre-Extraction
|
|
260
|
-
|
|
261
|
-
✅ **Use for:** Data collection flows (booking, forms, surveys)
|
|
262
|
-
✅ **Use for:** Multi-field information gathering
|
|
263
|
-
❌ **Skip for:** Pure Q&A or conversational routes
|
|
264
|
-
❌ **Skip for:** Single-field collection
|
|
265
|
-
|
|
266
|
-
## Advanced Patterns
|
|
267
|
-
|
|
268
|
-
### Optional Fields
|
|
269
|
-
|
|
270
|
-
```typescript
|
|
271
|
-
agent.createRoute({
|
|
272
|
-
title: "Booking",
|
|
273
|
-
requiredFields: ["hotel", "date"],
|
|
274
|
-
optionalFields: ["specialRequests", "dietaryRestrictions"],
|
|
275
|
-
// Route completes when it naturally reaches END_ROUTE
|
|
276
|
-
// Optional fields can be collected if user provides them,
|
|
277
|
-
// but they won't block steps from progressing.
|
|
278
|
-
});
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
### Conditional Completion
|
|
282
|
-
|
|
283
|
-
```typescript
|
|
284
|
-
agent.createRoute({
|
|
285
|
-
title: "Order",
|
|
286
|
-
requiredFields: ["items", "address"],
|
|
287
|
-
|
|
288
|
-
steps: [
|
|
289
|
-
// ... collection steps ...
|
|
290
|
-
{
|
|
291
|
-
id: "payment",
|
|
292
|
-
when: "Ready to process payment",
|
|
293
|
-
skipIf: (data) => data.paymentComplete,
|
|
294
|
-
// This step runs AFTER required fields are collected
|
|
295
|
-
// Allows post-completion actions
|
|
296
|
-
}
|
|
297
|
-
]
|
|
298
|
-
});
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
### Progressive Disclosure
|
|
302
|
-
|
|
303
|
-
```typescript
|
|
304
|
-
agent.createRoute({
|
|
305
|
-
title: "Support",
|
|
306
|
-
requiredFields: ["issueType"],
|
|
307
|
-
optionalFields: ["accountNumber", "orderNumber"],
|
|
308
|
-
|
|
309
|
-
steps: [
|
|
310
|
-
{
|
|
311
|
-
id: "ask_issue",
|
|
312
|
-
collect: ["issueType"],
|
|
313
|
-
},
|
|
314
|
-
{
|
|
315
|
-
id: "ask_account",
|
|
316
|
-
collect: ["accountNumber"],
|
|
317
|
-
when: (data) => data.issueType === "account",
|
|
318
|
-
// Only ask for account if issue is account-related
|
|
319
|
-
}
|
|
320
|
-
]
|
|
321
|
-
});
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
## Debugging
|
|
325
|
-
|
|
326
|
-
Enable debug logging to see the extraction flow:
|
|
327
|
-
|
|
328
|
-
```typescript
|
|
329
|
-
const agent = new Agent({
|
|
330
|
-
name: "Assistant",
|
|
331
|
-
provider: new GeminiProvider({ apiKey: "..." }),
|
|
332
|
-
debug: true // Enable detailed logging
|
|
333
|
-
});
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
Look for these log messages:
|
|
337
|
-
|
|
338
|
-
```
|
|
339
|
-
[ResponseModal] Pre-extracting data for route: Book Hotel
|
|
340
|
-
[ResponseModal] Pre-extracted data: { hotelName: "Grand Hotel", ... }
|
|
341
|
-
[RoutingEngine] Route Book Hotel completed - END_ROUTE reached
|
|
342
|
-
[RoutingEngine] Excluding completed route: Book Hotel
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
## Summary
|
|
346
|
-
|
|
347
|
-
The pre-extraction system creates efficient conversations by:
|
|
348
|
-
|
|
349
|
-
1. **Extracting data early** - Before entering steps
|
|
350
|
-
2. **Skipping unnecessary steps** - When data is already present
|
|
351
|
-
3. **Reaching completion naturally** - By skipping to the end when data is gathered
|
|
352
|
-
4. **Protecting completed routes** - Preventing re-entry
|
|
353
|
-
|
|
354
|
-
This results in natural, efficient conversations that respect user time.
|
|
355
|
-
|
|
356
|
-
---
|
|
357
|
-
|
|
358
|
-
**Next Steps:**
|
|
359
|
-
- [Route Configuration](../core/conversation-flows/routes.md)
|
|
360
|
-
- [Step Configuration](../core/conversation-flows/steps.md)
|
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
# Multi-Step Execution Architecture
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
@falai/agent supports **multi-step execution**, enabling multiple consecutive Steps to execute in a single LLM call. This reduces unnecessary multi-turn conversations, minimizes LLM costs, and improves user experience when steps don't require new user input.
|
|
6
|
-
|
|
7
|
-
The core insight is simple: **if a Step's data requirements are already satisfied, there's no reason to pause and wait for user input**. By detecting which Steps can execute together and combining them into a single batch, we reduce LLM calls while improving conversation UX.
|
|
8
|
-
|
|
9
|
-
> **Note:** Multi-step batching is **opt-in**. By default, `maxStepsPerBatch` is `1`, meaning steps execute one at a time (classic behavior). Set `maxStepsPerBatch` to a higher value or `Infinity` to enable batching.
|
|
10
|
-
|
|
11
|
-
## Configuration
|
|
12
|
-
|
|
13
|
-
Control batching behavior with the `maxStepsPerBatch` option on the agent:
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
const agent = new Agent({
|
|
17
|
-
name: "Assistant",
|
|
18
|
-
provider: provider,
|
|
19
|
-
// Default: 1 (single-step execution)
|
|
20
|
-
// Set higher to enable batching
|
|
21
|
-
maxStepsPerBatch: Infinity, // No limit — batch all eligible steps
|
|
22
|
-
});
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
| Value | Behavior |
|
|
26
|
-
|-------|----------|
|
|
27
|
-
| `1` (default) | Steps execute one at a time |
|
|
28
|
-
| `N` (e.g. `3`) | Up to N steps per batch |
|
|
29
|
-
| `Infinity` | No limit — all eligible steps batch together |
|
|
30
|
-
|
|
31
|
-
## Design Priorities
|
|
32
|
-
|
|
33
|
-
1. **Conversation UX** - Reduce unnecessary back-and-forth
|
|
34
|
-
2. **LLM Cost Optimization** - Fewer calls for the same outcome
|
|
35
|
-
3. **Predictability** - Clear, simple rules for when execution pauses
|
|
36
|
-
4. **Framework Understandability** - Keep the Step/Route mental model intact
|
|
37
|
-
|
|
38
|
-
## Batch Execution Flow
|
|
39
|
-
|
|
40
|
-
```mermaid
|
|
41
|
-
flowchart TD
|
|
42
|
-
A[User Message] --> B[Pre-Extraction]
|
|
43
|
-
B --> C[Batch Determination]
|
|
44
|
-
C --> D{More Steps?}
|
|
45
|
-
D -->|Yes| E[Evaluate Step]
|
|
46
|
-
E --> F{Needs Input?}
|
|
47
|
-
F -->|No| G[Add to Batch]
|
|
48
|
-
G --> G2{maxStepsPerBatch reached?}
|
|
49
|
-
G2 -->|No| D
|
|
50
|
-
G2 -->|Yes| H[Stop Batch]
|
|
51
|
-
F -->|Yes| H[Stop Batch]
|
|
52
|
-
D -->|No| H
|
|
53
|
-
H --> I[Execute Prepare Hooks]
|
|
54
|
-
I --> J[Build Combined Prompt]
|
|
55
|
-
J --> K[Single LLM Call]
|
|
56
|
-
K --> L[Extract Response Data]
|
|
57
|
-
L --> M[Execute Finalize Hooks]
|
|
58
|
-
M --> N[Update Session]
|
|
59
|
-
N --> O[Return Response]
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Execution Phases
|
|
63
|
-
|
|
64
|
-
### Phase 1: Pre-Extraction
|
|
65
|
-
|
|
66
|
-
When processing a user message, the engine performs **pre-extraction** before determining the batch. This phase:
|
|
67
|
-
|
|
68
|
-
1. Attempts to extract data for all fields defined in the Route's `requiredFields` and `optionalFields`
|
|
69
|
-
2. Merges pre-extracted data into session data
|
|
70
|
-
3. Maximizes batching by satisfying Step requirements upfront
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
// User: "I want to book the Grand Hotel for 2 people next Friday"
|
|
74
|
-
|
|
75
|
-
// Pre-extraction automatically captures:
|
|
76
|
-
{
|
|
77
|
-
hotelName: "Grand Hotel",
|
|
78
|
-
guests: 2,
|
|
79
|
-
date: "next Friday"
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Phase 2: Batch Determination
|
|
84
|
-
|
|
85
|
-
The `BatchExecutor` walks through Steps using this algorithm:
|
|
86
|
-
|
|
87
|
-
```
|
|
88
|
-
For each Step starting from current position:
|
|
89
|
-
a. Check if it's END_ROUTE → stop with 'end_route'
|
|
90
|
-
b. Evaluate skipIf condition
|
|
91
|
-
c. If skipIf is true → skip Step, continue to next
|
|
92
|
-
d. If skipIf throws error → treat as non-skippable
|
|
93
|
-
e. Evaluate needsInput(step, sessionDataAfterPreExtraction)
|
|
94
|
-
f. If needsInput is false → include Step in batch
|
|
95
|
-
g. If needsInput is true → stop with 'needs_input'
|
|
96
|
-
h. Check if batch size reached maxStepsPerBatch → stop with 'max_steps_reached'
|
|
97
|
-
i. Continue to next Step
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Phase 3: Hook Execution (Prepare)
|
|
101
|
-
|
|
102
|
-
Before the LLM call, all `prepare` hooks for batched Steps execute in Step order. If any prepare hook fails, batch execution stops immediately.
|
|
103
|
-
|
|
104
|
-
### Phase 4: LLM Call
|
|
105
|
-
|
|
106
|
-
A single LLM call is made with a combined prompt that includes all Step prompts and collect fields.
|
|
107
|
-
|
|
108
|
-
### Phase 5: Data Collection
|
|
109
|
-
|
|
110
|
-
All `collect` fields from all Steps in the batch are extracted from the LLM response and validated against the agent schema.
|
|
111
|
-
|
|
112
|
-
### Phase 6: Hook Execution (Finalize)
|
|
113
|
-
|
|
114
|
-
After the LLM response, all `finalize` hooks execute in Step order. Finalize hook failures are logged but don't stop execution.
|
|
115
|
-
|
|
116
|
-
## Needs-Input Detection Algorithm
|
|
117
|
-
|
|
118
|
-
The `needsInput` function implements the core execution rule:
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
function needsInput<TData>(
|
|
122
|
-
step: Step<unknown, TData>,
|
|
123
|
-
sessionDataAfterPreExtraction: Partial<TData>
|
|
124
|
-
): boolean {
|
|
125
|
-
// Check requires - all must be present (after pre-extraction)
|
|
126
|
-
if (step.requires && step.requires.length > 0) {
|
|
127
|
-
const missingRequired = step.requires.some(
|
|
128
|
-
field => sessionDataAfterPreExtraction[field] === undefined
|
|
129
|
-
);
|
|
130
|
-
if (missingRequired) return true;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Check collect - needs input if collecting and no data exists (after pre-extraction)
|
|
134
|
-
if (step.collect && step.collect.length > 0) {
|
|
135
|
-
const hasAnyCollectData = step.collect.some(
|
|
136
|
-
field => sessionDataAfterPreExtraction[field] !== undefined
|
|
137
|
-
);
|
|
138
|
-
if (!hasAnyCollectData) return true;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
A Step **needs input** when:
|
|
146
|
-
|
|
147
|
-
1. It has `requires` fields and at least one is missing from session data (after pre-extraction)
|
|
148
|
-
2. It has non-empty `collect` fields and none of those fields have data (after pre-extraction)
|
|
149
|
-
|
|
150
|
-
## Pre-Extraction's Role in Batching
|
|
151
|
-
|
|
152
|
-
Pre-extraction is critical for maximizing batch size. Consider this scenario:
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
// Route with 3 steps
|
|
156
|
-
const route = agent.createRoute({
|
|
157
|
-
title: "Booking",
|
|
158
|
-
requiredFields: ["hotel", "date", "guests"],
|
|
159
|
-
steps: [
|
|
160
|
-
{ prompt: "Which hotel?", collect: ["hotel"] },
|
|
161
|
-
{ prompt: "What date?", collect: ["date"] },
|
|
162
|
-
{ prompt: "How many guests?", collect: ["guests"] }
|
|
163
|
-
]
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
// User message: "Book Grand Hotel for 2 people on Friday"
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
**Without pre-extraction:**
|
|
170
|
-
- Step 1 needs input (no hotel data) → batch stops
|
|
171
|
-
- 3 separate LLM calls needed
|
|
172
|
-
|
|
173
|
-
**With pre-extraction:**
|
|
174
|
-
- Pre-extraction captures: `{ hotel: "Grand Hotel", date: "Friday", guests: 2 }`
|
|
175
|
-
- All steps have their data satisfied
|
|
176
|
-
- All 3 steps execute in a single batch
|
|
177
|
-
- 1 LLM call needed
|
|
178
|
-
|
|
179
|
-
## Key Components
|
|
180
|
-
|
|
181
|
-
### BatchExecutor
|
|
182
|
-
|
|
183
|
-
The core component responsible for:
|
|
184
|
-
- Determining which Steps can execute together (`determineBatch`)
|
|
185
|
-
- Executing prepare/finalize hooks (`executePrepareHooks`, `executeFinalizeHooks`)
|
|
186
|
-
- Collecting data from LLM responses (`collectBatchData`)
|
|
187
|
-
- Orchestrating complete batch execution (`executeBatch`)
|
|
188
|
-
|
|
189
|
-
### BatchPromptBuilder
|
|
190
|
-
|
|
191
|
-
Combines multiple Step prompts into a single coherent prompt:
|
|
192
|
-
- Preserves each Step's individual prompt intent
|
|
193
|
-
- Includes data collection instructions for all `collect` fields
|
|
194
|
-
- Produces a single LLM call regardless of Step count
|
|
195
|
-
|
|
196
|
-
## Example: Multi-Step Batch
|
|
197
|
-
|
|
198
|
-
```typescript
|
|
199
|
-
// Enable batching to process multiple steps at once
|
|
200
|
-
const agent = new Agent({
|
|
201
|
-
name: "Booking Agent",
|
|
202
|
-
provider: provider,
|
|
203
|
-
maxStepsPerBatch: Infinity, // Enable full batching
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// User provides all booking info at once
|
|
207
|
-
const response = await agent.respond(
|
|
208
|
-
"I want to book the Grand Hotel for 2 people next Friday"
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
// Response includes:
|
|
212
|
-
{
|
|
213
|
-
message: "Perfect! I've booked the Grand Hotel for 2 guests on Friday.",
|
|
214
|
-
executedSteps: [
|
|
215
|
-
{ id: "ask-hotel", routeId: "booking" },
|
|
216
|
-
{ id: "ask-date", routeId: "booking" },
|
|
217
|
-
{ id: "ask-guests", routeId: "booking" }
|
|
218
|
-
],
|
|
219
|
-
stoppedReason: "route_complete",
|
|
220
|
-
session: {
|
|
221
|
-
data: {
|
|
222
|
-
hotel: "Grand Hotel",
|
|
223
|
-
date: "Friday",
|
|
224
|
-
guests: 2
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
## Debugging
|
|
231
|
-
|
|
232
|
-
Enable debug mode to see batch execution decisions:
|
|
233
|
-
|
|
234
|
-
```typescript
|
|
235
|
-
const agent = new Agent({
|
|
236
|
-
name: "Assistant",
|
|
237
|
-
provider: provider,
|
|
238
|
-
debug: true, // Enable detailed logging
|
|
239
|
-
maxStepsPerBatch: 5, // Allow up to 5 steps per batch
|
|
240
|
-
});
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
Look for these log messages:
|
|
244
|
-
|
|
245
|
-
```
|
|
246
|
-
[BatchExecutor] Starting batch determination from step index 0
|
|
247
|
-
[BatchExecutor] Including step ask-hotel in batch (all requirements satisfied)
|
|
248
|
-
[BatchExecutor] Including step ask-date in batch (all requirements satisfied)
|
|
249
|
-
[BatchExecutor] Step ask-guests needs input, stopping batch
|
|
250
|
-
[BatchExecutor] Batch determination complete. Steps: 2, Stopped reason: needs_input
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
## Event Emission
|
|
254
|
-
|
|
255
|
-
The BatchExecutor emits events for observability:
|
|
256
|
-
|
|
257
|
-
- `batch_start` - When batch determination begins
|
|
258
|
-
- `step_included` - When a step is included in the batch
|
|
259
|
-
- `step_skipped` - When a step is skipped (due to skipIf)
|
|
260
|
-
- `batch_stop` - When batch determination stops
|
|
261
|
-
- `batch_complete` - When batch execution completes
|
|
262
|
-
|
|
263
|
-
```typescript
|
|
264
|
-
const executor = new BatchExecutor();
|
|
265
|
-
|
|
266
|
-
executor.addEventListener((event) => {
|
|
267
|
-
console.log(`[${event.type}]`, event.details);
|
|
268
|
-
});
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
---
|
|
272
|
-
|
|
273
|
-
**Related Documentation:**
|
|
274
|
-
- [Steps](../core/conversation-flows/steps.md) - Step configuration and batching
|
|
275
|
-
- [Step Transitions](../core/conversation-flows/step-transitions.md) - Stopping conditions
|
|
276
|
-
- [Data Collection](../core/conversation-flows/data-collection.md) - Pre-extraction details
|
|
277
|
-
- [Prompt Composition](../core/ai-integration/prompt-composition.md) - Combined prompts
|