@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,179 +1,125 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Instruction"
|
|
3
|
-
description: "
|
|
3
|
+
description: "One rule the model follows while it speaks, gated by an AI-judged `when` or a code-judged `if`, at agent, flow, step or idle scope."
|
|
4
4
|
type: reference
|
|
5
|
-
order:
|
|
5
|
+
order: 8
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Instruction
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
An instruction is one sentence the model obeys while it speaks: "never invent prices", "answer in three sentences". It has a `kind` (`must`, `never`, `should`), a `prompt`, and two optional tests: `when`, a string the model judges, and `if`, a predicate your code judges, which costs no model call. The same shape goes on the agent, a flow, a talk step or the idle speaker; only its place in the configuration changes.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
The set of instructions actually rendered into a given turn's prompt is reported back on the response as `appliedInstructions` — observability is deterministic, derived from rendering, not self-reported by the model. For instructions with a textual `when`, this means the condition was presented to the model, not that the model reported a match.
|
|
12
|
+
Source: `src/types/flow.ts`, `src/core/Runner.ts` (`speakRequest`), `src/core/Prompt.ts` (`instructionsSection`).
|
|
15
13
|
|
|
16
14
|
## Signature
|
|
17
15
|
|
|
18
|
-
```
|
|
19
|
-
interface Instruction<
|
|
16
|
+
```ts fragment
|
|
17
|
+
interface Instruction<C = unknown, D = unknown> {
|
|
20
18
|
id?: string;
|
|
21
|
-
kind?:
|
|
22
|
-
when?:
|
|
23
|
-
if?:
|
|
24
|
-
prompt: Template
|
|
25
|
-
enabled?: boolean; // default: true
|
|
26
|
-
tags?: string[];
|
|
27
|
-
metadata?: Record<string, unknown>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface ScopedInstructions<TContext = unknown, TData = unknown> {
|
|
31
|
-
global: Instruction<TContext, TData>[];
|
|
32
|
-
flow?: { flowTitle: string; items: Instruction<TContext, TData>[] };
|
|
33
|
-
step?: { stepId: string; items: Instruction<TContext, TData>[] };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface AppliedInstruction {
|
|
37
|
-
id: string;
|
|
38
|
-
scope: 'global' | 'flow' | 'step';
|
|
39
|
-
scopeRef?: string; // flowTitle for flow, stepId for step
|
|
19
|
+
kind?: "must" | "never" | "should";
|
|
20
|
+
when?: string | string[];
|
|
21
|
+
if?: Pred<C, D>;
|
|
22
|
+
prompt: Template;
|
|
40
23
|
}
|
|
41
24
|
```
|
|
42
25
|
|
|
43
26
|
## Fields
|
|
44
27
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
|
48
|
-
|
|
49
|
-
| `
|
|
50
|
-
| `
|
|
51
|
-
| `
|
|
52
|
-
| `if` | `ConditionIf<TContext, TData>` | no | — | Code-evaluated activation function (or array). Free to evaluate. When both `when` and `if` are set, `if` runs first; `when` is only evaluated if `if` passes. |
|
|
53
|
-
| `id` | `string` | no | auto | Stable identifier used in `AppliedInstruction.id`. Auto-generated when omitted. |
|
|
54
|
-
| `enabled` | `boolean` | no | `true` | Set `false` to skip the instruction without removing it from configuration. |
|
|
55
|
-
| `tags` | `string[]` | no | — | Free-form tags for filtering and grouping. |
|
|
56
|
-
| `metadata` | `Record<string, unknown>` | no | — | Free-form per-instruction metadata. |
|
|
57
|
-
|
|
58
|
-
### `AppliedInstruction`
|
|
59
|
-
|
|
60
|
-
| Field | Type | Notes |
|
|
61
|
-
|-------|------|-------|
|
|
62
|
-
| `id` | `string` | The `Instruction.id` that fired. |
|
|
63
|
-
| `scope` | `'global' \| 'flow' \| 'step'` | Where the instruction was declared. |
|
|
64
|
-
| `scopeRef` | `string \| undefined` | `flowTitle` for `flow`, `stepId` for `step`, `undefined` for `global`. |
|
|
65
|
-
|
|
66
|
-
## Scoping
|
|
28
|
+
| Field | Type | Default | Meaning |
|
|
29
|
+
|---|---|---|---|
|
|
30
|
+
| `id` | `string` | none | Yours. The framework carries it and never reads it. |
|
|
31
|
+
| `kind` | `"must" \| "never" \| "should"` | `"should"` | How hard the rule is. `must` is a hard rule, `never` a hard ban, `should` a preference. The word is written into the prompt as is. |
|
|
32
|
+
| `when` | `string \| string[]` | none | When the rule applies, judged by the model from the conversation. Several strings are alternatives (OR). Rendered into the prompt as text; it never costs a call of its own. |
|
|
33
|
+
| `if` | `Pred<C, D>` | none | When the rule applies, judged by code. A function or a JSON `ConditionSpec`. False: the instruction is left out of this call. |
|
|
34
|
+
| `prompt` | `Template` | required | The rule. `{{data.x}}`, `{{context.x}}` and `{{input.x}}` are filled in first. |
|
|
67
35
|
|
|
68
|
-
|
|
36
|
+
## Scopes
|
|
69
37
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
38
|
+
| Scope | Where | Applies |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| Agent | `AgentOptions.instructions` | On every speak call, talk steps and the idle speaker alike. |
|
|
41
|
+
| Flow | `Flow.instructions` | While a talk step of that flow speaks. |
|
|
42
|
+
| Step | `TalkStep.instructions` | While that step speaks. |
|
|
43
|
+
| Idle | `Idle.instructions` (`idle: { prompt, instructions }`) | While the idle speaker answers. |
|
|
73
44
|
|
|
74
|
-
|
|
45
|
+
The list the model sees is built in this order: agent, then flow, then step. For the idle speaker: agent, then idle. Duplicates are kept: the same sentence in two scopes appears twice.
|
|
75
46
|
|
|
76
|
-
|
|
77
|
-
- [<kind>] [<scope-caption>] <prompt> (apply only when: <when-clause> OR <when-clause>; do not apply when: <exclusion-clause>)
|
|
78
|
-
```
|
|
47
|
+
## Behaviour
|
|
79
48
|
|
|
80
|
-
|
|
49
|
+
- Instructions reach the **speak call only**. The understand call (routing, mentions, branches, extraction) never sees them.
|
|
50
|
+
- `if` is judged by code when the speak request is built, with a `PredCtx` of `{ context, data, input, run, silenced, now }`. `run` is the speaking run; while the idle speaker answers, `run` is absent and `input` is `undefined` for every instruction it judges — agent-level and `idle`-level alike. Write `if` predicates on the agent and on `idle` so they work without a run.
|
|
51
|
+
- `when` is not judged by code. It is appended to the line as `(apply only when: a OR b)` and the model decides.
|
|
52
|
+
- Each surviving instruction becomes one line under a `## Instructions` heading, in this exact form:
|
|
81
53
|
|
|
82
|
-
|
|
54
|
+
```text
|
|
55
|
+
- [should] [Always] Responda em até três frases.
|
|
56
|
+
- [must] [Always] Reconheça o problema antes de explicar qualquer coisa. (apply only when: a pessoa está irritada)
|
|
57
|
+
```
|
|
83
58
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
| Step | `[Step: <stepId>]` |
|
|
59
|
+
The first bracket is `kind` (or `should` when absent). The second is the group caption. Every scope goes into one group captioned `[Always]`, so the caption does not say which scope a line came from.
|
|
60
|
+
- `prompt` is rendered with the turn's `data`, `context` and the run's `input`, then trimmed. A line that renders to nothing is dropped. When no line survives, the whole section is left out.
|
|
61
|
+
- Instructions have no effect on movement, extraction or which flow starts. They shape wording only.
|
|
62
|
+
- In a stored flow (`FlowSpec`) an instruction is an `InstructionSpec`: the same fields with `if` in JSON form. `flowSpecSchema` lets a model write flow-level instructions and leaves step-level ones out.
|
|
89
63
|
|
|
90
|
-
Example
|
|
64
|
+
## Example
|
|
91
65
|
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
- [must] [Always] Always greet by name
|
|
96
|
-
- [never] [Always] Promise delivery dates you cannot guarantee
|
|
97
|
-
- [should] [In: Booking] Confirm dates before calling book_hotel
|
|
98
|
-
- [should] [Step: payment] If the card is declined, never retry without confirmation
|
|
99
|
-
```
|
|
66
|
+
```ts
|
|
67
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
100
68
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
69
|
+
interface Ctx {
|
|
70
|
+
plano: "gratis" | "pro";
|
|
71
|
+
horaLocal: number;
|
|
72
|
+
}
|
|
104
73
|
|
|
105
|
-
|
|
106
|
-
|
|
74
|
+
const f = falai<Ctx>().fields({
|
|
75
|
+
duvida: { type: "string", ask: "Pergunte qual é a dúvida, em uma frase." },
|
|
76
|
+
});
|
|
107
77
|
|
|
108
|
-
const agent =
|
|
109
|
-
name:
|
|
110
|
-
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY
|
|
78
|
+
const agent = f.agent({
|
|
79
|
+
name: "Bia",
|
|
80
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
111
81
|
instructions: [
|
|
112
|
-
{ kind:
|
|
113
|
-
|
|
82
|
+
{ kind: "never", prompt: "Nunca invente preços ou prazos." },
|
|
83
|
+
// The model judges `when` from the conversation.
|
|
84
|
+
{ kind: "must", when: "a pessoa está irritada", prompt: "Reconheça o problema antes de explicar qualquer coisa." },
|
|
85
|
+
// Code judges `if`; it costs nothing. No `run` here, so read only `context` and `data`.
|
|
86
|
+
{
|
|
87
|
+
kind: "should",
|
|
88
|
+
if: ({ context }) => context.horaLocal >= 18 || context.horaLocal < 9,
|
|
89
|
+
prompt: "Avise que o suporte humano volta às 9h.",
|
|
90
|
+
},
|
|
114
91
|
],
|
|
115
92
|
flows: [
|
|
116
|
-
{
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
93
|
+
f.flow({
|
|
94
|
+
id: "duvidas",
|
|
95
|
+
name: "Dúvidas",
|
|
96
|
+
on: [{ message: [] }], // no examples: the catch-all, starts when no other message flow wins
|
|
97
|
+
// Applies to every talk step of this flow.
|
|
98
|
+
instructions: [{ kind: "should", prompt: "Responda em até três frases." }],
|
|
121
99
|
steps: [
|
|
100
|
+
{ id: "qual", collect: ["duvida"] },
|
|
122
101
|
{
|
|
123
|
-
id:
|
|
124
|
-
prompt:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
],
|
|
102
|
+
id: "resposta",
|
|
103
|
+
prompt: "Responda a dúvida.",
|
|
104
|
+
// Applies to this step only.
|
|
105
|
+
instructions: [{ kind: "must", prompt: "Termine perguntando se ficou claro." }],
|
|
128
106
|
},
|
|
129
107
|
],
|
|
130
|
-
},
|
|
108
|
+
}),
|
|
131
109
|
],
|
|
132
110
|
});
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### 2. Conditional activation with `when` and `if`
|
|
136
|
-
|
|
137
|
-
```typescript
|
|
138
|
-
import type { Instruction } from '@falai/agent';
|
|
139
|
-
|
|
140
|
-
type Ctx = { tier: 'free' | 'pro' };
|
|
141
|
-
type Data = { hasQuoted: boolean };
|
|
142
|
-
|
|
143
|
-
const concise: Instruction<Ctx, Data> = {
|
|
144
|
-
kind: 'should',
|
|
145
|
-
when: 'User asks a simple yes/no question',
|
|
146
|
-
prompt: 'Answer in one sentence.',
|
|
147
|
-
};
|
|
148
111
|
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
### 3. Reading `appliedInstructions` from a response
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
const response = await agent.respond('Hi, I want to book a room.');
|
|
160
|
-
|
|
161
|
-
for (const a of response.appliedInstructions ?? []) {
|
|
162
|
-
console.log(`${a.scope}${a.scopeRef ? `:${a.scopeRef}` : ''} → ${a.id}`);
|
|
163
|
-
}
|
|
164
|
-
// global → ins_validate_dates
|
|
165
|
-
// flow:Booking → ins_offer_two_options
|
|
112
|
+
const r = await agent.turn({
|
|
113
|
+
sessionId: "demo",
|
|
114
|
+
context: { plano: "gratis", horaLocal: 21 },
|
|
115
|
+
message: "quanto custa o plano pro?",
|
|
116
|
+
});
|
|
117
|
+
console.log(r.messages[0]?.text);
|
|
166
118
|
```
|
|
167
119
|
|
|
168
|
-
##
|
|
169
|
-
|
|
170
|
-
- `FlowConfigurationError` — duplicate `id` across instructions in the same scope, or `kind` set to a value other than `'must' | 'never' | 'should'`.
|
|
171
|
-
- `DataValidationError` — a `Template` `prompt` references a `data` field not declared in the agent `schema`.
|
|
172
|
-
|
|
173
|
-
## Related
|
|
120
|
+
## See also
|
|
174
121
|
|
|
175
|
-
- [Instructions](../guides/instructions.md)
|
|
176
|
-
- [
|
|
177
|
-
- [
|
|
178
|
-
- [
|
|
179
|
-
- [Step](./step.md) — `StepOptions.instructions`
|
|
122
|
+
- [Instructions](../guides/instructions.md): choosing a scope and a kind.
|
|
123
|
+
- [Conditions](../guides/conditions.md): `when` versus `if`.
|
|
124
|
+
- [Actions, events, conditions](./actions-events-conditions.md): `Pred`, `PredCtx` and `ConditionSpec`.
|
|
125
|
+
- [Agent](./agent.md): `AgentOptions.instructions`, `idle`, `persona` and `goal`.
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Outcomes"
|
|
3
|
+
description: "Every line a turn writes about what a run did, with the full list of outcome codes and what produces each."
|
|
4
|
+
type: reference
|
|
5
|
+
order: 13
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Outcomes
|
|
9
|
+
|
|
10
|
+
A turn writes one line per thing a run did: a step ran, a step was skipped, a run parked, a value was dropped. Those lines are `StepOutcome`s. They come back on `TurnResult.outcomes` and stay on each run as `run.outcomes` (the last 50). Beside them, `TurnResult.started`, `ended` and `skipped` say which runs began, which ended and why, and which triggers matched but started nothing. This page lists every line the code can write, so a panel that shows runs can label each one.
|
|
11
|
+
|
|
12
|
+
Source: `src/types/session.ts`, `src/types/agent.ts`, `src/core/Runner.ts`, `src/core/Speak.ts`, `src/utils/outcomes.ts`, `src/utils/schema.ts`.
|
|
13
|
+
|
|
14
|
+
## Signature
|
|
15
|
+
|
|
16
|
+
```ts fragment
|
|
17
|
+
type StepOutcomeKind = "prompt" | "collect" | "say" | "do" | "wait" | "if" | "idle";
|
|
18
|
+
type StepOutcomeStatus = "ok" | "skipped" | "failed" | "waiting" | "deferred";
|
|
19
|
+
|
|
20
|
+
type StepOutcomeCode =
|
|
21
|
+
// The turn refused the input
|
|
22
|
+
| "no-session" | "duplicate-input" | "stale-wake" | "silence-broken"
|
|
23
|
+
// A trigger matched but started nothing
|
|
24
|
+
| "already-claimed" | "cooldown" | "hop-limit" | "already-running" | "flow-gone"
|
|
25
|
+
// A run ended early
|
|
26
|
+
| "step-loop" | "step-gone" | "customer-replied" | "premise-changed" | "silenced"
|
|
27
|
+
// A step
|
|
28
|
+
| "already-known" | "another-reply" | "already-sent" | "branch" | "max-asks"
|
|
29
|
+
| "inline-delay" | "awaiting-trigger" | "awaiting-event" | "event-arrived"
|
|
30
|
+
| "no-event" | "replied" | "no-reply"
|
|
31
|
+
// A host action
|
|
32
|
+
| "action-skipped" | "action-failed" | "action-deferred"
|
|
33
|
+
// A value the model gave
|
|
34
|
+
| "unknown-field" | "bad-value" | "not-in-enum"
|
|
35
|
+
// The model
|
|
36
|
+
| "provider-unavailable" | "provider-quota" | "provider-auth"
|
|
37
|
+
| "provider-context" | "provider-invalid";
|
|
38
|
+
|
|
39
|
+
interface StepOutcome {
|
|
40
|
+
runId?: string;
|
|
41
|
+
flowId?: string;
|
|
42
|
+
stepId?: string;
|
|
43
|
+
key?: string;
|
|
44
|
+
kind: StepOutcomeKind;
|
|
45
|
+
status: StepOutcomeStatus;
|
|
46
|
+
/** Why. Absent when the line needs no reason. Switch on this. */
|
|
47
|
+
code?: StepOutcomeCode;
|
|
48
|
+
/** The English sentence for `code`, filled by the framework. */
|
|
49
|
+
message?: string;
|
|
50
|
+
detail?: string;
|
|
51
|
+
next?: string;
|
|
52
|
+
until?: string;
|
|
53
|
+
at: string;
|
|
54
|
+
llmCalls?: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type EndReason = "end" | "flow" | "reset" | "skipped" | "failed" | "replaced";
|
|
58
|
+
|
|
59
|
+
interface TurnResult<D = unknown> {
|
|
60
|
+
outcomes: StepOutcome[];
|
|
61
|
+
started: Array<{ runId: string; flowId: string; anchor: string; dedupeKey: string }>;
|
|
62
|
+
ended: Array<Run & { reason: EndReason }>;
|
|
63
|
+
skipped: Array<{ flowId: string; anchor: string; triggerKey: string; code: StepOutcomeCode; message: string }>;
|
|
64
|
+
llmCalls: number;
|
|
65
|
+
// session, changed, messages, schedule: see Agent
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## StepOutcome fields
|
|
70
|
+
|
|
71
|
+
| Field | Type | Meaning |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `runId` | `string` | `${flowId}#${triggerKey}`. Absent on lines that belong to no run (an ignored input, a dropped value, the idle speaker). |
|
|
74
|
+
| `flowId` | `string` | The run's flow. Absent whenever `runId` is absent. |
|
|
75
|
+
| `stepId` | `string` | The step the line is about. Absent when the run has not entered a step, and whenever `runId` is absent. |
|
|
76
|
+
| `key` | `string` | Three shapes: `${runId}:${stepId}:${visit}` on a step line, the input's own key on an ignored input, `idle:${triggerKey}` on the idle speaker's `ok` line. Absent on three kinds of line. A run-ending line. A wait line written during Ingest (`replied`, `no-reply`, `no-event`, `event-arrived`, `awaiting-trigger`) — a message turn writes `replied` too, when the customer's reply resolves a parked `wait`. And a `collect / skipped` line for a value the model gave that could not be written (`unknown-field`, `bad-value`, `not-in-enum`). |
|
|
77
|
+
| `kind` | `StepOutcomeKind` | What kind of step. `prompt` and `collect` are both talk steps: `collect` when the step has a non-empty `collect` list. `idle` is the idle speaker. |
|
|
78
|
+
| `status` | `StepOutcomeStatus` | See below. |
|
|
79
|
+
| `code` | `StepOutcomeCode` | Why the line says what it says. Switch on this; it is stable across versions. Absent when the line needs no reason (a step that simply ran). |
|
|
80
|
+
| `message` | `string` | The English sentence for `code`, copied in by the framework so a log reads on its own. To show a line in another language, map `code` yourself. The whole table is exported as `OUTCOME_MESSAGES`. Absent whenever `code` is. |
|
|
81
|
+
| `detail` | `string` | Text this one occurrence adds: the field slug (`unknown-field`, `bad-value`, `not-in-enum`, `max-asks`), the action's own words (`action-skipped`, `action-failed`, `action-deferred`), your `silenced` reason, the event name (`awaiting-event`), `"5000ms"` (`inline-delay`). |
|
|
82
|
+
| `next` | `string` | Where the step's `then` sent the run: a step id, `end`, or `flow:<id>` when it chained into another flow. Absent when the step has no `then` (the run still moves to the next step in order), when it parked, when the line does not move it, and on the talk step's `ok` line after a speak call. |
|
|
83
|
+
| `until` | `string` | ISO time of the wake, on `waiting` and `deferred` lines. |
|
|
84
|
+
| `at` | `string` | ISO time of the turn (the agent's clock). |
|
|
85
|
+
| `llmCalls` | `number` | Model calls the speak call spent. Present on the talk step's `ok` line and on both idle lines (`ok` and `deferred`). The talk step's `deferred` line does not carry it; `TurnResult.llmCalls` still counts those calls. |
|
|
86
|
+
|
|
87
|
+
### Statuses
|
|
88
|
+
|
|
89
|
+
| Status | Meaning |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `ok` | The step did its job and the run moved (or is now asking). |
|
|
92
|
+
| `skipped` | Nothing happened here, on purpose. `code` says why. |
|
|
93
|
+
| `failed` | An action returned `failed`, or the run hit the 50-step cap. |
|
|
94
|
+
| `waiting` | The run parked. `until` says when the wake fires. |
|
|
95
|
+
| `deferred` | The step will be tried again later: an action asked for it, or the provider failed. |
|
|
96
|
+
|
|
97
|
+
### Where lines land
|
|
98
|
+
|
|
99
|
+
- `TurnResult.outcomes`: every line of this turn, in order, run lines and no-run lines alike.
|
|
100
|
+
- `run.outcomes`: the run's own lines, kept to the last 50, on the run inside `session.runs` and inside `TurnResult.ended`.
|
|
101
|
+
- `TurnResult.changed` is `false` when the input was ignored; the one ignored-input line is still on `outcomes` so you can log it, but there is nothing to save or send.
|
|
102
|
+
|
|
103
|
+
## Every code
|
|
104
|
+
|
|
105
|
+
Grouped by what produced it. `kind` and `status` are given as `kind / status`. A blank `code` cell means the line carries no code at all.
|
|
106
|
+
|
|
107
|
+
### The input was ignored
|
|
108
|
+
|
|
109
|
+
`wait / skipped`, no run, `key` = the input's key, `changed: false`.
|
|
110
|
+
|
|
111
|
+
| `code` | When |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `no-session` | `turn({ wake })` with no `session`. A wake never creates a session. |
|
|
114
|
+
| `duplicate-input` | `turn({ message, id })` with an `id` already among the session's last 50 input ids. A replay of an already applied message. |
|
|
115
|
+
| `stale-wake` | A wake key that no live run is waiting on. The run moved on, ended, or was re-parked under a newer key. |
|
|
116
|
+
| `silence-broken` | A silence wake whose time no longer matches `lastAssistantAt`, or the customer wrote since. The assistant or the customer spoke after the wake was set. |
|
|
117
|
+
|
|
118
|
+
### Waits and wakes
|
|
119
|
+
|
|
120
|
+
| `kind / status` | `code` | When | `next` |
|
|
121
|
+
|---|---|---|---|
|
|
122
|
+
| `wait / ok` | `inline-delay`, `detail` = `"5000ms"` | A `wait` of 10 s or less, followed by a `say` or talk step, became the next message's `afterMs` delay. No wake. | `then` |
|
|
123
|
+
| `wait / waiting` | none | A timer `wait` parked. Wake key `${runId}:${stepId}:${atMs}`. | |
|
|
124
|
+
| `wait / ok` | `no-reply` | The wake fired and the customer had not written since the wait was set. | `then` |
|
|
125
|
+
| `wait / ok` | `replied` | The customer wrote (a message, or an `inbound` event) while a timer `wait` with `else` was parked; or the wake fired after the customer had written. | `else`; when the customer's reply resolves the wait (a message or an `inbound` event), a matching `if` branch's `then` wins. When the wake fires after the customer had written, always `else` |
|
|
126
|
+
| `wait / waiting` | `awaiting-event`, `detail` = the event name | A `wait: { event }` parked. `until` = now + `upTo` (default 30 days). | |
|
|
127
|
+
| `wait / ok` | `event-arrived` | The event was reported before `upTo`. | `then` |
|
|
128
|
+
| `wait / ok` | `no-event` | The `upTo` wake fired first. | `else`, or `end` |
|
|
129
|
+
| `wait / waiting` | `awaiting-trigger` | A run started by an `event` trigger with `after` parked before its first step. Wake key `${runId}:start:${atMs}`. | |
|
|
130
|
+
|
|
131
|
+
### Talk steps (`prompt` / `collect`)
|
|
132
|
+
|
|
133
|
+
| `kind / status` | `code` | When | `next` |
|
|
134
|
+
|---|---|---|---|
|
|
135
|
+
| `prompt` or `collect / ok` | none; `llmCalls` set | The speak call answered. The run is asking if fields are still pending, else it moved. | none. This line never carries `next`, even when the run moves on; the lines that follow show where it went |
|
|
136
|
+
| `collect / skipped` | `already-known` | The step was entered and every field it collects was already known (or at `maxAsks`). No call. | `then` |
|
|
137
|
+
| `collect / ok` | none, no `llmCalls` | An asking step whose remaining fields were all known when the customer's next message resumed it: the understand call filled them in from the message, or an action's `ctx.set()` or a tool's `data` had written them since the step last asked. It moved without speaking. | `then` |
|
|
138
|
+
| `collect / skipped` | `max-asks`, `detail` = the field slug | One line per field still unknown when the step moves on because that field reached `maxAsks` (default 3). | |
|
|
139
|
+
| `prompt` or `collect / ok` | `branch` | A branch of the asking step fired: an `if` branch held, or the model answered `when` with true. | the branch's `then` |
|
|
140
|
+
| `prompt` or `collect / skipped` | `another-reply` | On a message turn, another run's `say` or an action with `spoke: true` already answered. The talk waits; the run stays asking. | |
|
|
141
|
+
| `prompt` or `collect / skipped` | `silenced`, `detail` = your reason | The step was reached fresh while `silenced`. The run ends (`reason: 'skipped'`). A step that was already asking stays asking silently and writes no line. | |
|
|
142
|
+
| `prompt` or `collect / deferred` | `provider-unavailable`, `provider-quota` | Waiting can still fix it: the provider was down, slow, rate-limited, or returned an empty message; or a usage window said when it reopens. The step is re-parked under `${runId}:${stepId}:${visit}:retry:${atMs}` at +1m, +5m, +15m, +1h, +6h, or at the stated reset when that is later. `until` set. | |
|
|
143
|
+
| `prompt` or `collect / failed` | `provider-auth`, `provider-context`, `provider-invalid`, `provider-quota` | Waiting cannot fix it: a rejected key, a prompt past the context window, a request the provider refused, a spent balance with no stated reset. No wake; the run ends `failed`. | |
|
|
144
|
+
| `prompt` or `collect / failed` | `provider-unavailable` | The retryable ladder ran out — six failures on the same step. The run ends `failed`. | |
|
|
145
|
+
|
|
146
|
+
### Say steps
|
|
147
|
+
|
|
148
|
+
| `kind / status` | `code` | When | `next` |
|
|
149
|
+
|---|---|---|---|
|
|
150
|
+
| `say / ok` | none | The text went into `messages[]` with `kind: 'verbatim'`. | `then` |
|
|
151
|
+
| `say / skipped` | `already-sent` | `once: true` and this step already sent in this session (claim `${flowId}:${stepId}:${sessionId}`). | `then` |
|
|
152
|
+
| `say / skipped` | `silenced`, `detail` = your reason | Reached while `silenced`. The run ends (`reason: 'skipped'`). | |
|
|
153
|
+
|
|
154
|
+
### Do steps
|
|
155
|
+
|
|
156
|
+
The action's own words arrive in `detail`, unprefixed, exactly as it returned them.
|
|
157
|
+
|
|
158
|
+
| `kind / status` | `code` | When | `next` |
|
|
159
|
+
|---|---|---|---|
|
|
160
|
+
| `do / ok` | none; `detail` when the action gave one | The action returned `{ ok: true }`. | `then` |
|
|
161
|
+
| `do / skipped` | `action-skipped`, `detail` = the action's words | The action returned `{ skipped: reason }`. | `then` |
|
|
162
|
+
| `do / failed` | `action-failed`, `detail` = the action's words | The action returned `{ failed: reason }` or threw, and then the error message is the reason. | `onFail`, else `then` |
|
|
163
|
+
| `do / failed` | `action-failed`, `detail: 'unknown action "notify"'` | The action name is not registered. The agent constructor refuses such a flow, so this appears only if registries changed under a running agent. | `onFail`, else `then` |
|
|
164
|
+
| `do / deferred` | `action-deferred`, `detail` = the action's words | The action returned `{ defer, detail }`. Wake key `${runId}:${stepId}:${atMs}`; the same step re-runs at the same visit, same `ctx.key`. `until` set. | |
|
|
165
|
+
|
|
166
|
+
### If steps
|
|
167
|
+
|
|
168
|
+
| `kind / status` | `code` | When | `next` |
|
|
169
|
+
|---|---|---|---|
|
|
170
|
+
| `if / ok` | none | The predicate was judged. | `then` on true; `else` or `end` on false |
|
|
171
|
+
|
|
172
|
+
### Values the model gave
|
|
173
|
+
|
|
174
|
+
`collect / skipped`, no run, `detail` = the field slug. The understand or speak call reported a value that could not be written.
|
|
175
|
+
|
|
176
|
+
| `code` | When |
|
|
177
|
+
|---|---|
|
|
178
|
+
| `unknown-field` | The model named a field the agent does not have. |
|
|
179
|
+
| `bad-value` | The value could not be turned into the field's type (`string`, `number`, `integer`, `boolean`). Strings become numbers and booleans when they parse; `sim`/`não` count as booleans. |
|
|
180
|
+
| `not-in-enum` | The value is not in the field's `enum`. |
|
|
181
|
+
|
|
182
|
+
Tool `data` is written without these checks and never produces these lines.
|
|
183
|
+
|
|
184
|
+
### The idle speaker
|
|
185
|
+
|
|
186
|
+
No run.
|
|
187
|
+
|
|
188
|
+
| `kind / status` | `code` | When |
|
|
189
|
+
|---|---|---|
|
|
190
|
+
| `idle / ok` | none; `llmCalls` and `key` (`idle:${triggerKey}`) set | No run held the floor on a message turn and `idle` is not `'silent'`; the model answered. |
|
|
191
|
+
| `idle / deferred` | any `provider-*` code; `llmCalls` set, no `key` | The idle speaker's call failed or came back empty. No retry wake either way: it has no step to re-park, and the next message tries again. |
|
|
192
|
+
|
|
193
|
+
### A run ended early
|
|
194
|
+
|
|
195
|
+
The run leaves `session.runs`, appears in `TurnResult.ended`, and writes one line whose `kind` is the current step's kind, or `if` when the run had not entered a step yet.
|
|
196
|
+
|
|
197
|
+
| `status` | `code` | `reason` on `ended` | When |
|
|
198
|
+
|---|---|---|---|
|
|
199
|
+
| `skipped` | `premise-changed` | `skipped` | The flow's `while` (default: the trigger's `if`) stopped holding when the run was about to move. |
|
|
200
|
+
| `skipped` | `customer-replied` | `skipped` | A silence run woke up, but the customer had written since the run started. |
|
|
201
|
+
| `skipped` | `flow-gone` | `skipped` | The run's flow is no longer on the agent. |
|
|
202
|
+
| `skipped` | `step-gone` | `skipped` | The run's step id, or a `then` target, is no longer in the flow. |
|
|
203
|
+
| `skipped` | `silenced`, `detail` = your reason | `skipped` | A talk or `say` step reached while `silenced` (see above). |
|
|
204
|
+
| `failed` | `step-loop` | `failed` | The run moved through 50 steps in one turn. A cycle with no wait, talk or end. |
|
|
205
|
+
|
|
206
|
+
## End reasons
|
|
207
|
+
|
|
208
|
+
`TurnResult.ended` carries each ended run with its `reason`:
|
|
209
|
+
|
|
210
|
+
| `reason` | When |
|
|
211
|
+
|---|---|
|
|
212
|
+
| `end` | The run passed its last step, hit `then: 'end'`, or `onEnd` is `'end'` (the default). |
|
|
213
|
+
| `flow` | The run followed `then: { flow }`; a child run started at `hop + 1`. |
|
|
214
|
+
| `reset` | `onEnd: 'reset'`: this run closed and a fresh run of the same flow started at step one, data kept, `hop + 1`. |
|
|
215
|
+
| `skipped` | One of the codes above: `premise-changed`, `customer-replied`, `flow-gone`, `step-gone` or `silenced`. |
|
|
216
|
+
| `failed` | `step-loop`. |
|
|
217
|
+
| `replaced` | The run was parked on its trigger's `after` (no step entered) and the same trigger fired again: the new run takes its place. |
|
|
218
|
+
|
|
219
|
+
## Triggers that matched but started nothing
|
|
220
|
+
|
|
221
|
+
`TurnResult.skipped` entries have `{ flowId, anchor, triggerKey, code, message }` and write no `StepOutcome`.
|
|
222
|
+
|
|
223
|
+
| `code` | When |
|
|
224
|
+
|---|---|
|
|
225
|
+
| `already-claimed` | `repeat: 'once'` and this flow already ran for this session or anchor; or `repeat: 'always'` and this exact trigger key was already used (a replayed event, start or chain). |
|
|
226
|
+
| `cooldown` | `repeat: { cooldown }` and the last run is younger than the cooldown. |
|
|
227
|
+
| `already-running` | A live run of this flow exists for this anchor, in this session or (through `turn({ claims })`) in another of the customer's sessions. |
|
|
228
|
+
| `hop-limit` | The start would be at hop 5. `{ flow }` jumps and `onEnd: 'reset'` each add a hop. |
|
|
229
|
+
| `flow-gone` | `turn({ start })`, a silence wake, or a `{ flow }` jump named a flow the agent does not have. |
|
|
230
|
+
|
|
231
|
+
A trigger whose `if` is false starts nothing and writes nothing.
|
|
232
|
+
|
|
233
|
+
## Example
|
|
234
|
+
|
|
235
|
+
```ts
|
|
236
|
+
import { falai, GeminiProvider } from "@falai/agent";
|
|
237
|
+
|
|
238
|
+
const f = falai().fields({
|
|
239
|
+
nome: { type: "string", ask: "Pergunte o nome." },
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const agent = f.agent({
|
|
243
|
+
name: "Ana",
|
|
244
|
+
provider: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY ?? "", model: "gemini-2.5-flash" }),
|
|
245
|
+
flows: [
|
|
246
|
+
f.flow({
|
|
247
|
+
id: "triagem",
|
|
248
|
+
name: "Triagem",
|
|
249
|
+
on: [{ message: [] }], // no examples: the catch-all, starts when no other message flow wins
|
|
250
|
+
steps: [
|
|
251
|
+
{ id: "quem", collect: ["nome"] },
|
|
252
|
+
{ id: "tchau", say: "Obrigada, {{data.nome}}. Um vendedor continua daqui." },
|
|
253
|
+
],
|
|
254
|
+
}),
|
|
255
|
+
],
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const r = await agent.turn({ sessionId: "demo", message: "oi, sou a Ana" });
|
|
259
|
+
|
|
260
|
+
for (const line of r.outcomes) {
|
|
261
|
+
console.log(`${line.stepId ?? "-"} ${line.kind}/${line.status} ${line.code ?? ""} ${line.detail ?? ""} → ${line.next ?? ""}`);
|
|
262
|
+
}
|
|
263
|
+
for (const run of r.ended) console.log(`${run.id} ended: ${run.reason}`);
|
|
264
|
+
for (const skip of r.skipped) console.log(`${skip.flowId} not started: ${skip.code}`);
|
|
265
|
+
console.log(`model calls: ${r.llmCalls}`);
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## See also
|
|
269
|
+
|
|
270
|
+
- [Runs and waits](../concepts/runs-and-waits.md): statuses, the floor, wakes and the key table.
|
|
271
|
+
- [Session](./session.md): `Run`, `RunStatus` and where `outcomes` live.
|
|
272
|
+
- [Error handling](../guides/error-handling.md): what a deferred talk step means for the host.
|
|
273
|
+
- [Actions, events, conditions](./actions-events-conditions.md): `ActionResult` and the `do` lines.
|