@falai/agent 3.4.5 → 4.0.0-alpha.2
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 +11 -6
- 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/providers/ZaiProvider.d.ts +6 -4
- package/dist/cjs/providers/ZaiProvider.d.ts.map +1 -1
- package/dist/cjs/providers/ZaiProvider.js +6 -4
- package/dist/cjs/providers/ZaiProvider.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 +11 -6
- 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/providers/ZaiProvider.d.ts +6 -4
- package/dist/providers/ZaiProvider.d.ts.map +1 -1
- package/dist/providers/ZaiProvider.js +6 -4
- package/dist/providers/ZaiProvider.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 +46 -13
- package/src/providers/ZaiProvider.ts +6 -4
- 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
|
@@ -1,415 +1,276 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Flow control"
|
|
3
|
-
description: "
|
|
3
|
+
description: "Every way a run moves, and the outcome line each move writes."
|
|
4
4
|
type: guide
|
|
5
|
-
order:
|
|
5
|
+
order: 4
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Flow control
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
A run walks its flow's steps in order. `then` changes where it goes next; `else` and `onFail` cover a step's other exit. That is the whole vocabulary.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
14
|
+
|
|
15
|
+
const f = falai().fields({});
|
|
16
|
+
|
|
17
|
+
const agent = f.agent({
|
|
18
|
+
name: "Ana",
|
|
19
|
+
// Set GEMINI_API_KEY in your environment before running this.
|
|
20
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
21
|
+
flows: [
|
|
22
|
+
f.flow({
|
|
23
|
+
id: "aviso",
|
|
24
|
+
name: "Aviso",
|
|
25
|
+
steps: [
|
|
26
|
+
{ id: "a", say: "Oi. Aqui é da loja." },
|
|
27
|
+
{ id: "b", say: "Chegou o iPhone 17, pronta entrega.", then: "end" },
|
|
28
|
+
// Only here to show that `then: 'end'` stops before it.
|
|
29
|
+
{ id: "c", say: "Este passo nunca sai." },
|
|
30
|
+
],
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
|
+
});
|
|
11
34
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
same primitive: emit a [`Directive`](../reference/directive.md).
|
|
35
|
+
const r = await agent.turn({ sessionId: "s1", start: { flow: "aviso", key: "k1" } });
|
|
36
|
+
console.log(r.messages.map((m) => m.text)); // ["Oi. Aqui é da loja.", "Chegou o iPhone 17, pronta entrega."]
|
|
37
|
+
console.log(r.outcomes.map((o) => [o.stepId, o.next])); // [["a", undefined], ["b", "end"]]
|
|
38
|
+
console.log(r.ended[0]?.reason); // "end"
|
|
39
|
+
```
|
|
18
40
|
|
|
19
|
-
|
|
20
|
-
code-block that does it. The shape stays the same across all of them;
|
|
21
|
-
what changes is which fields you set and where the directive comes
|
|
22
|
-
from. The [Directive reference](../reference/directive.md) is the
|
|
23
|
-
canonical contract for every shorthand, object form, and validation
|
|
24
|
-
rule.
|
|
41
|
+
## Which exit a step takes
|
|
25
42
|
|
|
26
|
-
|
|
43
|
+
Every step has `then`. Without it, the run goes to the next step in the list; after the last step, `onEnd` decides. What "then" means depends on the kind:
|
|
27
44
|
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
| Step | `then` is taken when | Other exit |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| talk (`prompt`, `collect`) | its fields are known, or a `prompt` without `collect` has spoken once | `branches[].then` while it asks |
|
|
48
|
+
| `say` | right after the message is queued | none |
|
|
49
|
+
| `do` | the action returned `ok` or `skipped` | `onFail` when it returned `failed` |
|
|
50
|
+
| `wait: '2d'` | the time passed | `else` when the customer replied first; `branches[].then` on that reply |
|
|
51
|
+
| `wait: { event }` | the event came | `else` when `upTo` passed (default 30 days) |
|
|
52
|
+
| `if` | the predicate holds | `else` when it does not (default `'end'`) |
|
|
30
53
|
|
|
31
|
-
|
|
32
|
-
goTo: "Booking", // position (one max)
|
|
33
|
-
reply: "Routing you to booking.", // verbatim utterance
|
|
34
|
-
dataUpdate: { source: "tool" }, // state write
|
|
35
|
-
};
|
|
36
|
-
```
|
|
54
|
+
Each exit is a `Next`, and every outcome line records where it went in `next`.
|
|
37
55
|
|
|
38
|
-
|
|
39
|
-
`contextUpdate`) and `reply` ride alongside any position field.
|
|
56
|
+
## The four forms of `Next`
|
|
40
57
|
|
|
41
|
-
|
|
58
|
+
### A step id
|
|
42
59
|
|
|
43
|
-
|
|
60
|
+
```ts fragment
|
|
61
|
+
{ id: "sem-humanos", say: "Nossa equipe está fora agora.", then: "dados" }
|
|
62
|
+
```
|
|
44
63
|
|
|
45
|
-
|
|
46
|
-
|------------|-----------------------------------------------------------------------|
|
|
47
|
-
| `goTo` | Jump to another flow. |
|
|
48
|
-
| `goToStep` | Jump to a step (within this flow, or — in object form — another flow).|
|
|
49
|
-
| `complete` | Mark the current flow done. Run the flow's completion path. |
|
|
50
|
-
| `abort` | End the conversation. Optionally clear the session. |
|
|
51
|
-
| `reset` | Restart the current flow. Optionally clear its declared fields. |
|
|
64
|
+
Jumps to that step of the same flow. Entering a step mints a new visit, so the messages and actions it produces get new keys (`suporte#m1:dados:2`). The step must exist; `validateFlow` refuses the flow otherwise. Jumping backward to a collect step whose fields are known skips it (`code: 'already-known'`), which is why the next form exists.
|
|
52
65
|
|
|
53
|
-
|
|
54
|
-
Setting two throws `FlowConfigurationError`. When more than one
|
|
55
|
-
emitter writes a position field on the same turn, the per-turn merge
|
|
56
|
-
picks one winner by precedence:
|
|
66
|
+
### `{ step, clear }`
|
|
57
67
|
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
```
|
|
68
|
+
```ts
|
|
69
|
+
import { falai } from "@falai/agent";
|
|
61
70
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
State writes and `reply` ride alongside whichever position wins.
|
|
68
|
-
|
|
69
|
-
## Recipe 1 — Redirect from a tool
|
|
70
|
-
|
|
71
|
-
Tools have two ways to emit a directive: imperative (`ctx.dispatch`)
|
|
72
|
-
mid-handler, or declarative (`ToolResult.directive`) on return. Both
|
|
73
|
-
land on the same per-turn bus and merge identically.
|
|
74
|
-
|
|
75
|
-
### Imperative — `ctx.dispatch`
|
|
76
|
-
|
|
77
|
-
```typescript
|
|
78
|
-
import type { Tool } from "@falai/agent";
|
|
79
|
-
|
|
80
|
-
const checkEligibility: Tool<{ userId: string }, BookingData, { ok: boolean }> = {
|
|
81
|
-
id: "check_eligibility",
|
|
82
|
-
description: "Verify the caller is allowed to book this destination.",
|
|
83
|
-
isReadOnly: () => true,
|
|
84
|
-
async handler(ctx) {
|
|
85
|
-
const ok = await isEligible(ctx.context.userId, ctx.data.destination);
|
|
86
|
-
if (!ok) {
|
|
87
|
-
ctx.dispatch({
|
|
88
|
-
goTo: "Denial",
|
|
89
|
-
reply: "Sorry — you're not eligible to book that destination.",
|
|
90
|
-
dataUpdate: { denialReason: "ineligible" },
|
|
91
|
-
});
|
|
92
|
-
return { ok: false };
|
|
93
|
-
}
|
|
94
|
-
return { ok: true };
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
```
|
|
71
|
+
const f = falai().fields({
|
|
72
|
+
nome: { type: "string", ask: "Pergunte o nome." },
|
|
73
|
+
confirmado: { type: "boolean", ask: "Resuma o que anotou e pergunte se está certo." },
|
|
74
|
+
});
|
|
98
75
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
data: { ok: false },
|
|
111
|
-
directive: {
|
|
112
|
-
goTo: "Denial",
|
|
113
|
-
reply: "Sorry — you're not eligible to book that destination.",
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
return { data: { ok: true } };
|
|
118
|
-
}
|
|
76
|
+
const triagem = f.flow({
|
|
77
|
+
id: "triagem",
|
|
78
|
+
name: "Triagem",
|
|
79
|
+
on: [{ message: ["quer saber como funciona"] }],
|
|
80
|
+
steps: [
|
|
81
|
+
{ id: "quem", collect: ["nome"] },
|
|
82
|
+
{ id: "confirma", collect: ["confirmado"] },
|
|
83
|
+
{ id: "ok", if: { equals: { confirmado: true } }, else: { step: "quem", clear: ["confirmado", "nome"] } },
|
|
84
|
+
{ id: "tchau", prompt: "Agradeça e diga que um vendedor continua daqui." },
|
|
85
|
+
],
|
|
86
|
+
});
|
|
119
87
|
```
|
|
120
88
|
|
|
121
|
-
|
|
122
|
-
decision. Reach for **declarative** when there's a single return
|
|
123
|
-
point.
|
|
124
|
-
|
|
125
|
-
## Recipe 2 — Complete with a chained next
|
|
126
|
-
|
|
127
|
-
A booking tool reserved the room. The flow is done, and the next
|
|
128
|
-
thing the agent should do is open a feedback flow. `complete` accepts
|
|
129
|
-
an object form whose `next` field is **another directive** applied
|
|
130
|
-
immediately after the flow's completion path runs:
|
|
131
|
-
|
|
132
|
-
```typescript
|
|
133
|
-
import type { Tool, Directive } from "@falai/agent";
|
|
134
|
-
|
|
135
|
-
const bookHotel: Tool<unknown, BookingData, { id: string }> = {
|
|
136
|
-
id: "book_hotel",
|
|
137
|
-
description: "Reserve the hotel for the collected fields.",
|
|
138
|
-
async handler(ctx, args) {
|
|
139
|
-
const id = await reserve(args);
|
|
140
|
-
const directive: Directive = {
|
|
141
|
-
complete: {
|
|
142
|
-
reason: "reservation confirmed",
|
|
143
|
-
next: { goTo: "Feedback", reply: "Booked. Mind a quick survey?" },
|
|
144
|
-
},
|
|
145
|
-
dataUpdate: { bookingId: id },
|
|
146
|
-
};
|
|
147
|
-
return { data: { id }, directive };
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
```
|
|
89
|
+
Deletes the listed fields from the collected data, then jumps. The steps that collect them ask again. Without `clear`, a backward edge logs a warning when the agent is built, because the run would skip straight past the steps you jumped to.
|
|
151
90
|
|
|
152
|
-
|
|
153
|
-
picks `complete`, the flow's `hooks.onComplete` runs, then
|
|
154
|
-
`complete.next` is applied — `goTo: "Feedback"` redirects with the
|
|
155
|
-
verbatim reply as that turn's assistant message.
|
|
91
|
+
### `'end'`
|
|
156
92
|
|
|
157
|
-
`
|
|
158
|
-
For the simple case, the shorthand `complete: true` is the right
|
|
159
|
-
call:
|
|
93
|
+
Ends the run now. `onEnd` (below) says what the flow does about it. `'end'` is a reserved word: no step may use it as an id.
|
|
160
94
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
```
|
|
95
|
+
### `{ flow, input }`
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
164
99
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
abort: { reason: "caller is not on the allow-list", clearSession: true },
|
|
181
|
-
};
|
|
182
|
-
return { data: { allowed: false }, directive };
|
|
183
|
-
}
|
|
184
|
-
return { data: { allowed: true } };
|
|
100
|
+
const f = falai().fields({
|
|
101
|
+
nome: { type: "string", ask: "Pergunte o nome." },
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const agent = f.agent({
|
|
105
|
+
name: "Ana",
|
|
106
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
107
|
+
actions: {
|
|
108
|
+
send_template: f.action({
|
|
109
|
+
parameters: { templateId: { type: "string" } },
|
|
110
|
+
run: (params) => {
|
|
111
|
+
console.log(`enviando ${params.templateId}`);
|
|
112
|
+
return { ok: true, spoke: true };
|
|
113
|
+
},
|
|
114
|
+
}),
|
|
185
115
|
},
|
|
186
|
-
|
|
116
|
+
flows: [
|
|
117
|
+
f.flow({
|
|
118
|
+
id: "campanha",
|
|
119
|
+
name: "Campanha",
|
|
120
|
+
steps: [
|
|
121
|
+
{ id: "envio", do: "send_template", with: { templateId: "{{input.templateId}}" } },
|
|
122
|
+
// The customer answered: hand the conversation to the flow named in the start input.
|
|
123
|
+
{ id: "espera", wait: "1d", else: { flow: "{{input.flowId}}" } },
|
|
124
|
+
{ id: "nudge", prompt: "Cutuque de leve: pergunte se a pessoa viu a mensagem." },
|
|
125
|
+
],
|
|
126
|
+
}),
|
|
127
|
+
f.flow({ id: "funil", name: "Funil", steps: [{ id: "q", collect: ["nome"] }] }),
|
|
128
|
+
],
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const t1 = await agent.turn({ sessionId: "s1", start: { flow: "campanha", input: { templateId: "t1", flowId: "funil" }, key: "camp:1" } });
|
|
132
|
+
// The customer replies before the day is over:
|
|
133
|
+
const t2 = await agent.turn({ sessionId: "s1", session: t1.session, message: "vi sim, me conta mais", id: "m1" });
|
|
134
|
+
console.log(t2.ended.map((run) => [run.flowId, run.reason])); // [["campanha", "flow"]]
|
|
135
|
+
console.log(t2.started.map((s) => s.runId)); // ["funil#campanha#camp:1:espera:1"]
|
|
136
|
+
console.log(t2.session.runs[0]?.hop); // 1
|
|
187
137
|
```
|
|
188
138
|
|
|
189
|
-
|
|
139
|
+
Ends this run with `reason: 'flow'` and starts the other flow in the same turn. The child:
|
|
190
140
|
|
|
191
|
-
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
-
|
|
195
|
-
|
|
141
|
+
- has the id `<childFlowId>#<parentRunId>:<stepId>:<visit>` and `trigger.kind: 'flow'`;
|
|
142
|
+
- gets `input` if you pass it, otherwise the parent's `input`, so `{{input.x}}` keeps working;
|
|
143
|
+
- takes the floor and moves in this same turn; a talk step reached this way speaks now;
|
|
144
|
+
- has `hop` one higher than the parent. A chain deeper than 5 stops: the child is skipped with `code: 'hop-limit'`.
|
|
145
|
+
- repeats by default (`'always'`), so a flow may be chained into many times; its claim carries the parent's step key.
|
|
196
146
|
|
|
197
|
-
|
|
147
|
+
`flow` is a template: `{{input.flowId}}` resolves against the run's input and context. A flow id that does not exist lands in `skipped[]` with `code: 'flow-gone'`; a child flow with a live run for the same anchor is skipped with `code: 'already-running'`. This is how one flow hands the conversation to another: the last step of a qualifying flow can `then: { flow: 'agendamento' }`.
|
|
198
148
|
|
|
199
|
-
|
|
200
|
-
boilerplate at flow boundaries. `reply: string` skips the LLM and
|
|
201
|
-
emits the literal text — no templating, no model rephrasing.
|
|
149
|
+
## `onEnd`: after the last step
|
|
202
150
|
|
|
203
|
-
|
|
204
|
-
|
|
151
|
+
| `onEnd` | What happens | `ended[].reason` |
|
|
152
|
+
|---|---|---|
|
|
153
|
+
| `'end'` (default) | the run ends; the session is idle | `'end'` |
|
|
154
|
+
| `'stay'` | the run stays at its last step and runs it again on the next message; each repetition mints a new key | none: the run does not end |
|
|
155
|
+
| `'reset'` | the run ends and a fresh run of the same flow starts at the first step, data kept, one hop deeper | `'reset'` |
|
|
205
156
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
prompt: "Confirm the handoff if the queue is clear.",
|
|
209
|
-
hooks: {
|
|
210
|
-
finalize: ({ data }): Directive | void => {
|
|
211
|
-
if (data.handoffReady) {
|
|
212
|
-
return { reply: "Connecting you with a specialist now." };
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
};
|
|
217
|
-
```
|
|
157
|
+
```ts
|
|
158
|
+
import { falai } from "@falai/agent";
|
|
218
159
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
complete: true,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
}
|
|
160
|
+
const f = falai().fields({});
|
|
161
|
+
|
|
162
|
+
// Every later question lands on the same step, with a new message key each time.
|
|
163
|
+
const faq = f.flow({
|
|
164
|
+
id: "faq",
|
|
165
|
+
name: "Dúvidas",
|
|
166
|
+
on: [{ message: ["tem uma dúvida sobre o produto"] }],
|
|
167
|
+
onEnd: "stay",
|
|
168
|
+
steps: [{ id: "r", prompt: "Responda a dúvida com base no que sabe e pergunte se ficou claro." }],
|
|
169
|
+
});
|
|
233
170
|
```
|
|
234
171
|
|
|
235
|
-
|
|
236
|
-
payloads — `reply`, `dataUpdate`, and the position field don't
|
|
237
|
-
compete for the same slot.
|
|
172
|
+
`'reset'` is a chain into the same flow, so it costs a hop: a flow with no talk step that resets forever stops at the hop cap instead of spinning.
|
|
238
173
|
|
|
239
|
-
|
|
240
|
-
*after*), return a `Directive` from a prepare hook with `halt: true`
|
|
241
|
-
— see below.
|
|
174
|
+
## `while`: the run's premise
|
|
242
175
|
|
|
243
|
-
|
|
176
|
+
`while` is a code predicate re-checked every time the run is about to move, including right after it starts. When it stops holding, the run ends with `code: 'premise-changed'` and `reason: 'skipped'`, without speaking.
|
|
244
177
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
post-LLM hooks, but with three fields that only take effect before
|
|
248
|
-
this turn's LLM call.
|
|
178
|
+
```ts
|
|
179
|
+
import { falai } from "@falai/agent";
|
|
249
180
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
// ...all position/state/reply fields...
|
|
253
|
-
appendPrompt?: string[];
|
|
254
|
-
injectTools?: Tool[];
|
|
255
|
-
halt?: boolean;
|
|
181
|
+
interface Ctx {
|
|
182
|
+
lead: { etapa: string };
|
|
256
183
|
}
|
|
257
|
-
```
|
|
258
184
|
|
|
259
|
-
|
|
260
|
-
`session.pendingDirective` — they're stripped before the write.
|
|
261
|
-
Returning a Directive with these fields from a post-LLM hook ignores
|
|
262
|
-
them with a WARN log.
|
|
263
|
-
|
|
264
|
-
### `appendPrompt` — nudge the system prompt
|
|
265
|
-
|
|
266
|
-
```typescript
|
|
267
|
-
const flow = {
|
|
268
|
-
title: "Booking",
|
|
269
|
-
hooks: {
|
|
270
|
-
onEnter: (ctx) => {
|
|
271
|
-
if (ctx.context.user.tier === "vip") {
|
|
272
|
-
return { appendPrompt: ["Caller is a VIP — confirm preferences first."] };
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
};
|
|
277
|
-
```
|
|
185
|
+
const f = falai<Ctx>().fields({});
|
|
278
186
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
187
|
+
const proposta = f.flow({
|
|
188
|
+
id: "proposta",
|
|
189
|
+
name: "Acompanhar proposta",
|
|
190
|
+
on: [{ event: "entrou_na_etapa", after: "1h", if: ({ context }) => context.lead.etapa === "proposta" }],
|
|
191
|
+
// The run only makes sense while the deal is still here. Without `while`, the trigger's `if` is re-checked instead.
|
|
192
|
+
while: ({ context }) => context.lead.etapa === "proposta",
|
|
193
|
+
steps: [{ id: "fala", prompt: "Pergunte se a proposta chegou bem e se há dúvidas." }],
|
|
194
|
+
});
|
|
195
|
+
```
|
|
282
196
|
|
|
283
|
-
|
|
197
|
+
Without `while`, the trigger's `if` is the premise. The run holds while any trigger of the same kind would still fire. A flow started by hand or by a chain has no such trigger, so its premise always holds. A run a silence trigger started has one more premise on a wake: if the customer wrote since the run started, the run ends with `code: 'customer-replied'`.
|
|
284
198
|
|
|
285
|
-
|
|
286
|
-
const step = {
|
|
287
|
-
id: "verify",
|
|
288
|
-
prompt: "Verify the caller before proceeding.",
|
|
289
|
-
hooks: {
|
|
290
|
-
prepare: async (ctx) => {
|
|
291
|
-
if (!ctx.data.verified) return { injectTools: [lookupAccount] };
|
|
292
|
-
},
|
|
293
|
-
},
|
|
294
|
-
};
|
|
295
|
-
```
|
|
199
|
+
## `onFail` on a `do` step
|
|
296
200
|
|
|
297
|
-
|
|
298
|
-
arrays concatenate, then dedupe by `Tool.id` (last definition wins).
|
|
201
|
+
An action that returns `{ failed }` writes `code: 'action-failed'` and the run follows `onFail`. Without `onFail` the run continues as if the action had succeeded, so give a step that matters an `onFail`.
|
|
299
202
|
|
|
300
|
-
|
|
203
|
+
```ts
|
|
204
|
+
import { falai } from "@falai/agent";
|
|
301
205
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
```
|
|
206
|
+
const f = falai().fields({
|
|
207
|
+
cep: { type: "string", ask: "Pergunte o CEP." },
|
|
208
|
+
cidade: { type: "string" },
|
|
209
|
+
});
|
|
309
210
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
caller upgraded. There's no turn running, so there's no bus.
|
|
321
|
-
|
|
322
|
-
`Agent.dispatch(target, session)` writes a `pendingDirective` onto
|
|
323
|
-
the session without invoking a turn. The directive is consumed at the
|
|
324
|
-
**start of the next** `respond` call — before routing, before
|
|
325
|
-
pre-extraction, before any phase runs.
|
|
326
|
-
|
|
327
|
-
```typescript
|
|
328
|
-
// Webhook handler: redirect a session from outside a turn.
|
|
329
|
-
import type { Directive } from "@falai/agent";
|
|
330
|
-
|
|
331
|
-
app.post("/webhook/account-upgraded", async (req, res) => {
|
|
332
|
-
const session = await agent.session.getOrCreate(req.body.sessionId);
|
|
333
|
-
await agent.dispatch(
|
|
334
|
-
{ goTo: "VipFlow", reply: "You've been upgraded. Let's start fresh." },
|
|
335
|
-
session
|
|
336
|
-
);
|
|
337
|
-
res.sendStatus(204);
|
|
211
|
+
const entrega = f.flow({
|
|
212
|
+
id: "entrega",
|
|
213
|
+
name: "Prazo de entrega",
|
|
214
|
+
on: [{ message: ["quer saber o prazo de entrega"] }],
|
|
215
|
+
steps: [
|
|
216
|
+
{ id: "cep", collect: ["cep"] },
|
|
217
|
+
{ id: "cidade", do: "buscarCidade", with: { cep: "{{data.cep}}" }, onFail: "cep_errado" },
|
|
218
|
+
{ id: "prazo", prompt: "Informe o prazo de entrega para {{data.cidade}}.", then: "end" },
|
|
219
|
+
{ id: "cep_errado", prompt: "Diga que não achou o CEP e peça de novo.", then: { step: "cep", clear: ["cep"] } },
|
|
220
|
+
],
|
|
338
221
|
});
|
|
339
222
|
```
|
|
340
223
|
|
|
341
|
-
|
|
224
|
+
The action side of this, `ctx.set` included, is in [Actions and events](actions-and-events.md).
|
|
342
225
|
|
|
343
|
-
|
|
344
|
-
// String shorthand — desugars to { goTo: "Feedback" }
|
|
345
|
-
await agent.dispatch("Feedback", session);
|
|
226
|
+
## The caps
|
|
346
227
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
```
|
|
228
|
+
- **50 steps per run per turn.** A run that moves 50 times without stopping to ask or wait ends with `code: 'step-loop'` and `reason: 'failed'`. Two `if` steps pointing at each other hit it.
|
|
229
|
+
- **Hop 5.** `{ flow }`, `onEnd: 'reset'` and `turn({ start, hop })` each add one; at 5 the start is skipped with `code: 'hop-limit'`.
|
|
350
230
|
|
|
351
|
-
|
|
352
|
-
`goTo`-named flow exists (throws `FlowConfigurationError` if not),
|
|
353
|
-
strips pre-LLM-only fields, writes `pendingDirective` onto the
|
|
354
|
-
session, and returns the updated session. With a persistence adapter
|
|
355
|
-
configured (and `autoSave` on — the default), dispatch also persists
|
|
356
|
-
immediately, so a webhook's redirect survives even if the next turn
|
|
357
|
-
runs in a different process; the save compare-and-swaps on the session
|
|
358
|
-
version, so a stale copy throws `SessionConflictError` rather than
|
|
359
|
-
clobbering another writer. Without an adapter (or with
|
|
360
|
-
`autoSave: false`) the directive is memory-only until the next turn's
|
|
361
|
-
auto-save — persisting sooner is then the caller's job.
|
|
362
|
-
|
|
363
|
-
`pendingDirective` is **single-shot** — consumed exactly once and
|
|
364
|
-
cleared. Calling `dispatch` again before the next turn overwrites the
|
|
365
|
-
previous one (last-wins). To merge with a pending directive instead
|
|
366
|
-
of overwriting, use `flow.merge`:
|
|
367
|
-
|
|
368
|
-
```typescript
|
|
369
|
-
import { flow } from "@falai/agent";
|
|
370
|
-
|
|
371
|
-
const merged = flow.merge(
|
|
372
|
-
session.pendingDirective ?? {},
|
|
373
|
-
{ dataUpdate: { tier: "vip" } }
|
|
374
|
-
);
|
|
375
|
-
await agent.dispatch(merged, session);
|
|
376
|
-
```
|
|
231
|
+
## When the flow changed under a live run
|
|
377
232
|
|
|
378
|
-
|
|
233
|
+
Flows are read from the agent on every turn, so a run may wake up in a flow you have since edited:
|
|
379
234
|
|
|
380
|
-
|
|
235
|
+
- The flow is gone (disabled or removed): the run ends with `code: 'flow-gone'`.
|
|
236
|
+
- The step is gone: the run ends with `code: 'step-gone'`.
|
|
381
237
|
|
|
382
|
-
|
|
383
|
-
|----------------|------|-----|
|
|
384
|
-
| Tool handler, mid-flight | `Directive` | `ctx.dispatch(d)` |
|
|
385
|
-
| Tool handler, on return | `Directive` | `return { data, directive: d }` |
|
|
386
|
-
| `prepare` / `onEnter` hook | `Directive` | `return d` (pre-LLM fields honored) |
|
|
387
|
-
| `finalize` / `onComplete` hook | `Directive` | `return d` |
|
|
388
|
-
| Branch `then` target | `Directive` | `then: d` (see [Branching](./branching.md)) |
|
|
389
|
-
| Outside a turn (webhook, job) | `Directive` | `await agent.dispatch(d, session)` |
|
|
238
|
+
Keep the ids of talk steps stable when you edit a flow that has live runs.
|
|
390
239
|
|
|
391
|
-
|
|
240
|
+
## Every outcome line, in one place
|
|
392
241
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
-
|
|
242
|
+
| `code` | Written when |
|
|
243
|
+
|---|---|
|
|
244
|
+
| none, `next` set | a step finished normally and moved |
|
|
245
|
+
| `branch` | a branch fired on an asking step |
|
|
246
|
+
| `code: 'already-known'` | a collect step's fields were already known |
|
|
247
|
+
| `code: 'max-asks'` (`detail` = the field) | a field hit `maxAsks` and was given up |
|
|
248
|
+
| `code: 'already-sent'` | a `say` with `once: true` had already gone out |
|
|
249
|
+
| `code: 'another-reply'` | another run's `say` or spoke action answered this message |
|
|
250
|
+
| `code: 'silenced'` (`detail` = your reason) | a talk or `say` step was reached while the host had silenced the assistant |
|
|
251
|
+
| `code: 'action-skipped'` | a `do` returned `skipped` |
|
|
252
|
+
| `code: 'action-failed'` | a `do` returned `failed` or threw |
|
|
253
|
+
| `code: 'replied'`, `code: 'no-reply'`, `code: 'inline-delay'` | a timer `wait` ended by a reply, by the timer, or rode on the next message |
|
|
254
|
+
| `code: 'awaiting-event'`, `code: 'event-arrived'`, `code: 'no-event'` | an event `wait` parked, resumed, or timed out |
|
|
255
|
+
| `code: 'awaiting-trigger'` | an event trigger's `after` parked the new run |
|
|
256
|
+
| `code: 'premise-changed'` | `while` (or the trigger's `if`) stopped holding |
|
|
257
|
+
| `code: 'customer-replied'` | a silence run woke after the customer wrote |
|
|
258
|
+
| `code: 'flow-gone'`, `code: 'step-gone'` | the flow or step no longer exists |
|
|
259
|
+
| `code: 'step-loop'` | the 50-step cap |
|
|
260
|
+
| `code: 'action-deferred'`, with `until` set | a `do` returned `{ defer }` |
|
|
261
|
+
| `code: 'provider-unavailable'`, `code: 'provider-quota'` | the speak call failed and a wait may help; the step is parked under a retry wake |
|
|
262
|
+
| `code: 'provider-auth'`, `code: 'provider-context'`, `code: 'provider-invalid'` | the speak call failed and no wait can help; the run ends `failed` |
|
|
263
|
+
| `code: 'no-session'`, `code: 'duplicate-input'`, `code: 'stale-wake'`, `code: 'silence-broken'` | the input was a no-op; the turn returns `changed: false` |
|
|
264
|
+
| `code: 'unknown-field'`, `code: 'bad-value'`, `code: 'not-in-enum'` | an extracted value was dropped instead of written |
|
|
398
265
|
|
|
399
|
-
|
|
266
|
+
Trigger-level skips (`code: 'already-claimed'`, `code: 'cooldown'`, `code: 'already-running'`, `code: 'hop-limit'`) go to `skipped[]` instead. The full list with every field is in [Outcomes](../reference/outcomes.md).
|
|
400
267
|
|
|
401
|
-
|
|
402
|
-
- From the model → leave `reply` unset; let the LLM call run.
|
|
268
|
+
## Coming from 3.x
|
|
403
269
|
|
|
404
|
-
|
|
270
|
+
Every position change is now a `then` or `else` on a step. A tool cannot move the run; an `if` step, a branch or a host `start` does that. Code that ran around a step is a `do` step at that position. The before-and-after is in [v3 → v4 migration](../migration/v3-to-v4.md#5-movement-then--else-replace-directives-and-hooks).
|
|
405
271
|
|
|
406
|
-
|
|
407
|
-
every shorthand, every validation rule.
|
|
408
|
-
- [Directives concept](../concepts/directives.md) — the mental model
|
|
409
|
-
and the inheritance chain.
|
|
410
|
-
- [Branching](./branching.md) — when the redirect is source-local
|
|
411
|
-
rather than dynamic.
|
|
412
|
-
- [Turn pipeline](../concepts/pipeline.md) — when and where directives
|
|
413
|
-
apply within a turn.
|
|
272
|
+
## Read next
|
|
414
273
|
|
|
415
|
-
|
|
274
|
+
- [Branching](branching.md): `when` and `if` branches on an asking step.
|
|
275
|
+
- [Runs and waits](../concepts/runs-and-waits.md): the floor, suspended runs, wakes and keys.
|
|
276
|
+
- [Step reference](../reference/step.md): every step kind and `Next`.
|