@falai/agent 3.4.5 → 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -34
- package/dist/cjs/core/Agent.d.ts +22 -378
- package/dist/cjs/core/Agent.d.ts.map +1 -1
- package/dist/cjs/core/Agent.js +104 -1178
- package/dist/cjs/core/Agent.js.map +1 -1
- package/dist/cjs/core/CompactionEngine.d.ts.map +1 -1
- package/dist/cjs/core/CompactionEngine.js +5 -3
- package/dist/cjs/core/CompactionEngine.js.map +1 -1
- package/dist/cjs/core/FlowSpec.d.ts +136 -0
- package/dist/cjs/core/FlowSpec.d.ts.map +1 -0
- package/dist/cjs/core/FlowSpec.js +522 -0
- package/dist/cjs/core/FlowSpec.js.map +1 -0
- package/dist/cjs/core/Migrate.d.ts +38 -0
- package/dist/cjs/core/Migrate.d.ts.map +1 -0
- package/dist/cjs/core/Migrate.js +270 -0
- package/dist/cjs/core/Migrate.js.map +1 -0
- package/dist/cjs/core/Prompt.d.ts +54 -0
- package/dist/cjs/core/Prompt.d.ts.map +1 -0
- package/dist/cjs/core/Prompt.js +143 -0
- package/dist/cjs/core/Prompt.js.map +1 -0
- package/dist/cjs/core/Runner.d.ts +160 -0
- package/dist/cjs/core/Runner.d.ts.map +1 -0
- package/dist/cjs/core/Runner.js +1131 -0
- package/dist/cjs/core/Runner.js.map +1 -0
- package/dist/cjs/core/Speak.d.ts +37 -0
- package/dist/cjs/core/Speak.d.ts.map +1 -0
- package/dist/cjs/core/Speak.js +364 -0
- package/dist/cjs/core/Speak.js.map +1 -0
- package/dist/cjs/core/Understand.d.ts +28 -0
- package/dist/cjs/core/Understand.d.ts.map +1 -0
- package/dist/cjs/core/Understand.js +353 -0
- package/dist/cjs/core/Understand.js.map +1 -0
- package/dist/cjs/core/contracts.d.ts +122 -0
- package/dist/cjs/core/contracts.d.ts.map +1 -0
- package/dist/cjs/core/contracts.js +11 -0
- package/dist/cjs/core/contracts.js.map +1 -0
- package/dist/cjs/core/falai.d.ts +57 -0
- package/dist/cjs/core/falai.d.ts.map +1 -0
- package/dist/cjs/core/falai.js +43 -0
- package/dist/cjs/core/falai.js.map +1 -0
- package/dist/cjs/core/predicate.d.ts +9 -0
- package/dist/cjs/core/predicate.d.ts.map +1 -0
- package/dist/cjs/core/predicate.js +58 -0
- package/dist/cjs/core/predicate.js.map +1 -0
- package/dist/cjs/index.d.ts +26 -31
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +46 -68
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/persistence/MemoryStore.d.ts +15 -0
- package/dist/cjs/persistence/MemoryStore.d.ts.map +1 -0
- package/dist/cjs/persistence/MemoryStore.js +39 -0
- package/dist/cjs/persistence/MemoryStore.js.map +1 -0
- package/dist/cjs/persistence/MongoStore.d.ts +42 -0
- package/dist/cjs/persistence/MongoStore.d.ts.map +1 -0
- package/dist/cjs/persistence/MongoStore.js +60 -0
- package/dist/cjs/persistence/MongoStore.js.map +1 -0
- package/dist/cjs/persistence/OpenSearchStore.d.ts +86 -0
- package/dist/cjs/persistence/OpenSearchStore.d.ts.map +1 -0
- package/dist/cjs/persistence/OpenSearchStore.js +120 -0
- package/dist/cjs/persistence/OpenSearchStore.js.map +1 -0
- package/dist/cjs/persistence/PostgresStore.d.ts +41 -0
- package/dist/cjs/persistence/PostgresStore.d.ts.map +1 -0
- package/dist/cjs/persistence/PostgresStore.js +58 -0
- package/dist/cjs/persistence/PostgresStore.js.map +1 -0
- package/dist/cjs/persistence/PrismaStore.d.ts +65 -0
- package/dist/cjs/persistence/PrismaStore.d.ts.map +1 -0
- package/dist/cjs/persistence/PrismaStore.js +95 -0
- package/dist/cjs/persistence/PrismaStore.js.map +1 -0
- package/dist/cjs/persistence/RedisStore.d.ts +34 -0
- package/dist/cjs/persistence/RedisStore.d.ts.map +1 -0
- package/dist/cjs/persistence/RedisStore.js +61 -0
- package/dist/cjs/persistence/RedisStore.js.map +1 -0
- package/dist/cjs/persistence/SQLiteStore.d.ts +45 -0
- package/dist/cjs/persistence/SQLiteStore.d.ts.map +1 -0
- package/dist/cjs/persistence/SQLiteStore.js +74 -0
- package/dist/cjs/persistence/SQLiteStore.js.map +1 -0
- package/dist/cjs/persistence/sessionRow.d.ts +14 -0
- package/dist/cjs/persistence/sessionRow.d.ts.map +1 -0
- package/dist/cjs/persistence/sessionRow.js +50 -0
- package/dist/cjs/persistence/sessionRow.js.map +1 -0
- package/dist/cjs/providers/DeepSeekProvider.d.ts.map +1 -1
- package/dist/cjs/providers/DeepSeekProvider.js +8 -3
- package/dist/cjs/providers/DeepSeekProvider.js.map +1 -1
- package/dist/cjs/providers/GeminiProvider.d.ts +4 -3
- package/dist/cjs/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/cjs/providers/GeminiProvider.js +4 -3
- package/dist/cjs/providers/GeminiProvider.js.map +1 -1
- package/dist/cjs/providers/OpenAICompatibleProvider.d.ts +4 -0
- package/dist/cjs/providers/OpenAICompatibleProvider.d.ts.map +1 -1
- package/dist/cjs/providers/OpenAICompatibleProvider.js +2 -0
- package/dist/cjs/providers/OpenAICompatibleProvider.js.map +1 -1
- package/dist/cjs/providers/OpenRouterProvider.d.ts.map +1 -1
- package/dist/cjs/providers/OpenRouterProvider.js +2 -4
- package/dist/cjs/providers/OpenRouterProvider.js.map +1 -1
- package/dist/cjs/providers/ProviderAdapter.d.ts +1 -1
- package/dist/cjs/providers/ProviderAdapter.d.ts.map +1 -1
- package/dist/cjs/providers/ProviderAdapter.js +33 -10
- package/dist/cjs/providers/ProviderAdapter.js.map +1 -1
- package/dist/cjs/types/agent.d.ts +153 -383
- package/dist/cjs/types/agent.d.ts.map +1 -1
- package/dist/cjs/types/agent.js +1 -1
- package/dist/cjs/types/ai.d.ts +32 -1
- package/dist/cjs/types/ai.d.ts.map +1 -1
- package/dist/cjs/types/compaction.d.ts +3 -1
- package/dist/cjs/types/compaction.d.ts.map +1 -1
- package/dist/cjs/types/errors.d.ts +9 -12
- package/dist/cjs/types/errors.d.ts.map +1 -1
- package/dist/cjs/types/errors.js +14 -17
- package/dist/cjs/types/errors.js.map +1 -1
- package/dist/cjs/types/flow.d.ts +265 -513
- package/dist/cjs/types/flow.d.ts.map +1 -1
- package/dist/cjs/types/flow.js +7 -1
- package/dist/cjs/types/flow.js.map +1 -1
- package/dist/cjs/types/history.d.ts +7 -18
- package/dist/cjs/types/history.d.ts.map +1 -1
- package/dist/cjs/types/history.js.map +1 -1
- package/dist/cjs/types/index.d.ts +9 -15
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +4 -14
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/session.d.ts +94 -64
- package/dist/cjs/types/session.d.ts.map +1 -1
- package/dist/cjs/types/session.js +5 -1
- package/dist/cjs/types/session.js.map +1 -1
- package/dist/cjs/types/tool.d.ts +37 -207
- package/dist/cjs/types/tool.d.ts.map +1 -1
- package/dist/cjs/types/tool.js +5 -14
- package/dist/cjs/types/tool.js.map +1 -1
- package/dist/cjs/utils/clock.d.ts +28 -0
- package/dist/cjs/utils/clock.d.ts.map +1 -0
- package/dist/cjs/utils/clock.js +64 -0
- package/dist/cjs/utils/clock.js.map +1 -0
- package/dist/cjs/utils/duration.d.ts +11 -0
- package/dist/cjs/utils/duration.d.ts.map +1 -0
- package/dist/cjs/utils/duration.js +31 -0
- package/dist/cjs/utils/duration.js.map +1 -0
- package/dist/cjs/utils/history.d.ts +4 -1
- package/dist/cjs/utils/history.d.ts.map +1 -1
- package/dist/cjs/utils/history.js +2 -2
- package/dist/cjs/utils/history.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +4 -10
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +14 -61
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/json.d.ts +2 -0
- package/dist/cjs/utils/json.d.ts.map +1 -1
- package/dist/cjs/utils/json.js +5 -0
- package/dist/cjs/utils/json.js.map +1 -1
- package/dist/cjs/utils/outcomes.d.ts +48 -0
- package/dist/cjs/utils/outcomes.d.ts.map +1 -0
- package/dist/cjs/utils/outcomes.js +51 -0
- package/dist/cjs/utils/outcomes.js.map +1 -0
- package/dist/cjs/utils/schema.d.ts +50 -0
- package/dist/cjs/utils/schema.d.ts.map +1 -0
- package/dist/cjs/utils/schema.js +138 -0
- package/dist/cjs/utils/schema.js.map +1 -0
- package/dist/cjs/utils/streamingMessage.d.ts +3 -2
- package/dist/cjs/utils/streamingMessage.d.ts.map +1 -1
- package/dist/cjs/utils/streamingMessage.js +38 -4
- package/dist/cjs/utils/streamingMessage.js.map +1 -1
- package/dist/cjs/utils/template.d.ts +13 -149
- package/dist/cjs/utils/template.d.ts.map +1 -1
- package/dist/cjs/utils/template.js +31 -363
- package/dist/cjs/utils/template.js.map +1 -1
- package/dist/cjs/utils/usage.d.ts +19 -0
- package/dist/cjs/utils/usage.d.ts.map +1 -0
- package/dist/cjs/utils/usage.js +35 -0
- package/dist/cjs/utils/usage.js.map +1 -0
- package/dist/core/Agent.d.ts +22 -378
- package/dist/core/Agent.d.ts.map +1 -1
- package/dist/core/Agent.js +107 -1181
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/CompactionEngine.d.ts.map +1 -1
- package/dist/core/CompactionEngine.js +5 -3
- package/dist/core/CompactionEngine.js.map +1 -1
- package/dist/core/FlowSpec.d.ts +136 -0
- package/dist/core/FlowSpec.d.ts.map +1 -0
- package/dist/core/FlowSpec.js +516 -0
- package/dist/core/FlowSpec.js.map +1 -0
- package/dist/core/Migrate.d.ts +38 -0
- package/dist/core/Migrate.d.ts.map +1 -0
- package/dist/core/Migrate.js +264 -0
- package/dist/core/Migrate.js.map +1 -0
- package/dist/core/Prompt.d.ts +54 -0
- package/dist/core/Prompt.d.ts.map +1 -0
- package/dist/core/Prompt.js +133 -0
- package/dist/core/Prompt.js.map +1 -0
- package/dist/core/Runner.d.ts +160 -0
- package/dist/core/Runner.d.ts.map +1 -0
- package/dist/core/Runner.js +1127 -0
- package/dist/core/Runner.js.map +1 -0
- package/dist/core/Speak.d.ts +37 -0
- package/dist/core/Speak.d.ts.map +1 -0
- package/dist/core/Speak.js +360 -0
- package/dist/core/Speak.js.map +1 -0
- package/dist/core/Understand.d.ts +28 -0
- package/dist/core/Understand.d.ts.map +1 -0
- package/dist/core/Understand.js +349 -0
- package/dist/core/Understand.js.map +1 -0
- package/dist/core/contracts.d.ts +122 -0
- package/dist/core/contracts.d.ts.map +1 -0
- package/dist/core/contracts.js +10 -0
- package/dist/core/contracts.js.map +1 -0
- package/dist/core/falai.d.ts +57 -0
- package/dist/core/falai.d.ts.map +1 -0
- package/dist/core/falai.js +40 -0
- package/dist/core/falai.js.map +1 -0
- package/dist/core/predicate.d.ts +9 -0
- package/dist/core/predicate.d.ts.map +1 -0
- package/dist/core/predicate.js +54 -0
- package/dist/core/predicate.js.map +1 -0
- package/dist/index.d.ts +26 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -24
- package/dist/index.js.map +1 -1
- package/dist/persistence/MemoryStore.d.ts +15 -0
- package/dist/persistence/MemoryStore.d.ts.map +1 -0
- package/dist/persistence/MemoryStore.js +35 -0
- package/dist/persistence/MemoryStore.js.map +1 -0
- package/dist/persistence/MongoStore.d.ts +42 -0
- package/dist/persistence/MongoStore.d.ts.map +1 -0
- package/dist/persistence/MongoStore.js +56 -0
- package/dist/persistence/MongoStore.js.map +1 -0
- package/dist/persistence/OpenSearchStore.d.ts +86 -0
- package/dist/persistence/OpenSearchStore.d.ts.map +1 -0
- package/dist/persistence/OpenSearchStore.js +116 -0
- package/dist/persistence/OpenSearchStore.js.map +1 -0
- package/dist/persistence/PostgresStore.d.ts +41 -0
- package/dist/persistence/PostgresStore.d.ts.map +1 -0
- package/dist/persistence/PostgresStore.js +54 -0
- package/dist/persistence/PostgresStore.js.map +1 -0
- package/dist/persistence/PrismaStore.d.ts +65 -0
- package/dist/persistence/PrismaStore.d.ts.map +1 -0
- package/dist/persistence/PrismaStore.js +91 -0
- package/dist/persistence/PrismaStore.js.map +1 -0
- package/dist/persistence/RedisStore.d.ts +34 -0
- package/dist/persistence/RedisStore.d.ts.map +1 -0
- package/dist/persistence/RedisStore.js +57 -0
- package/dist/persistence/RedisStore.js.map +1 -0
- package/dist/persistence/SQLiteStore.d.ts +45 -0
- package/dist/persistence/SQLiteStore.d.ts.map +1 -0
- package/dist/persistence/SQLiteStore.js +70 -0
- package/dist/persistence/SQLiteStore.js.map +1 -0
- package/dist/persistence/sessionRow.d.ts +14 -0
- package/dist/persistence/sessionRow.d.ts.map +1 -0
- package/dist/persistence/sessionRow.js +45 -0
- package/dist/persistence/sessionRow.js.map +1 -0
- package/dist/providers/DeepSeekProvider.d.ts.map +1 -1
- package/dist/providers/DeepSeekProvider.js +8 -3
- package/dist/providers/DeepSeekProvider.js.map +1 -1
- package/dist/providers/GeminiProvider.d.ts +4 -3
- package/dist/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/GeminiProvider.js +4 -3
- package/dist/providers/GeminiProvider.js.map +1 -1
- package/dist/providers/OpenAICompatibleProvider.d.ts +4 -0
- package/dist/providers/OpenAICompatibleProvider.d.ts.map +1 -1
- package/dist/providers/OpenAICompatibleProvider.js +2 -0
- package/dist/providers/OpenAICompatibleProvider.js.map +1 -1
- package/dist/providers/OpenRouterProvider.d.ts.map +1 -1
- package/dist/providers/OpenRouterProvider.js +2 -4
- package/dist/providers/OpenRouterProvider.js.map +1 -1
- package/dist/providers/ProviderAdapter.d.ts +1 -1
- package/dist/providers/ProviderAdapter.d.ts.map +1 -1
- package/dist/providers/ProviderAdapter.js +34 -11
- package/dist/providers/ProviderAdapter.js.map +1 -1
- package/dist/types/agent.d.ts +153 -383
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/agent.js +1 -1
- package/dist/types/ai.d.ts +32 -1
- package/dist/types/ai.d.ts.map +1 -1
- package/dist/types/compaction.d.ts +3 -1
- package/dist/types/compaction.d.ts.map +1 -1
- package/dist/types/errors.d.ts +9 -12
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +12 -15
- package/dist/types/errors.js.map +1 -1
- package/dist/types/flow.d.ts +265 -513
- package/dist/types/flow.d.ts.map +1 -1
- package/dist/types/flow.js +7 -1
- package/dist/types/flow.js.map +1 -1
- package/dist/types/history.d.ts +7 -18
- package/dist/types/history.d.ts.map +1 -1
- package/dist/types/history.js.map +1 -1
- package/dist/types/index.d.ts +9 -15
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -7
- package/dist/types/index.js.map +1 -1
- package/dist/types/session.d.ts +94 -64
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types/session.js +5 -1
- package/dist/types/session.js.map +1 -1
- package/dist/types/tool.d.ts +37 -207
- package/dist/types/tool.d.ts.map +1 -1
- package/dist/types/tool.js +6 -13
- package/dist/types/tool.js.map +1 -1
- package/dist/utils/clock.d.ts +28 -0
- package/dist/utils/clock.d.ts.map +1 -0
- package/dist/utils/clock.js +59 -0
- package/dist/utils/clock.js.map +1 -0
- package/dist/utils/duration.d.ts +11 -0
- package/dist/utils/duration.d.ts.map +1 -0
- package/dist/utils/duration.js +26 -0
- package/dist/utils/duration.js.map +1 -0
- package/dist/utils/history.d.ts +4 -1
- package/dist/utils/history.d.ts.map +1 -1
- package/dist/utils/history.js +2 -2
- package/dist/utils/history.js.map +1 -1
- package/dist/utils/index.d.ts +4 -10
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -21
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/json.d.ts +2 -0
- package/dist/utils/json.d.ts.map +1 -1
- package/dist/utils/json.js +4 -0
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/outcomes.d.ts +48 -0
- package/dist/utils/outcomes.d.ts.map +1 -0
- package/dist/utils/outcomes.js +48 -0
- package/dist/utils/outcomes.js.map +1 -0
- package/dist/utils/schema.d.ts +50 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/schema.js +129 -0
- package/dist/utils/schema.js.map +1 -0
- package/dist/utils/streamingMessage.d.ts +3 -2
- package/dist/utils/streamingMessage.d.ts.map +1 -1
- package/dist/utils/streamingMessage.js +38 -4
- package/dist/utils/streamingMessage.js.map +1 -1
- package/dist/utils/template.d.ts +13 -149
- package/dist/utils/template.d.ts.map +1 -1
- package/dist/utils/template.js +28 -355
- package/dist/utils/template.js.map +1 -1
- package/dist/utils/usage.d.ts +19 -0
- package/dist/utils/usage.d.ts.map +1 -0
- package/dist/utils/usage.js +31 -0
- package/dist/utils/usage.js.map +1 -0
- package/docs/README.md +37 -19
- package/docs/concepts/architecture.md +117 -239
- package/docs/concepts/collection.md +170 -0
- package/docs/concepts/pipeline.md +132 -378
- package/docs/concepts/runs-and-waits.md +192 -0
- package/docs/guides/actions-and-events.md +276 -0
- package/docs/guides/branching.md +119 -208
- package/docs/guides/compaction.md +63 -158
- package/docs/guides/conditions.md +164 -128
- package/docs/guides/error-handling.md +168 -164
- package/docs/guides/flow-control.md +210 -349
- package/docs/guides/flows-from-json.md +224 -0
- package/docs/guides/instructions.md +125 -161
- package/docs/guides/persistence.md +182 -206
- package/docs/guides/streaming.md +50 -114
- package/docs/guides/testing.md +284 -0
- package/docs/guides/triggers.md +401 -0
- package/docs/migration/README.md +8 -15
- package/docs/migration/v1-to-v2.md +1 -1
- package/docs/migration/v2-3-to-v2-4.md +2 -2
- package/docs/migration/v2-6-to-v2-7.md +4 -4
- package/docs/migration/v3-to-v4.md +452 -0
- package/docs/reference/actions-events-conditions.md +396 -0
- package/docs/reference/agent.md +244 -0
- package/docs/reference/branches.md +75 -203
- package/docs/reference/errors.md +188 -144
- package/docs/reference/fields.md +125 -0
- package/docs/reference/flow-spec.md +248 -0
- package/docs/reference/flow.md +104 -192
- package/docs/reference/instruction.md +83 -137
- package/docs/reference/outcomes.md +273 -0
- package/docs/reference/providers.md +525 -302
- package/docs/reference/session.md +210 -0
- package/docs/reference/step.md +194 -312
- package/docs/reference/stores.md +496 -0
- package/docs/reference/tool.md +162 -231
- package/docs/reference/trigger.md +180 -0
- package/docs/rfc/v4-one-flow.md +477 -0
- package/docs/start/01-install.md +59 -44
- package/docs/start/02-first-agent.md +97 -147
- package/docs/start/03-collect-data.md +78 -183
- package/docs/start/04-add-tools.md +159 -227
- package/docs/start/05-go-to-production.md +167 -164
- package/examples/01-quickstart.ts +26 -16
- package/examples/02-fields.ts +75 -0
- package/examples/03-tools.ts +79 -119
- package/examples/04-instructions.ts +60 -87
- package/examples/05-branches.ts +78 -0
- package/examples/06-triggers-and-waits.ts +148 -0
- package/examples/07-streaming.ts +34 -60
- package/examples/08-store-and-migration.ts +97 -0
- package/examples/09-flows-from-json.ts +107 -0
- package/package.json +9 -6
- package/src/core/Agent.ts +116 -1512
- package/src/core/CompactionEngine.ts +7 -4
- package/src/core/FlowSpec.ts +712 -0
- package/src/core/Migrate.ts +256 -0
- package/src/core/Prompt.ts +156 -0
- package/src/core/Runner.ts +1181 -0
- package/src/core/Speak.ts +451 -0
- package/src/core/Understand.ts +422 -0
- package/src/core/contracts.ts +111 -0
- package/src/core/falai.ts +86 -0
- package/src/core/predicate.ts +56 -0
- package/src/index.ts +119 -147
- package/src/persistence/MemoryStore.ts +37 -0
- package/src/persistence/MongoStore.ts +89 -0
- package/src/persistence/OpenSearchStore.ts +153 -0
- package/src/persistence/PostgresStore.ts +89 -0
- package/src/persistence/PrismaStore.ts +127 -0
- package/src/persistence/RedisStore.ts +90 -0
- package/src/persistence/SQLiteStore.ts +103 -0
- package/src/persistence/sessionRow.ts +45 -0
- package/src/providers/DeepSeekProvider.ts +8 -3
- package/src/providers/GeminiProvider.ts +4 -3
- package/src/providers/OpenAICompatibleProvider.ts +6 -0
- package/src/providers/OpenRouterProvider.ts +2 -4
- package/src/providers/ProviderAdapter.ts +36 -8
- package/src/types/agent.ts +124 -397
- package/src/types/ai.ts +33 -1
- package/src/types/compaction.ts +3 -1
- package/src/types/errors.ts +13 -16
- package/src/types/flow.ts +249 -550
- package/src/types/history.ts +7 -20
- package/src/types/index.ts +87 -139
- package/src/types/session.ts +135 -70
- package/src/types/tool.ts +42 -267
- package/src/utils/clock.ts +70 -0
- package/src/utils/duration.ts +33 -0
- package/src/utils/history.ts +3 -2
- package/src/utils/index.ts +8 -66
- package/src/utils/json.ts +5 -0
- package/src/utils/outcomes.ts +56 -0
- package/src/utils/schema.ts +145 -0
- package/src/utils/streamingMessage.ts +34 -4
- package/src/utils/template.ts +32 -423
- package/src/utils/usage.ts +37 -0
- package/dist/adapters/MemoryAdapter.d.ts +0 -47
- package/dist/adapters/MemoryAdapter.d.ts.map +0 -1
- package/dist/adapters/MemoryAdapter.js +0 -204
- package/dist/adapters/MemoryAdapter.js.map +0 -1
- package/dist/adapters/MongoAdapter.d.ts +0 -97
- package/dist/adapters/MongoAdapter.d.ts.map +0 -1
- package/dist/adapters/MongoAdapter.js +0 -196
- package/dist/adapters/MongoAdapter.js.map +0 -1
- package/dist/adapters/OpenSearchAdapter.d.ts +0 -169
- package/dist/adapters/OpenSearchAdapter.d.ts.map +0 -1
- package/dist/adapters/OpenSearchAdapter.js +0 -471
- package/dist/adapters/OpenSearchAdapter.js.map +0 -1
- package/dist/adapters/PostgreSQLAdapter.d.ts +0 -85
- package/dist/adapters/PostgreSQLAdapter.d.ts.map +0 -1
- package/dist/adapters/PostgreSQLAdapter.js +0 -308
- package/dist/adapters/PostgreSQLAdapter.js.map +0 -1
- package/dist/adapters/PrismaAdapter.d.ts +0 -115
- package/dist/adapters/PrismaAdapter.d.ts.map +0 -1
- package/dist/adapters/PrismaAdapter.js +0 -406
- package/dist/adapters/PrismaAdapter.js.map +0 -1
- package/dist/adapters/RedisAdapter.d.ts +0 -72
- package/dist/adapters/RedisAdapter.d.ts.map +0 -1
- package/dist/adapters/RedisAdapter.js +0 -286
- package/dist/adapters/RedisAdapter.js.map +0 -1
- package/dist/adapters/SQLiteAdapter.d.ts +0 -86
- package/dist/adapters/SQLiteAdapter.d.ts.map +0 -1
- package/dist/adapters/SQLiteAdapter.js +0 -337
- package/dist/adapters/SQLiteAdapter.js.map +0 -1
- package/dist/adapters/index.d.ts +0 -17
- package/dist/adapters/index.d.ts.map +0 -1
- package/dist/adapters/index.js +0 -11
- package/dist/adapters/index.js.map +0 -1
- package/dist/adapters/sessionRow.d.ts +0 -22
- package/dist/adapters/sessionRow.d.ts.map +0 -1
- package/dist/adapters/sessionRow.js +0 -48
- package/dist/adapters/sessionRow.js.map +0 -1
- package/dist/cjs/adapters/MemoryAdapter.d.ts +0 -47
- package/dist/cjs/adapters/MemoryAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/MemoryAdapter.js +0 -208
- package/dist/cjs/adapters/MemoryAdapter.js.map +0 -1
- package/dist/cjs/adapters/MongoAdapter.d.ts +0 -97
- package/dist/cjs/adapters/MongoAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/MongoAdapter.js +0 -200
- package/dist/cjs/adapters/MongoAdapter.js.map +0 -1
- package/dist/cjs/adapters/OpenSearchAdapter.d.ts +0 -169
- package/dist/cjs/adapters/OpenSearchAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/OpenSearchAdapter.js +0 -475
- package/dist/cjs/adapters/OpenSearchAdapter.js.map +0 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.d.ts +0 -85
- package/dist/cjs/adapters/PostgreSQLAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.js +0 -312
- package/dist/cjs/adapters/PostgreSQLAdapter.js.map +0 -1
- package/dist/cjs/adapters/PrismaAdapter.d.ts +0 -115
- package/dist/cjs/adapters/PrismaAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/PrismaAdapter.js +0 -410
- package/dist/cjs/adapters/PrismaAdapter.js.map +0 -1
- package/dist/cjs/adapters/RedisAdapter.d.ts +0 -72
- package/dist/cjs/adapters/RedisAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/RedisAdapter.js +0 -290
- package/dist/cjs/adapters/RedisAdapter.js.map +0 -1
- package/dist/cjs/adapters/SQLiteAdapter.d.ts +0 -86
- package/dist/cjs/adapters/SQLiteAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/SQLiteAdapter.js +0 -341
- package/dist/cjs/adapters/SQLiteAdapter.js.map +0 -1
- package/dist/cjs/adapters/index.d.ts +0 -17
- package/dist/cjs/adapters/index.d.ts.map +0 -1
- package/dist/cjs/adapters/index.js +0 -21
- package/dist/cjs/adapters/index.js.map +0 -1
- package/dist/cjs/adapters/sessionRow.d.ts +0 -22
- package/dist/cjs/adapters/sessionRow.d.ts.map +0 -1
- package/dist/cjs/adapters/sessionRow.js +0 -52
- package/dist/cjs/adapters/sessionRow.js.map +0 -1
- package/dist/cjs/constants/index.d.ts +0 -1
- package/dist/cjs/constants/index.d.ts.map +0 -1
- package/dist/cjs/constants/index.js +0 -4
- package/dist/cjs/constants/index.js.map +0 -1
- package/dist/cjs/core/AutoChainExecutor.d.ts +0 -97
- package/dist/cjs/core/AutoChainExecutor.d.ts.map +0 -1
- package/dist/cjs/core/AutoChainExecutor.js +0 -288
- package/dist/cjs/core/AutoChainExecutor.js.map +0 -1
- package/dist/cjs/core/BranchEvaluator.d.ts +0 -55
- package/dist/cjs/core/BranchEvaluator.d.ts.map +0 -1
- package/dist/cjs/core/BranchEvaluator.js +0 -125
- package/dist/cjs/core/BranchEvaluator.js.map +0 -1
- package/dist/cjs/core/DirectiveChainTracker.d.ts +0 -49
- package/dist/cjs/core/DirectiveChainTracker.d.ts.map +0 -1
- package/dist/cjs/core/DirectiveChainTracker.js +0 -121
- package/dist/cjs/core/DirectiveChainTracker.js.map +0 -1
- package/dist/cjs/core/Events.d.ts +0 -26
- package/dist/cjs/core/Events.d.ts.map +0 -1
- package/dist/cjs/core/Events.js +0 -144
- package/dist/cjs/core/Events.js.map +0 -1
- package/dist/cjs/core/Flow.d.ts +0 -183
- package/dist/cjs/core/Flow.d.ts.map +0 -1
- package/dist/cjs/core/Flow.js +0 -551
- package/dist/cjs/core/Flow.js.map +0 -1
- package/dist/cjs/core/FlowRouter.d.ts +0 -183
- package/dist/cjs/core/FlowRouter.d.ts.map +0 -1
- package/dist/cjs/core/FlowRouter.js +0 -1047
- package/dist/cjs/core/FlowRouter.js.map +0 -1
- package/dist/cjs/core/PersistenceManager.d.ts +0 -114
- package/dist/cjs/core/PersistenceManager.d.ts.map +0 -1
- package/dist/cjs/core/PersistenceManager.js +0 -336
- package/dist/cjs/core/PersistenceManager.js.map +0 -1
- package/dist/cjs/core/PromptComposer.d.ts +0 -47
- package/dist/cjs/core/PromptComposer.d.ts.map +0 -1
- package/dist/cjs/core/PromptComposer.js +0 -397
- package/dist/cjs/core/PromptComposer.js.map +0 -1
- package/dist/cjs/core/PromptSectionCache.d.ts +0 -48
- package/dist/cjs/core/PromptSectionCache.d.ts.map +0 -1
- package/dist/cjs/core/PromptSectionCache.js +0 -108
- package/dist/cjs/core/PromptSectionCache.js.map +0 -1
- package/dist/cjs/core/ResponseEngine.d.ts +0 -43
- package/dist/cjs/core/ResponseEngine.d.ts.map +0 -1
- package/dist/cjs/core/ResponseEngine.js +0 -235
- package/dist/cjs/core/ResponseEngine.js.map +0 -1
- package/dist/cjs/core/ResponseGenerationError.d.ts +0 -30
- package/dist/cjs/core/ResponseGenerationError.d.ts.map +0 -1
- package/dist/cjs/core/ResponseGenerationError.js +0 -35
- package/dist/cjs/core/ResponseGenerationError.js.map +0 -1
- package/dist/cjs/core/ResponseModal.d.ts +0 -305
- package/dist/cjs/core/ResponseModal.d.ts.map +0 -1
- package/dist/cjs/core/ResponseModal.js +0 -1414
- package/dist/cjs/core/ResponseModal.js.map +0 -1
- package/dist/cjs/core/ResponsePipeline.d.ts +0 -220
- package/dist/cjs/core/ResponsePipeline.d.ts.map +0 -1
- package/dist/cjs/core/ResponsePipeline.js +0 -1040
- package/dist/cjs/core/ResponsePipeline.js.map +0 -1
- package/dist/cjs/core/SessionFinalizer.d.ts +0 -34
- package/dist/cjs/core/SessionFinalizer.d.ts.map +0 -1
- package/dist/cjs/core/SessionFinalizer.js +0 -88
- package/dist/cjs/core/SessionFinalizer.js.map +0 -1
- package/dist/cjs/core/SessionManager.d.ts +0 -112
- package/dist/cjs/core/SessionManager.d.ts.map +0 -1
- package/dist/cjs/core/SessionManager.js +0 -308
- package/dist/cjs/core/SessionManager.js.map +0 -1
- package/dist/cjs/core/SignalCoordinator.d.ts +0 -103
- package/dist/cjs/core/SignalCoordinator.d.ts.map +0 -1
- package/dist/cjs/core/SignalCoordinator.js +0 -207
- package/dist/cjs/core/SignalCoordinator.js.map +0 -1
- package/dist/cjs/core/SignalEvaluator.d.ts +0 -86
- package/dist/cjs/core/SignalEvaluator.d.ts.map +0 -1
- package/dist/cjs/core/SignalEvaluator.js +0 -319
- package/dist/cjs/core/SignalEvaluator.js.map +0 -1
- package/dist/cjs/core/SignalProcessor.d.ts +0 -152
- package/dist/cjs/core/SignalProcessor.d.ts.map +0 -1
- package/dist/cjs/core/SignalProcessor.js +0 -505
- package/dist/cjs/core/SignalProcessor.js.map +0 -1
- package/dist/cjs/core/Step.d.ts +0 -184
- package/dist/cjs/core/Step.d.ts.map +0 -1
- package/dist/cjs/core/Step.js +0 -599
- package/dist/cjs/core/Step.js.map +0 -1
- package/dist/cjs/core/StepLifecycle.d.ts +0 -43
- package/dist/cjs/core/StepLifecycle.d.ts.map +0 -1
- package/dist/cjs/core/StepLifecycle.js +0 -180
- package/dist/cjs/core/StepLifecycle.js.map +0 -1
- package/dist/cjs/core/StreamingToolExecutor.d.ts +0 -142
- package/dist/cjs/core/StreamingToolExecutor.d.ts.map +0 -1
- package/dist/cjs/core/StreamingToolExecutor.js +0 -490
- package/dist/cjs/core/StreamingToolExecutor.js.map +0 -1
- package/dist/cjs/core/ToolLoopExecutor.d.ts +0 -133
- package/dist/cjs/core/ToolLoopExecutor.d.ts.map +0 -1
- package/dist/cjs/core/ToolLoopExecutor.js +0 -568
- package/dist/cjs/core/ToolLoopExecutor.js.map +0 -1
- package/dist/cjs/core/ToolManager.d.ts +0 -250
- package/dist/cjs/core/ToolManager.d.ts.map +0 -1
- package/dist/cjs/core/ToolManager.js +0 -1104
- package/dist/cjs/core/ToolManager.js.map +0 -1
- package/dist/cjs/core/createAgent.d.ts +0 -35
- package/dist/cjs/core/createAgent.d.ts.map +0 -1
- package/dist/cjs/core/createAgent.js +0 -39
- package/dist/cjs/core/createAgent.js.map +0 -1
- package/dist/cjs/core/flow-namespace.d.ts +0 -64
- package/dist/cjs/core/flow-namespace.d.ts.map +0 -1
- package/dist/cjs/core/flow-namespace.js +0 -182
- package/dist/cjs/core/flow-namespace.js.map +0 -1
- package/dist/cjs/core/toolGates.d.ts +0 -24
- package/dist/cjs/core/toolGates.d.ts.map +0 -1
- package/dist/cjs/core/toolGates.js +0 -52
- package/dist/cjs/core/toolGates.js.map +0 -1
- package/dist/cjs/types/persistence.d.ts +0 -254
- package/dist/cjs/types/persistence.d.ts.map +0 -1
- package/dist/cjs/types/persistence.js +0 -7
- package/dist/cjs/types/persistence.js.map +0 -1
- package/dist/cjs/types/prompt-cache.d.ts +0 -15
- package/dist/cjs/types/prompt-cache.d.ts.map +0 -1
- package/dist/cjs/types/prompt-cache.js +0 -6
- package/dist/cjs/types/prompt-cache.js.map +0 -1
- package/dist/cjs/types/signals.d.ts +0 -263
- package/dist/cjs/types/signals.d.ts.map +0 -1
- package/dist/cjs/types/signals.js +0 -11
- package/dist/cjs/types/signals.js.map +0 -1
- package/dist/cjs/types/template.d.ts +0 -84
- package/dist/cjs/types/template.d.ts.map +0 -1
- package/dist/cjs/types/template.js +0 -3
- package/dist/cjs/types/template.js.map +0 -1
- package/dist/cjs/utils/condition.d.ts +0 -63
- package/dist/cjs/utils/condition.d.ts.map +0 -1
- package/dist/cjs/utils/condition.js +0 -239
- package/dist/cjs/utils/condition.js.map +0 -1
- package/dist/cjs/utils/event.d.ts +0 -6
- package/dist/cjs/utils/event.d.ts.map +0 -1
- package/dist/cjs/utils/event.js +0 -20
- package/dist/cjs/utils/event.js.map +0 -1
- package/dist/cjs/utils/id.d.ts +0 -33
- package/dist/cjs/utils/id.d.ts.map +0 -1
- package/dist/cjs/utils/id.js +0 -84
- package/dist/cjs/utils/id.js.map +0 -1
- package/dist/cjs/utils/serialize.d.ts +0 -36
- package/dist/cjs/utils/serialize.d.ts.map +0 -1
- package/dist/cjs/utils/serialize.js +0 -77
- package/dist/cjs/utils/serialize.js.map +0 -1
- package/dist/cjs/utils/session.d.ts +0 -124
- package/dist/cjs/utils/session.d.ts.map +0 -1
- package/dist/cjs/utils/session.js +0 -396
- package/dist/cjs/utils/session.js.map +0 -1
- package/dist/constants/index.d.ts +0 -2
- package/dist/constants/index.d.ts.map +0 -1
- package/dist/constants/index.js +0 -4
- package/dist/constants/index.js.map +0 -1
- package/dist/core/AutoChainExecutor.d.ts +0 -97
- package/dist/core/AutoChainExecutor.d.ts.map +0 -1
- package/dist/core/AutoChainExecutor.js +0 -284
- package/dist/core/AutoChainExecutor.js.map +0 -1
- package/dist/core/BranchEvaluator.d.ts +0 -55
- package/dist/core/BranchEvaluator.d.ts.map +0 -1
- package/dist/core/BranchEvaluator.js +0 -121
- package/dist/core/BranchEvaluator.js.map +0 -1
- package/dist/core/DirectiveChainTracker.d.ts +0 -49
- package/dist/core/DirectiveChainTracker.d.ts.map +0 -1
- package/dist/core/DirectiveChainTracker.js +0 -117
- package/dist/core/DirectiveChainTracker.js.map +0 -1
- package/dist/core/Events.d.ts +0 -26
- package/dist/core/Events.d.ts.map +0 -1
- package/dist/core/Events.js +0 -137
- package/dist/core/Events.js.map +0 -1
- package/dist/core/Flow.d.ts +0 -183
- package/dist/core/Flow.d.ts.map +0 -1
- package/dist/core/Flow.js +0 -547
- package/dist/core/Flow.js.map +0 -1
- package/dist/core/FlowRouter.d.ts +0 -183
- package/dist/core/FlowRouter.d.ts.map +0 -1
- package/dist/core/FlowRouter.js +0 -1043
- package/dist/core/FlowRouter.js.map +0 -1
- package/dist/core/PersistenceManager.d.ts +0 -114
- package/dist/core/PersistenceManager.d.ts.map +0 -1
- package/dist/core/PersistenceManager.js +0 -332
- package/dist/core/PersistenceManager.js.map +0 -1
- package/dist/core/PromptComposer.d.ts +0 -47
- package/dist/core/PromptComposer.d.ts.map +0 -1
- package/dist/core/PromptComposer.js +0 -393
- package/dist/core/PromptComposer.js.map +0 -1
- package/dist/core/PromptSectionCache.d.ts +0 -48
- package/dist/core/PromptSectionCache.d.ts.map +0 -1
- package/dist/core/PromptSectionCache.js +0 -104
- package/dist/core/PromptSectionCache.js.map +0 -1
- package/dist/core/ResponseEngine.d.ts +0 -43
- package/dist/core/ResponseEngine.d.ts.map +0 -1
- package/dist/core/ResponseEngine.js +0 -231
- package/dist/core/ResponseEngine.js.map +0 -1
- package/dist/core/ResponseGenerationError.d.ts +0 -30
- package/dist/core/ResponseGenerationError.d.ts.map +0 -1
- package/dist/core/ResponseGenerationError.js +0 -31
- package/dist/core/ResponseGenerationError.js.map +0 -1
- package/dist/core/ResponseModal.d.ts +0 -305
- package/dist/core/ResponseModal.d.ts.map +0 -1
- package/dist/core/ResponseModal.js +0 -1410
- package/dist/core/ResponseModal.js.map +0 -1
- package/dist/core/ResponsePipeline.d.ts +0 -220
- package/dist/core/ResponsePipeline.d.ts.map +0 -1
- package/dist/core/ResponsePipeline.js +0 -1035
- package/dist/core/ResponsePipeline.js.map +0 -1
- package/dist/core/SessionFinalizer.d.ts +0 -34
- package/dist/core/SessionFinalizer.d.ts.map +0 -1
- package/dist/core/SessionFinalizer.js +0 -84
- package/dist/core/SessionFinalizer.js.map +0 -1
- package/dist/core/SessionManager.d.ts +0 -112
- package/dist/core/SessionManager.d.ts.map +0 -1
- package/dist/core/SessionManager.js +0 -301
- package/dist/core/SessionManager.js.map +0 -1
- package/dist/core/SignalCoordinator.d.ts +0 -103
- package/dist/core/SignalCoordinator.d.ts.map +0 -1
- package/dist/core/SignalCoordinator.js +0 -203
- package/dist/core/SignalCoordinator.js.map +0 -1
- package/dist/core/SignalEvaluator.d.ts +0 -86
- package/dist/core/SignalEvaluator.d.ts.map +0 -1
- package/dist/core/SignalEvaluator.js +0 -312
- package/dist/core/SignalEvaluator.js.map +0 -1
- package/dist/core/SignalProcessor.d.ts +0 -152
- package/dist/core/SignalProcessor.d.ts.map +0 -1
- package/dist/core/SignalProcessor.js +0 -498
- package/dist/core/SignalProcessor.js.map +0 -1
- package/dist/core/Step.d.ts +0 -184
- package/dist/core/Step.d.ts.map +0 -1
- package/dist/core/Step.js +0 -594
- package/dist/core/Step.js.map +0 -1
- package/dist/core/StepLifecycle.d.ts +0 -43
- package/dist/core/StepLifecycle.d.ts.map +0 -1
- package/dist/core/StepLifecycle.js +0 -176
- package/dist/core/StepLifecycle.js.map +0 -1
- package/dist/core/StreamingToolExecutor.d.ts +0 -142
- package/dist/core/StreamingToolExecutor.d.ts.map +0 -1
- package/dist/core/StreamingToolExecutor.js +0 -483
- package/dist/core/StreamingToolExecutor.js.map +0 -1
- package/dist/core/ToolLoopExecutor.d.ts +0 -133
- package/dist/core/ToolLoopExecutor.d.ts.map +0 -1
- package/dist/core/ToolLoopExecutor.js +0 -564
- package/dist/core/ToolLoopExecutor.js.map +0 -1
- package/dist/core/ToolManager.d.ts +0 -250
- package/dist/core/ToolManager.d.ts.map +0 -1
- package/dist/core/ToolManager.js +0 -1098
- package/dist/core/ToolManager.js.map +0 -1
- package/dist/core/createAgent.d.ts +0 -35
- package/dist/core/createAgent.d.ts.map +0 -1
- package/dist/core/createAgent.js +0 -36
- package/dist/core/createAgent.js.map +0 -1
- package/dist/core/flow-namespace.d.ts +0 -64
- package/dist/core/flow-namespace.d.ts.map +0 -1
- package/dist/core/flow-namespace.js +0 -179
- package/dist/core/flow-namespace.js.map +0 -1
- package/dist/core/toolGates.d.ts +0 -24
- package/dist/core/toolGates.d.ts.map +0 -1
- package/dist/core/toolGates.js +0 -49
- package/dist/core/toolGates.js.map +0 -1
- package/dist/types/persistence.d.ts +0 -254
- package/dist/types/persistence.d.ts.map +0 -1
- package/dist/types/persistence.js +0 -6
- package/dist/types/persistence.js.map +0 -1
- package/dist/types/prompt-cache.d.ts +0 -15
- package/dist/types/prompt-cache.d.ts.map +0 -1
- package/dist/types/prompt-cache.js +0 -5
- package/dist/types/prompt-cache.js.map +0 -1
- package/dist/types/signals.d.ts +0 -263
- package/dist/types/signals.d.ts.map +0 -1
- package/dist/types/signals.js +0 -10
- package/dist/types/signals.js.map +0 -1
- package/dist/types/template.d.ts +0 -84
- package/dist/types/template.d.ts.map +0 -1
- package/dist/types/template.js +0 -2
- package/dist/types/template.js.map +0 -1
- package/dist/utils/condition.d.ts +0 -63
- package/dist/utils/condition.d.ts.map +0 -1
- package/dist/utils/condition.js +0 -230
- package/dist/utils/condition.js.map +0 -1
- package/dist/utils/event.d.ts +0 -6
- package/dist/utils/event.d.ts.map +0 -1
- package/dist/utils/event.js +0 -17
- package/dist/utils/event.js.map +0 -1
- package/dist/utils/id.d.ts +0 -33
- package/dist/utils/id.d.ts.map +0 -1
- package/dist/utils/id.js +0 -77
- package/dist/utils/id.js.map +0 -1
- package/dist/utils/serialize.d.ts +0 -36
- package/dist/utils/serialize.d.ts.map +0 -1
- package/dist/utils/serialize.js +0 -72
- package/dist/utils/serialize.js.map +0 -1
- package/dist/utils/session.d.ts +0 -124
- package/dist/utils/session.d.ts.map +0 -1
- package/dist/utils/session.js +0 -379
- package/dist/utils/session.js.map +0 -1
- package/docs/concepts/directives.md +0 -369
- package/docs/reference/adapters.md +0 -543
- package/docs/reference/create-agent.md +0 -216
- package/docs/reference/directive.md +0 -242
- package/docs/reference/signals.md +0 -368
- package/examples/02-data-extraction.ts +0 -90
- package/examples/05-branching.ts +0 -140
- package/examples/06-flow-control.ts +0 -103
- package/examples/08-persistence.ts +0 -98
- package/examples/09-signals.ts +0 -144
- package/src/adapters/MemoryAdapter.ts +0 -281
- package/src/adapters/MongoAdapter.ts +0 -341
- package/src/adapters/OpenSearchAdapter.ts +0 -693
- package/src/adapters/PostgreSQLAdapter.ts +0 -487
- package/src/adapters/PrismaAdapter.ts +0 -617
- package/src/adapters/RedisAdapter.ts +0 -439
- package/src/adapters/SQLiteAdapter.ts +0 -496
- package/src/adapters/index.ts +0 -43
- package/src/adapters/sessionRow.ts +0 -57
- package/src/constants/index.ts +0 -2
- package/src/core/AutoChainExecutor.ts +0 -397
- package/src/core/BranchEvaluator.ts +0 -161
- package/src/core/DirectiveChainTracker.ts +0 -144
- package/src/core/Events.ts +0 -164
- package/src/core/Flow.ts +0 -665
- package/src/core/FlowRouter.ts +0 -1540
- package/src/core/PersistenceManager.ts +0 -446
- package/src/core/PromptComposer.ts +0 -448
- package/src/core/PromptSectionCache.ts +0 -125
- package/src/core/ResponseEngine.ts +0 -338
- package/src/core/ResponseGenerationError.ts +0 -53
- package/src/core/ResponseModal.ts +0 -1902
- package/src/core/ResponsePipeline.ts +0 -1404
- package/src/core/SessionFinalizer.ts +0 -108
- package/src/core/SessionManager.ts +0 -372
- package/src/core/SignalCoordinator.ts +0 -263
- package/src/core/SignalEvaluator.ts +0 -404
- package/src/core/SignalProcessor.ts +0 -663
- package/src/core/Step.ts +0 -782
- package/src/core/StepLifecycle.ts +0 -242
- package/src/core/StreamingToolExecutor.ts +0 -609
- package/src/core/ToolLoopExecutor.ts +0 -749
- package/src/core/ToolManager.ts +0 -1379
- package/src/core/createAgent.ts +0 -40
- package/src/core/flow-namespace.ts +0 -227
- package/src/core/toolGates.ts +0 -72
- package/src/types/persistence.ts +0 -303
- package/src/types/prompt-cache.ts +0 -17
- package/src/types/signals.ts +0 -338
- package/src/types/template.ts +0 -98
- package/src/utils/condition.ts +0 -296
- package/src/utils/event.ts +0 -16
- package/src/utils/id.ts +0 -91
- package/src/utils/serialize.ts +0 -86
- package/src/utils/session.ts +0 -501
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Flow spec"
|
|
3
|
+
description: "A Flow as JSON: flat steps with a kind, predicates in JSON form, and the functions that convert, validate and describe it to a model."
|
|
4
|
+
type: reference
|
|
5
|
+
order: 12
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Flow spec
|
|
9
|
+
|
|
10
|
+
A `FlowSpec` is a `Flow` written as plain JSON: the same object, with each step carrying a `kind` and every predicate in its JSON form (`ConditionSpec`). No functions anywhere, so you can store it in a database row, edit it in a form, and let a model write one. Four functions work on it: `fromSpec` turns it into a `Flow`, `toSpec` goes the other way, `validateFlow` checks that it can run, and `flowSpecSchema` describes it to a model that writes one.
|
|
11
|
+
|
|
12
|
+
Source: `src/core/FlowSpec.ts`, `src/core/Agent.ts`.
|
|
13
|
+
|
|
14
|
+
## Signature
|
|
15
|
+
|
|
16
|
+
```ts fragment
|
|
17
|
+
type StepKind = "prompt" | "collect" | "say" | "do" | "wait" | "waitEvent" | "if";
|
|
18
|
+
|
|
19
|
+
interface FlowSpec {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
on?: TriggerSpec[];
|
|
24
|
+
anchor?: string;
|
|
25
|
+
while?: ConditionSpec;
|
|
26
|
+
clearOnStart?: string[];
|
|
27
|
+
steps: StepSpec[];
|
|
28
|
+
onEnd?: "end" | "stay" | "reset";
|
|
29
|
+
instructions?: InstructionSpec[];
|
|
30
|
+
tools?: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type StepSpec = StepBase &
|
|
34
|
+
(
|
|
35
|
+
| { kind: "prompt"; prompt: Template; ask?; maxAsks?; branches?: BranchSpec[]; tools?; instructions?: InstructionSpec[] }
|
|
36
|
+
| { kind: "collect"; collect: string[]; prompt?: Template; ask?; maxAsks?; branches?: BranchSpec[]; tools?; instructions?: InstructionSpec[] }
|
|
37
|
+
| { kind: "say"; say: Template; media?: { slug: string }; once?: boolean }
|
|
38
|
+
| { kind: "do"; do: string; with?: Record<string, unknown>; onFail?: Next }
|
|
39
|
+
| { kind: "wait"; wait: Duration; businessHours?: boolean; else?: Next; branches?: BranchSpec[] }
|
|
40
|
+
| { kind: "waitEvent"; wait: { event: string; upTo?: Duration }; else?: Next }
|
|
41
|
+
| { kind: "if"; if: ConditionSpec; else?: Next }
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
type TriggerSpec = { repeat?: Repeat } & (
|
|
45
|
+
| { message: string[]; if?: ConditionSpec }
|
|
46
|
+
| { mention: string[]; extract?: ParamDefs; if?: ConditionSpec }
|
|
47
|
+
| { silence: Duration; if?: ConditionSpec; businessHours?: boolean }
|
|
48
|
+
| { event: string; if?: ConditionSpec; after?: Duration; businessHours?: boolean }
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
type BranchSpec = { then: Next } & ({ when: string } | { if: ConditionSpec });
|
|
52
|
+
|
|
53
|
+
type InstructionSpec = Omit<Instruction, "if"> & { if?: ConditionSpec };
|
|
54
|
+
|
|
55
|
+
/** What a flow's names resolve against. */
|
|
56
|
+
type Registries = Pick<AgentOptions, "fields" | "actions" | "events" | "conditions" | "tools">;
|
|
57
|
+
|
|
58
|
+
function fromSpec<C = unknown, D = InferData<FieldDefs>>(spec: FlowSpec): Flow<C, D>;
|
|
59
|
+
function toSpec<C, D>(flow: Flow<C, D>): FlowSpec;
|
|
60
|
+
function validateFlow<C, D>(input: Flow<C, D> | FlowSpec, registries: Registries): { warnings: string[] };
|
|
61
|
+
function flowSpecSchema(registries: Registries): StructuredSchema;
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`f.fromSpec(spec)` is `fromSpec` with the toolkit's `C` and `D` filled in.
|
|
65
|
+
|
|
66
|
+
## FlowSpec fields
|
|
67
|
+
|
|
68
|
+
Every field means what it means on [Flow](./flow.md). The differences:
|
|
69
|
+
|
|
70
|
+
| Field | Spec type | Difference from `Flow` |
|
|
71
|
+
|---|---|---|
|
|
72
|
+
| `steps` | `StepSpec[]` | Each step carries `kind`. |
|
|
73
|
+
| `while` | `ConditionSpec` | JSON form only. |
|
|
74
|
+
| `on[].if` | `ConditionSpec` | JSON form only. |
|
|
75
|
+
| `instructions[].if` | `ConditionSpec` | JSON form only. |
|
|
76
|
+
| `steps[].branches[].if` | `ConditionSpec` | JSON form only. |
|
|
77
|
+
| `steps[].if` | `ConditionSpec` | JSON form only. |
|
|
78
|
+
| any optional field | may be `null` | `null` means "not set" on the way in; `fromSpec` drops it. |
|
|
79
|
+
|
|
80
|
+
## StepKind
|
|
81
|
+
|
|
82
|
+
| `kind` | Flow step | Rule |
|
|
83
|
+
|---|---|---|
|
|
84
|
+
| `prompt` | talk step with `prompt` alone | A guideline, nothing to collect. |
|
|
85
|
+
| `collect` | talk step with `collect` | Has a `collect` list, with or without a `prompt`. |
|
|
86
|
+
| `say` | `say` step | A fixed text. |
|
|
87
|
+
| `do` | `do` step | A host action. |
|
|
88
|
+
| `wait` | `wait: '5m'` | A duration. |
|
|
89
|
+
| `waitEvent` | `wait: { event }` | An event. |
|
|
90
|
+
| `if` | `if` step | A code fork. |
|
|
91
|
+
|
|
92
|
+
`fromSpec` drops `kind`; `toSpec` derives it from the step's shape by this table. A talk step with neither `prompt` nor `collect` makes `toSpec` throw.
|
|
93
|
+
|
|
94
|
+
## fromSpec
|
|
95
|
+
|
|
96
|
+
- Strips `null` from every optional value, at any depth.
|
|
97
|
+
- Removes `kind` from each step. Nothing else changes.
|
|
98
|
+
- Throws `FlowConfigurationError` when `steps` is not a list: `[FlowConfigurationError] flow "x": has no steps list. Write steps as a list, even an empty one.`
|
|
99
|
+
- Does **not** check names. The result is typed as a `Flow` but nothing is verified yet; `validateFlow` does that, and the agent runs it on every flow it is built with.
|
|
100
|
+
|
|
101
|
+
## toSpec
|
|
102
|
+
|
|
103
|
+
- Never writes `null` or `undefined`; a field that was not set is absent.
|
|
104
|
+
- Throws `FlowConfigurationError` on a function predicate anywhere (`while`, a trigger `if`, an instruction `if`, a branch `if`, an `if` step): `[FlowConfigurationError] flow "x", step "y" if: is a function, which cannot be stored as JSON. Write it as a condition ({ equals }, { known }, { silenced } or a named condition) to store this flow.`
|
|
105
|
+
- `toSpec(fromSpec(spec))` is `spec` with its `null`s dropped, and `spec` itself when it had none.
|
|
106
|
+
|
|
107
|
+
## validateFlow
|
|
108
|
+
|
|
109
|
+
`validateFlow(input, registries)` accepts a typed `Flow` or a `FlowSpec`. It throws `FlowConfigurationError` on the first problem that would break at run time and returns `{ warnings }` for what runs but probably not as you meant. The agent constructor calls it on every flow and logs each warning through the logger with an `[Agent]` prefix.
|
|
110
|
+
|
|
111
|
+
Every message has the form `[FlowConfigurationError] <where>: <what>. <fix>`, where `<where>` is `flow` (no id yet), `flow "id"`, `flow "id", trigger #n`, `flow "id", step #n` (step n has no id) or `flow "id", step "sid"`.
|
|
112
|
+
|
|
113
|
+
### Errors
|
|
114
|
+
|
|
115
|
+
| Family | Example of `<what>` | Fix in the message |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| No flow id | `has no id` | Give the flow a short unique id. |
|
|
118
|
+
| Steps missing | `has no steps list` | Write steps as a list, even an empty one. |
|
|
119
|
+
| Step without id | `has no id` (`<where>` is `flow "id", step #2`) | Give every step a unique id. |
|
|
120
|
+
| Reserved step id | `uses the reserved id "end"` | "end" ends the run; pick another id. |
|
|
121
|
+
| Duplicate step id | `duplicates an earlier step id` | Give each step its own id. |
|
|
122
|
+
| Triggers, no steps | `has triggers but no steps` | Add at least one step or remove `on`. |
|
|
123
|
+
| Unknown field | `unknown field "x" in collect` (also `ask`, `clearOnStart`, `then.clear`, `while.equals`, `if.known`, …) | Add it to the agent's fields or fix the slug. |
|
|
124
|
+
| Unknown tool | `unknown tool "x"` (flow or step `tools`) | Register it in the agent's tools or fix the name. |
|
|
125
|
+
| Unknown action | `unknown action "x"` | Register it in actions or fix the name. |
|
|
126
|
+
| Unknown event | `unknown event "x"` (trigger) or `unknown event "x" in wait` | Register it in events or fix the name. |
|
|
127
|
+
| Unknown condition | `unknown condition "x" in if` | Register it in conditions or use equals, known, silenced. |
|
|
128
|
+
| `equals` shape | `if.equals is not an object` | Write equals as { field: value }. |
|
|
129
|
+
| `equals` type | `if.equals gives "orcamento" a string, but the field is a number` | Write a number; values are not coerced. |
|
|
130
|
+
| `known` shape | `if.known is not a list` | Write known as [field, ...]. |
|
|
131
|
+
| `silenced` shape | `if.silenced is not a boolean` | Write true or false. |
|
|
132
|
+
| Bad duration | `wait has duration "5 min", which does not parse` (also `silence`, `after`, `repeat.cooldown`, `wait.upTo`) | Write a number and a unit: "30s", "5m", "24h" or "3d". |
|
|
133
|
+
| Dangling jump | `then points at step "x", which does not exist` (also `else`, `onFail`, `branches[n].then`) | Use an existing step id or "end". |
|
|
134
|
+
| Missing parameter | `action "notify" needs parameter "message"` | Add it to `with`. |
|
|
135
|
+
| Wrong parameter type | `parameter "tags" of action "add_tags" must be a list of string, got string` | Values are not coerced; write the right type. |
|
|
136
|
+
| Extra parameter | `action "notify" has no parameter "to"` | Remove it or fix the name. |
|
|
137
|
+
| Branch without a test | `branches[0] has neither when nor if` | Give the branch an AI condition (when) or a code one (if). |
|
|
138
|
+
| Backward `if` with no `else` | `"if" jumps back to "quem" with no else` | Add else so the false branch has somewhere to go. |
|
|
139
|
+
|
|
140
|
+
Parameter values are checked strictly: `"3"` is not a number, `3.5` is not an integer, and an `enum` must contain the value unless the string holds `{{`, because a template's value is only known at run time.
|
|
141
|
+
|
|
142
|
+
Two checks live in the agent constructor rather than in `validateFlow`: `flow "x" is declared twice` and `idle: unknown tool "x"`.
|
|
143
|
+
|
|
144
|
+
### Warnings
|
|
145
|
+
|
|
146
|
+
| Warning | Why |
|
|
147
|
+
|---|---|
|
|
148
|
+
| `flow "f", step "s": then jumps back to "quem" without clear; the fields collected since stay known and those steps skip. Add clear: [...] to re-ask them.` | A `then`, `else`, `onFail` or branch target points at the same or an earlier step and clears nothing, so a collect step it lands on is skipped with `code: 'already-known'`. |
|
|
149
|
+
| `flow "f", step "s": collects "nome", "empresa" with no prompt and no ask; the model has nothing to go on. Add a prompt or an ask per field.` | A collect step with no `prompt`, where no listed field has an `ask` on the step or on the agent. |
|
|
150
|
+
|
|
151
|
+
## flowSpecSchema
|
|
152
|
+
|
|
153
|
+
`flowSpecSchema(registries)` returns a `StructuredSchema` for `FlowSpec` with this agent's field slugs, actions (each with its parameter schema), events and conditions as enums. Pass it as `parameters.jsonSchema` of a provider call and the model can only write a flow that names things you have.
|
|
154
|
+
|
|
155
|
+
- Every object is closed (`additionalProperties: false`) and every property is required; `null` stands for "not set". Gemini accepts it as a response schema.
|
|
156
|
+
- Steps are an `anyOf` with one variant per `kind`, and one `do` variant per registered action. `anyOf` is the union keyword both Gemini and OpenAI strict schemas accept; `oneOf` is not.
|
|
157
|
+
- A variant whose registry is empty is left out: no actions, no `do` step; no events, no `event` trigger and no `waitEvent` step; no fields, no `collect` step.
|
|
158
|
+
- Condition arguments are typed loosely (string, number, boolean or list of strings) because a `Condition` carries no argument schema.
|
|
159
|
+
- Left out on purpose, so a model does not write them: `ui`, `tools`, step-level `instructions`, `ask`, a mention trigger's `extract`, and the `input` of `{ flow }`.
|
|
160
|
+
|
|
161
|
+
The schema shapes the answer; `validateFlow` checks it. Run it on every generated spec before it reaches an agent.
|
|
162
|
+
|
|
163
|
+
## Example
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import { falai, FlowConfigurationError, flowSpecSchema, GeminiProvider, toSpec, validateFlow, type FlowSpec } from "@falai/agent";
|
|
167
|
+
|
|
168
|
+
const f = falai().fields({
|
|
169
|
+
nome: { type: "string", ask: "Pergunte o nome." },
|
|
170
|
+
empresa: { type: "string", ask: "Pergunte a empresa." },
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Everything a stored flow may name, registered once.
|
|
174
|
+
const registries = {
|
|
175
|
+
fields: f.fields,
|
|
176
|
+
actions: {
|
|
177
|
+
notify: f.action({
|
|
178
|
+
parameters: { recipient: { type: "string" }, message: { type: "string" } },
|
|
179
|
+
run: (params) => {
|
|
180
|
+
console.log(`[notify] ${params.recipient}: ${params.message}`);
|
|
181
|
+
return { ok: true };
|
|
182
|
+
},
|
|
183
|
+
}),
|
|
184
|
+
add_tags: f.action({
|
|
185
|
+
parameters: { tags: { type: "array", items: { type: "string" } } },
|
|
186
|
+
run: (params) => {
|
|
187
|
+
console.log("[add_tags]", params.tags);
|
|
188
|
+
return { ok: true };
|
|
189
|
+
},
|
|
190
|
+
}),
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// A flow typed in a chat and stored as a row: flat steps with a `kind`, no functions.
|
|
195
|
+
const concorrente: FlowSpec = {
|
|
196
|
+
id: "concorrente",
|
|
197
|
+
name: "Lead falou de concorrente",
|
|
198
|
+
on: [{ mention: ["o lead cita ou compara com um concorrente"], extract: { trecho: { type: "string" } }, repeat: "once" }],
|
|
199
|
+
steps: [
|
|
200
|
+
{ id: "tag", kind: "do", do: "add_tags", with: { tags: ["concorrente"] } },
|
|
201
|
+
{ id: "avisa", kind: "do", do: "notify", with: { recipient: "owner", message: '{{data.nome}} falou de concorrente: "{{input.trecho}}"' } },
|
|
202
|
+
],
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// Validate on save. The error names the unknown field, action, event, condition or step.
|
|
206
|
+
console.log(validateFlow(concorrente, registries).warnings); // []
|
|
207
|
+
try {
|
|
208
|
+
validateFlow({ ...concorrente, steps: [{ id: "x", kind: "do", do: "send_email", with: {} }] }, registries);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
if (error instanceof FlowConfigurationError) console.log(error.message);
|
|
211
|
+
// [FlowConfigurationError] flow "concorrente", step "x": unknown action "send_email". Register it in actions or fix the name.
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// The TypeScript form is the same object.
|
|
215
|
+
const triagem = f.flow({
|
|
216
|
+
id: "triagem",
|
|
217
|
+
name: "Triagem",
|
|
218
|
+
on: [{ message: ["quer um orçamento"] }],
|
|
219
|
+
steps: [
|
|
220
|
+
{ id: "quem", prompt: "Descubra quem é.", collect: ["nome", "empresa"] },
|
|
221
|
+
{ id: "avisa", do: "notify", with: { recipient: "owner", message: "Lead: {{data.nome}} ({{data.empresa}})" } },
|
|
222
|
+
],
|
|
223
|
+
});
|
|
224
|
+
console.log(toSpec(triagem).steps[0]); // { id: "quem", kind: "collect", prompt: "Descubra quem é.", collect: ["nome", "empresa"] }
|
|
225
|
+
|
|
226
|
+
// Let a model write one: the schema is the response schema of an ordinary generation call.
|
|
227
|
+
const provider = new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" });
|
|
228
|
+
const generated = await provider.generateMessage<undefined, FlowSpec>({
|
|
229
|
+
prompt: "Write a flow, as JSON, for: 'quando o lead pedir para falar com uma pessoa, avise o dono e marque a tag humano'. Texts in Brazilian Portuguese.",
|
|
230
|
+
history: [],
|
|
231
|
+
context: undefined,
|
|
232
|
+
parameters: { jsonSchema: flowSpecSchema(registries), schemaName: "flow" },
|
|
233
|
+
});
|
|
234
|
+
const spec = generated.structured;
|
|
235
|
+
if (!spec) throw new Error("The model returned no flow JSON. It usually ignored the schema or hit its token limit; check the raw response and ask again.");
|
|
236
|
+
validateFlow(spec, registries);
|
|
237
|
+
|
|
238
|
+
// Rows load like any other flow.
|
|
239
|
+
const agent = f.agent({ name: "Ana", provider, ...registries, flows: [triagem, f.fromSpec(concorrente), f.fromSpec(spec)] });
|
|
240
|
+
console.log(agent.options.flows?.map((flow) => flow.id));
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## See also
|
|
244
|
+
|
|
245
|
+
- [Flows from JSON](../guides/flows-from-json.md): storing, editing and generating flows.
|
|
246
|
+
- [Flow](./flow.md), [Step](./step.md), [Trigger](./trigger.md), [Branches](./branches.md): the typed forms.
|
|
247
|
+
- [Actions, events, conditions](./actions-events-conditions.md): what the names resolve against, and `ConditionSpec`.
|
|
248
|
+
- [Errors](./errors.md): `FlowConfigurationError` and the message contract.
|
package/docs/reference/flow.md
CHANGED
|
@@ -1,238 +1,150 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: Flow
|
|
3
|
-
description:
|
|
2
|
+
title: "Flow"
|
|
3
|
+
description: "Every Flow field with its type and default, what the runtime does with each one, and what validateFlow rejects."
|
|
4
4
|
type: reference
|
|
5
5
|
order: 2
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Flow
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
A `Flow` is one of the six primitives in `@falai/agent`. It models a single conversational goal — booking a hotel, escalating a complaint, onboarding a teammate — as an ordered set of steps that share the agent's typed `TData` schema. Flows declare what data they need (`requiredFields`), what extra data they can use (`optionalFields`), when they should activate (`when` for AI strings, `if` for code), and what happens when they finish (`onComplete` or `hooks.onComplete`). The router selects exactly one flow per turn; once the active flow's required fields are satisfied, the engine fires its completion path.
|
|
10
|
+
A flow is a trigger plus an ordered list of steps. Its `on` list says when a run starts; its `steps` say what the run does; `onEnd` says what happens after the last step. A run is one live execution of a flow inside a session. Flows are plain objects, so the same shape round-trips through JSON as a [FlowSpec](flow-spec.md).
|
|
13
11
|
|
|
14
12
|
## Signature
|
|
15
13
|
|
|
16
|
-
```
|
|
17
|
-
interface
|
|
18
|
-
id
|
|
19
|
-
|
|
14
|
+
```ts fragment
|
|
15
|
+
interface Flow<C = unknown, D = unknown> {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
20
18
|
description?: string;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
responseOutputSchema?: StructuredSchema;
|
|
30
|
-
|
|
31
|
-
requiredFields?: (keyof TData)[];
|
|
32
|
-
optionalFields?: (keyof TData)[];
|
|
33
|
-
initialData?: Partial<TData>;
|
|
34
|
-
|
|
35
|
-
steps?: StepOptions<TContext, TData>[];
|
|
36
|
-
|
|
37
|
-
onComplete?: string; // top-level: string sugar only
|
|
38
|
-
reentrant?: boolean; // default false
|
|
39
|
-
|
|
40
|
-
hooks?: FlowLifecycleHooks<TContext, TData>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
class Flow<TContext = unknown, TData = unknown> {
|
|
44
|
-
readonly id: string;
|
|
45
|
-
readonly title: string;
|
|
46
|
-
readonly description?: string;
|
|
47
|
-
readonly when?: ConditionWhen;
|
|
48
|
-
readonly if?: ConditionIf<TContext, TData>;
|
|
49
|
-
readonly initialStep: Step<TContext, TData>;
|
|
50
|
-
readonly requiredFields?: (keyof TData)[];
|
|
51
|
-
readonly optionalFields?: (keyof TData)[];
|
|
52
|
-
readonly initialData?: Partial<TData>;
|
|
53
|
-
readonly onComplete?: string;
|
|
54
|
-
readonly reentrant: boolean;
|
|
55
|
-
readonly hooks?: FlowLifecycleHooks<TContext, TData>;
|
|
56
|
-
|
|
57
|
-
constructor(options: FlowOptions<TContext, TData>, parentAgent?: Agent<TContext, TData>);
|
|
58
|
-
|
|
59
|
-
addStep(options: StepOptions<TContext, TData>): Step<TContext, TData>;
|
|
60
|
-
getSteps(): Step<TContext, TData>[];
|
|
61
|
-
getStep(stepId: string): Step<TContext, TData> | undefined;
|
|
62
|
-
getInstructions(): Instruction<TContext, TData>[];
|
|
63
|
-
getTools(): Tool<TContext, TData>[];
|
|
64
|
-
|
|
65
|
-
isComplete(data: Partial<TData>): boolean;
|
|
66
|
-
getMissingRequiredFields(data: Partial<TData>): (keyof TData)[];
|
|
67
|
-
getCompletionProgress(data: Partial<TData>): number;
|
|
19
|
+
on?: Trigger<C, D>[];
|
|
20
|
+
anchor?: string;
|
|
21
|
+
while?: Pred<C, D>;
|
|
22
|
+
clearOnStart?: (keyof D & string)[];
|
|
23
|
+
steps: Step<C, D>[];
|
|
24
|
+
onEnd?: "end" | "stay" | "reset";
|
|
25
|
+
instructions?: Instruction<C, D>[];
|
|
26
|
+
tools?: string[];
|
|
68
27
|
}
|
|
69
28
|
```
|
|
70
29
|
|
|
71
30
|
## Fields
|
|
72
31
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
|
76
|
-
|
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `requiredFields` | `(keyof TData)[]` | no | — | Fields that must be present in `session.data` for the flow to complete. Drives `isComplete` and progress calculation. |
|
|
87
|
-
| `optionalFields` | `(keyof TData)[]` | no | — | Fields the flow uses but doesn't require. Tracked for re-entry resets and progress visibility only. |
|
|
88
|
-
| `initialData` | `Partial<TData>` | no | — | Pre-populated values applied when the flow is entered. Merged into `session.data`. |
|
|
89
|
-
| `steps` | `StepOptions<TContext, TData>[]` | no | — | Sequential steps. The first becomes the initial step; the rest are chained as linear successors. The last step is the implicit terminus. |
|
|
90
|
-
| `onComplete` | `string` | no | — | **String only.** Sugar for `hooks.onComplete = () => ({ goTo: '<id>' })`. For dynamic completion logic, use `hooks.onComplete`. |
|
|
91
|
-
| `reentrant` | `boolean` | no | `false` | If `true`, the router may select this flow again after it has completed in the current session. On re-entry, declared `requiredFields` and `optionalFields` are cleared. |
|
|
92
|
-
| `hooks` | `FlowLifecycleHooks<TContext, TData>` | no | — | Lifecycle hooks: `onEnter`, `onExit`, `onComplete`, `onDataUpdate`, `onContextUpdate`. See below. |
|
|
93
|
-
|
|
94
|
-
### `FlowLifecycleHooks`
|
|
95
|
-
|
|
96
|
-
| Hook | Returns | Phase | Notes |
|
|
97
|
-
| ----------------- | -------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
98
|
-
| `onEnter` | `void \| Directive` | pre-LLM | Fires when the flow is entered. May augment the prompt, inject tools, or `halt`. Pre-LLM fields honored here.|
|
|
99
|
-
| `onExit` | `void` | post | Informational. Receives an `ExitReason`; cannot influence flow control. |
|
|
100
|
-
| `onComplete` | `void \| Directive` | post-LLM | Handler form of completion. Mutually exclusive with top-level `onComplete: string` — setting both throws. |
|
|
101
|
-
| `onDataUpdate` | `Partial<TData>` | post | Mutate or enrich the data update before it is committed to `session.data`. |
|
|
102
|
-
| `onContextUpdate` | `void` | post | Informational reaction to context updates while this flow is active. |
|
|
103
|
-
|
|
104
|
-
### `Flow` instance methods
|
|
32
|
+
| Field | Type | Default | Meaning |
|
|
33
|
+
|---|---|---|---|
|
|
34
|
+
| `id` | `string` | required | Unique across the agent. Part of every run id (`${id}#${triggerKey}`) and every claim key. Keep it stable once sessions exist: a run whose flow id is gone ends with `code: 'flow-gone'`. |
|
|
35
|
+
| `name` | `string` | required | The human name. The model reads it when routing and when speaking. |
|
|
36
|
+
| `description` | `string` | none | When this flow should be used. The model reads it when scoring flows and while speaking. |
|
|
37
|
+
| `on` | `Trigger<C, D>[]` | none | What starts a run. Absent or empty: only `turn({ start })` or another flow's `then: { flow }` starts it. See [Trigger](trigger.md). |
|
|
38
|
+
| `anchor` | `string` | `'session'` | What a run is keyed to. `'session'` uses the session id. Any other name reads `input.anchors[name].key`, and falls back to the session id when the host did not pass that anchor. |
|
|
39
|
+
| `while` | `Pred<C, D>` | the trigger's `if` | Re-checked before the run moves. When it stops holding, the run ends with `code: 'premise-changed'`. |
|
|
40
|
+
| `clearOnStart` | `(keyof D & string)[]` | none | Fields forgotten when a run of this flow starts, so a second run asks for them again. |
|
|
41
|
+
| `steps` | `Step<C, D>[]` | required | In order. A run enters `steps[0]` and moves to the next step unless `then` says otherwise. See [Step](step.md). |
|
|
42
|
+
| `onEnd` | `'end' \| 'stay' \| 'reset'` | `'end'` | What the run does after its last step. |
|
|
43
|
+
| `instructions` | `Instruction<C, D>[]` | none | Rules that apply while a step of this flow speaks. See [Instruction](instruction.md). |
|
|
44
|
+
| `tools` | `string[]` | every agent tool | Tools the model may call while a step of this flow speaks. A step's own `tools` list wins over this one. |
|
|
105
45
|
|
|
106
|
-
|
|
107
|
-
| -------------------------------------------- | -------------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
108
|
-
| `addStep(options)` | `Step<TContext, TData>` | Imperatively append a step as the successor of the current last step. Same validations as `steps[]`. |
|
|
109
|
-
| `getSteps()` | `Step<TContext, TData>[]` | All steps reachable from the initial step via BFS traversal. |
|
|
110
|
-
| `getStep(stepId)` | `Step \| undefined` | Look up a step by id. |
|
|
111
|
-
| `getInstructions()` | `Instruction[]` | Flow-scoped instructions (a copy). |
|
|
112
|
-
| `getTools()` | `Tool[]` | Flow-scoped tools (a copy). |
|
|
113
|
-
| `isComplete(data)` | `boolean` | `true` when all `requiredFields` are populated. Optional-only flows complete on terminus, not data. |
|
|
114
|
-
| `getMissingRequiredFields(data)` | `(keyof TData)[]` | Fields from `requiredFields` not yet present in `data`. |
|
|
115
|
-
| `getCompletionProgress(data)` | `number` (0–1) | Fraction of `requiredFields` satisfied. `0` when only `optionalFields` are declared. |
|
|
46
|
+
## Behaviour
|
|
116
47
|
|
|
117
|
-
|
|
48
|
+
**Starting a run.** Whatever the trigger, a run starts in one order.
|
|
118
49
|
|
|
119
|
-
|
|
50
|
+
1. The trigger's `if` is judged.
|
|
51
|
+
2. The claim is checked against `repeat` (`code: 'already-claimed'`, `code: 'cooldown'`).
|
|
52
|
+
3. The chain depth is checked (`code: 'hop-limit'` at 5 hops).
|
|
53
|
+
4. One live run per flow and anchor is enforced (`code: 'already-running'`). The one exception: a run still parked on an event trigger's `after` ends with reason `'replaced'` and the new run takes its place.
|
|
54
|
+
5. The claim is written, `clearOnStart` fields are deleted, and the run is added with `stepId: null`.
|
|
120
55
|
|
|
121
|
-
|
|
122
|
-
2. **The last step in `steps[]` runs and `requiredFields` is empty.** The terminus rule applies — the flow is implicitly complete, and the same completion path runs.
|
|
123
|
-
3. **A `Directive` with `complete: true` is returned** from a tool, hook, or branch while the flow is active. Completion fires immediately regardless of field state.
|
|
56
|
+
It enters `steps[0]` in the same turn unless the trigger has `after`. Keys and skip reasons are in [Trigger](trigger.md).
|
|
124
57
|
|
|
125
|
-
`
|
|
58
|
+
**`anchor`.** The anchor is part of the run's `dedupeKey` (`${flowId}:${anchor}:${nonce}`) and of the one-live-run rule. With `anchor: 'lead'` and `anchors: { lead: { key: 'lead:456' } }` on every turn, a flow runs once per customer even when the customer has several sessions, as long as the host also passes `claims` from the other sessions. `anchors.lead.lastInboundAt` also counts as "the customer wrote" when a silence wake fires and when a wait's wake decides whether the customer replied.
|
|
126
59
|
|
|
127
|
-
|
|
128
|
-
- **Progress visibility.** `getCompletionProgress` ignores optional fields by design — progress reflects what the flow is *blocked on*, not what it has *touched*.
|
|
60
|
+
**`while`.** Checked every time the run is about to move: at the start of each turn's run phase for a running run, and when an asking run resumes on a message. A parked run (`waiting`) or a suspended one is not checked until it moves again. Without `while`, the check is the trigger's `if`: the run holds while any trigger of the same kind as the one that started it would still fire. A run started by `start` or by another flow has no such trigger, so without `while` it always holds. A silence run also ends, with `code: 'customer-replied'`, when a wake finds that the customer wrote after the run started.
|
|
129
61
|
|
|
130
|
-
|
|
62
|
+
**`clearOnStart`.** Applied at start for every trigger kind, `start` and `{ flow }` chains included. Not applied when `onEnd: 'reset'` restarts the flow: reset keeps the data.
|
|
131
63
|
|
|
132
|
-
|
|
64
|
+
**`onEnd`.**
|
|
65
|
+
- `'end'`: the run ends with reason `'end'`.
|
|
66
|
+
- `'stay'`: the run re-enters the last step (a new visit, so new keys) and stays asking. It speaks that step again on the next message. Meant for a last talk step that answers follow-up questions.
|
|
67
|
+
- `'reset'`: the run ends with reason `'reset'` and a fresh run of the same flow starts at `steps[0]`, data kept, one hop deeper. A flow that resets forever without asking anything stops at hop 5, with `code: 'hop-limit'`.
|
|
133
68
|
|
|
134
|
-
|
|
135
|
-
- Other fields in `session.data` are preserved.
|
|
136
|
-
- The flow restarts from its initial step.
|
|
69
|
+
**Instructions and tools while speaking.** The speak call sees the agent's instructions, then this flow's, then the step's, each already filtered by its `if`. Tools are the step's `tools`; without one, the flow's `tools`; without that, every agent tool.
|
|
137
70
|
|
|
138
|
-
|
|
71
|
+
**Editing flows under live sessions.** A stored run names its flow and step by id. If the flow is gone, the run ends with `code: 'flow-gone'`; if its step is gone, with `code: 'step-gone'`. Renaming ids is a breaking change for sessions in flight.
|
|
139
72
|
|
|
140
|
-
|
|
73
|
+
## What validateFlow rejects
|
|
141
74
|
|
|
142
|
-
|
|
75
|
+
`f.agent()` runs `validateFlow(flow, registries)` on every flow. It throws `FlowConfigurationError` on the first of these:
|
|
143
76
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
77
|
+
- no `id`, or `steps` is not a list
|
|
78
|
+
- a step with no `id`, the id `'end'`, or an id used twice
|
|
79
|
+
- triggers with zero steps
|
|
80
|
+
- an unknown field slug in `clearOnStart`, `collect`, `ask`, `equals`, `known` or a `clear` list
|
|
81
|
+
- an unknown action in `do`; a `with` that misses a required parameter, names one the action does not have, or gives a value of the wrong type (`with` values are not coerced; a `{{template}}` string is accepted for any enum)
|
|
82
|
+
- an unknown event in a trigger or in `wait: { event }`
|
|
83
|
+
- an unknown condition name, or a malformed built-in (`equals` not an object, `known` not a list, `silenced` not a boolean); an `equals` value whose type does not match the field
|
|
84
|
+
- an unknown tool in the flow's or a step's `tools`
|
|
85
|
+
- a `silence`, `after`, `cooldown`, `wait` or `upTo` that is not a duration (`"30s"`, `"5m"`, `"24h"`, `"3d"`)
|
|
86
|
+
- a `then`, `else`, `onFail` or branch `then` that points at a step that does not exist
|
|
87
|
+
- a branch with neither `when` nor `if`
|
|
88
|
+
- an `if` step whose `then` jumps backward with no `else`
|
|
148
89
|
|
|
149
|
-
|
|
90
|
+
It returns warnings, logged by the agent, for two things that run but probably not as intended: a jump backward without `clear` (the fields collected since stay known, so those steps skip), and a `collect` step with no `prompt` and no `ask` on any of its fields.
|
|
150
91
|
|
|
151
|
-
|
|
92
|
+
`toSpec(flow)` throws `FlowConfigurationError` when a predicate is a function, because a function cannot be stored as JSON.
|
|
152
93
|
|
|
153
|
-
|
|
94
|
+
## Example
|
|
154
95
|
|
|
155
|
-
```
|
|
156
|
-
import {
|
|
96
|
+
```ts
|
|
97
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
157
98
|
|
|
158
|
-
interface
|
|
159
|
-
|
|
160
|
-
checkIn: string;
|
|
161
|
-
guests: number;
|
|
99
|
+
interface Ctx {
|
|
100
|
+
lead: { etapa: string };
|
|
162
101
|
}
|
|
163
102
|
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
103
|
+
const f = falai<Ctx>().fields({
|
|
104
|
+
confirmado: { type: "boolean", ask: "Pergunte se a proposta chegou bem e se está tudo claro." },
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const proposta = f.flow({
|
|
108
|
+
id: "proposta",
|
|
109
|
+
name: "Acompanhar proposta",
|
|
110
|
+
description: "Uma hora depois que a proposta foi enviada, enquanto o lead continua nessa etapa.",
|
|
111
|
+
on: [{ event: "entrou_na_etapa", after: "1h", if: { naEtapa: "proposta" } }],
|
|
112
|
+
anchor: "lead",
|
|
113
|
+
while: { naEtapa: "proposta" },
|
|
114
|
+
clearOnStart: ["confirmado"],
|
|
169
115
|
steps: [
|
|
170
|
-
{
|
|
171
|
-
{
|
|
172
|
-
{
|
|
116
|
+
{ id: "chegou", collect: ["confirmado"] },
|
|
117
|
+
{ id: "ok", if: { equals: { confirmado: true } }, else: "avisa" },
|
|
118
|
+
{ id: "tchau", say: "Ótimo. Qualquer dúvida, é só chamar.", then: "end" },
|
|
119
|
+
{ id: "avisa", do: "avisar", with: { texto: "Proposta não chegou bem para o lead em {{context.lead.etapa}}." } },
|
|
173
120
|
],
|
|
121
|
+
onEnd: "end",
|
|
174
122
|
});
|
|
175
123
|
|
|
176
|
-
const agent =
|
|
177
|
-
|
|
178
|
-
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY
|
|
179
|
-
|
|
124
|
+
const agent = f.agent({
|
|
125
|
+
name: "Ana",
|
|
126
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
127
|
+
events: { entrou_na_etapa: f.event<{ etapa: string }>() },
|
|
128
|
+
conditions: { naEtapa: f.condition((ctx, etapa: string) => ctx.context.lead.etapa === etapa) },
|
|
129
|
+
actions: { avisar: f.action({ parameters: { texto: { type: "string" } }, run: () => ({ ok: true }) }) },
|
|
130
|
+
flows: [proposta],
|
|
180
131
|
});
|
|
181
|
-
```
|
|
182
132
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
reentrant: true, // allow "book another?" loops
|
|
192
|
-
steps: [/* ... */],
|
|
193
|
-
hooks: {
|
|
194
|
-
onComplete: ({ data }) => ({
|
|
195
|
-
dataUpdate: { lastBookedAt: new Date().toISOString() },
|
|
196
|
-
goTo: data.guests > 4 ? "Group Coordination" : "Confirmation",
|
|
197
|
-
reason: "booking finalized",
|
|
198
|
-
}),
|
|
199
|
-
},
|
|
133
|
+
const context: Ctx = { lead: { etapa: "proposta" } };
|
|
134
|
+
const r = await agent.turn({
|
|
135
|
+
sessionId: "s1",
|
|
136
|
+
context,
|
|
137
|
+
anchors: { lead: { key: "lead:456" } },
|
|
138
|
+
event: "entrou_na_etapa",
|
|
139
|
+
payload: { etapa: "proposta" },
|
|
140
|
+
key: "stage:456:proposta",
|
|
200
141
|
});
|
|
142
|
+
console.log(r.started[0]?.dedupeKey, r.schedule[0]?.key); // 'proposta:lead:456:stage:456:proposta', 'proposta#stage:456:proposta:start:<ms>'
|
|
201
143
|
```
|
|
202
144
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
```typescript
|
|
206
|
-
const supportFlow = new Flow({
|
|
207
|
-
title: "Support",
|
|
208
|
-
steps: [{ description: "Capture issue summary", collect: ["issue"] }],
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// Later — extend the flow programmatically.
|
|
212
|
-
supportFlow.addStep({
|
|
213
|
-
description: "Triage severity",
|
|
214
|
-
collect: ["severity"],
|
|
215
|
-
});
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
> Calling `addStep` after the agent has handled a turn emits a debug-level warning that the flow graph is being mutated mid-session. The new step is still registered and connected as the successor of the current last step.
|
|
219
|
-
|
|
220
|
-
## Errors
|
|
221
|
-
|
|
222
|
-
| Error | When it's thrown |
|
|
223
|
-
| --------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
224
|
-
| `FlowConfigurationError` | Both top-level `onComplete` and `hooks.onComplete` are set on the same flow. |
|
|
225
|
-
| `FlowConfigurationError` | A function appears in `when` (functions belong on `if`). |
|
|
226
|
-
| `FlowConfigurationError` | A step inside `steps[]` violates auto-step or reply-step shape rules (raised from the underlying `Step` constructor). |
|
|
227
|
-
|
|
228
|
-
All `FlowConfigurationError` messages follow the format `[FlowConfigurationError] <what>: <why>. <how to fix>.` See [Errors](./errors.md).
|
|
229
|
-
|
|
230
|
-
## Related
|
|
145
|
+
## See also
|
|
231
146
|
|
|
232
|
-
- [
|
|
233
|
-
- [
|
|
234
|
-
- [
|
|
235
|
-
- [
|
|
236
|
-
- [Instruction](./instruction.md) — flow-scoped behavioral nudges
|
|
237
|
-
- [Branching](../guides/branching.md) — explicit forks inside a flow
|
|
238
|
-
- [Flow control](../guides/flow-control.md) — completion, dispatch, and verbatim replies
|
|
147
|
+
- [Trigger](trigger.md) for `on`, `repeat`, keys and skip reasons
|
|
148
|
+
- [Step](step.md) for the six step kinds and `Next`
|
|
149
|
+
- [Flow spec](flow-spec.md) for the JSON form and `validateFlow`
|
|
150
|
+
- [Flow control](../guides/flow-control.md) and [Runs and waits](../concepts/runs-and-waits.md)
|