@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,396 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Actions, events, conditions"
|
|
3
|
+
description: "The three host registries a flow names by string: actions a do step runs, events the host reports, conditions a JSON predicate can call."
|
|
4
|
+
type: reference
|
|
5
|
+
order: 7
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Actions, events, conditions
|
|
9
|
+
|
|
10
|
+
You write these three in your code, and a flow names them with a string. An **action** does something when a `do` step reaches it: send an email, add a tag. An **event** is something that happened in your system. You report it with `turn({ event })`, and triggers and `wait` steps react. A **condition** is a yes/no check your code answers, so a flow stored as JSON can ask something the built-in tests cannot. Register all three on the agent, under `actions`, `events` and `conditions`. Every name a flow uses is checked when the agent is built.
|
|
11
|
+
|
|
12
|
+
Source: `src/types/flow.ts`, `src/core/Runner.ts`, `src/core/predicate.ts`, `src/core/falai.ts`.
|
|
13
|
+
|
|
14
|
+
## Action
|
|
15
|
+
|
|
16
|
+
An action is a host function with typed parameters. A `do` step names it and passes `with`. It runs at least once per step visit, so make it idempotent: safe to run twice. Check `ctx.key` and skip work you already did for that key.
|
|
17
|
+
|
|
18
|
+
### Signature
|
|
19
|
+
|
|
20
|
+
```ts fragment
|
|
21
|
+
interface Action<C = unknown, D = unknown, P = Record<string, unknown>> {
|
|
22
|
+
description?: string;
|
|
23
|
+
parameters: ParamDefs;
|
|
24
|
+
run(params: P, ctx: ActionCtx<C, D>): ActionResult | Promise<ActionResult>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type ActionMap<C = unknown, D = unknown> = Record<string, Action<C, D>>;
|
|
28
|
+
|
|
29
|
+
type ParamDefs = Record<string, ParamDef>;
|
|
30
|
+
|
|
31
|
+
type ParamDef =
|
|
32
|
+
| (ScalarDef & { optional?: true })
|
|
33
|
+
| { type: "array"; items: ScalarDef; description?: string; optional?: true };
|
|
34
|
+
|
|
35
|
+
interface ScalarDef<T extends ScalarType = ScalarType> {
|
|
36
|
+
type: T; // "string" | "number" | "integer" | "boolean"
|
|
37
|
+
description?: string;
|
|
38
|
+
enum?: readonly (string | number)[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The `with` shape of an action, from its parameter definitions. */
|
|
42
|
+
type InferParams<P extends ParamDefs> = { /* required keys */ } & { /* optional keys? */ };
|
|
43
|
+
|
|
44
|
+
interface ActionCtx<C = unknown, D = unknown> {
|
|
45
|
+
context: C;
|
|
46
|
+
data: Partial<D>;
|
|
47
|
+
input: unknown;
|
|
48
|
+
run: Run;
|
|
49
|
+
key: string;
|
|
50
|
+
dedupeKey: string;
|
|
51
|
+
silenced?: string;
|
|
52
|
+
now: Date;
|
|
53
|
+
set(patch: Partial<D>): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type ActionResult =
|
|
57
|
+
| { ok: true; detail?: string; spoke?: true }
|
|
58
|
+
| { skipped: string }
|
|
59
|
+
| { failed: string }
|
|
60
|
+
| { defer: Duration; detail: string };
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`f.action(def)` returns the same object, with `params` typed from `parameters`:
|
|
64
|
+
|
|
65
|
+
```ts fragment
|
|
66
|
+
f.action<const P extends ParamDefs>(def: {
|
|
67
|
+
description?: string;
|
|
68
|
+
parameters: P;
|
|
69
|
+
run: (params: InferParams<P>, ctx: ActionCtx<C, D>) => ActionResult | Promise<ActionResult>;
|
|
70
|
+
}): Action<C, D, InferParams<P>>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Action fields
|
|
74
|
+
|
|
75
|
+
| Field | Type | Default | Meaning |
|
|
76
|
+
|---|---|---|---|
|
|
77
|
+
| `description` | `string` | none | For people and editors. The framework never reads it. |
|
|
78
|
+
| `parameters` | `ParamDefs` | required | What `with` must carry. Every parameter is required unless `optional: true`. `{}` means the action takes nothing. |
|
|
79
|
+
| `run` | `(params, ctx) => ActionResult \| Promise<ActionResult>` | required | Your code. Return one of the four results; a thrown error counts as `{ failed: error.message }`. |
|
|
80
|
+
|
|
81
|
+
### ParamDef fields
|
|
82
|
+
|
|
83
|
+
| Field | Type | Default | Meaning |
|
|
84
|
+
|---|---|---|---|
|
|
85
|
+
| `type` | `"string" \| "number" \| "integer" \| "boolean" \| "array"` | required | The value's type. `array` needs `items`. |
|
|
86
|
+
| `items` | `ScalarDef` | required for `array` | The type of each element. |
|
|
87
|
+
| `enum` | `readonly (string \| number)[]` | none | Allowed values. Becomes a literal union in `InferParams`. |
|
|
88
|
+
| `description` | `string` | none | Shown to a model that writes flows (`flowSpecSchema`). |
|
|
89
|
+
| `optional` | `true` | absent | The parameter may be left out of `with`. |
|
|
90
|
+
|
|
91
|
+
### ActionCtx fields
|
|
92
|
+
|
|
93
|
+
| Field | Type | Meaning |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| `context` | `C` | The host context passed to this `turn()`. |
|
|
96
|
+
| `data` | `Partial<D>` | The session's collected fields, live. |
|
|
97
|
+
| `input` | `unknown` | The run's input: a mention trigger's `extract` values, an event's `payload`, a `start` input, or, for a `{ flow }` jump, its `input` when given, else the parent run's input. |
|
|
98
|
+
| `run` | `Run` | The run this step belongs to: id, flow, anchor, status, visits, asked counts, outcomes. |
|
|
99
|
+
| `key` | `string` | `${runId}:${stepId}:${visit}`. The same input replayed mints the same key, and a deferred action re-runs under the same key. Use it as your idempotency key. |
|
|
100
|
+
| `dedupeKey` | `string` | `${flowId}:${anchor}:${nonce}`. `nonce` is the trigger key when `repeat` is `'always'`, empty for `'once'` and cooldown. The host may share it across a customer's sessions through `turn({ claims })`. |
|
|
101
|
+
| `silenced` | `string \| undefined` | The host's reason the assistant may not speak. `do` steps still run while silenced; check this before sending anything the customer would read. |
|
|
102
|
+
| `now` | `Date` | The agent's clock at this turn. Never read `Date.now()` inside an action. |
|
|
103
|
+
| `set(patch)` | `(patch: Partial<D>) => void` | Writes fields into `data` at once, as given. Values are not coerced or checked against the field's type or `enum`. |
|
|
104
|
+
|
|
105
|
+
### ActionResult and what the runner does
|
|
106
|
+
|
|
107
|
+
| Result | Outcome line | Movement |
|
|
108
|
+
|---|---|---|
|
|
109
|
+
| `{ ok: true, detail?, spoke? }` | `do` / `ok`, no `code`, `detail` only when you gave one | `then`, or the next step. |
|
|
110
|
+
| `{ skipped: reason }` | `do` / `skipped`, `code: 'action-skipped'`, `detail` = your reason, unprefixed | `then`, or the next step. |
|
|
111
|
+
| `{ failed: reason }` | `do` / `failed`, `code: 'action-failed'`, `detail` = your reason, unprefixed | `onFail` if the step has one, else `then` or the next step. |
|
|
112
|
+
| `{ defer: '24h', detail }` | `do` / `deferred`, `code: 'action-deferred'`, `detail` as you gave it, `until` set | The run parks. A wake with key `${runId}:${stepId}:${atMs}` goes into `schedule[]`. At fire time the same step runs again at the same visit, so `ctx.key` is unchanged. |
|
|
113
|
+
| thrown error | as `{ failed: error.message }` | as `failed`. |
|
|
114
|
+
|
|
115
|
+
`spoke: true` tells the runner your action itself answered the customer (it sent a template, say). Three things follow: the assistant counts as having spoken, so `lastAssistantAt` moves and silence triggers re-arm; the idle speaker stays quiet this turn; and on a message turn, a talk step in another run that was about to speak is held back with `code: 'another-reply'` and its run stays `asking`.
|
|
116
|
+
|
|
117
|
+
### Behaviour
|
|
118
|
+
|
|
119
|
+
- `with` is rendered before `run` sees it. `{{data.x}}`, `{{context.x}}` and `{{input.x}}` are replaced inside every string, at any depth. A path that resolves to nothing keeps its placeholder, so a typo stays visible.
|
|
120
|
+
- `with` is checked when the agent is built, not on the turn that reaches the step. A missing required parameter, an unknown parameter, or a value outside `enum` throws `FlowConfigurationError`. So does a wrong type: `"3"` is not a number, because values are never coerced. A string that contains `{{` skips the `enum` check, because its value is only known at run time.
|
|
121
|
+
- Actions run in the Run phase, by code, with zero model calls. They run while `silenced` too.
|
|
122
|
+
- A `do` step whose action name is not registered throws at build. If the registry changed under a running agent, the step reports `code: 'action-failed'` with `detail: 'unknown action "notify"'`.
|
|
123
|
+
- The runner awaits `run`. Keep it short; nothing else in the turn moves until it returns.
|
|
124
|
+
|
|
125
|
+
### Example
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
129
|
+
|
|
130
|
+
const f = falai().fields({
|
|
131
|
+
nome: { type: "string", ask: "Pergunte o nome." },
|
|
132
|
+
empresa: { type: "string", ask: "Pergunte a empresa." },
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// `params` is typed from `parameters`: { recipient: string; message: string; urgent?: boolean }.
|
|
136
|
+
const notify = f.action({
|
|
137
|
+
description: "Avisa alguém da equipe.",
|
|
138
|
+
parameters: {
|
|
139
|
+
recipient: { type: "string" },
|
|
140
|
+
message: { type: "string" },
|
|
141
|
+
urgent: { type: "boolean", optional: true },
|
|
142
|
+
},
|
|
143
|
+
run: (params, ctx) => {
|
|
144
|
+
console.log(`[${ctx.key}] ${params.recipient}: ${params.message}`);
|
|
145
|
+
return { ok: true, detail: "aviso enviado" };
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const agent = f.agent({
|
|
150
|
+
name: "Ana",
|
|
151
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
152
|
+
actions: { notify },
|
|
153
|
+
flows: [
|
|
154
|
+
f.flow({
|
|
155
|
+
id: "triagem",
|
|
156
|
+
name: "Triagem",
|
|
157
|
+
on: [{ message: ["quer um orçamento"] }],
|
|
158
|
+
steps: [
|
|
159
|
+
{ id: "quem", collect: ["nome", "empresa"] },
|
|
160
|
+
{
|
|
161
|
+
id: "avisa",
|
|
162
|
+
do: "notify",
|
|
163
|
+
with: { recipient: "owner", message: "Lead: {{data.nome}} ({{data.empresa}})" },
|
|
164
|
+
onFail: "falhou",
|
|
165
|
+
},
|
|
166
|
+
{ id: "tchau", say: "Um vendedor continua daqui.", then: "end" },
|
|
167
|
+
// The action failed: say so, and say what happens next.
|
|
168
|
+
{ id: "falhou", say: "Não consegui avisar o time agora. Seus dados estão salvos e um vendedor fala com você ainda hoje." },
|
|
169
|
+
],
|
|
170
|
+
}),
|
|
171
|
+
],
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const r = await agent.turn({ sessionId: "demo", message: "quero um orçamento" });
|
|
175
|
+
console.log(r.outcomes.map((o) => [o.stepId, o.status, o.code, o.detail]));
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Event
|
|
179
|
+
|
|
180
|
+
An event is a fact the host reports: a deal moved stage, a meeting was booked, a human replied. Register it by name so triggers (`on: [{ event }]`) and steps (`wait: { event }`) can use it. The definition carries a direction and a `payload` type that exists only for TypeScript; nothing is ever stored in it.
|
|
181
|
+
|
|
182
|
+
### Signature
|
|
183
|
+
|
|
184
|
+
```ts fragment
|
|
185
|
+
interface EventDef<P = unknown> {
|
|
186
|
+
direction?: "inbound" | "outbound";
|
|
187
|
+
readonly payload?: P; // phantom: the payload type, never set at run time
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
type EventMap = Record<string, EventDef>;
|
|
191
|
+
|
|
192
|
+
f.event<P = undefined>(def?: { direction?: "inbound" | "outbound" }): EventDef<P>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### EventDef fields
|
|
196
|
+
|
|
197
|
+
| Field | Type | Default | Meaning |
|
|
198
|
+
|---|---|---|---|
|
|
199
|
+
| `direction` | `"inbound" \| "outbound"` | none | `'inbound'`: the customer spoke through this event. `'outbound'`: the assistant spoke. Absent: neither side spoke. |
|
|
200
|
+
| `payload` | `P` | never set | Only types the payload. Never set it. |
|
|
201
|
+
|
|
202
|
+
### Reporting an event
|
|
203
|
+
|
|
204
|
+
The host calls `turn()` with the event variant of `TurnInput`:
|
|
205
|
+
|
|
206
|
+
```ts fragment
|
|
207
|
+
{ event: string; payload?: unknown; key: string; hop?: number }
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
| Field | Meaning |
|
|
211
|
+
|---|---|
|
|
212
|
+
| `event` | The registered name. |
|
|
213
|
+
| `payload` | Becomes the run's `input`; `{{input.x}}` reads it in prompts, `say` texts and `with`. |
|
|
214
|
+
| `key` | The trigger key. Runs it starts get id `${flowId}#${key}`, and with the default `repeat: 'always'` the claim `${flowId}:${anchor}:${key}` is written. Reporting the same event again with the same key starts nothing: the start is skipped with `code: 'already-claimed'`. |
|
|
215
|
+
| `hop` | Chaining depth, default 0. A start that would be at hop 5 is skipped with `code: 'hop-limit'`. |
|
|
216
|
+
|
|
217
|
+
An event turn never spends an understand call. It costs one speak call (plus tool rounds) only when a run it moved reaches a talk step.
|
|
218
|
+
|
|
219
|
+
### What an event turn does, in order
|
|
220
|
+
|
|
221
|
+
1. **Direction.** `'inbound'` sets `lastUserAt` to now and resolves reply waits: every run parked on a timer `wait` that has an `else` resumes with `code: 'replied'` and follows a matching `if` branch's `then`, else `else`. `'outbound'` sets `lastAssistantAt` to now, which re-arms `silence` triggers at the end of the turn.
|
|
222
|
+
2. **Waiting runs.** Every run parked on `wait: { event: name }` for this name resumes with `code: 'event-arrived'` and follows `then`. The first one to resume takes the floor for this turn.
|
|
223
|
+
3. **Triggers.** Every flow with `on: [{ event: name }]` goes through the start order: trigger `if`, `repeat` (default `'always'` for events), the hop cap, one live run per flow and anchor. With `after`, the run parks first (`code: 'awaiting-trigger'`, wake key `${runId}:start:${atMs}`) and enters its first step when the wake fires; `businessHours: true` snaps that time forward through the agent's `businessHours` function.
|
|
224
|
+
|
|
225
|
+
`wait: { event, upTo }` in a step parks the run for at most `upTo` (default `'30d'`, from `src/core/Runner.ts`). If the event never comes, the line carries `code: 'no-event'` and the run follows `else`, or ends when there is none.
|
|
226
|
+
|
|
227
|
+
### Example
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
231
|
+
|
|
232
|
+
interface Ctx {
|
|
233
|
+
lead: { id: string };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const f = falai<Ctx>().fields({
|
|
237
|
+
nome: { type: "string", ask: "Pergunte o nome." },
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const events = {
|
|
241
|
+
stage_entered: f.event<{ stageId: string }>(),
|
|
242
|
+
reaction: f.event<{ emoji: string }>({ direction: "inbound" }),
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const agent = f.agent({
|
|
246
|
+
name: "Ana",
|
|
247
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
248
|
+
events,
|
|
249
|
+
flows: [
|
|
250
|
+
f.flow({
|
|
251
|
+
id: "proposta",
|
|
252
|
+
name: "Proposta enviada",
|
|
253
|
+
// Starts on every `stage_entered`, ten minutes after it is reported.
|
|
254
|
+
on: [{ event: "stage_entered", after: "10m" }],
|
|
255
|
+
steps: [{ id: "avisa", say: "Você entrou na etapa {{input.stageId}}. Quer que eu explique os próximos passos?" }],
|
|
256
|
+
}),
|
|
257
|
+
],
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const r = await agent.turn({
|
|
261
|
+
sessionId: "demo",
|
|
262
|
+
context: { lead: { id: "l1" } },
|
|
263
|
+
event: "stage_entered",
|
|
264
|
+
payload: { stageId: "proposta" },
|
|
265
|
+
key: "stage:proposta:1",
|
|
266
|
+
});
|
|
267
|
+
console.log(r.schedule); // one wake, ten minutes from now
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Condition
|
|
271
|
+
|
|
272
|
+
A condition is a named yes/no check in code. Flows written in TypeScript can pass a function anywhere a predicate (`Pred`, below) is accepted; flows stored as JSON cannot, so they name a condition and give it an argument: `{ tagsAny: ["vip"] }`.
|
|
273
|
+
|
|
274
|
+
### Signature
|
|
275
|
+
|
|
276
|
+
```ts fragment
|
|
277
|
+
interface Condition<C = unknown, D = unknown, Arg = unknown> {
|
|
278
|
+
check(ctx: PredCtx<C, D>, arg: Arg): boolean;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
type ConditionMap<C = unknown, D = unknown> = Record<string, Condition<C, D>>;
|
|
282
|
+
|
|
283
|
+
/** The JSON form of a predicate. Every listed entry must hold. */
|
|
284
|
+
interface ConditionSpec<D = unknown> {
|
|
285
|
+
equals?: Partial<D>;
|
|
286
|
+
known?: (keyof D & string)[];
|
|
287
|
+
silenced?: boolean;
|
|
288
|
+
[condition: string]: unknown; // a registered condition and its argument
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** A code predicate (free) or its JSON form. */
|
|
292
|
+
type Pred<C = unknown, D = unknown, P = unknown> =
|
|
293
|
+
| ((ctx: PredCtx<C, D, P>) => boolean)
|
|
294
|
+
| ConditionSpec<D>;
|
|
295
|
+
|
|
296
|
+
interface PredCtx<C = unknown, D = unknown, P = unknown> {
|
|
297
|
+
context: C;
|
|
298
|
+
data: Partial<D>;
|
|
299
|
+
input: P;
|
|
300
|
+
run?: Run;
|
|
301
|
+
silenced?: string;
|
|
302
|
+
now: Date;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
f.condition<Arg>(check: (ctx: PredCtx<C, D>, arg: Arg) => boolean): Condition<C, D, Arg>
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### PredCtx fields
|
|
309
|
+
|
|
310
|
+
| Field | Type | Meaning |
|
|
311
|
+
|---|---|---|
|
|
312
|
+
| `context` | `C` | The host context of this turn. |
|
|
313
|
+
| `data` | `Partial<D>` | Collected fields, live. |
|
|
314
|
+
| `input` | `P` | The run's input (see `ActionCtx.input`). `undefined` when there is no run. |
|
|
315
|
+
| `run` | `Run \| undefined` | The run being judged. Present for a trigger `if`, `while`, an `if` step, a branch `if`, and a flow or step instruction `if`. Absent whenever the idle speaker answers, because no run holds the floor — for agent-level and `idle`-level instructions alike. |
|
|
316
|
+
| `silenced` | `string \| undefined` | The host's reason the assistant may not speak, when given. |
|
|
317
|
+
| `now` | `Date` | The agent's clock. |
|
|
318
|
+
|
|
319
|
+
For a trigger `if`, `run` is the run as it would be if it started now: id `${flowId}#${triggerKey}`, `stepId: null`, `status: 'running'`, empty `asked`, `visits` and `outcomes`. Nothing has been written to the session yet.
|
|
320
|
+
|
|
321
|
+
### ConditionSpec built-ins
|
|
322
|
+
|
|
323
|
+
A `ConditionSpec` holds when every key holds (AND). A key whose value is `undefined` is skipped.
|
|
324
|
+
|
|
325
|
+
| Key | Argument | Holds when |
|
|
326
|
+
|---|---|---|
|
|
327
|
+
| `equals` | `{ field: value, … }` | Every `data[field]` deep-equals the value as written. Values are compared, not rendered: `"{{context.x}}"` is a literal string here. |
|
|
328
|
+
| `known` | `["field", …]` | Every field is known: not `undefined`, not `null`, not `''`. |
|
|
329
|
+
| `silenced` | `true \| false` | `true`: the host passed `silenced`. `false`: it did not. |
|
|
330
|
+
| any other key | anything | `conditions[key].check(ctx, arg)` returns true. The argument arrives from JSON unvalidated; test its shape inside `check`. |
|
|
331
|
+
|
|
332
|
+
Naming a condition the agent does not have throws `FlowConfigurationError` when the agent is built (`validateFlow`), and again at evaluation if it ever gets that far.
|
|
333
|
+
|
|
334
|
+
### Where a predicate may appear
|
|
335
|
+
|
|
336
|
+
| Place | Field | Judged |
|
|
337
|
+
|---|---|---|
|
|
338
|
+
| Trigger | `on[].if` | Before a run starts. For `message` and `silence` triggers also earlier, when the turn works out which flows may start; `run` is then the run as it would be (see above). |
|
|
339
|
+
| Flow | `while` | Every time the run is about to move. Default: the trigger's `if`. When it stops holding the run ends with `code: 'premise-changed'`. |
|
|
340
|
+
| Step | `if` step | When the run reaches it. `then` on true, `else` (default `'end'`) on false. |
|
|
341
|
+
| Branch | `branches[].if` | On the asking talk step when the customer writes, and on a timer `wait` when the customer replies first. |
|
|
342
|
+
| Instruction | `if` | When the speak prompt is built. A false `if` drops the instruction from this call. |
|
|
343
|
+
|
|
344
|
+
A function predicate is free and runs on every check. A `when` string is different: the model judges it, and it costs part of a call. See [Conditions](../guides/conditions.md).
|
|
345
|
+
|
|
346
|
+
### Example
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
350
|
+
|
|
351
|
+
interface Ctx {
|
|
352
|
+
lead: { tags: string[]; owner: "ai" | "human" };
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const f = falai<Ctx>().fields({
|
|
356
|
+
nome: { type: "string", ask: "Pergunte o nome." },
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
const conditions = {
|
|
360
|
+
// JSON flows write { tagsAny: ["vip"] }; `arg` arrives unvalidated, so check its shape.
|
|
361
|
+
tagsAny: f.condition((ctx, tags: string[]) => Array.isArray(tags) && tags.some((t) => ctx.context.lead.tags.includes(t))),
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const agent = f.agent({
|
|
365
|
+
name: "Ana",
|
|
366
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
367
|
+
conditions,
|
|
368
|
+
flows: [
|
|
369
|
+
f.flow({
|
|
370
|
+
id: "vip",
|
|
371
|
+
name: "Atendimento VIP",
|
|
372
|
+
on: [{ message: ["quer falar com alguém"], if: { tagsAny: ["vip"] } }],
|
|
373
|
+
steps: [
|
|
374
|
+
// A function predicate, free, judged by code.
|
|
375
|
+
{ id: "dono", if: ({ context }) => context.lead.owner === "ai", then: "quem", else: "end" },
|
|
376
|
+
{ id: "quem", collect: ["nome"] },
|
|
377
|
+
],
|
|
378
|
+
}),
|
|
379
|
+
],
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
const r = await agent.turn({
|
|
383
|
+
sessionId: "demo",
|
|
384
|
+
context: { lead: { tags: ["vip"], owner: "ai" } },
|
|
385
|
+
message: "quero falar com alguém",
|
|
386
|
+
});
|
|
387
|
+
console.log(r.started.map((s) => s.flowId)); // ["vip"]
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## See also
|
|
391
|
+
|
|
392
|
+
- [Actions and events](../guides/actions-and-events.md): idempotency, publishing events, waiting on them.
|
|
393
|
+
- [Conditions](../guides/conditions.md): `when` versus `if`, and where each is allowed.
|
|
394
|
+
- [Flow spec](./flow-spec.md): how names in a JSON flow resolve against these registries.
|
|
395
|
+
- [Outcomes](./outcomes.md): every line a `do` step or a skipped start can produce.
|
|
396
|
+
- [Step](./step.md): the `do`, `if` and `wait` steps.
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Agent"
|
|
3
|
+
description: "How to build an agent with falai(), every AgentOptions field, and what turn() takes and returns."
|
|
4
|
+
type: reference
|
|
5
|
+
order: 1
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Agent
|
|
9
|
+
|
|
10
|
+
An `Agent` is immutable configuration plus one method, `turn()`. You build it once with `falai<C>().fields(...).agent(...)`; the same instance serves every session. Each call to `turn()` brings its own `sessionId`, `session`, `context` and `history`, and returns the messages to send, the wakes to schedule and the session to save. The framework never sends, never sleeps and never saves. The program that does those three things is the host.
|
|
11
|
+
|
|
12
|
+
A turn spends at most two model calls: the understand call, which routes the message and pulls values out of it, and the speak call, which phrases the reply.
|
|
13
|
+
|
|
14
|
+
## Signature
|
|
15
|
+
|
|
16
|
+
```ts fragment
|
|
17
|
+
function falai<C = undefined>(): FalaiRoot<C>;
|
|
18
|
+
|
|
19
|
+
interface FalaiRoot<C> {
|
|
20
|
+
fields<const F extends FieldDefs>(defs: F): Falai<C, InferData<F>, F>;
|
|
21
|
+
// plus every Falai method below, with loose data (any slug is a string)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface Falai<C, D, F extends FieldDefs> {
|
|
25
|
+
readonly fields: F;
|
|
26
|
+
action<const P extends ParamDefs>(def: {
|
|
27
|
+
description?: string;
|
|
28
|
+
parameters: P;
|
|
29
|
+
run(params: InferParams<P>, ctx: ActionCtx<C, D>): ActionResult | Promise<ActionResult>;
|
|
30
|
+
}): Action<C, D, InferParams<P>>;
|
|
31
|
+
event<P = undefined>(def?: { direction?: "inbound" | "outbound" }): EventDef<P>;
|
|
32
|
+
condition<Arg>(check: (ctx: PredCtx<C, D>, arg: Arg) => boolean): Condition<C, D, Arg>;
|
|
33
|
+
flow(def: Flow<C, D>): Flow<C, D>;
|
|
34
|
+
fromSpec(spec: FlowSpec): Flow<C, D>;
|
|
35
|
+
agent(options: Omit<AgentOptions<C, D>, "fields">): Agent<C, D>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type DataOf<T extends { fields: FieldDefs }> = InferData<T["fields"]>;
|
|
39
|
+
|
|
40
|
+
class Agent<C, D> {
|
|
41
|
+
constructor(readonly options: AgentOptions<C, D>);
|
|
42
|
+
turn(input: TurnInput<C, D>): Promise<TurnResult<D>>;
|
|
43
|
+
turnStream(input: TurnInput<C, D>): AsyncIterable<TurnStreamChunk<D>>;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## The toolkit
|
|
48
|
+
|
|
49
|
+
`falai<C>()` takes one generic: the type of the `context` your host passes on every turn. `falai()` alone means no context. Everything else is inferred from values.
|
|
50
|
+
|
|
51
|
+
| Method | Returns | What it does |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| `fields(defs)` | `Falai<C, D, F>` | Binds the collected-data type `D`. Every `collect`, `ask`, `clearOnStart`, `equals`, `known` and action `ctx.set` downstream is checked against these slugs. |
|
|
54
|
+
| `fields` (property) | `F` | The definitions you passed, unchanged. `DataOf<typeof f>` reads the data type from it. |
|
|
55
|
+
| `flow(def)` | `Flow<C, D>` | Returns the flow unchanged, typed. See [Flow](flow.md). |
|
|
56
|
+
| `fromSpec(spec)` | `Flow<C, D>` | A stored JSON flow as a typed flow. Validated when the agent is built. See [Flow spec](flow-spec.md). |
|
|
57
|
+
| `action(def)` | `Action<C, D, P>` | A host action. `params` inside `run` is typed from `parameters`. |
|
|
58
|
+
| `event<P>(def?)` | `EventDef<P>` | A host event; `P` is its payload type. `direction` says whether it counts as the customer or the assistant speaking. |
|
|
59
|
+
| `condition(check)` | `Condition<C, D, Arg>` | A named code predicate that JSON flows may use by name. |
|
|
60
|
+
| `agent(options)` | `Agent<C, D>` | Builds the agent. `fields` comes from the toolkit; you pass everything else. |
|
|
61
|
+
|
|
62
|
+
`Agent` is also exported directly: `new Agent(options)` takes the same options with `fields` included.
|
|
63
|
+
|
|
64
|
+
## AgentOptions
|
|
65
|
+
|
|
66
|
+
| Field | Type | Default | Meaning |
|
|
67
|
+
|---|---|---|---|
|
|
68
|
+
| `name` | `string` | required | The assistant's name. Both model calls open with "You are `name`". |
|
|
69
|
+
| `goal` | `Template` | none | What the agent is for. Rendered into the prompt. |
|
|
70
|
+
| `persona` | `Template` | none | Who the agent is and how it talks. |
|
|
71
|
+
| `provider` | `AiProvider` | required | The model. See [Providers](providers.md). |
|
|
72
|
+
| `fields` | `FieldDefs` | from the toolkit | Every collectable field, authored once. See [Fields](fields.md). |
|
|
73
|
+
| `flows` | `Flow<C, D>[]` | `[]` | The flows. Ids must be unique. |
|
|
74
|
+
| `actions` | `ActionMap<C, D>` | `{}` | Host actions that `do` steps name. |
|
|
75
|
+
| `events` | `EventMap` | `{}` | Host events that `event` triggers and `wait: { event }` steps name. |
|
|
76
|
+
| `conditions` | `ConditionMap<C, D>` | `{}` | Host conditions that JSON predicates name. |
|
|
77
|
+
| `tools` | `Tool<C, D>[]` | `[]` | Functions the model may call while it speaks. See [Tool](tool.md). |
|
|
78
|
+
| `instructions` | `Instruction<C, D>[]` | `[]` | Agent-level rules, rendered into every speak call. See [Instruction](instruction.md). |
|
|
79
|
+
| `knowledgeBase` | `Record<string, unknown>` | none | Any JSON the model should know. Rendered as nested bullets. |
|
|
80
|
+
| `idle` | `Idle<C, D>` | `{ prompt: "" }` | The one speaker that is not a step. Answers a message when no run holds the floor. `'silent'` mutes it. |
|
|
81
|
+
| `clock` | `Clock` | `() => new Date()` | Returns "now". Tests pass `fakeClock(iso)`. |
|
|
82
|
+
| `businessHours` | `BusinessHours<C>` | none | `(at, { context }) => Date`. Moves a timer forward to the next working moment when a trigger or wait says `businessHours: true`. |
|
|
83
|
+
| `maxToolLoops` | `number` | `5` | Tool rounds per speak call. `0` disables tools. After the last round the model is asked once more without tools, so a message always comes back. |
|
|
84
|
+
| `compaction` | `AgentCompactionConfig` | none | Trims the history both calls see, once per turn, when it grows past `maxTokens`. See [Compaction](../guides/compaction.md). |
|
|
85
|
+
| `debug` | `boolean` | `false` | Sets the logger to debug level. |
|
|
86
|
+
|
|
87
|
+
`Idle` is `{ prompt: Template; tools?: string[]; instructions?: Instruction[] } | 'silent'`. Its `tools` list must name tools registered on the agent.
|
|
88
|
+
|
|
89
|
+
`AgentCompactionConfig` is `{ maxTokens: number; compactionThreshold?: number; preserveRecentCount?: number; maxToolResultChars?: number; enabled?: boolean }`. Defaults: `compactionThreshold` `0.8` — compaction runs when the history passes 80% of `maxTokens` (allowed 0.5 to 0.95); keep the 4 most recent messages (at least 2); cut each tool result at 5000 characters (more than 0); `enabled: true`. Values outside those ranges throw at construction.
|
|
90
|
+
|
|
91
|
+
## turn()
|
|
92
|
+
|
|
93
|
+
`turn(input)` runs one turn and resolves to a `TurnResult`. It never throws for a model failure during the speak call; that becomes a retry wake (see [Error handling](../guides/error-handling.md)). A failure during the understand call does throw, and nothing was written: replay the same input.
|
|
94
|
+
|
|
95
|
+
`turnStream(input)` runs the same turn and yields `{ delta: string }` chunks while the model phrases the reply, then one `{ done: true, result: TurnResult }`. When nobody speaks, only the last chunk comes. See [Streaming](../guides/streaming.md).
|
|
96
|
+
|
|
97
|
+
## TurnInput
|
|
98
|
+
|
|
99
|
+
Every input carries the common fields, plus exactly one of the four kinds.
|
|
100
|
+
|
|
101
|
+
### Common fields
|
|
102
|
+
|
|
103
|
+
| Field | Type | Meaning |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| `sessionId` | `string` | The conversation's id. A first turn creates the session under this id. |
|
|
106
|
+
| `session` | `Session<D>` | The stored session, as the store returned it. Absent on a first turn. A `wake` without a session is ignored. |
|
|
107
|
+
| `context` | `C` | Your ambient data for this turn. Required unless `C` allows `undefined` (`falai()` with no generic). |
|
|
108
|
+
| `history` | `History` | The conversation so far. Pass it on every input kind, wakes included; both calls read it. Without it the framework falls back to `session.history`, then to an empty list. |
|
|
109
|
+
| `silenced` | `Silenced` | Your reason the assistant cannot speak right now. See below. |
|
|
110
|
+
| `anchors` | `Record<string, { key: string; lastInboundAt?: string }>` | The host anchors this session belongs to, by name, e.g. `{ lead: { key: 'lead:456', lastInboundAt } }`. A flow with `anchor: 'lead'` keys its runs and claims by `anchors.lead.key`. |
|
|
111
|
+
| `claims` | `{ held: Record<string, string>; active: string[] }` | Claims from the customer's other sessions: `held` maps a dedupe key to the ISO time it was taken; `active` lists live `${flowId}:${anchor}` pairs. A flow already active elsewhere is skipped with `code: 'already-running'`. |
|
|
112
|
+
|
|
113
|
+
### The four kinds
|
|
114
|
+
|
|
115
|
+
| Kind | Shape | When to send it |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| message | `{ message: string; id?: string; at?: string }` | The customer wrote. `id` is the channel's message id; a repeated `id` is ignored (`code: 'duplicate-input'`, `changed: false`). `at` is the receipt time; it defaults to the clock's now. |
|
|
118
|
+
| wake | `{ wake: string }` | A `schedule[]` entry fired. Pass its `key`. A `silence:` key starts that flow's silence run, and only while the silence still holds (`code: 'silence-broken'` otherwise). Any other key moves only the run whose wait holds it exactly; anything else is `code: 'stale-wake'`. |
|
|
119
|
+
| event | `{ event: string; payload?: unknown; key: string; hop?: number }` | Something happened in the host. `event` names a registered event; `key` is your idempotency key for it; `payload` becomes the run's `input`. |
|
|
120
|
+
| start | `{ start: { flow: string; input?: unknown; key: string; hop?: number } }` | Start a flow by hand. Works for any flow, with or without `on`. |
|
|
121
|
+
|
|
122
|
+
### Silenced
|
|
123
|
+
|
|
124
|
+
```ts fragment
|
|
125
|
+
type Silenced = string | { reason: string; understand?: boolean };
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
A string closes the gate: `do` steps still run, nothing is phrased, zero model calls. A talk or `say` step reached while the gate is closed ends its run with `code: 'silenced'` (`detail` = your reason); a run that was already asking stays asking and speaks when the gate opens. `{ reason, understand: true }` keeps the understand call on, so routing, mentions and extraction still happen while the assistant stays quiet. Predicates see the reason as `ctx.silenced`.
|
|
129
|
+
|
|
130
|
+
## TurnResult
|
|
131
|
+
|
|
132
|
+
| Field | Type | Meaning |
|
|
133
|
+
|---|---|---|
|
|
134
|
+
| `session` | `Session<D>` | The session after this turn. `version` is unchanged; the host saves it with the version it loaded and the store bumps it. |
|
|
135
|
+
| `changed` | `boolean` | `false` means save nothing and send nothing: the input was ignored or nothing moved. |
|
|
136
|
+
| `messages` | `OutboundMessage[]` | What to send, in order. |
|
|
137
|
+
| `schedule` | `ScheduleEntry[]` | Wakes to enqueue with `jobId = key`. At fire time call `turn({ wake: key })`. |
|
|
138
|
+
| `outcomes` | `StepOutcome[]` | One line per step this turn, for your execution log. See [Outcomes](outcomes.md). |
|
|
139
|
+
| `started` | `Array<{ runId; flowId; anchor; dedupeKey }>` | Runs that started this turn. |
|
|
140
|
+
| `ended` | `Array<Run & { reason: EndReason }>` | Runs that ended, with the run's last state and why: `'end'`, `'flow'`, `'reset'`, `'skipped'`, `'failed'` or `'replaced'`. |
|
|
141
|
+
| `skipped` | `Array<{ flowId; anchor; triggerKey; code; message }>` | Triggers that matched but did not start a run, and why (`code: 'already-claimed'`, `code: 'cooldown'`, `code: 'already-running'`, `code: 'hop-limit'`, `code: 'flow-gone'`). |
|
|
142
|
+
| `llmCalls` | `number` | Model calls this turn: at most one understand call, plus one speak call and one per tool round, plus one when compaction summarized. |
|
|
143
|
+
| `usage` | `TokenUsage` | What those calls cost, added up. Absent when the turn spent no call, and when the provider reported no counts. |
|
|
144
|
+
|
|
145
|
+
### TokenUsage
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
interface TokenUsage {
|
|
149
|
+
promptTokens: number;
|
|
150
|
+
completionTokens: number;
|
|
151
|
+
cachedInputTokens: number;
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
| Field | Type | Meaning |
|
|
156
|
+
|---|---|---|
|
|
157
|
+
| `promptTokens` | `number` | Tokens read, the cached ones included. |
|
|
158
|
+
| `completionTokens` | `number` | Tokens written. Thinking tokens count here. |
|
|
159
|
+
| `cachedInputTokens` | `number` | The part of `promptTokens` the provider served from its cache, billed far cheaper. `0` when the provider caches nothing or the prefix was cold. |
|
|
160
|
+
|
|
161
|
+
The counts are the providers' own, summed over every call the turn made. `usage` is absent rather than zero when nobody counted, so an unreported turn never looks free:
|
|
162
|
+
|
|
163
|
+
```ts fragment
|
|
164
|
+
const r = await agent.turn({ sessionId: "s1", message: "oi" });
|
|
165
|
+
if (r.usage) {
|
|
166
|
+
const fresh = r.usage.promptTokens - r.usage.cachedInputTokens;
|
|
167
|
+
console.log(`${r.llmCalls} call(s): ${fresh} read, ${r.usage.cachedInputTokens} cached, ${r.usage.completionTokens} written`);
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### OutboundMessage
|
|
172
|
+
|
|
173
|
+
| Field | Type | Meaning |
|
|
174
|
+
|---|---|---|
|
|
175
|
+
| `text` | `string` | The message. |
|
|
176
|
+
| `kind` | `'ai' \| 'verbatim'` | `'ai'` was phrased by the model; `'verbatim'` came from a `say` step. |
|
|
177
|
+
| `media` | `{ slug: string }` | From a `say` step's `media`. |
|
|
178
|
+
| `afterMs` | `number` | Delay before sending. A `wait` of 10 seconds or less right before a `say` or talk step lands here instead of scheduling a wake. |
|
|
179
|
+
| `key` | `string` | `${runId}:${stepId}:${visit}` for a step; `idle:${triggerKey}` for the idle speaker. The same on a replay of the same input, so your sender can dedupe on it. |
|
|
180
|
+
| `runId`, `stepId` | `string` | Which run and step spoke. Absent for the idle speaker. |
|
|
181
|
+
|
|
182
|
+
### ScheduleEntry
|
|
183
|
+
|
|
184
|
+
| Field | Type | Meaning |
|
|
185
|
+
|---|---|---|
|
|
186
|
+
| `key` | `string` | The wake key. Use it as the job id and pass it back as `turn({ wake: key })`. |
|
|
187
|
+
| `at` | `Date` | When to fire. |
|
|
188
|
+
| `replaces` | `string` | An earlier wake this one supersedes. Removing it is best effort; a stale wake is ignored anyway. |
|
|
189
|
+
|
|
190
|
+
## Behaviour
|
|
191
|
+
|
|
192
|
+
- **Construction validates everything.** `f.agent()` throws `FlowConfigurationError` when:
|
|
193
|
+
- two flows share an id
|
|
194
|
+
- `idle.tools` names a tool that is not registered
|
|
195
|
+
- a tool's `parameters` is not a JSON Schema object (`{ type: "object", properties, required }`) — the shape a function declaration needs, and easy to confuse with an action's `{ name: { type } }` map
|
|
196
|
+
- `validateFlow` rejects any flow (see [Flow](flow.md#what-validateflow-rejects))
|
|
197
|
+
|
|
198
|
+
Warnings — a backward jump without `clear`, a `collect` with no prompt and no `ask` — are logged with the `[Agent]` prefix. Compaction options outside their ranges throw a plain `Error`.
|
|
199
|
+
- **The input is never mutated.** `turn()` deep-copies `session` and works on the copy. `result.session` is that copy.
|
|
200
|
+
- **Ignored inputs.** A wake with no `session`, a wake whose key no live run holds, a silence wake after the customer wrote, and a message whose `id` is in the session's last 50 input ids all return `changed: false` with one `skipped` outcome line whose `code` says which: `no-session`, `stale-wake`, `silence-broken` or `duplicate-input`.
|
|
201
|
+
- **`changed` is computed, not flagged.** It is `true` when the session differs from the one you passed, or when there is anything in `messages`, `schedule`, `outcomes` or `skipped`.
|
|
202
|
+
- **Keys are deterministic.** Run id `${flowId}#${triggerKey}`, step key `${runId}:${stepId}:${visit}`. Replaying the same input against the same session version mints the same keys. See [Session](session.md) for the full table.
|
|
203
|
+
- **One speaker per turn.** At most one run asks at a time (the floor). A `say` or an action that reports `spoke: true` from another run makes the floor's talk step wait for the next message (`code: 'another-reply'`). The idle speaker answers a message only when no run is asking and nothing else spoke.
|
|
204
|
+
- **`context` is passed through as is.** Templates read it as `{{context.x}}`; predicates, actions and tools get it on `ctx.context`.
|
|
205
|
+
|
|
206
|
+
## Example
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
210
|
+
|
|
211
|
+
const f = falai().fields({
|
|
212
|
+
nome: { type: "string", ask: "Pergunte o nome da pessoa, sem tom de formulário." },
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
const agent = f.agent({
|
|
216
|
+
name: "Ana",
|
|
217
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
218
|
+
flows: [
|
|
219
|
+
f.flow({
|
|
220
|
+
id: "boas-vindas",
|
|
221
|
+
name: "Boas-vindas",
|
|
222
|
+
on: [{ message: [] }],
|
|
223
|
+
steps: [
|
|
224
|
+
{ id: "nome", collect: ["nome"] },
|
|
225
|
+
{ id: "ajuda", prompt: "Agradeça pelo nome e pergunte como pode ajudar." },
|
|
226
|
+
],
|
|
227
|
+
}),
|
|
228
|
+
],
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const first = await agent.turn({ sessionId: "s1", message: "oi", id: "m1" });
|
|
232
|
+
console.log(first.messages[0]?.text, first.llmCalls); // the question for `nome`, 1
|
|
233
|
+
|
|
234
|
+
const second = await agent.turn({ sessionId: "s1", session: first.session, message: "sou a Ana", id: "m2" });
|
|
235
|
+
console.log(second.session.data.nome, second.messages[0]?.key, second.llmCalls); // 'Ana', 'boas-vindas#m1:ajuda:1', 2
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## See also
|
|
239
|
+
|
|
240
|
+
- [Flow](flow.md), [Step](step.md), [Trigger](trigger.md), [Fields](fields.md)
|
|
241
|
+
- [Session](session.md) for `Session`, `Run` and the key formats
|
|
242
|
+
- [Outcomes](outcomes.md) for every outcome code
|
|
243
|
+
- [Architecture](../concepts/architecture.md) and [Pipeline](../concepts/pipeline.md)
|
|
244
|
+
- [Go to production](../start/05-go-to-production.md) for the host loop
|