@falai/agent 3.4.5 → 4.0.0-alpha.10
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 +29 -378
- package/dist/cjs/core/Agent.d.ts.map +1 -1
- package/dist/cjs/core/Agent.js +113 -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 +573 -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 +149 -0
- package/dist/cjs/core/Prompt.js.map +1 -0
- package/dist/cjs/core/Runner.d.ts +171 -0
- package/dist/cjs/core/Runner.d.ts.map +1 -0
- package/dist/cjs/core/Runner.js +1158 -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 +373 -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 +357 -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 +163 -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/phrases.d.ts +25 -0
- package/dist/cjs/utils/phrases.d.ts.map +1 -0
- package/dist/cjs/utils/phrases.js +38 -0
- package/dist/cjs/utils/phrases.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 +22 -150
- package/dist/cjs/utils/template.d.ts.map +1 -1
- package/dist/cjs/utils/template.js +64 -359
- 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 +29 -378
- package/dist/core/Agent.d.ts.map +1 -1
- package/dist/core/Agent.js +116 -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 +567 -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 +139 -0
- package/dist/core/Prompt.js.map +1 -0
- package/dist/core/Runner.d.ts +171 -0
- package/dist/core/Runner.d.ts.map +1 -0
- package/dist/core/Runner.js +1154 -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 +369 -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 +353 -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 +163 -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/phrases.d.ts +25 -0
- package/dist/utils/phrases.d.ts.map +1 -0
- package/dist/utils/phrases.js +35 -0
- package/dist/utils/phrases.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 +22 -150
- package/dist/utils/template.d.ts.map +1 -1
- package/dist/utils/template.js +61 -351
- 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 +170 -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 +457 -0
- package/docs/reference/actions-events-conditions.md +396 -0
- package/docs/reference/agent.md +248 -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 +200 -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 +181 -163
- 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 +149 -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 +11 -6
- package/src/core/Agent.ts +126 -1512
- package/src/core/CompactionEngine.ts +7 -4
- package/src/core/FlowSpec.ts +778 -0
- package/src/core/Migrate.ts +256 -0
- package/src/core/Prompt.ts +162 -0
- package/src/core/Runner.ts +1214 -0
- package/src/core/Speak.ts +460 -0
- package/src/core/Understand.ts +423 -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 +120 -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 +135 -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 +88 -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/phrases.ts +40 -0
- package/src/utils/schema.ts +145 -0
- package/src/utils/streamingMessage.ts +34 -4
- package/src/utils/template.ts +63 -418
- 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,369 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Directives"
|
|
3
|
-
description: "The flat object shape any tool, hook, or branch returns to write state, redirect the conversation, or speak verbatim."
|
|
4
|
-
type: concept
|
|
5
|
-
order: 3
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Directives
|
|
9
|
-
|
|
10
|
-
> **Where this is introduced:** [Turn pipeline](./pipeline.md)
|
|
11
|
-
|
|
12
|
-
A directive is the single language `@falai/agent` speaks for control
|
|
13
|
-
flow. When a tool decides "this user is ineligible," it returns
|
|
14
|
-
`{ goTo: "Denial", reply: "Sorry — you don't qualify." }`. When a
|
|
15
|
-
finalize hook closes a booking, it returns
|
|
16
|
-
`{ complete: true, dataUpdate: { bookingId } }`. When a pre-phase
|
|
17
|
-
signal detects a frustrated user, it dispatches
|
|
18
|
-
`{ appendPrompt: ["Lead with empathy."] }`. Different jobs, different
|
|
19
|
-
emitters, one shape.
|
|
20
|
-
|
|
21
|
-
This page explains why the shape is flat, what each field does, how
|
|
22
|
-
they merge when more than one handler emits during the same turn, and
|
|
23
|
-
how `Directive` and `SignalDirective` relate. The page is conceptual —
|
|
24
|
-
the [directive reference](../reference/directive.md) carries the
|
|
25
|
-
field-by-field contract.
|
|
26
|
-
|
|
27
|
-
## Why a flat shape
|
|
28
|
-
|
|
29
|
-
An earlier draft of v2 modeled directives as a discriminated union:
|
|
30
|
-
`{ type: 'goto_flow', flow: 'X' }`, `{ type: 'complete', next: ... }`,
|
|
31
|
-
`{ type: 'abort', reason: ... }`, and so on. The shape that ships is
|
|
32
|
-
flat — a single interface with optional fields, no `type`
|
|
33
|
-
discriminator, no builder, no factory functions. Four reasons drove
|
|
34
|
-
the decision, and each one is visible at the call site once you know
|
|
35
|
-
to look for it.
|
|
36
|
-
|
|
37
|
-
**Single shape.** Every emitter returns the same object literal. A
|
|
38
|
-
finalize hook does not have to choose between `Directive.goto({...})`
|
|
39
|
-
and `Directive.complete({...})` and `Directive.reply({...})` — it
|
|
40
|
-
returns `{}` with whichever fields it needs. Authors learn one shape
|
|
41
|
-
and reach for it from tools, from prepare hooks, from finalize hooks,
|
|
42
|
-
from signal handlers, from branch `then` targets. The framework's
|
|
43
|
-
control-flow vocabulary is one type wide. The same object literal is
|
|
44
|
-
also persistable as `session.pendingDirective`, so the shape
|
|
45
|
-
that sits in source code is the same shape that crosses the
|
|
46
|
-
persistence boundary.
|
|
47
|
-
|
|
48
|
-
**Trivially mergeable.** Algorithm 4 — the per-turn merge that the
|
|
49
|
-
pipeline runs over the directive bus — works on a flat object: pick
|
|
50
|
-
the winning position field by precedence, last-wins for `reply`,
|
|
51
|
-
shallow-merge state writes, concatenate the pre-LLM arrays. A nested
|
|
52
|
-
discriminated union would force a per-variant merge case at every
|
|
53
|
-
combinator: how do you merge a `goto_flow` with a `complete`? With a
|
|
54
|
-
`reply`? With a `dataUpdate`? Every cross-variant combination becomes
|
|
55
|
-
its own special case. With a flat object, "merge" is one function
|
|
56
|
-
that does not branch on shape.
|
|
57
|
-
|
|
58
|
-
**Validates statically.** TypeScript narrowing on field presence is
|
|
59
|
-
clean. `if (d.goTo) { /* d.goTo is string | object */ }` is the
|
|
60
|
-
entire pattern. A discriminated union adds one extra branching level
|
|
61
|
-
at every call site — `if (d.type === 'goto_flow') { /* d is the
|
|
62
|
-
goto_flow variant */ }` — and the variant types repeat the same
|
|
63
|
-
optional-fields prose for state writes and `reply`. The flat shape
|
|
64
|
-
moves "is this a position directive or a state directive or a reply"
|
|
65
|
-
from a type-level question to a runtime question that the merge
|
|
66
|
-
algorithm answers once.
|
|
67
|
-
|
|
68
|
-
**Composable.** A directive carries up to four orthogonal payloads
|
|
69
|
-
without forcing them into a hierarchy: at most one position field,
|
|
70
|
-
optional state writes (`dataUpdate` / `contextUpdate`), an optional
|
|
71
|
-
verbatim `reply`, and optional pre-LLM augmentations (`appendPrompt`,
|
|
72
|
-
`injectTools`, `halt`). `dataUpdate` works alongside `goTo`. `reply`
|
|
73
|
-
works alongside `complete`. A booking tool's success result writes the
|
|
74
|
-
booking id and finishes the flow in one return value:
|
|
75
|
-
`{ complete: true, dataUpdate: { bookingId } }`. A bridge utterance
|
|
76
|
-
at a flow boundary writes nothing and only speaks: `{ reply: "Let me
|
|
77
|
-
transfer you." }`. The same primitive covers both because the fields
|
|
78
|
-
do not exclude each other by shape — only by validation.
|
|
79
|
-
|
|
80
|
-
The trade-off is that exhaustive `case` checking on a `type`
|
|
81
|
-
discriminator is gone. The pipeline replaces it with structural
|
|
82
|
-
validation (`flow.validate`) — one position field at most, no empty
|
|
83
|
-
`goTo: {}`, no `reply` alongside `abort` — that runs at apply time
|
|
84
|
-
anyway, since flow and step lookups are runtime checks regardless. The
|
|
85
|
-
exchange is one less compile-time check for a far cleaner authoring
|
|
86
|
-
surface and a merge algorithm that does not branch on shape.
|
|
87
|
-
|
|
88
|
-
## Position fields and their precedence
|
|
89
|
-
|
|
90
|
-
A directive carries at most one **position field**. Position fields
|
|
91
|
-
answer the question "where does the conversation go next?" The five
|
|
92
|
-
options span every form of position control the framework offers:
|
|
93
|
-
|
|
94
|
-
| Field | What it means |
|
|
95
|
-
|-------|---------------|
|
|
96
|
-
| `goTo` | Jump to another flow. |
|
|
97
|
-
| `goToStep` | Jump to a step (within the current flow, or — in the object form — within another flow). |
|
|
98
|
-
| `complete` | Mark the current flow done. The flow's completion logic runs. |
|
|
99
|
-
| `abort` | End the conversation. Optionally clear the session. |
|
|
100
|
-
| `reset` | Restart the current flow. Optionally clear its declared fields. |
|
|
101
|
-
|
|
102
|
-
Each of `goTo`, `goToStep`, `complete`, `abort`, and `reset` accepts
|
|
103
|
-
both a shorthand and an object form. The shorthand expresses the
|
|
104
|
-
common case (`goTo: "Booking"`, `complete: true`, `abort: "denied"`).
|
|
105
|
-
The object form exposes the optional knobs — `reason` strings for
|
|
106
|
-
observability, `data` for pre-entry state writes, `clearSession` /
|
|
107
|
-
`clearData` flags for the destructive variants. The fields are
|
|
108
|
-
mutually exclusive: setting two at once throws
|
|
109
|
-
`FlowConfigurationError` at validation. There is no "go to *and*
|
|
110
|
-
abort" — only one position can win per directive.
|
|
111
|
-
|
|
112
|
-
When more than one emitter writes a position field during the same
|
|
113
|
-
turn — a tool returns `goTo` and a finalize hook returns `complete` —
|
|
114
|
-
the merge algorithm picks one winner by precedence:
|
|
115
|
-
|
|
116
|
-
```
|
|
117
|
-
abort > complete > goTo / goToStep > reset
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
The order encodes intent. **`abort` always wins.** A handler that
|
|
121
|
-
ended the conversation cannot be overridden by a later "go somewhere
|
|
122
|
-
else" — there is no somewhere else. **`complete` beats `goTo` and
|
|
123
|
-
`goToStep`.** The flow is ending; any follow-up jump belongs in
|
|
124
|
-
`complete.next` (which chains another directive after completion),
|
|
125
|
-
not as a competing position field. **`goTo` and `goToStep` share a
|
|
126
|
-
tier.** Both express "next position is here" — the difference is
|
|
127
|
-
flow-level vs step-level granularity, and within the tier last
|
|
128
|
-
emission wins. **`reset` is lowest.** Any explicit jump out of the
|
|
129
|
-
current flow beats a "restart this flow" emitted earlier in the
|
|
130
|
-
phase.
|
|
131
|
-
|
|
132
|
-
Within the same tier, the most recent emission wins, with a debug
|
|
133
|
-
log naming all losers so a noisy turn is diagnosable from the trace.
|
|
134
|
-
The precedence ordering does not change between phases: it applies to
|
|
135
|
-
the pre-LLM bus, the post-LLM bus, and the signal phases identically.
|
|
136
|
-
|
|
137
|
-
## State writes
|
|
138
|
-
|
|
139
|
-
Two fields — `dataUpdate` and `contextUpdate` — write to session
|
|
140
|
-
state. Both are `Partial<>` slices of their respective surfaces:
|
|
141
|
-
`dataUpdate?: Partial<TData>` writes into `session.data`,
|
|
142
|
-
`contextUpdate?: Partial<TContext>` writes into `session.context`.
|
|
143
|
-
Both fire their respective hooks (`flow.hooks.onDataUpdate`,
|
|
144
|
-
`flow.hooks.onContextUpdate`) after the merge applies, and both run
|
|
145
|
-
through schema validation atomically — every field across every
|
|
146
|
-
emitter on this turn is checked together, and the session is not
|
|
147
|
-
mutated unless the whole set passes.
|
|
148
|
-
|
|
149
|
-
State writes are **additive** and shallow-merged across emitters in
|
|
150
|
-
emission order. If a flow-level `onEnter` writes
|
|
151
|
-
`{ dataUpdate: { tier: "vip" } }` and a step-level `prepare` writes
|
|
152
|
-
`{ dataUpdate: { lastSeen: now } }`, the merged result is
|
|
153
|
-
`{ tier: "vip", lastSeen: now }` — neither hook needs to know about
|
|
154
|
-
the other. On key collision, last write wins. The merge is shallow —
|
|
155
|
-
top-level keys are replaced wholesale, nested objects are not
|
|
156
|
-
deep-merged. To update a nested object, read it from `data`, merge
|
|
157
|
-
in code, write back the full sub-object. Deep merge is intentionally
|
|
158
|
-
absent because it would silently disagree with TypeScript's
|
|
159
|
-
`Partial<>` shape: the type says "I'm overwriting this key," and the
|
|
160
|
-
runtime should agree.
|
|
161
|
-
|
|
162
|
-
State writes always apply, regardless of what the position fields do.
|
|
163
|
-
A directive with `{ goTo: "Denial", dataUpdate: { reason: "expired" }
|
|
164
|
-
}` jumps flows *and* writes the reason. A directive with only
|
|
165
|
-
`{ dataUpdate: {...} }` writes state and stays where it is. Position
|
|
166
|
-
fields and state writes are orthogonal payloads; they don't compete
|
|
167
|
-
for the same slot.
|
|
168
|
-
|
|
169
|
-
## Reply as a verbatim utterance
|
|
170
|
-
|
|
171
|
-
The `reply: string` field is the framework's way of letting code
|
|
172
|
-
speak. When a directive sets `reply`, the LLM call for the entered
|
|
173
|
-
step is skipped this turn and the literal string becomes the
|
|
174
|
-
assistant's message. The text is taken verbatim — no templating, no
|
|
175
|
-
post-processing, no "the model rephrased it" surprise.
|
|
176
|
-
|
|
177
|
-
`reply` is the right tool for utterances that should be exact:
|
|
178
|
-
confirmations ("Booking confirmed."), bridges ("Connecting you with a
|
|
179
|
-
specialist now."), refusals ("Sorry — you don't qualify."), and
|
|
180
|
-
boilerplate at flow boundaries. It is the wrong tool for anything
|
|
181
|
-
that should adapt to context — that's what the model is for. The two
|
|
182
|
-
shapes coexist on the same step boundary: `reply` for the line, the
|
|
183
|
-
LLM for the conversation.
|
|
184
|
-
|
|
185
|
-
`reply` co-validates with two other fields. With **`abort`**, it is
|
|
186
|
-
rejected at validation — an aborted conversation cannot deliver a
|
|
187
|
-
reply. With **`halt: true`**, it is the assistant message and the
|
|
188
|
-
turn ends with `stoppedReason: 'reply'`; if `halt` is set without
|
|
189
|
-
`reply`, the turn ends with `stoppedReason: 'halt'` and an empty
|
|
190
|
-
body. Across multiple emitters in the same turn, `reply` is
|
|
191
|
-
**last-wins** — the most recent emission overrides earlier ones,
|
|
192
|
-
with a debug log so the override is visible in the trace.
|
|
193
|
-
|
|
194
|
-
`reply` works the same regardless of which phase emits it. The phase
|
|
195
|
-
determines whether the reply replaces a message that would have been
|
|
196
|
-
generated (pre-LLM) or replaces one that just was (post-LLM).
|
|
197
|
-
|
|
198
|
-
## Pre-LLM-only fields
|
|
199
|
-
|
|
200
|
-
Three fields on `Directive` only take effect in pre-LLM hooks
|
|
201
|
-
(`onEnter`, `prepare`). When emitted from post-LLM hooks (`finalize`,
|
|
202
|
-
`onComplete`) or persisted to `session.pendingDirective`, they are
|
|
203
|
-
**ignored with a WARN log** — a visible signal in your logs that
|
|
204
|
-
says "hey, this did nothing here."
|
|
205
|
-
|
|
206
|
-
**`appendPrompt: string[]`** is the prompt nudge slot. Each string is
|
|
207
|
-
a sentence the prompt composer appends to the system prompt for this
|
|
208
|
-
turn only. A flow-level `onEnter` that detects a VIP caller can add
|
|
209
|
-
"This caller is a VIP — confirm preferences before suggesting
|
|
210
|
-
options." A step-level `prepare` that detects a returning customer
|
|
211
|
-
can add "The user is a returning customer; skip introductions." Both
|
|
212
|
-
fire on the same turn, and both sentences land in the prompt's
|
|
213
|
-
per-turn appendage slot in emission order. The slot is never cached
|
|
214
|
-
(the prompt section cache memoizes static sections only) and never
|
|
215
|
-
persisted — `appendPrompt` lives for one turn and is gone.
|
|
216
|
-
|
|
217
|
-
**`injectTools: Tool[]`** is the per-turn tool slot. Tools listed
|
|
218
|
-
here are added to the available tool list for this turn only,
|
|
219
|
-
stacked on top of the agent → flow → step → transient resolution
|
|
220
|
-
chain. A `prepare` hook that detects an ambiguous request can inject
|
|
221
|
-
a `lookup_account` tool for a single LLM call without registering it
|
|
222
|
-
on the step or the flow. The slot is never persisted — tool
|
|
223
|
-
references are functions, and functions are not JSON-serializable —
|
|
224
|
-
so the field is structurally one-turn-only.
|
|
225
|
-
|
|
226
|
-
**`halt: boolean`** is the kill switch. When any pre-phase emitter
|
|
227
|
-
sets `halt: true`, the LLM call is skipped entirely. If `reply` is
|
|
228
|
-
also set, the verbatim string becomes the assistant message. If not,
|
|
229
|
-
the turn ends with `stoppedReason: 'halt'` and an empty body. `halt`
|
|
230
|
-
merges by **logical-OR** — a single emitter setting it is enough to
|
|
231
|
-
halt the turn. The field is the framework's circuit breaker: a hook
|
|
232
|
-
that detects an unresolvable state can stop the turn outright
|
|
233
|
-
without competing with other emitters.
|
|
234
|
-
|
|
235
|
-
These fields are stripped from `session.pendingDirective` before
|
|
236
|
-
persistence — they cannot survive across turns by design. If a
|
|
237
|
-
post-LLM hook returns a directive with these fields set, they are
|
|
238
|
-
dropped with a WARN log: an `appendPrompt` after the fact has no
|
|
239
|
-
prompt to append to, an `injectTools` after the fact has no LLM call
|
|
240
|
-
to inject into, and a `halt` after the fact has no LLM call to halt.
|
|
241
|
-
The remaining fields are honored normally.
|
|
242
|
-
|
|
243
|
-
`appendPrompt` is concatenated across emitters in emission order
|
|
244
|
-
without deduplication — duplicate sentences from different sources
|
|
245
|
-
are preserved (a flow-level "be polite" plus a step-level "be polite"
|
|
246
|
-
is acceptable redundancy). `injectTools` is concatenated and then
|
|
247
|
-
deduped by `Tool.id`, with the later definition winning — typically a
|
|
248
|
-
step-level injection overriding a flow-level default. `halt` is
|
|
249
|
-
logical-OR. The merge rules for the base fields stay identical:
|
|
250
|
-
position fields by precedence, `reply` last-wins, state writes
|
|
251
|
-
shallow-merged.
|
|
252
|
-
|
|
253
|
-
## SignalDirective
|
|
254
|
-
|
|
255
|
-
`SignalDirective` extends `Directive` with two signal-pipeline-specific
|
|
256
|
-
fields: `stopOtherSignals` and `replyWith`.
|
|
257
|
-
|
|
258
|
-
```mermaid
|
|
259
|
-
classDiagram
|
|
260
|
-
Directive <|-- SignalDirective
|
|
261
|
-
|
|
262
|
-
class Directive {
|
|
263
|
-
+goTo? string | object
|
|
264
|
-
+goToStep? string | object
|
|
265
|
-
+complete? true | object
|
|
266
|
-
+abort? string | object
|
|
267
|
-
+reset? true | object
|
|
268
|
-
+reply? string
|
|
269
|
-
+dataUpdate? Partial~TData~
|
|
270
|
-
+contextUpdate? Partial~TContext~
|
|
271
|
-
+appendPrompt? string[]
|
|
272
|
-
+injectTools? Tool[]
|
|
273
|
-
+halt? boolean
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
class SignalDirective {
|
|
277
|
-
+stopOtherSignals? boolean
|
|
278
|
-
+replyWith? string | function
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
note for Directive "One type for all hooks, tools, and branches.\nPre-LLM fields ignored with WARN log outside pre-LLM hooks."
|
|
282
|
-
note for SignalDirective "Returned by signal handlers (pre / post / both phases)."
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
`SignalDirective` is what signal handlers return — pre-phase
|
|
286
|
-
handlers, post-phase handlers, and `both`-phase handlers all use the
|
|
287
|
-
same type. `stopOtherSignals` skips remaining handlers in the same
|
|
288
|
-
phase (consumed inside the signal pipeline, not the directive bus).
|
|
289
|
-
`replyWith` is a late-binding `reply` that accepts a function form
|
|
290
|
-
evaluated at emit time. Phase semantics still apply: when a
|
|
291
|
-
`SignalDirective` runs in the post-phase, `appendPrompt` /
|
|
292
|
-
`injectTools` / `halt` are dropped (they have no meaning after the
|
|
293
|
-
LLM call) and position fields set `pendingDirective` for the *next*
|
|
294
|
-
turn rather than redirecting this one.
|
|
295
|
-
|
|
296
|
-
Both types share one merge algorithm and one validation pass. A
|
|
297
|
-
pre-phase signal can dispatch a `SignalDirective`, a `prepare` hook
|
|
298
|
-
can return a `Directive`, and the engine merges them through the same
|
|
299
|
-
`flow.merge`.
|
|
300
|
-
|
|
301
|
-
## The `flow` namespace
|
|
302
|
-
|
|
303
|
-
There are no constructor builders for directives. Directives are
|
|
304
|
-
plain object literals — that is the whole point of the flat shape.
|
|
305
|
-
What the framework does export is a small runtime helper namespace
|
|
306
|
-
for working with directives in code: validating shapes that arrived
|
|
307
|
-
from outside the framework, merging two directives by hand, and
|
|
308
|
-
narrowing `unknown` values in type guards.
|
|
309
|
-
|
|
310
|
-
```typescript
|
|
311
|
-
import { flow } from "@falai/agent";
|
|
312
|
-
|
|
313
|
-
flow.isDirective(x); // structural type guard
|
|
314
|
-
flow.merge(a, b); // Algorithm 4 merge of two directives
|
|
315
|
-
flow.validate(d); // throws FlowConfigurationError on invalid shape
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
`flow.isDirective(x)` is a structural type guard. It returns `true`
|
|
319
|
-
for any non-null, non-array object — primitives, `null`, `undefined`,
|
|
320
|
-
arrays, and functions are filtered out. Use it to narrow an `unknown`
|
|
321
|
-
value coming off an RPC payload or a queue message before passing it
|
|
322
|
-
to `applyDirective` or `agent.dispatch`.
|
|
323
|
-
|
|
324
|
-
`flow.merge(a, b)` is the same Algorithm 4 the engine runs internally
|
|
325
|
-
on the per-turn directive bus, exposed for callers that need to
|
|
326
|
-
compose results before dispatching them. Position fields merge by
|
|
327
|
-
precedence (`abort > complete > goTo / goToStep > reset`, last-wins
|
|
328
|
-
within the same tier), `reply` is last-wins, `dataUpdate` and
|
|
329
|
-
`contextUpdate` shallow-merge in emission order, `appendPrompt`
|
|
330
|
-
concatenates without deduplication, `injectTools` concatenates and
|
|
331
|
-
then dedupes by `Tool.id` (later definition wins), and `halt` is
|
|
332
|
-
logical-OR. The function is generic: merging two `Directive`s yields
|
|
333
|
-
a `Directive`.
|
|
334
|
-
|
|
335
|
-
`flow.validate(d)` enforces three structural invariants and throws
|
|
336
|
-
`FlowConfigurationError` when any fails: at most one position field
|
|
337
|
-
per directive, no empty `goTo: {}` (the object form requires a flow
|
|
338
|
-
id), no `reply` alongside `abort`. The pipeline calls it eagerly on
|
|
339
|
-
every emitted directive, so downstream code can rely on shape. It
|
|
340
|
-
does **not** validate that referenced flows or steps exist — that
|
|
341
|
-
check happens at apply time, against the agent's flow registry, which
|
|
342
|
-
the validator does not have a handle on.
|
|
343
|
-
|
|
344
|
-
The namespace's design intent is "runtime helpers, not authoring
|
|
345
|
-
sugar." If you're constructing a directive in source, write the
|
|
346
|
-
object literal. If you're handling a directive that came from
|
|
347
|
-
elsewhere, narrow it with `flow.isDirective`, validate it with
|
|
348
|
-
`flow.validate`, and merge it with `flow.merge`. The seam between
|
|
349
|
-
"control flow as code" and "control flow as data" is exactly that
|
|
350
|
-
small.
|
|
351
|
-
|
|
352
|
-
## Where to go next
|
|
353
|
-
|
|
354
|
-
The directive's mental model is in this page; the field-by-field
|
|
355
|
-
contract — every position field's shorthand and object form, every
|
|
356
|
-
state-write rule, every typed error the validator can throw — is in
|
|
357
|
-
the [Directive reference](../reference/directive.md).
|
|
358
|
-
The signal-specific additions live in [Signals](../reference/signals.md).
|
|
359
|
-
|
|
360
|
-
When the goal is to *use* directives in handlers, the
|
|
361
|
-
[Flow control guide](../guides/flow-control.md) walks through the
|
|
362
|
-
recipes: redirecting from a tool, completing a flow with a chained
|
|
363
|
-
follow-up, aborting on a permission failure, replying verbatim from a
|
|
364
|
-
finalize hook, dispatching a directive from outside a turn. When the
|
|
365
|
-
goal is to *understand* where directives sit in the per-turn
|
|
366
|
-
sequence, [Turn pipeline](./pipeline.md) covers the bus, the merge
|
|
367
|
-
phases, and the resolution precedence around the directive surface.
|
|
368
|
-
|
|
369
|
-
**Next:** [createAgent reference](../reference/create-agent.md)
|