@falai/agent 0.8.0 → 0.9.0-alpha-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +306 -133
- package/dist/{adapters → cjs/src/adapters}/MemoryAdapter.d.ts +4 -4
- package/dist/cjs/src/adapters/MemoryAdapter.d.ts.map +1 -0
- package/dist/cjs/{adapters → src/adapters}/MemoryAdapter.js +41 -21
- package/dist/cjs/src/adapters/MemoryAdapter.js.map +1 -0
- package/dist/{adapters → cjs/src/adapters}/MongoAdapter.d.ts +3 -3
- package/dist/cjs/src/adapters/MongoAdapter.d.ts.map +1 -0
- package/dist/cjs/{adapters → src/adapters}/MongoAdapter.js +2 -1
- package/dist/cjs/src/adapters/MongoAdapter.js.map +1 -0
- package/dist/cjs/{adapters → src/adapters}/OpenSearchAdapter.d.ts +3 -3
- package/dist/cjs/src/adapters/OpenSearchAdapter.d.ts.map +1 -0
- package/dist/cjs/{adapters → src/adapters}/OpenSearchAdapter.js +10 -13
- package/dist/cjs/src/adapters/OpenSearchAdapter.js.map +1 -0
- package/dist/cjs/{adapters → src/adapters}/PostgreSQLAdapter.d.ts +3 -3
- package/dist/cjs/src/adapters/PostgreSQLAdapter.d.ts.map +1 -0
- package/dist/cjs/{adapters → src/adapters}/PostgreSQLAdapter.js +1 -1
- package/dist/cjs/src/adapters/PostgreSQLAdapter.js.map +1 -0
- package/dist/cjs/{adapters → src/adapters}/PrismaAdapter.d.ts +3 -3
- package/dist/cjs/src/adapters/PrismaAdapter.d.ts.map +1 -0
- package/dist/cjs/{adapters → src/adapters}/PrismaAdapter.js +35 -5
- package/dist/cjs/src/adapters/PrismaAdapter.js.map +1 -0
- package/dist/cjs/{adapters → src/adapters}/RedisAdapter.d.ts +3 -3
- package/dist/cjs/src/adapters/RedisAdapter.d.ts.map +1 -0
- package/dist/cjs/{adapters → src/adapters}/RedisAdapter.js +3 -2
- package/dist/cjs/src/adapters/RedisAdapter.js.map +1 -0
- package/dist/{adapters → cjs/src/adapters}/SQLiteAdapter.d.ts +3 -3
- package/dist/cjs/src/adapters/SQLiteAdapter.d.ts.map +1 -0
- package/dist/cjs/{adapters → src/adapters}/SQLiteAdapter.js +2 -1
- package/dist/cjs/src/adapters/SQLiteAdapter.js.map +1 -0
- package/dist/cjs/src/adapters/index.d.ts.map +1 -0
- package/dist/cjs/src/adapters/index.js.map +1 -0
- package/dist/cjs/src/constants/index.d.ts.map +1 -0
- package/dist/cjs/src/constants/index.js.map +1 -0
- package/dist/{core → cjs/src/core}/Agent.d.ts +67 -69
- package/dist/cjs/src/core/Agent.d.ts.map +1 -0
- package/dist/cjs/src/core/Agent.js +1433 -0
- package/dist/cjs/src/core/Agent.js.map +1 -0
- package/dist/cjs/src/core/Events.d.ts +26 -0
- package/dist/cjs/src/core/Events.d.ts.map +1 -0
- package/dist/cjs/src/core/Events.js +144 -0
- package/dist/cjs/src/core/Events.js.map +1 -0
- package/dist/cjs/src/core/PersistenceManager.d.ts +98 -0
- package/dist/cjs/src/core/PersistenceManager.d.ts.map +1 -0
- package/dist/cjs/{core → src/core}/PersistenceManager.js +62 -32
- package/dist/cjs/src/core/PersistenceManager.js.map +1 -0
- package/dist/cjs/src/core/PromptComposer.d.ts +27 -0
- package/dist/cjs/src/core/PromptComposer.d.ts.map +1 -0
- package/dist/cjs/src/core/PromptComposer.js +157 -0
- package/dist/cjs/src/core/PromptComposer.js.map +1 -0
- package/dist/cjs/src/core/ResponseEngine.d.ts +31 -0
- package/dist/cjs/src/core/ResponseEngine.d.ts.map +1 -0
- package/dist/cjs/src/core/ResponseEngine.js +84 -0
- package/dist/cjs/src/core/ResponseEngine.js.map +1 -0
- package/dist/cjs/src/core/ResponsePipeline.d.ts +143 -0
- package/dist/cjs/src/core/ResponsePipeline.d.ts.map +1 -0
- package/dist/cjs/src/core/ResponsePipeline.js +446 -0
- package/dist/cjs/src/core/ResponsePipeline.js.map +1 -0
- package/dist/cjs/src/core/Route.d.ts +126 -0
- package/dist/cjs/src/core/Route.d.ts.map +1 -0
- package/dist/cjs/{core → src/core}/Route.js +116 -20
- package/dist/cjs/src/core/Route.js.map +1 -0
- package/dist/{core → cjs/src/core}/RoutingEngine.d.ts +33 -38
- package/dist/cjs/src/core/RoutingEngine.d.ts.map +1 -0
- package/dist/cjs/{core → src/core}/RoutingEngine.js +102 -108
- package/dist/cjs/src/core/RoutingEngine.js.map +1 -0
- package/dist/cjs/src/core/SessionManager.d.ts +76 -0
- package/dist/cjs/src/core/SessionManager.d.ts.map +1 -0
- package/dist/cjs/src/core/SessionManager.js +197 -0
- package/dist/cjs/src/core/SessionManager.js.map +1 -0
- package/dist/cjs/src/core/Step.d.ts +96 -0
- package/dist/cjs/src/core/Step.d.ts.map +1 -0
- package/dist/cjs/src/core/Step.js +206 -0
- package/dist/cjs/src/core/Step.js.map +1 -0
- package/dist/cjs/src/core/ToolExecutor.d.ts +43 -0
- package/dist/cjs/src/core/ToolExecutor.d.ts.map +1 -0
- package/dist/cjs/{core → src/core}/ToolExecutor.js +19 -18
- package/dist/cjs/src/core/ToolExecutor.js.map +1 -0
- package/dist/{index.d.ts → cjs/src/index.d.ts} +7 -15
- package/dist/cjs/src/index.d.ts.map +1 -0
- package/dist/cjs/{index.js → src/index.js} +21 -19
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/{providers → src/providers}/AnthropicProvider.d.ts +1 -1
- package/dist/cjs/src/providers/AnthropicProvider.d.ts.map +1 -0
- package/dist/cjs/{providers → src/providers}/AnthropicProvider.js +54 -2
- package/dist/cjs/src/providers/AnthropicProvider.js.map +1 -0
- package/dist/{providers → cjs/src/providers}/GeminiProvider.d.ts +1 -1
- package/dist/cjs/src/providers/GeminiProvider.d.ts.map +1 -0
- package/dist/cjs/{providers → src/providers}/GeminiProvider.js +65 -0
- package/dist/cjs/src/providers/GeminiProvider.js.map +1 -0
- package/dist/cjs/{providers → src/providers}/OpenAIProvider.d.ts +1 -1
- package/dist/cjs/src/providers/OpenAIProvider.d.ts.map +1 -0
- package/dist/cjs/{providers → src/providers}/OpenAIProvider.js +70 -1
- package/dist/cjs/src/providers/OpenAIProvider.js.map +1 -0
- package/dist/{providers → cjs/src/providers}/OpenRouterProvider.d.ts +1 -1
- package/dist/cjs/src/providers/OpenRouterProvider.d.ts.map +1 -0
- package/dist/cjs/{providers → src/providers}/OpenRouterProvider.js +76 -0
- package/dist/cjs/src/providers/OpenRouterProvider.js.map +1 -0
- package/dist/cjs/src/providers/index.d.ts.map +1 -0
- package/dist/cjs/src/providers/index.js.map +1 -0
- package/dist/cjs/{types → src/types}/agent.d.ts +54 -35
- package/dist/cjs/src/types/agent.d.ts.map +1 -0
- package/dist/cjs/src/types/agent.js.map +1 -0
- package/dist/cjs/{types → src/types}/ai.d.ts +7 -0
- package/dist/cjs/src/types/ai.d.ts.map +1 -0
- package/dist/cjs/src/types/ai.js.map +1 -0
- package/dist/{types → cjs/src/types}/history.d.ts +76 -18
- package/dist/cjs/src/types/history.d.ts.map +1 -0
- package/dist/cjs/src/types/history.js +33 -0
- package/dist/cjs/src/types/history.js.map +1 -0
- package/dist/cjs/src/types/index.d.ts +20 -0
- package/dist/cjs/src/types/index.d.ts.map +1 -0
- package/dist/cjs/src/types/index.js +30 -0
- package/dist/cjs/src/types/index.js.map +1 -0
- package/dist/{types → cjs/src/types}/persistence.d.ts +39 -23
- package/dist/cjs/src/types/persistence.d.ts.map +1 -0
- package/dist/cjs/src/types/persistence.js.map +1 -0
- package/dist/cjs/{types → src/types}/route.d.ts +85 -31
- package/dist/cjs/src/types/route.d.ts.map +1 -0
- package/dist/cjs/{types → src/types}/route.js.map +1 -1
- package/dist/cjs/src/types/routing.d.ts.map +1 -0
- package/dist/{types → cjs/src/types}/routing.js.map +1 -1
- package/dist/cjs/src/types/schema.d.ts.map +1 -0
- package/dist/{types → cjs/src/types}/schema.js.map +1 -1
- package/dist/cjs/src/types/session.d.ts +70 -0
- package/dist/cjs/src/types/session.d.ts.map +1 -0
- package/dist/cjs/src/types/session.js +6 -0
- package/dist/cjs/src/types/session.js.map +1 -0
- package/dist/cjs/src/types/template.d.ts +30 -0
- package/dist/cjs/src/types/template.d.ts.map +1 -0
- package/dist/cjs/src/types/template.js +3 -0
- package/dist/cjs/src/types/template.js.map +1 -0
- package/dist/cjs/{types → src/types}/tool.d.ts +6 -8
- package/dist/cjs/src/types/tool.d.ts.map +1 -0
- package/dist/cjs/{types → src/types}/tool.js.map +1 -1
- package/dist/cjs/src/utils/clone.d.ts +8 -0
- package/dist/cjs/src/utils/clone.d.ts.map +1 -0
- package/dist/cjs/src/utils/clone.js +36 -0
- package/dist/cjs/src/utils/clone.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/event.d.ts +1 -1
- package/dist/cjs/src/utils/event.d.ts.map +1 -0
- package/dist/cjs/{utils → src/utils}/event.js +2 -2
- package/dist/cjs/src/utils/event.js.map +1 -0
- package/dist/cjs/src/utils/history.d.ts +31 -0
- package/dist/cjs/src/utils/history.d.ts.map +1 -0
- package/dist/cjs/src/utils/history.js +128 -0
- package/dist/cjs/src/utils/history.js.map +1 -0
- package/dist/cjs/src/utils/id.d.ts.map +1 -0
- package/dist/cjs/src/utils/id.js.map +1 -0
- package/dist/cjs/src/utils/index.d.ts +13 -0
- package/dist/cjs/src/utils/index.d.ts.map +1 -0
- package/dist/cjs/src/utils/index.js +49 -0
- package/dist/cjs/src/utils/index.js.map +1 -0
- package/dist/cjs/src/utils/logger.d.ts.map +1 -0
- package/dist/cjs/src/utils/logger.js.map +1 -0
- package/dist/cjs/src/utils/retry.d.ts.map +1 -0
- package/dist/cjs/src/utils/retry.js.map +1 -0
- package/dist/cjs/src/utils/session.d.ts +51 -0
- package/dist/cjs/src/utils/session.d.ts.map +1 -0
- package/dist/cjs/{types → src/utils}/session.js +36 -13
- package/dist/cjs/src/utils/session.js.map +1 -0
- package/dist/cjs/src/utils/template.d.ts +107 -0
- package/dist/cjs/src/utils/template.d.ts.map +1 -0
- package/dist/cjs/src/utils/template.js +283 -0
- package/dist/cjs/src/utils/template.js.map +1 -0
- package/dist/{cjs → src}/adapters/MemoryAdapter.d.ts +4 -4
- package/dist/src/adapters/MemoryAdapter.d.ts.map +1 -0
- package/dist/{adapters → src/adapters}/MemoryAdapter.js +41 -21
- package/dist/src/adapters/MemoryAdapter.js.map +1 -0
- package/dist/{cjs → src}/adapters/MongoAdapter.d.ts +3 -3
- package/dist/src/adapters/MongoAdapter.d.ts.map +1 -0
- package/dist/{adapters → src/adapters}/MongoAdapter.js +2 -1
- package/dist/src/adapters/MongoAdapter.js.map +1 -0
- package/dist/{adapters → src/adapters}/OpenSearchAdapter.d.ts +3 -3
- package/dist/src/adapters/OpenSearchAdapter.d.ts.map +1 -0
- package/dist/{adapters → src/adapters}/OpenSearchAdapter.js +10 -13
- package/dist/src/adapters/OpenSearchAdapter.js.map +1 -0
- package/dist/{adapters → src/adapters}/PostgreSQLAdapter.d.ts +3 -3
- package/dist/src/adapters/PostgreSQLAdapter.d.ts.map +1 -0
- package/dist/{adapters → src/adapters}/PostgreSQLAdapter.js +1 -1
- package/dist/src/adapters/PostgreSQLAdapter.js.map +1 -0
- package/dist/{adapters → src/adapters}/PrismaAdapter.d.ts +3 -3
- package/dist/src/adapters/PrismaAdapter.d.ts.map +1 -0
- package/dist/{adapters → src/adapters}/PrismaAdapter.js +35 -5
- package/dist/src/adapters/PrismaAdapter.js.map +1 -0
- package/dist/{adapters → src/adapters}/RedisAdapter.d.ts +3 -3
- package/dist/src/adapters/RedisAdapter.d.ts.map +1 -0
- package/dist/{adapters → src/adapters}/RedisAdapter.js +3 -2
- package/dist/src/adapters/RedisAdapter.js.map +1 -0
- package/dist/{cjs → src}/adapters/SQLiteAdapter.d.ts +3 -3
- package/dist/src/adapters/SQLiteAdapter.d.ts.map +1 -0
- package/dist/{adapters → src/adapters}/SQLiteAdapter.js +2 -1
- package/dist/src/adapters/SQLiteAdapter.js.map +1 -0
- package/dist/src/adapters/index.js.map +1 -0
- package/dist/src/constants/index.js.map +1 -0
- package/dist/{cjs → src}/core/Agent.d.ts +67 -69
- package/dist/src/core/Agent.d.ts.map +1 -0
- package/dist/src/core/Agent.js +1429 -0
- package/dist/src/core/Agent.js.map +1 -0
- package/dist/src/core/Events.d.ts +26 -0
- package/dist/src/core/Events.d.ts.map +1 -0
- package/dist/src/core/Events.js +137 -0
- package/dist/src/core/Events.js.map +1 -0
- package/dist/src/core/PersistenceManager.d.ts +98 -0
- package/dist/src/core/PersistenceManager.d.ts.map +1 -0
- package/dist/{core → src/core}/PersistenceManager.js +56 -26
- package/dist/src/core/PersistenceManager.js.map +1 -0
- package/dist/src/core/PromptComposer.d.ts +27 -0
- package/dist/src/core/PromptComposer.d.ts.map +1 -0
- package/dist/src/core/PromptComposer.js +153 -0
- package/dist/src/core/PromptComposer.js.map +1 -0
- package/dist/src/core/ResponseEngine.d.ts +31 -0
- package/dist/src/core/ResponseEngine.d.ts.map +1 -0
- package/dist/src/core/ResponseEngine.js +80 -0
- package/dist/src/core/ResponseEngine.js.map +1 -0
- package/dist/src/core/ResponsePipeline.d.ts +143 -0
- package/dist/src/core/ResponsePipeline.d.ts.map +1 -0
- package/dist/src/core/ResponsePipeline.js +442 -0
- package/dist/src/core/ResponsePipeline.js.map +1 -0
- package/dist/src/core/Route.d.ts +126 -0
- package/dist/src/core/Route.d.ts.map +1 -0
- package/dist/{core → src/core}/Route.js +116 -20
- package/dist/src/core/Route.js.map +1 -0
- package/dist/{cjs → src}/core/RoutingEngine.d.ts +33 -38
- package/dist/src/core/RoutingEngine.d.ts.map +1 -0
- package/dist/{core → src/core}/RoutingEngine.js +98 -104
- package/dist/src/core/RoutingEngine.js.map +1 -0
- package/dist/src/core/SessionManager.d.ts +76 -0
- package/dist/src/core/SessionManager.d.ts.map +1 -0
- package/dist/src/core/SessionManager.js +193 -0
- package/dist/src/core/SessionManager.js.map +1 -0
- package/dist/src/core/Step.d.ts +96 -0
- package/dist/src/core/Step.d.ts.map +1 -0
- package/dist/src/core/Step.js +202 -0
- package/dist/src/core/Step.js.map +1 -0
- package/dist/src/core/ToolExecutor.d.ts +43 -0
- package/dist/src/core/ToolExecutor.d.ts.map +1 -0
- package/dist/src/core/ToolExecutor.js +70 -0
- package/dist/src/core/ToolExecutor.js.map +1 -0
- package/dist/{cjs → src}/index.d.ts +7 -15
- package/dist/src/index.d.ts.map +1 -0
- package/dist/{index.js → src/index.js} +6 -7
- package/dist/src/index.js.map +1 -0
- package/dist/{providers → src/providers}/AnthropicProvider.d.ts +1 -1
- package/dist/src/providers/AnthropicProvider.d.ts.map +1 -0
- package/dist/{providers → src/providers}/AnthropicProvider.js +54 -2
- package/dist/src/providers/AnthropicProvider.js.map +1 -0
- package/dist/{cjs → src}/providers/GeminiProvider.d.ts +1 -1
- package/dist/{cjs → src}/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/{providers → src/providers}/GeminiProvider.js +65 -0
- package/dist/src/providers/GeminiProvider.js.map +1 -0
- package/dist/{providers → src/providers}/OpenAIProvider.d.ts +1 -1
- package/dist/{cjs → src}/providers/OpenAIProvider.d.ts.map +1 -1
- package/dist/{providers → src/providers}/OpenAIProvider.js +70 -1
- package/dist/src/providers/OpenAIProvider.js.map +1 -0
- package/dist/{cjs → src}/providers/OpenRouterProvider.d.ts +1 -1
- package/dist/{cjs → src}/providers/OpenRouterProvider.d.ts.map +1 -1
- package/dist/{providers → src/providers}/OpenRouterProvider.js +76 -0
- package/dist/src/providers/OpenRouterProvider.js.map +1 -0
- package/dist/src/providers/index.js.map +1 -0
- package/dist/{types → src/types}/agent.d.ts +54 -35
- package/dist/src/types/agent.d.ts.map +1 -0
- package/dist/src/types/agent.js.map +1 -0
- package/dist/{types → src/types}/ai.d.ts +7 -0
- package/dist/src/types/ai.d.ts.map +1 -0
- package/dist/{cjs → src}/types/ai.js.map +1 -1
- package/dist/{cjs → src}/types/history.d.ts +76 -18
- package/dist/src/types/history.d.ts.map +1 -0
- package/dist/src/types/history.js +30 -0
- package/dist/src/types/history.js.map +1 -0
- package/dist/src/types/index.d.ts +20 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +10 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/{cjs → src}/types/persistence.d.ts +39 -23
- package/dist/src/types/persistence.d.ts.map +1 -0
- package/dist/src/types/persistence.js.map +1 -0
- package/dist/{types → src/types}/route.d.ts +85 -31
- package/dist/src/types/route.d.ts.map +1 -0
- package/dist/{types → src/types}/route.js.map +1 -1
- package/dist/src/types/session.d.ts +70 -0
- package/dist/src/types/session.d.ts.map +1 -0
- package/dist/src/types/session.js +5 -0
- package/dist/src/types/session.js.map +1 -0
- package/dist/src/types/template.d.ts +30 -0
- package/dist/src/types/template.d.ts.map +1 -0
- package/dist/src/types/template.js +2 -0
- package/dist/src/types/template.js.map +1 -0
- package/dist/{types → src/types}/tool.d.ts +6 -8
- package/dist/{cjs → src}/types/tool.d.ts.map +1 -1
- package/dist/{types → src/types}/tool.js.map +1 -1
- package/dist/src/utils/clone.d.ts +8 -0
- package/dist/src/utils/clone.d.ts.map +1 -0
- package/dist/src/utils/clone.js +33 -0
- package/dist/src/utils/clone.js.map +1 -0
- package/dist/{cjs → src}/utils/event.d.ts +1 -1
- package/dist/{cjs → src}/utils/event.d.ts.map +1 -1
- package/dist/{utils → src/utils}/event.js +1 -1
- package/dist/src/utils/event.js.map +1 -0
- package/dist/src/utils/history.d.ts +31 -0
- package/dist/src/utils/history.d.ts.map +1 -0
- package/dist/src/utils/history.js +121 -0
- package/dist/src/utils/history.js.map +1 -0
- package/dist/src/utils/id.js.map +1 -0
- package/dist/src/utils/index.d.ts +13 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +19 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/dist/src/utils/retry.js.map +1 -0
- package/dist/src/utils/session.d.ts +51 -0
- package/dist/src/utils/session.d.ts.map +1 -0
- package/dist/{types → src/utils}/session.js +34 -13
- package/dist/src/utils/session.js.map +1 -0
- package/dist/src/utils/template.d.ts +107 -0
- package/dist/src/utils/template.d.ts.map +1 -0
- package/dist/src/utils/template.js +276 -0
- package/dist/src/utils/template.js.map +1 -0
- package/docs/README.md +174 -68
- package/docs/{API_REFERENCE.md → api/README.md} +902 -263
- package/docs/api/overview.md +798 -0
- package/docs/core/agent/README.md +642 -0
- package/docs/{CONTEXT_MANAGEMENT.md → core/agent/context-management.md} +144 -95
- package/docs/{ARCHITECTURE.md → core/agent/session-management.md} +74 -59
- package/docs/core/ai-integration/prompt-composition.md +196 -0
- package/docs/core/ai-integration/providers.md +515 -0
- package/docs/core/ai-integration/response-processing.md +165 -0
- package/docs/core/conversation-flows/data-collection.md +545 -0
- package/docs/core/conversation-flows/route-dsl.md +479 -0
- package/docs/core/conversation-flows/routes.md +61 -0
- package/docs/core/conversation-flows/step-transitions.md +595 -0
- package/docs/core/conversation-flows/steps.md +130 -0
- package/docs/{ADAPTERS.md → core/persistence/adapters.md} +2 -2
- package/docs/core/persistence/session-storage.md +644 -0
- package/docs/core/routing/intelligent-routing.md +339 -0
- package/docs/core/tools/tool-definition.md +346 -0
- package/docs/core/tools/tool-execution.md +815 -0
- package/docs/core/tools/tool-scoping.md +628 -0
- package/docs/guides/getting-started/README.md +384 -0
- package/examples/{company-qna-agent.ts → advanced-patterns/knowledge-based-agent.ts} +104 -69
- package/examples/{persistent-onboarding.ts → advanced-patterns/persistent-onboarding.ts} +181 -103
- package/examples/{rules-prohibitions.ts → advanced-patterns/route-lifecycle-hooks.ts} +102 -82
- package/examples/{streaming-agent.ts → advanced-patterns/streaming-responses.ts} +90 -69
- package/examples/ai-providers/anthropic-integration.ts +377 -0
- package/examples/{openai-agent.ts → ai-providers/openai-integration.ts} +37 -43
- package/examples/{route-transitions.ts → conversation-flows/completion-transitions.ts} +115 -108
- package/examples/{declarative-agent.ts → core-concepts/basic-agent.ts} +175 -131
- package/examples/core-concepts/schema-driven-extraction.ts +301 -0
- package/examples/core-concepts/session-management.ts +394 -0
- package/examples/integrations/database-integration.ts +615 -0
- package/examples/{healthcare-agent.ts → integrations/healthcare-integration.ts} +204 -111
- package/examples/{opensearch-persistence.ts → integrations/search-integration.ts} +159 -128
- package/examples/integrations/server-session-management.ts +299 -0
- package/examples/persistence/custom-adapter.ts +529 -0
- package/examples/{prisma-persistence.ts → persistence/database-persistence.ts} +168 -241
- package/examples/persistence/memory-sessions.ts +506 -0
- package/examples/{prisma-schema.example.prisma → persistence/prisma-schema.example.prisma} +1 -1
- package/examples/{redis-persistence.ts → persistence/redis-persistence.ts} +152 -173
- package/examples/tools/basic-tools.ts +550 -0
- package/examples/{extracted-data-modification.ts → tools/data-enrichment-tools.ts} +82 -79
- package/package.json +14 -10
- package/src/adapters/MemoryAdapter.ts +74 -46
- package/src/adapters/MongoAdapter.ts +33 -24
- package/src/adapters/OpenSearchAdapter.ts +41 -37
- package/src/adapters/PostgreSQLAdapter.ts +35 -24
- package/src/adapters/PrismaAdapter.ts +69 -27
- package/src/adapters/RedisAdapter.ts +38 -26
- package/src/adapters/SQLiteAdapter.ts +32 -22
- package/src/core/Agent.ts +1102 -487
- package/src/core/Events.ts +100 -112
- package/src/core/PersistenceManager.ts +87 -57
- package/src/core/PromptComposer.ts +158 -85
- package/src/core/ResponseEngine.ts +118 -38
- package/src/core/ResponsePipeline.ts +715 -0
- package/src/core/Route.ts +168 -51
- package/src/core/RoutingEngine.ts +178 -209
- package/src/core/SessionManager.ts +241 -0
- package/src/core/Step.ts +149 -67
- package/src/core/ToolExecutor.ts +37 -42
- package/src/index.ts +31 -37
- package/src/providers/AnthropicProvider.ts +71 -5
- package/src/providers/GeminiProvider.ts +83 -2
- package/src/providers/OpenAIProvider.ts +95 -3
- package/src/providers/OpenRouterProvider.ts +102 -2
- package/src/types/agent.ts +50 -38
- package/src/types/ai.ts +7 -0
- package/src/types/history.ts +91 -18
- package/src/types/index.ts +43 -7
- package/src/types/persistence.ts +46 -28
- package/src/types/route.ts +104 -45
- package/src/types/session.ts +19 -213
- package/src/types/template.ts +36 -0
- package/src/types/tool.ts +9 -11
- package/src/utils/clone.ts +36 -0
- package/src/utils/event.ts +1 -1
- package/src/utils/history.ts +143 -0
- package/src/utils/index.ts +53 -0
- package/src/utils/session.ts +229 -0
- package/src/utils/template.ts +335 -0
- package/dist/adapters/MemoryAdapter.d.ts.map +0 -1
- package/dist/adapters/MemoryAdapter.js.map +0 -1
- package/dist/adapters/MongoAdapter.d.ts.map +0 -1
- package/dist/adapters/MongoAdapter.js.map +0 -1
- package/dist/adapters/OpenSearchAdapter.d.ts.map +0 -1
- package/dist/adapters/OpenSearchAdapter.js.map +0 -1
- package/dist/adapters/PostgreSQLAdapter.d.ts.map +0 -1
- package/dist/adapters/PostgreSQLAdapter.js.map +0 -1
- package/dist/adapters/PrismaAdapter.d.ts.map +0 -1
- package/dist/adapters/PrismaAdapter.js.map +0 -1
- package/dist/adapters/RedisAdapter.d.ts.map +0 -1
- package/dist/adapters/RedisAdapter.js.map +0 -1
- package/dist/adapters/SQLiteAdapter.d.ts.map +0 -1
- package/dist/adapters/SQLiteAdapter.js.map +0 -1
- package/dist/adapters/index.d.ts.map +0 -1
- package/dist/adapters/index.js.map +0 -1
- package/dist/cjs/adapters/MemoryAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/MemoryAdapter.js.map +0 -1
- package/dist/cjs/adapters/MongoAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/MongoAdapter.js.map +0 -1
- package/dist/cjs/adapters/OpenSearchAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/OpenSearchAdapter.js.map +0 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.js.map +0 -1
- package/dist/cjs/adapters/PrismaAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/PrismaAdapter.js.map +0 -1
- package/dist/cjs/adapters/RedisAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/RedisAdapter.js.map +0 -1
- package/dist/cjs/adapters/SQLiteAdapter.d.ts.map +0 -1
- package/dist/cjs/adapters/SQLiteAdapter.js.map +0 -1
- package/dist/cjs/adapters/index.js.map +0 -1
- package/dist/cjs/constants/index.js.map +0 -1
- package/dist/cjs/core/Agent.d.ts.map +0 -1
- package/dist/cjs/core/Agent.js +0 -966
- package/dist/cjs/core/Agent.js.map +0 -1
- package/dist/cjs/core/DomainRegistry.d.ts +0 -36
- package/dist/cjs/core/DomainRegistry.d.ts.map +0 -1
- package/dist/cjs/core/DomainRegistry.js +0 -72
- package/dist/cjs/core/DomainRegistry.js.map +0 -1
- package/dist/cjs/core/Events.d.ts +0 -41
- package/dist/cjs/core/Events.d.ts.map +0 -1
- package/dist/cjs/core/Events.js +0 -99
- package/dist/cjs/core/Events.js.map +0 -1
- package/dist/cjs/core/PersistenceManager.d.ts +0 -96
- package/dist/cjs/core/PersistenceManager.d.ts.map +0 -1
- package/dist/cjs/core/PersistenceManager.js.map +0 -1
- package/dist/cjs/core/PromptComposer.d.ts +0 -24
- package/dist/cjs/core/PromptComposer.d.ts.map +0 -1
- package/dist/cjs/core/PromptComposer.js +0 -127
- package/dist/cjs/core/PromptComposer.js.map +0 -1
- package/dist/cjs/core/ResponseEngine.d.ts +0 -14
- package/dist/cjs/core/ResponseEngine.d.ts.map +0 -1
- package/dist/cjs/core/ResponseEngine.js +0 -56
- package/dist/cjs/core/ResponseEngine.js.map +0 -1
- package/dist/cjs/core/Route.d.ts +0 -90
- package/dist/cjs/core/Route.d.ts.map +0 -1
- package/dist/cjs/core/Route.js.map +0 -1
- package/dist/cjs/core/RoutingEngine.d.ts.map +0 -1
- package/dist/cjs/core/RoutingEngine.js.map +0 -1
- package/dist/cjs/core/Step.d.ts +0 -72
- package/dist/cjs/core/Step.d.ts.map +0 -1
- package/dist/cjs/core/Step.js +0 -150
- package/dist/cjs/core/Step.js.map +0 -1
- package/dist/cjs/core/Tool.d.ts +0 -39
- package/dist/cjs/core/Tool.d.ts.map +0 -1
- package/dist/cjs/core/Tool.js +0 -34
- package/dist/cjs/core/Tool.js.map +0 -1
- package/dist/cjs/core/ToolExecutor.d.ts +0 -29
- package/dist/cjs/core/ToolExecutor.d.ts.map +0 -1
- package/dist/cjs/core/ToolExecutor.js.map +0 -1
- package/dist/cjs/core/Transition.d.ts +0 -32
- package/dist/cjs/core/Transition.d.ts.map +0 -1
- package/dist/cjs/core/Transition.js +0 -89
- package/dist/cjs/core/Transition.js.map +0 -1
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/providers/AnthropicProvider.d.ts.map +0 -1
- package/dist/cjs/providers/AnthropicProvider.js.map +0 -1
- package/dist/cjs/providers/GeminiProvider.js.map +0 -1
- package/dist/cjs/providers/OpenAIProvider.js.map +0 -1
- package/dist/cjs/providers/OpenRouterProvider.js.map +0 -1
- package/dist/cjs/providers/index.js.map +0 -1
- package/dist/cjs/types/agent.d.ts.map +0 -1
- package/dist/cjs/types/agent.js.map +0 -1
- package/dist/cjs/types/ai.d.ts.map +0 -1
- package/dist/cjs/types/history.d.ts.map +0 -1
- package/dist/cjs/types/history.js +0 -37
- package/dist/cjs/types/history.js.map +0 -1
- package/dist/cjs/types/index.d.ts +0 -12
- package/dist/cjs/types/index.d.ts.map +0 -1
- package/dist/cjs/types/index.js +0 -12
- package/dist/cjs/types/index.js.map +0 -1
- package/dist/cjs/types/persistence.d.ts.map +0 -1
- package/dist/cjs/types/persistence.js.map +0 -1
- package/dist/cjs/types/route.d.ts.map +0 -1
- package/dist/cjs/types/session.d.ts +0 -104
- package/dist/cjs/types/session.d.ts.map +0 -1
- package/dist/cjs/types/session.js.map +0 -1
- package/dist/cjs/utils/event.js.map +0 -1
- package/dist/cjs/utils/id.js.map +0 -1
- package/dist/cjs/utils/logger.js.map +0 -1
- package/dist/cjs/utils/retry.js.map +0 -1
- package/dist/constants/index.d.ts.map +0 -1
- package/dist/constants/index.js.map +0 -1
- package/dist/core/Agent.d.ts.map +0 -1
- package/dist/core/Agent.js +0 -962
- package/dist/core/Agent.js.map +0 -1
- package/dist/core/DomainRegistry.d.ts +0 -36
- package/dist/core/DomainRegistry.d.ts.map +0 -1
- package/dist/core/DomainRegistry.js +0 -68
- package/dist/core/DomainRegistry.js.map +0 -1
- package/dist/core/Events.d.ts +0 -41
- package/dist/core/Events.d.ts.map +0 -1
- package/dist/core/Events.js +0 -94
- package/dist/core/Events.js.map +0 -1
- package/dist/core/PersistenceManager.d.ts +0 -96
- package/dist/core/PersistenceManager.d.ts.map +0 -1
- package/dist/core/PersistenceManager.js.map +0 -1
- package/dist/core/PromptComposer.d.ts +0 -24
- package/dist/core/PromptComposer.d.ts.map +0 -1
- package/dist/core/PromptComposer.js +0 -123
- package/dist/core/PromptComposer.js.map +0 -1
- package/dist/core/ResponseEngine.d.ts +0 -14
- package/dist/core/ResponseEngine.d.ts.map +0 -1
- package/dist/core/ResponseEngine.js +0 -52
- package/dist/core/ResponseEngine.js.map +0 -1
- package/dist/core/Route.d.ts +0 -90
- package/dist/core/Route.d.ts.map +0 -1
- package/dist/core/Route.js.map +0 -1
- package/dist/core/RoutingEngine.d.ts.map +0 -1
- package/dist/core/RoutingEngine.js.map +0 -1
- package/dist/core/Step.d.ts +0 -72
- package/dist/core/Step.d.ts.map +0 -1
- package/dist/core/Step.js +0 -146
- package/dist/core/Step.js.map +0 -1
- package/dist/core/Tool.d.ts +0 -39
- package/dist/core/Tool.d.ts.map +0 -1
- package/dist/core/Tool.js +0 -31
- package/dist/core/Tool.js.map +0 -1
- package/dist/core/ToolExecutor.d.ts +0 -29
- package/dist/core/ToolExecutor.d.ts.map +0 -1
- package/dist/core/ToolExecutor.js +0 -69
- package/dist/core/ToolExecutor.js.map +0 -1
- package/dist/core/Transition.d.ts +0 -32
- package/dist/core/Transition.d.ts.map +0 -1
- package/dist/core/Transition.js +0 -85
- package/dist/core/Transition.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/providers/AnthropicProvider.d.ts.map +0 -1
- package/dist/providers/AnthropicProvider.js.map +0 -1
- package/dist/providers/GeminiProvider.d.ts.map +0 -1
- package/dist/providers/GeminiProvider.js.map +0 -1
- package/dist/providers/OpenAIProvider.d.ts.map +0 -1
- package/dist/providers/OpenAIProvider.js.map +0 -1
- package/dist/providers/OpenRouterProvider.d.ts.map +0 -1
- package/dist/providers/OpenRouterProvider.js.map +0 -1
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/index.js.map +0 -1
- package/dist/types/agent.d.ts.map +0 -1
- package/dist/types/agent.js.map +0 -1
- package/dist/types/ai.d.ts.map +0 -1
- package/dist/types/ai.js.map +0 -1
- package/dist/types/history.d.ts.map +0 -1
- package/dist/types/history.js +0 -34
- package/dist/types/history.js.map +0 -1
- package/dist/types/index.d.ts +0 -12
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -6
- package/dist/types/index.js.map +0 -1
- package/dist/types/persistence.d.ts.map +0 -1
- package/dist/types/persistence.js.map +0 -1
- package/dist/types/route.d.ts.map +0 -1
- package/dist/types/routing.d.ts.map +0 -1
- package/dist/types/schema.d.ts.map +0 -1
- package/dist/types/session.d.ts +0 -104
- package/dist/types/session.d.ts.map +0 -1
- package/dist/types/session.js.map +0 -1
- package/dist/types/tool.d.ts.map +0 -1
- package/dist/utils/event.d.ts.map +0 -1
- package/dist/utils/event.js.map +0 -1
- package/dist/utils/id.d.ts.map +0 -1
- package/dist/utils/id.js.map +0 -1
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/retry.d.ts.map +0 -1
- package/dist/utils/retry.js.map +0 -1
- package/docs/AGENT.md +0 -535
- package/docs/DOCS.md +0 -263
- package/docs/DOMAINS.md +0 -735
- package/docs/EXAMPLES.md +0 -467
- package/docs/GETTING_STARTED.md +0 -424
- package/docs/PERSISTENCE.md +0 -815
- package/docs/PROVIDERS.md +0 -612
- package/docs/ROUTES.md +0 -1085
- package/docs/STEPS.md +0 -883
- package/examples/business-onboarding.ts +0 -791
- package/examples/custom-database-persistence.ts +0 -574
- package/examples/domain-scoping.ts +0 -366
- package/examples/travel-agent.ts +0 -584
- package/src/core/DomainRegistry.ts +0 -80
- package/src/core/Tool.ts +0 -112
- package/src/core/Transition.ts +0 -115
- /package/dist/{adapters → cjs/src/adapters}/index.d.ts +0 -0
- /package/dist/cjs/{adapters → src/adapters}/index.js +0 -0
- /package/dist/cjs/{constants → src/constants}/index.d.ts +0 -0
- /package/dist/cjs/{constants → src/constants}/index.js +0 -0
- /package/dist/cjs/{providers → src/providers}/index.d.ts +0 -0
- /package/dist/cjs/{providers → src/providers}/index.js +0 -0
- /package/dist/cjs/{types → src/types}/agent.js +0 -0
- /package/dist/cjs/{types → src/types}/ai.js +0 -0
- /package/dist/cjs/{types → src/types}/persistence.js +0 -0
- /package/dist/cjs/{types → src/types}/route.js +0 -0
- /package/dist/cjs/{types → src/types}/routing.d.ts +0 -0
- /package/dist/cjs/{types → src/types}/routing.js +0 -0
- /package/dist/cjs/{types → src/types}/schema.d.ts +0 -0
- /package/dist/cjs/{types → src/types}/schema.js +0 -0
- /package/dist/cjs/{types → src/types}/tool.js +0 -0
- /package/dist/cjs/{utils → src/utils}/id.d.ts +0 -0
- /package/dist/cjs/{utils → src/utils}/id.js +0 -0
- /package/dist/cjs/{utils → src/utils}/logger.d.ts +0 -0
- /package/dist/cjs/{utils → src/utils}/logger.js +0 -0
- /package/dist/cjs/{utils → src/utils}/retry.d.ts +0 -0
- /package/dist/cjs/{utils → src/utils}/retry.js +0 -0
- /package/dist/{cjs → src}/adapters/index.d.ts +0 -0
- /package/dist/{cjs → src}/adapters/index.d.ts.map +0 -0
- /package/dist/{adapters → src/adapters}/index.js +0 -0
- /package/dist/{constants → src/constants}/index.d.ts +0 -0
- /package/dist/{cjs → src}/constants/index.d.ts.map +0 -0
- /package/dist/{constants → src/constants}/index.js +0 -0
- /package/dist/{providers → src/providers}/index.d.ts +0 -0
- /package/dist/{cjs → src}/providers/index.d.ts.map +0 -0
- /package/dist/{providers → src/providers}/index.js +0 -0
- /package/dist/{types → src/types}/agent.js +0 -0
- /package/dist/{types → src/types}/ai.js +0 -0
- /package/dist/{types → src/types}/persistence.js +0 -0
- /package/dist/{types → src/types}/route.js +0 -0
- /package/dist/{types → src/types}/routing.d.ts +0 -0
- /package/dist/{cjs → src}/types/routing.d.ts.map +0 -0
- /package/dist/{types → src/types}/routing.js +0 -0
- /package/dist/{cjs → src}/types/routing.js.map +0 -0
- /package/dist/{types → src/types}/schema.d.ts +0 -0
- /package/dist/{cjs → src}/types/schema.d.ts.map +0 -0
- /package/dist/{types → src/types}/schema.js +0 -0
- /package/dist/{cjs → src}/types/schema.js.map +0 -0
- /package/dist/{types → src/types}/tool.js +0 -0
- /package/dist/{utils → src/utils}/id.d.ts +0 -0
- /package/dist/{cjs → src}/utils/id.d.ts.map +0 -0
- /package/dist/{utils → src/utils}/id.js +0 -0
- /package/dist/{utils → src/utils}/logger.d.ts +0 -0
- /package/dist/{cjs → src}/utils/logger.d.ts.map +0 -0
- /package/dist/{utils → src/utils}/logger.js +0 -0
- /package/dist/{utils → src/utils}/retry.d.ts +0 -0
- /package/dist/{cjs → src}/utils/retry.d.ts.map +0 -0
- /package/dist/{utils → src/utils}/retry.js +0 -0
- /package/docs/{PUBLISHING.md → guides/advanced-patterns/publishing.md} +0 -0
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
# API Reference
|
|
2
2
|
|
|
3
|
-
Complete API documentation for `@falai/agent`.
|
|
3
|
+
Complete API documentation for `@falai/agent`. This framework provides a strongly-typed, modular agent architecture with AI-powered routing and schema-driven data collection.
|
|
4
|
+
|
|
5
|
+
## 📋 Documentation Structure
|
|
6
|
+
|
|
7
|
+
- **[Complete API Overview](./overview.md)** - Comprehensive reference for all classes, interfaces, and utilities
|
|
8
|
+
- **[Agent Architecture](../core/agent/README.md)** - Agent class, context management, and lifecycle
|
|
9
|
+
- **[AI Routing System](../core/routing/intelligent-routing.md)** - Intelligent route and step selection
|
|
10
|
+
- **[Route DSL](../core/conversation-flows/route-dsl.md)** - Declarative conversation flow design
|
|
11
|
+
- **[Data Collection](../core/conversation-flows/data-collection.md)** - Schema-driven data extraction
|
|
12
|
+
- **[Tool Execution](../core/tools/tool-execution.md)** - Dynamic tool calling and context updates
|
|
13
|
+
- **[Session Storage](../core/persistence/session-storage.md)** - Persistence and session management
|
|
14
|
+
- **[AI Providers](../core/ai-integration/providers.md)** - Provider integrations and configuration
|
|
4
15
|
|
|
5
16
|
---
|
|
6
17
|
|
|
@@ -32,21 +43,108 @@ Adds a domain glossary term. Returns `this` for chaining.
|
|
|
32
43
|
|
|
33
44
|
Adds a behavioral guideline. Returns `this` for chaining.
|
|
34
45
|
|
|
35
|
-
##### `
|
|
46
|
+
##### `respond(input: RespondInput<TContext>): Promise<RespondOutput>`
|
|
47
|
+
|
|
48
|
+
Generates an AI response with session step management, tool execution, data extraction, and intelligent routing.
|
|
49
|
+
|
|
50
|
+
**Enhanced Response Pipeline:**
|
|
51
|
+
|
|
52
|
+
1. **Tool Execution** - Execute tools if current step has `tool` (enriches context before AI response)
|
|
53
|
+
2. **Always-On Routing** - Score all routes, respect user intent to change direction
|
|
54
|
+
3. **Step Traversal** - Use `skipIf` and `requires` to determine next step
|
|
55
|
+
4. **Response Generation** - Build schema with `collect` fields, extract data
|
|
56
|
+
5. **Session Update** - Merge collected data into session step
|
|
57
|
+
|
|
58
|
+
**Tool Execution (Pre-Response):**
|
|
59
|
+
Tools execute before AI response generation, allowing them to:
|
|
60
|
+
|
|
61
|
+
- Enrich context with external data
|
|
62
|
+
- Update collected session data
|
|
63
|
+
- Perform business logic
|
|
64
|
+
- Access APIs and databases
|
|
65
|
+
|
|
66
|
+
This design enables more intelligent, context-aware responses.
|
|
67
|
+
|
|
68
|
+
##### `getKnowledgeBase(): Record<string, unknown>`
|
|
69
|
+
|
|
70
|
+
Gets the agent's knowledge base containing any JSON structure the AI should know.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const knowledge = agent.getKnowledgeBase();
|
|
74
|
+
// Returns the agent's knowledge base
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
##### `getRoutes(): Route<TContext, unknown>[]`
|
|
78
|
+
|
|
79
|
+
Gets all routes configured in the agent.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const routes = agent.getRoutes();
|
|
83
|
+
// Returns array of all configured routes
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
##### `getTerms(): Term<TContext>[]`
|
|
87
|
+
|
|
88
|
+
Gets all terms configured in the agent.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
const terms = agent.getTerms();
|
|
92
|
+
// Returns array of all configured terms
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
##### `getGuidelines(): Guideline<TContext>[]`
|
|
96
|
+
|
|
97
|
+
Gets all guidelines configured in the agent.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const guidelines = agent.getGuidelines();
|
|
101
|
+
// Returns array of all configured guidelines
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
````typescript
|
|
105
|
+
|
|
106
|
+
##### `getPersistenceManager(): PersistenceManager | undefined`
|
|
107
|
+
|
|
108
|
+
Gets the persistence manager if configured.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
const persistence = agent.getPersistenceManager();
|
|
112
|
+
// Returns PersistenceManager instance or undefined if not configured
|
|
113
|
+
````
|
|
114
|
+
|
|
115
|
+
##### `hasPersistence(): boolean`
|
|
116
|
+
|
|
117
|
+
Checks if persistence is enabled.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
if (agent.hasPersistence()) {
|
|
121
|
+
// Persistence is configured
|
|
122
|
+
}
|
|
123
|
+
```
|
|
36
124
|
|
|
37
|
-
|
|
125
|
+
##### `nextStepRoute(routeIdOrTitle, session?, condition?, history?): Promise<SessionState>`
|
|
38
126
|
|
|
39
|
-
|
|
127
|
+
Manually transition to a different route by setting a pending transition that will be executed on the next `respond()` call.
|
|
40
128
|
|
|
41
|
-
|
|
129
|
+
```typescript
|
|
130
|
+
// Transition to feedback route after completion
|
|
131
|
+
const updatedSession = await agent.nextStepRoute(
|
|
132
|
+
"feedback-collection",
|
|
133
|
+
session
|
|
134
|
+
);
|
|
42
135
|
|
|
43
|
-
|
|
136
|
+
// Next respond() call will automatically transition
|
|
137
|
+
const response = await agent.respond({ history, session: updatedSession });
|
|
138
|
+
```
|
|
44
139
|
|
|
45
|
-
|
|
140
|
+
**Parameters:**
|
|
46
141
|
|
|
47
|
-
|
|
142
|
+
- `routeIdOrTitle`: Route ID or title to transition to
|
|
143
|
+
- `session`: Session step to update (uses current session if not provided)
|
|
144
|
+
- `condition`: Optional AI-evaluated condition for the transition
|
|
145
|
+
- `history`: Optional history for template context
|
|
48
146
|
|
|
49
|
-
|
|
147
|
+
**Returns:** Updated session with pending transition
|
|
50
148
|
|
|
51
149
|
##### `getData<TData>(routeId?): Partial<TData>`
|
|
52
150
|
|
|
@@ -91,7 +189,7 @@ const routeData = agent.getData("onboarding");
|
|
|
91
189
|
|
|
92
190
|
- `session`: Session step to use as current session
|
|
93
191
|
|
|
94
|
-
##### `getCurrentSession():
|
|
192
|
+
##### `getCurrentSession(): SessionState | undefined`
|
|
95
193
|
|
|
96
194
|
Gets the currently set session.
|
|
97
195
|
|
|
@@ -119,7 +217,7 @@ Generates an AI response with session step management, data extraction, and inte
|
|
|
119
217
|
```typescript
|
|
120
218
|
interface RespondInput<TContext> {
|
|
121
219
|
history: Event[];
|
|
122
|
-
session?:
|
|
220
|
+
session?: SessionState; // NEW: Session step for conversation tracking
|
|
123
221
|
contextOverride?: Partial<TContext>;
|
|
124
222
|
signal?: AbortSignal;
|
|
125
223
|
}
|
|
@@ -128,7 +226,7 @@ interface RespondOutput {
|
|
|
128
226
|
/** The message to send to the user */
|
|
129
227
|
message: string;
|
|
130
228
|
/** Updated session step (includes collected data, current route/step) */
|
|
131
|
-
session?:
|
|
229
|
+
session?: SessionState;
|
|
132
230
|
/** Tool calls executed during response (for debugging) */
|
|
133
231
|
toolCalls?: Array<{
|
|
134
232
|
toolName: string;
|
|
@@ -159,87 +257,53 @@ interface RespondOutput {
|
|
|
159
257
|
- Automatically merges new collected data with existing session data
|
|
160
258
|
- **Per-route data preservation** - Collected data is organized by route ID, allowing users to switch routes without losing progress
|
|
161
259
|
|
|
162
|
-
**Example with
|
|
260
|
+
**Example with Automatic Session Management:**
|
|
163
261
|
|
|
164
262
|
```typescript
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
263
|
+
// Server endpoint with automatic session management
|
|
264
|
+
app.post('/chat', async (req, res) => {
|
|
265
|
+
const { sessionId, message } = req.body;
|
|
266
|
+
|
|
267
|
+
const agent = new Agent({
|
|
268
|
+
name: "Travel Agent",
|
|
269
|
+
provider: new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY }),
|
|
270
|
+
persistence: { adapter: new PrismaAdapter({ prisma }) },
|
|
271
|
+
sessionId // Automatically loads or creates this session
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const response = await agent.respond(message);
|
|
275
|
+
|
|
276
|
+
res.json({
|
|
277
|
+
message: response.message,
|
|
278
|
+
sessionId: agent.session.id,
|
|
279
|
+
isComplete: response.isRouteComplete
|
|
172
280
|
});
|
|
173
|
-
|
|
174
|
-
// Option 1: Set current session for convenience
|
|
175
|
-
agent.setCurrentSession(sessionStep);
|
|
176
|
-
|
|
177
|
-
const response = await agent.respond({
|
|
178
|
-
history,
|
|
179
|
-
// session: sessionStep, // No longer required!
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
// Use convenience methods without passing session
|
|
183
|
-
const data = agent.getData();
|
|
184
|
-
|
|
185
|
-
// Option 2: Still pass session explicitly if preferred
|
|
186
|
-
const response2 = await agent.respond({
|
|
187
|
-
history,
|
|
188
|
-
session: sessionStep,
|
|
189
281
|
});
|
|
190
282
|
```
|
|
191
283
|
|
|
192
|
-
**
|
|
284
|
+
**SessionManager API:**
|
|
193
285
|
|
|
194
286
|
```typescript
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// Load from your custom database
|
|
198
|
-
const dbSession = await yourDb.sessions.findOne({ id: sessionId });
|
|
287
|
+
// Access session manager
|
|
288
|
+
const sessionManager = agent.session;
|
|
199
289
|
|
|
200
|
-
//
|
|
201
|
-
|
|
290
|
+
// Get or create session (works for existing, new, or auto-generated IDs)
|
|
291
|
+
await sessionManager.getOrCreate("user-123");
|
|
292
|
+
await sessionManager.getOrCreate(); // Auto-generates ID
|
|
202
293
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
currentRoute: {
|
|
207
|
-
id: dbSession.currentRoute,
|
|
208
|
-
title:
|
|
209
|
-
dbSession.collectedData?.currentRouteTitle || dbSession.currentRoute,
|
|
210
|
-
enteredAt: new Date(),
|
|
211
|
-
},
|
|
212
|
-
currentStep: dbSession.currentStep
|
|
213
|
-
? {
|
|
214
|
-
id: dbSession.currentStep,
|
|
215
|
-
description: dbSession.collectedData?.currentStepDescription,
|
|
216
|
-
enteredAt: new Date(),
|
|
217
|
-
}
|
|
218
|
-
: undefined,
|
|
219
|
-
data: dbSession.collectedData?.data || {},
|
|
220
|
-
routeHistory: dbSession.collectedData?.routeHistory || [],
|
|
221
|
-
metadata: {
|
|
222
|
-
sessionId: dbSession.id,
|
|
223
|
-
createdAt: dbSession.createdAt,
|
|
224
|
-
lastUpdatedAt: new Date(),
|
|
225
|
-
},
|
|
226
|
-
};
|
|
227
|
-
} else {
|
|
228
|
-
// Create new session
|
|
229
|
-
agentSession = createSession<YourDataType>({
|
|
230
|
-
sessionId: dbSession?.id || "new-session-id",
|
|
231
|
-
});
|
|
232
|
-
}
|
|
294
|
+
// Data access
|
|
295
|
+
const data = sessionManager.getData<FlightData>();
|
|
296
|
+
await sessionManager.setData({ destination: "Paris" });
|
|
233
297
|
|
|
234
|
-
//
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
});
|
|
298
|
+
// History management
|
|
299
|
+
await sessionManager.addMessage("user", "Hello");
|
|
300
|
+
const history = sessionManager.getHistory();
|
|
301
|
+
sessionManager.clearHistory();
|
|
239
302
|
|
|
240
|
-
//
|
|
241
|
-
await
|
|
242
|
-
|
|
303
|
+
// Session operations
|
|
304
|
+
await sessionManager.save(); // Manual save (auto-saves on addMessage)
|
|
305
|
+
await sessionManager.delete();
|
|
306
|
+
const newSession = await sessionManager.reset(true); // Preserve history
|
|
243
307
|
currentRoute: response.session?.currentRoute?.id,
|
|
244
308
|
currentStep: response.session?.currentStep?.id,
|
|
245
309
|
collectedData: {
|
|
@@ -255,7 +319,7 @@ await yourDb.sessions.update({
|
|
|
255
319
|
// Save message
|
|
256
320
|
await yourDb.messages.create({
|
|
257
321
|
sessionId: dbSession.id,
|
|
258
|
-
role: "
|
|
322
|
+
role: "assistant",
|
|
259
323
|
content: response.message,
|
|
260
324
|
route: response.session?.currentRoute?.id,
|
|
261
325
|
step: response.session?.currentStep?.id,
|
|
@@ -310,21 +374,21 @@ const onboardingRoute = agent.createRoute<OnboardingData>({
|
|
|
310
374
|
// Build steps with skipIf conditions
|
|
311
375
|
const welcome = onboardingRoute.initialStep.nextStep({
|
|
312
376
|
id: "ask_name",
|
|
313
|
-
|
|
377
|
+
prompt: "What's your name?",
|
|
314
378
|
collect: ["name"],
|
|
315
379
|
skipIf: (data) => !!data.name, // Skip if name already collected
|
|
316
380
|
});
|
|
317
381
|
|
|
318
382
|
const askEmail = welcome.nextStep({
|
|
319
383
|
id: "ask_email",
|
|
320
|
-
|
|
384
|
+
prompt: "What's your email?",
|
|
321
385
|
collect: ["email"],
|
|
322
386
|
skipIf: (data) => !!data.email, // Skip if email already collected
|
|
323
387
|
});
|
|
324
388
|
|
|
325
389
|
const complete = askEmail.nextStep({
|
|
326
390
|
id: "complete",
|
|
327
|
-
|
|
391
|
+
prompt: "All done! Thank you.",
|
|
328
392
|
});
|
|
329
393
|
|
|
330
394
|
complete.nextStep({ step: END_ROUTE });
|
|
@@ -342,17 +406,13 @@ if (response.isRouteComplete) {
|
|
|
342
406
|
return "Profile updated successfully!";
|
|
343
407
|
}
|
|
344
408
|
|
|
345
|
-
// Get route-specific data if needed
|
|
346
|
-
const onboardingData = agent.getDataForRoute("onboarding");
|
|
347
|
-
const bookingData = agent.getDataForRoute("booking");
|
|
348
|
-
|
|
349
409
|
return response.message;
|
|
350
410
|
```
|
|
351
411
|
|
|
352
412
|
**Important Notes:**
|
|
353
413
|
|
|
354
414
|
- `isRouteComplete` is `true` when the route reaches an `END_ROUTE` transition
|
|
355
|
-
- The `message`
|
|
415
|
+
- The `message` contains the completion message generated by the AI when `isRouteComplete` is `true`
|
|
356
416
|
- You should check `isRouteComplete` and handle completion appropriately
|
|
357
417
|
- If all steps are skipped (due to `skipIf` conditions), the route can complete immediately on entry
|
|
358
418
|
- Use `agent.getData(session)` to retrieve all collected data
|
|
@@ -372,7 +432,7 @@ interface StreamChunk {
|
|
|
372
432
|
/** Whether this is the final chunk */
|
|
373
433
|
done: boolean;
|
|
374
434
|
/** Updated session step (includes collected data, current route/step) */
|
|
375
|
-
session?:
|
|
435
|
+
session?: SessionState;
|
|
376
436
|
/** Tool calls requested by the agent (only in final chunk) */
|
|
377
437
|
toolCalls?: Array<{
|
|
378
438
|
toolName: string;
|
|
@@ -462,7 +522,7 @@ for await (const chunk of agent.respondStream({ history })) {
|
|
|
462
522
|
// Save to database
|
|
463
523
|
await db.agentMessages.create({
|
|
464
524
|
sessionId: session.id,
|
|
465
|
-
role: "
|
|
525
|
+
role: "assistant",
|
|
466
526
|
content: fullMessage,
|
|
467
527
|
route: finalChunk.route?.title,
|
|
468
528
|
toolCalls: finalChunk.toolCalls || [],
|
|
@@ -485,9 +545,9 @@ Agent's description (readonly).
|
|
|
485
545
|
|
|
486
546
|
Agent's goal (readonly).
|
|
487
547
|
|
|
488
|
-
##### `
|
|
548
|
+
##### `identity(): Template<TContext> | undefined`
|
|
489
549
|
|
|
490
|
-
|
|
550
|
+
Agent's identity template (readonly).
|
|
491
551
|
|
|
492
552
|
---
|
|
493
553
|
|
|
@@ -504,9 +564,11 @@ interface RouteOptions<TData = unknown> {
|
|
|
504
564
|
id?: string; // Optional custom ID (deterministic ID generated from title if not provided)
|
|
505
565
|
title: string; // Route title
|
|
506
566
|
description?: string; // Route description
|
|
567
|
+
identity?: string; // Optional identity prompt defining the agent's role and persona for this route
|
|
568
|
+
personality?: Template; // Optional personality prompt defining the agent's communication style for this route
|
|
507
569
|
conditions?: string[]; // Conditions that activate this route
|
|
508
570
|
guidelines?: Guideline[]; // Initial guidelines for this route
|
|
509
|
-
|
|
571
|
+
terms?: Term[]; // Initial terms for the route's domain glossary
|
|
510
572
|
rules?: string[]; // Absolute rules the agent MUST follow in this route
|
|
511
573
|
prohibitions?: string[]; // Absolute prohibitions the agent MUST NEVER do in this route
|
|
512
574
|
|
|
@@ -524,14 +586,20 @@ interface RouteOptions<TData = unknown> {
|
|
|
524
586
|
// NEW: Configure the initial step
|
|
525
587
|
initialStep?: {
|
|
526
588
|
id?: string; // Custom ID for the initial step
|
|
527
|
-
|
|
589
|
+
prompt?: string; // Description for the initial step
|
|
528
590
|
collect?: string[]; // Fields to collect in the initial step
|
|
529
591
|
skipIf?: (data: Partial<TData>) => boolean; // Skip condition
|
|
530
592
|
requires?: string[]; // Required data prerequisites
|
|
531
593
|
};
|
|
532
594
|
|
|
533
595
|
// NEW: Sequential steps for simple linear flows
|
|
534
|
-
steps?:
|
|
596
|
+
steps?: StepOptions<unknown, TData>[];
|
|
597
|
+
/** Knowledge base specific to this route containing any JSON structure the AI should know */
|
|
598
|
+
knowledgeBase?: Record<string, unknown>;
|
|
599
|
+
/**
|
|
600
|
+
* Route lifecycle hooks
|
|
601
|
+
*/
|
|
602
|
+
hooks?: RouteLifecycleHooks<TContext, TData>;
|
|
535
603
|
}
|
|
536
604
|
```
|
|
537
605
|
|
|
@@ -552,9 +620,13 @@ Adds a guideline specific to this route. Returns `this` for chaining.
|
|
|
552
620
|
|
|
553
621
|
Returns all guidelines for this route.
|
|
554
622
|
|
|
555
|
-
##### `
|
|
623
|
+
##### `createTerm(term: Term): this`
|
|
624
|
+
|
|
625
|
+
Adds a term to the route's domain glossary. Returns `this` for chaining.
|
|
626
|
+
|
|
627
|
+
##### `getTerms(): Term[]`
|
|
556
628
|
|
|
557
|
-
Returns
|
|
629
|
+
Returns all terms in the route's domain glossary.
|
|
558
630
|
|
|
559
631
|
##### `getRules(): string[]`
|
|
560
632
|
|
|
@@ -564,15 +636,101 @@ Returns the rules that must be followed in this route.
|
|
|
564
636
|
|
|
565
637
|
Returns the prohibitions that must never be done in this route.
|
|
566
638
|
|
|
639
|
+
##### `getKnowledgeBase(): Record<string, unknown>`
|
|
640
|
+
|
|
641
|
+
Gets the route's knowledge base containing any JSON structure the AI should know.
|
|
642
|
+
|
|
643
|
+
```typescript
|
|
644
|
+
const knowledge = route.getKnowledgeBase();
|
|
645
|
+
// Returns the route-specific knowledge base
|
|
646
|
+
```
|
|
647
|
+
|
|
567
648
|
##### `getRef(): RouteRef`
|
|
568
649
|
|
|
569
650
|
Returns a reference to this route.
|
|
570
651
|
|
|
571
|
-
|
|
652
|
+
##### `getAllSteps(): Step<TContext, TData>[]`
|
|
653
|
+
|
|
654
|
+
Gets all steps in this route via traversal from the initial step.
|
|
655
|
+
|
|
656
|
+
```typescript
|
|
657
|
+
const steps = route.getAllSteps();
|
|
658
|
+
// Returns array of all steps in the route
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
##### `getStep(stepId: string): Step<TContext, TData> | undefined`
|
|
662
|
+
|
|
663
|
+
Gets a specific step by ID.
|
|
664
|
+
|
|
665
|
+
```typescript
|
|
666
|
+
const step = route.getStep("ask_destination");
|
|
667
|
+
// Returns the step with the specified ID or undefined
|
|
668
|
+
```
|
|
572
669
|
|
|
573
670
|
##### `describe(): string`
|
|
574
671
|
|
|
575
|
-
Generates a description of this route's structure.
|
|
672
|
+
Generates a description of this route's structure for debugging.
|
|
673
|
+
|
|
674
|
+
```typescript
|
|
675
|
+
const description = route.describe();
|
|
676
|
+
console.log(description);
|
|
677
|
+
// Output:
|
|
678
|
+
// Route: Book Flight
|
|
679
|
+
// ID: route_book_flight
|
|
680
|
+
// Description: N/A
|
|
681
|
+
// Conditions: None
|
|
682
|
+
//
|
|
683
|
+
// Steps:
|
|
684
|
+
// - step_ask_destination: Ask where to fly
|
|
685
|
+
// -> step_ask_dates: Ask about travel dates
|
|
686
|
+
// -> step_ask_passengers: How many passengers?
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
##### `handleDataUpdate(data, previousCollected): Promise<Partial<TData>>`
|
|
690
|
+
|
|
691
|
+
Handles data updates for this route, calling the onDataUpdate hook if configured. Returns modified data after hook processing, or original data if no hook.
|
|
692
|
+
|
|
693
|
+
```typescript
|
|
694
|
+
const updatedData = await route.handleDataUpdate(newData, previousData);
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
**Parameters:**
|
|
698
|
+
|
|
699
|
+
- `data`: New collected data
|
|
700
|
+
- `previousCollected`: Previously collected data
|
|
701
|
+
|
|
702
|
+
**Returns:** Modified data after hook processing
|
|
703
|
+
|
|
704
|
+
##### `handleContextUpdate(newContext, previousContext): Promise<void>`
|
|
705
|
+
|
|
706
|
+
Handles context updates for this route, calling the onContextUpdate hook if configured.
|
|
707
|
+
|
|
708
|
+
```typescript
|
|
709
|
+
await route.handleContextUpdate(newContext, previousContext);
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
**Parameters:**
|
|
713
|
+
|
|
714
|
+
- `newContext`: New context
|
|
715
|
+
- `previousContext`: Previous context
|
|
716
|
+
|
|
717
|
+
##### `evaluateOnComplete(session, context?): Promise<RouteTransitionConfig<TContext, TData> | undefined>`
|
|
718
|
+
|
|
719
|
+
Evaluates the onComplete handler and returns transition config.
|
|
720
|
+
|
|
721
|
+
```typescript
|
|
722
|
+
const transition = await route.evaluateOnComplete(
|
|
723
|
+
{ data: session.data },
|
|
724
|
+
context
|
|
725
|
+
);
|
|
726
|
+
|
|
727
|
+
if (transition) {
|
|
728
|
+
// Transition to next route
|
|
729
|
+
console.log(`Next route: ${transition.nextStep}`);
|
|
730
|
+
}
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
**Note:** Routes no longer have a `getData()` method. Use `agent.getData()` or `agent.getData(routeId)` instead.
|
|
576
734
|
|
|
577
735
|
#### Properties
|
|
578
736
|
|
|
@@ -596,6 +754,10 @@ Conditions that trigger this route (readonly).
|
|
|
596
754
|
|
|
597
755
|
Starting step of the route (readonly).
|
|
598
756
|
|
|
757
|
+
##### `hooks?: RouteLifecycleHooks<TContext, TData>`
|
|
758
|
+
|
|
759
|
+
Route lifecycle hooks for managing route-specific data and behavior (readonly).
|
|
760
|
+
|
|
599
761
|
---
|
|
600
762
|
|
|
601
763
|
### `Step`
|
|
@@ -604,13 +766,15 @@ Represents a step within a conversation route.
|
|
|
604
766
|
|
|
605
767
|
#### Methods
|
|
606
768
|
|
|
607
|
-
##### `nextStep(spec:
|
|
769
|
+
##### `nextStep(spec: StepOptions): StepResult`
|
|
608
770
|
|
|
609
771
|
Creates a transition from this step and returns a chainable result.
|
|
610
772
|
|
|
611
773
|
```typescript
|
|
612
|
-
interface
|
|
613
|
-
|
|
774
|
+
interface StepOptions<TData = unknown> {
|
|
775
|
+
id?: string; // step id
|
|
776
|
+
description?: string; // Step description
|
|
777
|
+
prompt?: string; // Transition to a chat interaction
|
|
614
778
|
tool?: ToolRef; // Transition to execute a tool
|
|
615
779
|
step?: StepRef | symbol; // Transition to specific step or END_ROUTE
|
|
616
780
|
|
|
@@ -627,18 +791,18 @@ interface TransitionSpec<TData = unknown> {
|
|
|
627
791
|
condition?: string;
|
|
628
792
|
}
|
|
629
793
|
|
|
630
|
-
interface
|
|
794
|
+
interface StepResult<TData = unknown> {
|
|
631
795
|
id: string; // Step identifier
|
|
632
796
|
routeId: string; // Route identifier
|
|
633
|
-
nextStep: (spec:
|
|
797
|
+
nextStep: (spec: StepOptions<TData>) => StepResult<TData>;
|
|
634
798
|
}
|
|
635
799
|
```
|
|
636
800
|
|
|
637
801
|
**Parameters:**
|
|
638
802
|
|
|
639
|
-
- `spec`: The transition specification (see `
|
|
803
|
+
- `spec`: The transition specification (see `StepOptions` above). Can include an optional `condition` property for AI-evaluated step selection guidance.
|
|
640
804
|
|
|
641
|
-
**Returns:** A `
|
|
805
|
+
**Returns:** A `StepResult` that includes the target step's reference (`id`, `routeId`) and a `nextStep` method for chaining additional transitions.
|
|
642
806
|
|
|
643
807
|
**Example:**
|
|
644
808
|
|
|
@@ -666,14 +830,14 @@ const flightRoute = agent.createRoute<FlightData>({
|
|
|
666
830
|
|
|
667
831
|
// Approach 1: Step-by-step with data extraction and text conditions
|
|
668
832
|
const askDestination = flightRoute.initialStep.nextStep({
|
|
669
|
-
|
|
833
|
+
prompt: "Ask where they want to fly",
|
|
670
834
|
collect: ["destination"],
|
|
671
835
|
skipIf: (data) => !!data.destination, // Skip if already have destination
|
|
672
836
|
condition: "Customer hasn't specified destination yet", // AI-evaluated condition
|
|
673
837
|
});
|
|
674
838
|
|
|
675
839
|
const askDates = askDestination.nextStep({
|
|
676
|
-
|
|
840
|
+
prompt: "Ask about travel dates",
|
|
677
841
|
collect: ["departureDate"],
|
|
678
842
|
skipIf: (data) => !!data.departureDate,
|
|
679
843
|
requires: ["destination"], // Must have destination first
|
|
@@ -681,7 +845,7 @@ const askDates = askDestination.nextStep({
|
|
|
681
845
|
});
|
|
682
846
|
|
|
683
847
|
const askPassengers = askDates.nextStep({
|
|
684
|
-
|
|
848
|
+
prompt: "How many passengers?",
|
|
685
849
|
collect: ["passengers"],
|
|
686
850
|
skipIf: (data) => !!data.passengers,
|
|
687
851
|
});
|
|
@@ -693,24 +857,77 @@ console.log(askDestination.routeId); // Route ID
|
|
|
693
857
|
// Approach 2: Fluent chaining for linear flows
|
|
694
858
|
flightRoute.initialStep
|
|
695
859
|
.nextStep({
|
|
696
|
-
|
|
860
|
+
prompt: "Extract travel details",
|
|
697
861
|
collect: ["destination", "departureDate", "passengers"],
|
|
698
862
|
})
|
|
699
863
|
.nextStep({
|
|
700
|
-
|
|
864
|
+
prompt: "Present available flights",
|
|
701
865
|
})
|
|
702
866
|
.nextStep({ step: END_ROUTE });
|
|
703
867
|
|
|
704
|
-
//
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
868
|
+
// Automatic session management
|
|
869
|
+
const agent = new Agent({
|
|
870
|
+
name: "Travel Agent",
|
|
871
|
+
provider: new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY }),
|
|
872
|
+
persistence: { adapter: new PrismaAdapter({ prisma }) },
|
|
873
|
+
sessionId: "user-123" // Automatically loads or creates session
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
const response = await agent.respond("I want to book a flight to Paris");
|
|
877
|
+
console.log(agent.session.getData<FlightData>()); // { destination: "Paris", ... }
|
|
708
878
|
```
|
|
709
879
|
|
|
710
880
|
##### `addGuideline(guideline: Guideline): void`
|
|
711
881
|
|
|
712
882
|
Adds a guideline specific to this step.
|
|
713
883
|
|
|
884
|
+
##### `getGuidelines(): Guideline<TContext>[]`
|
|
885
|
+
|
|
886
|
+
Gets all guidelines for this step.
|
|
887
|
+
|
|
888
|
+
```typescript
|
|
889
|
+
const guidelines = step.getGuidelines();
|
|
890
|
+
// Returns array of guidelines specific to this step
|
|
891
|
+
```
|
|
892
|
+
|
|
893
|
+
##### `getTransitions(): Step<TContext, TData>[]`
|
|
894
|
+
|
|
895
|
+
Gets all transitions from this step.
|
|
896
|
+
|
|
897
|
+
```typescript
|
|
898
|
+
const nextSteps = step.getTransitions();
|
|
899
|
+
// Returns array of possible next steps
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
##### `shouldSkip(data: Partial<TData>): boolean`
|
|
903
|
+
|
|
904
|
+
Checks if this step should be skipped based on collected data.
|
|
905
|
+
|
|
906
|
+
```typescript
|
|
907
|
+
if (step.shouldSkip(session.data)) {
|
|
908
|
+
// Skip this step
|
|
909
|
+
}
|
|
910
|
+
```
|
|
911
|
+
|
|
912
|
+
##### `hasRequires(data: Partial<TData>): boolean`
|
|
913
|
+
|
|
914
|
+
Checks if this step has all required data to proceed.
|
|
915
|
+
|
|
916
|
+
```typescript
|
|
917
|
+
if (step.hasRequires(session.data)) {
|
|
918
|
+
// Step can proceed
|
|
919
|
+
}
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
##### `asStepResult(): StepResult<TContext, TData>`
|
|
923
|
+
|
|
924
|
+
Creates a transition result for this step that supports chaining.
|
|
925
|
+
|
|
926
|
+
```typescript
|
|
927
|
+
const result = step.asStepResult();
|
|
928
|
+
// Returns StepResult with nextStep method for chaining
|
|
929
|
+
```
|
|
930
|
+
|
|
714
931
|
##### `configure(config): this`
|
|
715
932
|
|
|
716
933
|
Configure the step properties after creation. Useful for overriding initial step configuration. Returns `this` for chaining.
|
|
@@ -719,15 +936,16 @@ Configure the step properties after creation. Useful for overriding initial step
|
|
|
719
936
|
// Configure initial step after route creation
|
|
720
937
|
route.initialStep.configure({
|
|
721
938
|
description: "Welcome! Let's get started",
|
|
722
|
-
|
|
939
|
+
collect: ["name", "email"],
|
|
723
940
|
skipIf: (data) => !!data.name && !!data.email,
|
|
724
941
|
requires: [],
|
|
942
|
+
prompt: "Hello! Let's get started with your information.",
|
|
725
943
|
});
|
|
726
944
|
|
|
727
945
|
// Or configure any step
|
|
728
|
-
const askName = route.initialStep.nextStep({
|
|
946
|
+
const askName = route.initialStep.nextStep({ prompt: "Ask for name" });
|
|
729
947
|
askName.configure({
|
|
730
|
-
|
|
948
|
+
collect: ["firstName", "lastName"],
|
|
731
949
|
});
|
|
732
950
|
```
|
|
733
951
|
|
|
@@ -735,9 +953,10 @@ askName.configure({
|
|
|
735
953
|
|
|
736
954
|
- `config`: Configuration object with optional properties:
|
|
737
955
|
- `description?: string` - Step description
|
|
738
|
-
- `
|
|
956
|
+
- `collect?: string[]` - Fields to collect in this step
|
|
739
957
|
- `skipIf?: (data: Partial<TData>) => boolean` - Skip condition function
|
|
740
958
|
- `requires?: string[]` - Required data prerequisites
|
|
959
|
+
- `prompt?: Template<TContext, TData>` - Step prompt template
|
|
741
960
|
|
|
742
961
|
**Returns:** `this` for method chaining
|
|
743
962
|
|
|
@@ -757,59 +976,13 @@ Step description (readonly).
|
|
|
757
976
|
|
|
758
977
|
---
|
|
759
978
|
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
Registry for organizing agent tools and methods by domain.
|
|
763
|
-
|
|
764
|
-
#### Methods
|
|
765
|
-
|
|
766
|
-
##### `register<TDomain>(name: string, domain: TDomain): void`
|
|
767
|
-
|
|
768
|
-
Registers a new domain with its tools/methods. Throws error if domain name already exists.
|
|
769
|
-
|
|
770
|
-
##### `get<TDomain>(name: string): TDomain | undefined`
|
|
771
|
-
|
|
772
|
-
Gets a registered domain by name. Returns `undefined` if not found.
|
|
773
|
-
|
|
774
|
-
##### `has(name: string): boolean`
|
|
775
|
-
|
|
776
|
-
Checks if a domain is registered.
|
|
777
|
-
|
|
778
|
-
##### `all(): Record<string, Record<string, unknown>>`
|
|
779
|
-
|
|
780
|
-
Returns all registered domains as a single object.
|
|
781
|
-
|
|
782
|
-
##### `getFiltered(allowedNames?: string[]): Record<string, Record<string, unknown>>`
|
|
783
|
-
|
|
784
|
-
Returns filtered domains by names. If `allowedNames` is `undefined`, returns all domains.
|
|
785
|
-
|
|
786
|
-
**Example:**
|
|
787
|
-
|
|
788
|
-
```typescript
|
|
789
|
-
const registry = new DomainRegistry();
|
|
790
|
-
|
|
791
|
-
registry.register("payment", {
|
|
792
|
-
processPayment: async (amount: number) => {
|
|
793
|
-
/* ... */
|
|
794
|
-
},
|
|
795
|
-
});
|
|
796
|
-
|
|
797
|
-
registry.register("shipping", {
|
|
798
|
-
calculateShipping: (zipCode: string) => {
|
|
799
|
-
/* ... */
|
|
800
|
-
},
|
|
801
|
-
});
|
|
802
|
-
|
|
803
|
-
// Get specific domains
|
|
804
|
-
const filtered = registry.getFiltered(["payment"]); // Only payment domain
|
|
979
|
+
---
|
|
805
980
|
|
|
806
|
-
|
|
807
|
-
const all = registry.getFiltered(); // payment + shipping
|
|
808
|
-
```
|
|
981
|
+
## Tool Execution
|
|
809
982
|
|
|
810
|
-
|
|
983
|
+
Tools provide a powerful way to execute custom logic, access external APIs, and enrich conversation context before AI response generation.
|
|
811
984
|
|
|
812
|
-
|
|
985
|
+
**See Also:** [TOOLS.md](./TOOLS.md) - Complete guide to tool execution, lifecycle, and best practices
|
|
813
986
|
|
|
814
987
|
---
|
|
815
988
|
|
|
@@ -1077,6 +1250,192 @@ Marks a session as completed.
|
|
|
1077
1250
|
|
|
1078
1251
|
Marks a session as abandoned.
|
|
1079
1252
|
|
|
1253
|
+
##### `updateCollectedData(sessionId: string, collectedData: Record<string, unknown>): Promise<SessionData | null>`
|
|
1254
|
+
|
|
1255
|
+
Updates collected data in session.
|
|
1256
|
+
|
|
1257
|
+
##### `updateRouteStep(sessionId: string, route?: string, step?: string): Promise<SessionData | null>`
|
|
1258
|
+
|
|
1259
|
+
Updates current route and step in session.
|
|
1260
|
+
|
|
1261
|
+
##### `getUserMessages(userId?: string, limit?: number): Promise<MessageData[]>`
|
|
1262
|
+
|
|
1263
|
+
Gets messages for a user.
|
|
1264
|
+
|
|
1265
|
+
##### `deleteSession(sessionId: string): Promise<boolean>`
|
|
1266
|
+
|
|
1267
|
+
Deletes a session and all its messages.
|
|
1268
|
+
|
|
1269
|
+
##### `messageToEvent(message: MessageData): Event | undefined`
|
|
1270
|
+
|
|
1271
|
+
Helper: Convert message data to Event format.
|
|
1272
|
+
|
|
1273
|
+
##### `saveSessionState(sessionId: string, sessionStep: SessionState): Promise<SessionData | null>`
|
|
1274
|
+
|
|
1275
|
+
Saves SessionState to database by converting to SessionData.
|
|
1276
|
+
|
|
1277
|
+
```typescript
|
|
1278
|
+
const saved = await persistence.saveSessionState(sessionId, sessionState);
|
|
1279
|
+
```
|
|
1280
|
+
|
|
1281
|
+
##### `loadSessionState(sessionId: string): Promise<SessionState | null>`
|
|
1282
|
+
|
|
1283
|
+
Loads SessionState from database by converting from SessionData.
|
|
1284
|
+
|
|
1285
|
+
```typescript
|
|
1286
|
+
const sessionState = await persistence.loadSessionState(sessionId);
|
|
1287
|
+
```
|
|
1288
|
+
|
|
1289
|
+
##### `createSessionWithStep(options: CreateSessionOptions): Promise<{ sessionData: SessionData; sessionStep: SessionState }>`
|
|
1290
|
+
|
|
1291
|
+
Creates a new session with both SessionData and initialized SessionState.
|
|
1292
|
+
|
|
1293
|
+
```typescript
|
|
1294
|
+
const { sessionData, sessionStep } = await persistence.createSessionWithStep({
|
|
1295
|
+
userId: "user_123",
|
|
1296
|
+
agentName: "Travel Agent",
|
|
1297
|
+
initialData: { channel: "web" },
|
|
1298
|
+
});
|
|
1299
|
+
```
|
|
1300
|
+
|
|
1301
|
+
---
|
|
1302
|
+
|
|
1303
|
+
### `RoutingEngine<TContext, TData>`
|
|
1304
|
+
|
|
1305
|
+
Handles route and step selection logic for conversation orchestration.
|
|
1306
|
+
|
|
1307
|
+
#### Constructor
|
|
1308
|
+
|
|
1309
|
+
```typescript
|
|
1310
|
+
new RoutingEngine<TContext, TData>(options?: RoutingEngineOptions)
|
|
1311
|
+
|
|
1312
|
+
interface RoutingEngineOptions {
|
|
1313
|
+
allowRouteSwitch?: boolean; // Default: true
|
|
1314
|
+
switchThreshold?: number; // Default: 70 (0-100)
|
|
1315
|
+
maxCandidates?: number; // Default: 5
|
|
1316
|
+
}
|
|
1317
|
+
```
|
|
1318
|
+
|
|
1319
|
+
#### Methods
|
|
1320
|
+
|
|
1321
|
+
##### `decideRouteAndStep(params): Promise<RoutingDecision>`
|
|
1322
|
+
|
|
1323
|
+
Combines route selection and step selection into a single orchestrated decision.
|
|
1324
|
+
|
|
1325
|
+
**Parameters:**
|
|
1326
|
+
|
|
1327
|
+
- `routes`: Array of available routes
|
|
1328
|
+
- `session`: Current session state
|
|
1329
|
+
- `history`: Conversation history
|
|
1330
|
+
- `agentOptions`: Agent metadata
|
|
1331
|
+
- `provider`: AI provider for scoring
|
|
1332
|
+
- `context`: Agent context
|
|
1333
|
+
- `signal`: Optional abort signal
|
|
1334
|
+
|
|
1335
|
+
**Returns:** Routing decision with selected route, step, directives, and updated session
|
|
1336
|
+
|
|
1337
|
+
---
|
|
1338
|
+
|
|
1339
|
+
### `ResponseEngine<TContext>`
|
|
1340
|
+
|
|
1341
|
+
Builds prompts and response schemas for AI message generation.
|
|
1342
|
+
|
|
1343
|
+
#### Constructor
|
|
1344
|
+
|
|
1345
|
+
```typescript
|
|
1346
|
+
new ResponseEngine<TContext>();
|
|
1347
|
+
```
|
|
1348
|
+
|
|
1349
|
+
#### Methods
|
|
1350
|
+
|
|
1351
|
+
##### `responseSchemaForRoute(route, currentStep?): StructuredSchema`
|
|
1352
|
+
|
|
1353
|
+
Builds JSON schema for AI responses based on route and current step.
|
|
1354
|
+
|
|
1355
|
+
##### `buildResponsePrompt(params): Promise<string>`
|
|
1356
|
+
|
|
1357
|
+
Builds a comprehensive prompt for AI response generation including context, guidelines, and route information.
|
|
1358
|
+
|
|
1359
|
+
**Parameters:**
|
|
1360
|
+
|
|
1361
|
+
- `route`: Current route
|
|
1362
|
+
- `currentStep`: Current step in route
|
|
1363
|
+
- `rules`: Route-specific rules
|
|
1364
|
+
- `prohibitions`: Route-specific prohibitions
|
|
1365
|
+
- `directives`: Response directives
|
|
1366
|
+
- `history`: Conversation history
|
|
1367
|
+
- `lastMessage`: Last user message
|
|
1368
|
+
- `agentOptions`: Agent metadata
|
|
1369
|
+
- `context`: Agent context
|
|
1370
|
+
- `session`: Current session state
|
|
1371
|
+
|
|
1372
|
+
##### `buildFallbackPrompt(params): Promise<string>`
|
|
1373
|
+
|
|
1374
|
+
Builds a fallback prompt when no routes are configured.
|
|
1375
|
+
|
|
1376
|
+
---
|
|
1377
|
+
|
|
1378
|
+
### `ToolExecutor<TContext, TData>`
|
|
1379
|
+
|
|
1380
|
+
Executes tools with context and security enforcement.
|
|
1381
|
+
|
|
1382
|
+
#### Constructor
|
|
1383
|
+
|
|
1384
|
+
```typescript
|
|
1385
|
+
new ToolExecutor<TContext, TData>();
|
|
1386
|
+
```
|
|
1387
|
+
|
|
1388
|
+
#### Methods
|
|
1389
|
+
|
|
1390
|
+
##### `executeTool(params): Promise<ToolExecutionResult>`
|
|
1391
|
+
|
|
1392
|
+
Executes a single tool with domain security enforcement.
|
|
1393
|
+
|
|
1394
|
+
**Parameters:**
|
|
1395
|
+
|
|
1396
|
+
- `tool`: Tool reference to execute
|
|
1397
|
+
- `context`: Agent context
|
|
1398
|
+
- `updateContext`: Function to update context
|
|
1399
|
+
- `history`: Conversation history
|
|
1400
|
+
- `data`: Collected session data
|
|
1401
|
+
- `allowedDomains`: Array of allowed domain names
|
|
1402
|
+
|
|
1403
|
+
**Returns:** Tool execution result with success status and data
|
|
1404
|
+
|
|
1405
|
+
##### `executeTools(params): Promise<ToolExecutionResult[]>`
|
|
1406
|
+
|
|
1407
|
+
Executes multiple tools in sequence, stopping on first failure.
|
|
1408
|
+
|
|
1409
|
+
---
|
|
1410
|
+
|
|
1411
|
+
### `Events`
|
|
1412
|
+
|
|
1413
|
+
Utility functions for creating and adapting conversation events.
|
|
1414
|
+
|
|
1415
|
+
#### Functions
|
|
1416
|
+
|
|
1417
|
+
##### `adaptEvent(event): string`
|
|
1418
|
+
|
|
1419
|
+
Adapts an event for inclusion in AI prompts by transforming it into serializable format.
|
|
1420
|
+
|
|
1421
|
+
```typescript
|
|
1422
|
+
const promptText = adaptEvent(messageEvent);
|
|
1423
|
+
```
|
|
1424
|
+
|
|
1425
|
+
##### History Format
|
|
1426
|
+
|
|
1427
|
+
For conversation history, use the simplified `History` type instead of manually creating events. See the [History Format](#history-format) section below for details.
|
|
1428
|
+
|
|
1429
|
+
##### `createToolEvent(source, toolCalls, timestamp?): Event`
|
|
1430
|
+
|
|
1431
|
+
Creates a tool execution event.
|
|
1432
|
+
|
|
1433
|
+
```typescript
|
|
1434
|
+
const toolEvent = createToolEvent(MessageRole.AGENT, [
|
|
1435
|
+
{ tool_id: "search_flights", arguments: { from: "NYC", to: "LAX" }, result: { flights: [...] } }
|
|
1436
|
+
]);
|
|
1437
|
+
```
|
|
1438
|
+
|
|
1080
1439
|
---
|
|
1081
1440
|
|
|
1082
1441
|
### `PrismaAdapter`
|
|
@@ -1476,7 +1835,7 @@ interface MessageData {
|
|
|
1476
1835
|
id: string;
|
|
1477
1836
|
sessionId: string;
|
|
1478
1837
|
userId?: string;
|
|
1479
|
-
role: MessageRole; // "user" | "agent" | "system"
|
|
1838
|
+
role: MessageRole; // "user" | "assistant" | "agent" | "system"
|
|
1480
1839
|
content: string;
|
|
1481
1840
|
route?: string;
|
|
1482
1841
|
step?: string;
|
|
@@ -1532,15 +1891,45 @@ Adds domain glossary terms.
|
|
|
1532
1891
|
|
|
1533
1892
|
Adds guidelines section.
|
|
1534
1893
|
|
|
1535
|
-
##### `
|
|
1894
|
+
##### `addActiveRoutes(routes): this`
|
|
1895
|
+
|
|
1896
|
+
Adds active routes to the prompt.
|
|
1897
|
+
|
|
1898
|
+
##### `build(): string`
|
|
1899
|
+
|
|
1900
|
+
Builds the final prompt string.
|
|
1901
|
+
|
|
1902
|
+
---
|
|
1903
|
+
|
|
1904
|
+
### `PromptComposer`
|
|
1905
|
+
|
|
1906
|
+
Constructs prompts for AI generation.
|
|
1907
|
+
|
|
1908
|
+
**Note:** As of the latest version, many methods in `PromptComposer` are `async` to support function-based templates.
|
|
1909
|
+
|
|
1910
|
+
#### Methods
|
|
1536
1911
|
|
|
1537
|
-
|
|
1912
|
+
##### `addIdentity(name: string, description?: string, goal?: string): this`
|
|
1913
|
+
|
|
1914
|
+
Adds agent identity section.
|
|
1915
|
+
|
|
1916
|
+
##### `addContext(variables: ContextVariable[]): this`
|
|
1917
|
+
|
|
1918
|
+
Adds context variables.
|
|
1919
|
+
|
|
1920
|
+
##### `addGlossary(terms: Term[]): this`
|
|
1921
|
+
|
|
1922
|
+
Adds domain glossary terms.
|
|
1923
|
+
|
|
1924
|
+
##### `addGuidelinesForMessageGeneration(guidelines: GuidelineMatch[]): this`
|
|
1925
|
+
|
|
1926
|
+
Adds guidelines section.
|
|
1538
1927
|
|
|
1539
1928
|
##### `addActiveRoutes(routes): this`
|
|
1540
1929
|
|
|
1541
1930
|
Adds active routes to the prompt.
|
|
1542
1931
|
|
|
1543
|
-
##### `build(): string
|
|
1932
|
+
##### `build(): Promise<string>`
|
|
1544
1933
|
|
|
1545
1934
|
Builds the final prompt string.
|
|
1546
1935
|
|
|
@@ -1548,67 +1937,181 @@ Builds the final prompt string.
|
|
|
1548
1937
|
|
|
1549
1938
|
## Utility Functions
|
|
1550
1939
|
|
|
1551
|
-
### `
|
|
1940
|
+
### `Tool<TContext, TArgs, TResult, TData>`
|
|
1552
1941
|
|
|
1553
|
-
Defines a type-safe tool.
|
|
1942
|
+
Defines a type-safe tool using the Tool interface.
|
|
1554
1943
|
|
|
1555
1944
|
```typescript
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1945
|
+
interface Tool<
|
|
1946
|
+
TContext = unknown,
|
|
1947
|
+
TArgs extends unknown[] = unknown[],
|
|
1948
|
+
TResult = unknown,
|
|
1949
|
+
TData = unknown
|
|
1950
|
+
> {
|
|
1951
|
+
id: string; // Unique tool identifier
|
|
1952
|
+
description?: string; // Description for AI discovery
|
|
1953
|
+
parameters?: unknown; // JSON Schema for tool parameters
|
|
1954
|
+
handler: ToolHandler<TContext, TArgs, TResult, TData>; // Tool execution handler
|
|
1955
|
+
}
|
|
1956
|
+
```
|
|
1957
|
+
|
|
1958
|
+
**Example:**
|
|
1959
|
+
|
|
1960
|
+
```typescript
|
|
1961
|
+
const getTool: Tool<MyContext, [id: string], Data> = {
|
|
1962
|
+
id: "get_data",
|
|
1963
|
+
description: "Fetches data by ID",
|
|
1964
|
+
parameters: {
|
|
1965
|
+
type: "object",
|
|
1966
|
+
properties: {
|
|
1967
|
+
id: { type: "string", description: "The data ID to fetch" },
|
|
1968
|
+
},
|
|
1969
|
+
required: ["id"],
|
|
1970
|
+
},
|
|
1971
|
+
handler: async (toolContext, args) => {
|
|
1972
|
+
return { data: await fetchData(args.id) };
|
|
1973
|
+
},
|
|
1974
|
+
};
|
|
1975
|
+
```
|
|
1976
|
+
|
|
1977
|
+
---
|
|
1978
|
+
|
|
1979
|
+
### `formatKnowledgeBase(data, title?, maxDepth?)`
|
|
1980
|
+
|
|
1981
|
+
Formats a JSON structure into readable markdown format for AI prompts. Handles nested objects, arrays, and primitive values.
|
|
1982
|
+
|
|
1983
|
+
```typescript
|
|
1984
|
+
formatKnowledgeBase(
|
|
1985
|
+
data: Record<string, unknown> | unknown,
|
|
1986
|
+
title?: string,
|
|
1987
|
+
maxDepth?: number
|
|
1988
|
+
): string
|
|
1565
1989
|
```
|
|
1566
1990
|
|
|
1567
|
-
**
|
|
1991
|
+
**Parameters:**
|
|
1992
|
+
|
|
1993
|
+
- `data` - The JSON data to format
|
|
1994
|
+
- `title` - Optional title for the knowledge base section
|
|
1995
|
+
- `maxDepth` - Maximum nesting depth (default: 3)
|
|
1996
|
+
|
|
1997
|
+
**Returns:** Formatted markdown string
|
|
1568
1998
|
|
|
1569
1999
|
**Example:**
|
|
1570
2000
|
|
|
1571
2001
|
```typescript
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
2002
|
+
import { formatKnowledgeBase } from "@falai/agent";
|
|
2003
|
+
|
|
2004
|
+
const knowledge = {
|
|
2005
|
+
company: {
|
|
2006
|
+
name: "Acme Corp",
|
|
2007
|
+
products: ["Widget A", "Widget B"],
|
|
2008
|
+
locations: {
|
|
2009
|
+
headquarters: "NYC",
|
|
2010
|
+
branches: ["LA", "Chicago"],
|
|
2011
|
+
},
|
|
1576
2012
|
},
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
2013
|
+
};
|
|
2014
|
+
|
|
2015
|
+
const markdown = formatKnowledgeBase(knowledge, "Company Information");
|
|
2016
|
+
// Output:
|
|
2017
|
+
// ## Company Information
|
|
2018
|
+
//
|
|
2019
|
+
// - **name**: Acme Corp
|
|
2020
|
+
// - **products**:
|
|
2021
|
+
// - Widget A
|
|
2022
|
+
// - Widget B
|
|
2023
|
+
// - **locations**:
|
|
2024
|
+
// - **headquarters**: NYC
|
|
2025
|
+
// - **branches**:
|
|
2026
|
+
// - LA
|
|
2027
|
+
// - Chicago
|
|
1582
2028
|
```
|
|
1583
2029
|
|
|
1584
2030
|
---
|
|
1585
2031
|
|
|
1586
|
-
###
|
|
2032
|
+
### History Format
|
|
1587
2033
|
|
|
1588
|
-
|
|
2034
|
+
The agent accepts a simplified history format for conversation context. This format is easier to use than the internal Event structure.
|
|
2035
|
+
|
|
2036
|
+
#### Types
|
|
1589
2037
|
|
|
1590
2038
|
```typescript
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
2039
|
+
type Role = "user" | "assistant" | "tool" | "system";
|
|
2040
|
+
|
|
2041
|
+
type HistoryItem =
|
|
2042
|
+
| {
|
|
2043
|
+
role: "user";
|
|
2044
|
+
content: string;
|
|
2045
|
+
name?: string; // Optional participant name
|
|
2046
|
+
}
|
|
2047
|
+
| {
|
|
2048
|
+
role: "assistant";
|
|
2049
|
+
content: string | null;
|
|
2050
|
+
tool_calls?: Array<{
|
|
2051
|
+
id: string;
|
|
2052
|
+
name: string;
|
|
2053
|
+
arguments: Record<string, unknown>;
|
|
2054
|
+
}>;
|
|
2055
|
+
}
|
|
2056
|
+
| {
|
|
2057
|
+
role: "tool";
|
|
2058
|
+
tool_call_id: string;
|
|
2059
|
+
name: string;
|
|
2060
|
+
content: any;
|
|
2061
|
+
}
|
|
2062
|
+
| {
|
|
2063
|
+
role: "system";
|
|
2064
|
+
content: string;
|
|
2065
|
+
};
|
|
2066
|
+
|
|
2067
|
+
type History = HistoryItem[];
|
|
1597
2068
|
```
|
|
1598
2069
|
|
|
1599
2070
|
**Example:**
|
|
1600
2071
|
|
|
1601
2072
|
```typescript
|
|
1602
|
-
//
|
|
1603
|
-
|
|
2073
|
+
// Simple conversation history
|
|
2074
|
+
const history: History = [
|
|
2075
|
+
{
|
|
2076
|
+
role: "user",
|
|
2077
|
+
content: "Hello! Can you help me book a flight?",
|
|
2078
|
+
name: "Alice"
|
|
2079
|
+
},
|
|
2080
|
+
{
|
|
2081
|
+
role: "assistant",
|
|
2082
|
+
content: "I'd be happy to help you book a flight. Where would you like to go?"
|
|
2083
|
+
},
|
|
2084
|
+
{
|
|
2085
|
+
role: "user",
|
|
2086
|
+
content: "I want to go to Paris next Friday for 2 people.",
|
|
2087
|
+
name: "Alice"
|
|
2088
|
+
}
|
|
2089
|
+
];
|
|
1604
2090
|
|
|
1605
|
-
//
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
2091
|
+
// Assistant with tool calls
|
|
2092
|
+
const historyWithTools: History = [
|
|
2093
|
+
{
|
|
2094
|
+
role: "assistant",
|
|
2095
|
+
content: "I'll search for flights to Paris.",
|
|
2096
|
+
tool_calls: [
|
|
2097
|
+
{
|
|
2098
|
+
id: "search_flights_1",
|
|
2099
|
+
name: "search_flights",
|
|
2100
|
+
arguments: {
|
|
2101
|
+
destination: "Paris",
|
|
2102
|
+
date: "2025-10-18",
|
|
2103
|
+
passengers: 2
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
]
|
|
2107
|
+
},
|
|
2108
|
+
{
|
|
2109
|
+
role: "tool",
|
|
2110
|
+
tool_call_id: "search_flights_1",
|
|
2111
|
+
name: "search_flights",
|
|
2112
|
+
content: { flights: [...] } // Tool execution result
|
|
2113
|
+
}
|
|
2114
|
+
];
|
|
1612
2115
|
```
|
|
1613
2116
|
|
|
1614
2117
|
---
|
|
@@ -1619,7 +2122,7 @@ Creates a tool execution event.
|
|
|
1619
2122
|
|
|
1620
2123
|
```typescript
|
|
1621
2124
|
createToolEvent(
|
|
1622
|
-
source:
|
|
2125
|
+
source: MessageRole,
|
|
1623
2126
|
toolCalls: ToolCall[],
|
|
1624
2127
|
timestamp?: string // Optional: provide custom timestamp (ISO 8601 format)
|
|
1625
2128
|
): Event
|
|
@@ -1629,13 +2132,13 @@ createToolEvent(
|
|
|
1629
2132
|
|
|
1630
2133
|
```typescript
|
|
1631
2134
|
// With auto-generated timestamp
|
|
1632
|
-
createToolEvent(
|
|
2135
|
+
createToolEvent(MessageRole.AGENT, [
|
|
1633
2136
|
{ tool_id: "get_data", arguments: { id: "123" }, result: { data: {...} } }
|
|
1634
2137
|
]);
|
|
1635
2138
|
|
|
1636
2139
|
// With custom timestamp
|
|
1637
2140
|
createToolEvent(
|
|
1638
|
-
|
|
2141
|
+
MessageRole.AGENT,
|
|
1639
2142
|
[{ tool_id: "get_data", arguments: { id: "123" }, result: { data: {...} } }],
|
|
1640
2143
|
"2025-10-13T10:30:00Z"
|
|
1641
2144
|
);
|
|
@@ -1658,10 +2161,10 @@ adaptEvent(event: EmittedEvent): Event
|
|
|
1658
2161
|
### `Term`
|
|
1659
2162
|
|
|
1660
2163
|
```typescript
|
|
1661
|
-
interface Term {
|
|
1662
|
-
name:
|
|
1663
|
-
description:
|
|
1664
|
-
synonyms?:
|
|
2164
|
+
interface Term<TContext = unknown> {
|
|
2165
|
+
name: Template<TContext>;
|
|
2166
|
+
description: Template<TContext>;
|
|
2167
|
+
synonyms?: Template<TContext>[];
|
|
1665
2168
|
}
|
|
1666
2169
|
```
|
|
1667
2170
|
|
|
@@ -1670,10 +2173,10 @@ interface Term {
|
|
|
1670
2173
|
### `Guideline`
|
|
1671
2174
|
|
|
1672
2175
|
```typescript
|
|
1673
|
-
interface Guideline {
|
|
2176
|
+
interface Guideline<TContext = unknown> {
|
|
1674
2177
|
id?: string;
|
|
1675
|
-
condition?:
|
|
1676
|
-
action:
|
|
2178
|
+
condition?: Template<TContext>;
|
|
2179
|
+
action: Template<TContext>;
|
|
1677
2180
|
enabled?: boolean; // Default: true
|
|
1678
2181
|
tags?: string[];
|
|
1679
2182
|
tools?: ToolRef[];
|
|
@@ -1683,25 +2186,47 @@ interface Guideline {
|
|
|
1683
2186
|
|
|
1684
2187
|
---
|
|
1685
2188
|
|
|
1686
|
-
### `
|
|
2189
|
+
### `RouteLifecycleHooks<TContext, TData>`
|
|
2190
|
+
|
|
2191
|
+
Route lifecycle hooks for managing route-specific data and behavior.
|
|
1687
2192
|
|
|
1688
2193
|
```typescript
|
|
1689
|
-
interface
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
2194
|
+
interface RouteLifecycleHooks<TContext = unknown, TData = unknown> {
|
|
2195
|
+
/**
|
|
2196
|
+
* Called after collected data is updated for this route (from AI response or tool execution)
|
|
2197
|
+
* Useful for validation, enrichment, or persistence of route-specific collected data
|
|
2198
|
+
* Return modified collected data or the same data to keep it unchanged
|
|
2199
|
+
*
|
|
2200
|
+
* Unlike Agent-level onDataUpdate, this only triggers for data changes in this specific route.
|
|
2201
|
+
*/
|
|
2202
|
+
onDataUpdate?: (
|
|
2203
|
+
data: Partial<TData>,
|
|
2204
|
+
previousCollected: Partial<TData>
|
|
2205
|
+
) => Partial<TData> | Promise<Partial<TData>>;
|
|
2206
|
+
|
|
2207
|
+
/**
|
|
2208
|
+
* Called after context is updated via updateContext() when this route is active
|
|
2209
|
+
* Useful for route-specific context reactions, validation, or side effects
|
|
2210
|
+
*
|
|
2211
|
+
* Unlike Agent-level onContextUpdate, this only triggers when this specific route is active.
|
|
2212
|
+
*/
|
|
2213
|
+
onContextUpdate?: (
|
|
2214
|
+
newContext: TContext,
|
|
2215
|
+
previousContext: TContext
|
|
2216
|
+
) => void | Promise<void>;
|
|
1694
2217
|
}
|
|
1695
2218
|
```
|
|
1696
2219
|
|
|
1697
2220
|
---
|
|
1698
2221
|
|
|
2222
|
+
---
|
|
2223
|
+
|
|
1699
2224
|
### `Event`
|
|
1700
2225
|
|
|
1701
2226
|
```typescript
|
|
1702
2227
|
interface Event {
|
|
1703
2228
|
kind: EventKind;
|
|
1704
|
-
source:
|
|
2229
|
+
source: MessageRole;
|
|
1705
2230
|
data: MessageEventData | ToolEventData | StatusEventData;
|
|
1706
2231
|
creation_utc: string;
|
|
1707
2232
|
}
|
|
@@ -1712,9 +2237,10 @@ enum EventKind {
|
|
|
1712
2237
|
STATUS = "status",
|
|
1713
2238
|
}
|
|
1714
2239
|
|
|
1715
|
-
enum
|
|
1716
|
-
|
|
1717
|
-
|
|
2240
|
+
enum MessageRole {
|
|
2241
|
+
USER = "user",
|
|
2242
|
+
ASSISTANT = "assistant",
|
|
2243
|
+
AGENT = "agent",
|
|
1718
2244
|
SYSTEM = "system",
|
|
1719
2245
|
}
|
|
1720
2246
|
```
|
|
@@ -1743,14 +2269,47 @@ interface ToolResult<TReturn> {
|
|
|
1743
2269
|
|
|
1744
2270
|
---
|
|
1745
2271
|
|
|
2272
|
+
### `RoutingDecision`
|
|
2273
|
+
|
|
2274
|
+
Result of route and step selection process.
|
|
2275
|
+
|
|
2276
|
+
```typescript
|
|
2277
|
+
interface RoutingDecision {
|
|
2278
|
+
context: string;
|
|
2279
|
+
routes: Record<string, number>; // Route scores
|
|
2280
|
+
responseDirectives?: string[];
|
|
2281
|
+
extractions?: unknown;
|
|
2282
|
+
contextUpdate?: Record<string, unknown>;
|
|
2283
|
+
}
|
|
2284
|
+
```
|
|
2285
|
+
|
|
2286
|
+
---
|
|
2287
|
+
|
|
2288
|
+
### `ToolExecutionResult`
|
|
2289
|
+
|
|
2290
|
+
Result of tool execution.
|
|
2291
|
+
|
|
2292
|
+
```typescript
|
|
2293
|
+
interface ToolExecutionResult {
|
|
2294
|
+
toolName: string;
|
|
2295
|
+
success: boolean;
|
|
2296
|
+
data?: unknown;
|
|
2297
|
+
contextUpdate?: Record<string, unknown>;
|
|
2298
|
+
dataUpdate?: Record<string, unknown>;
|
|
2299
|
+
error?: string;
|
|
2300
|
+
}
|
|
2301
|
+
```
|
|
2302
|
+
|
|
2303
|
+
---
|
|
2304
|
+
|
|
1746
2305
|
## Types
|
|
1747
2306
|
|
|
1748
|
-
### `
|
|
2307
|
+
### `SessionState<TData>`
|
|
1749
2308
|
|
|
1750
2309
|
Tracks the current position in the conversation flow and data collected during route progression.
|
|
1751
2310
|
|
|
1752
2311
|
```typescript
|
|
1753
|
-
interface
|
|
2312
|
+
interface SessionState<TData = Record<string, unknown>> {
|
|
1754
2313
|
/** Unique session identifier (useful for persistence) */
|
|
1755
2314
|
id?: string;
|
|
1756
2315
|
|
|
@@ -1772,14 +2331,14 @@ interface SessionStep<TData = Record<string, unknown>> {
|
|
|
1772
2331
|
* Data collected during the current route
|
|
1773
2332
|
* Convenience reference to dataByRoute[currentRoute.id]
|
|
1774
2333
|
*/
|
|
1775
|
-
data
|
|
2334
|
+
data?: Partial<TData>;
|
|
1776
2335
|
|
|
1777
2336
|
/**
|
|
1778
|
-
*
|
|
1779
|
-
*
|
|
1780
|
-
*
|
|
2337
|
+
* Data collected organized by route ID
|
|
2338
|
+
* Persists data when switching between routes
|
|
2339
|
+
* Allows resuming incomplete routes where they left off
|
|
1781
2340
|
*/
|
|
1782
|
-
dataByRoute
|
|
2341
|
+
dataByRoute?: Record<string, Partial<unknown>>;
|
|
1783
2342
|
|
|
1784
2343
|
/** History of routes visited in this session */
|
|
1785
2344
|
routeHistory: Array<{
|
|
@@ -1789,6 +2348,16 @@ interface SessionStep<TData = Record<string, unknown>> {
|
|
|
1789
2348
|
completed: boolean;
|
|
1790
2349
|
}>;
|
|
1791
2350
|
|
|
2351
|
+
/**
|
|
2352
|
+
* Pending route transition after completion
|
|
2353
|
+
* Set when a route completes with onComplete handler
|
|
2354
|
+
*/
|
|
2355
|
+
pendingTransition?: {
|
|
2356
|
+
targetRouteId: string;
|
|
2357
|
+
condition?: string;
|
|
2358
|
+
reason: "route_complete" | "manual";
|
|
2359
|
+
};
|
|
2360
|
+
|
|
1792
2361
|
/** Session metadata */
|
|
1793
2362
|
metadata?: {
|
|
1794
2363
|
createdAt?: Date;
|
|
@@ -1802,9 +2371,10 @@ interface SessionStep<TData = Record<string, unknown>> {
|
|
|
1802
2371
|
|
|
1803
2372
|
- **`id`** - Optional session identifier that persists across database operations
|
|
1804
2373
|
- **`data`** - Type-safe data collected via `schema` for the **current route**
|
|
1805
|
-
- **`dataByRoute`** - **
|
|
2374
|
+
- **`dataByRoute`** - **Per-route data map that preserves collected data when switching routes**
|
|
1806
2375
|
- **`currentRoute`** / **`currentStep`** - Track conversation position
|
|
1807
2376
|
- **`routeHistory`** - Full audit trail of route transitions
|
|
2377
|
+
- **`pendingTransition`** - Handles route completion transitions
|
|
1808
2378
|
- **`metadata`** - Custom data (timestamps, user info, etc.)
|
|
1809
2379
|
|
|
1810
2380
|
**Per-Route Data Preservation:**
|
|
@@ -1843,7 +2413,7 @@ console.log(response.session?.data.destination); // Type-safe!
|
|
|
1843
2413
|
|
|
1844
2414
|
### Session Helper Functions
|
|
1845
2415
|
|
|
1846
|
-
#### `createSession<TData>(sessionId?, metadata?):
|
|
2416
|
+
#### `createSession<TData>(sessionId?, metadata?): SessionState<TData>`
|
|
1847
2417
|
|
|
1848
2418
|
Creates a new session step object.
|
|
1849
2419
|
|
|
@@ -1868,7 +2438,7 @@ const session = createSession<OnboardingData>("session_123", {
|
|
|
1868
2438
|
});
|
|
1869
2439
|
```
|
|
1870
2440
|
|
|
1871
|
-
#### `enterRoute<TData>(session, routeId, routeTitle):
|
|
2441
|
+
#### `enterRoute<TData>(session, routeId, routeTitle): SessionState<TData>`
|
|
1872
2442
|
|
|
1873
2443
|
Updates session when entering a new route. Automatically:
|
|
1874
2444
|
|
|
@@ -1889,7 +2459,7 @@ console.log(session.currentRoute?.title); // "Book a Flight"
|
|
|
1889
2459
|
console.log(session.data); // {} (reset for new route)
|
|
1890
2460
|
```
|
|
1891
2461
|
|
|
1892
|
-
#### `enterStep<TData>(session, stepId, description?):
|
|
2462
|
+
#### `enterStep<TData>(session, stepId, description?): SessionState<TData>`
|
|
1893
2463
|
|
|
1894
2464
|
Updates session when entering a new step within a route.
|
|
1895
2465
|
|
|
@@ -1902,14 +2472,14 @@ console.log(session.currentStep?.id); // "ask_destination"
|
|
|
1902
2472
|
console.log(session.currentStep?.description); // "Ask where to fly"
|
|
1903
2473
|
```
|
|
1904
2474
|
|
|
1905
|
-
#### `
|
|
2475
|
+
#### `mergeCollected<TData>(session, data): SessionState<TData>`
|
|
1906
2476
|
|
|
1907
2477
|
Merges new collected data into session. Updates timestamps automatically.
|
|
1908
2478
|
|
|
1909
2479
|
**Example:**
|
|
1910
2480
|
|
|
1911
2481
|
```typescript
|
|
1912
|
-
session =
|
|
2482
|
+
session = mergeCollected(session, {
|
|
1913
2483
|
destination: "Paris",
|
|
1914
2484
|
departureDate: "2025-06-15",
|
|
1915
2485
|
});
|
|
@@ -1919,7 +2489,7 @@ console.log(session.data); // { destination: "Paris", departureDate: "2025-06-15
|
|
|
1919
2489
|
|
|
1920
2490
|
#### `sessionStepToData<TData>(session): object`
|
|
1921
2491
|
|
|
1922
|
-
Converts
|
|
2492
|
+
Converts SessionState to persistence-friendly format for database storage.
|
|
1923
2493
|
|
|
1924
2494
|
**Returns:**
|
|
1925
2495
|
|
|
@@ -1952,9 +2522,9 @@ await db.sessions.update(session.id!, {
|
|
|
1952
2522
|
});
|
|
1953
2523
|
```
|
|
1954
2524
|
|
|
1955
|
-
#### `sessionDataToStep<TData>(sessionId, data):
|
|
2525
|
+
#### `sessionDataToStep<TData>(sessionId, data): SessionState<TData>`
|
|
1956
2526
|
|
|
1957
|
-
Converts database data back to
|
|
2527
|
+
Converts database data back to SessionState for resuming conversations.
|
|
1958
2528
|
|
|
1959
2529
|
**Parameters:**
|
|
1960
2530
|
|
|
@@ -2088,7 +2658,7 @@ Symbol marking the end of a conversation route. Use this when building routes to
|
|
|
2088
2658
|
import { END_ROUTE } from "@falai/agent";
|
|
2089
2659
|
|
|
2090
2660
|
const thankYou = askEmail.nextStep({
|
|
2091
|
-
|
|
2661
|
+
prompt: "Thank you for your information!",
|
|
2092
2662
|
});
|
|
2093
2663
|
|
|
2094
2664
|
// Mark the end of the route
|
|
@@ -2144,7 +2714,7 @@ enum BuiltInSection {
|
|
|
2144
2714
|
GLOSSARY = "glossary",
|
|
2145
2715
|
CONTEXT = "context",
|
|
2146
2716
|
GUIDELINES = "guidelines",
|
|
2147
|
-
|
|
2717
|
+
TOOLS
|
|
2148
2718
|
ACTIVE_ROUTES = "active_routes",
|
|
2149
2719
|
}
|
|
2150
2720
|
```
|
|
@@ -2165,23 +2735,92 @@ interface AiProvider {
|
|
|
2165
2735
|
}
|
|
2166
2736
|
```
|
|
2167
2737
|
|
|
2168
|
-
|
|
2738
|
+
---
|
|
2739
|
+
|
|
2740
|
+
## Template Utilities
|
|
2741
|
+
|
|
2742
|
+
### Dynamic Content with Templates
|
|
2743
|
+
|
|
2744
|
+
The framework supports dynamic content generation through a versatile `Template` system. A `Template` can be either a simple string with `{{variable}}` placeholders or a function that returns a string, allowing for more complex, context-aware logic.
|
|
2169
2745
|
|
|
2170
|
-
|
|
2746
|
+
Templates are evaluated at runtime with a `TemplateContext` object that provides access to the agent's state:
|
|
2171
2747
|
|
|
2172
2748
|
```typescript
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2749
|
+
interface TemplateContext<TContext = unknown, TData = unknown> {
|
|
2750
|
+
context?: TContext;
|
|
2751
|
+
session?: SessionState<TData>;
|
|
2752
|
+
history?: Event[];
|
|
2753
|
+
data?: Partial<TData>; // Convenience alias for session.data
|
|
2754
|
+
}
|
|
2755
|
+
```
|
|
2756
|
+
|
|
2757
|
+
#### `Template<TContext, TData>` Type
|
|
2758
|
+
|
|
2759
|
+
This is the core type for all dynamic content:
|
|
2760
|
+
|
|
2761
|
+
```typescript
|
|
2762
|
+
type Template<TContext = unknown, TData = unknown> =
|
|
2763
|
+
| string
|
|
2764
|
+
| ((params: TemplateContext<TContext, TData>) => string | Promise<string>);
|
|
2765
|
+
```
|
|
2181
2766
|
|
|
2182
|
-
|
|
2767
|
+
**String Templates:**
|
|
2183
2768
|
|
|
2184
|
-
|
|
2769
|
+
Simple strings with `{{variable}}` placeholders are rendered using values from the `context` object.
|
|
2770
|
+
|
|
2771
|
+
```typescript
|
|
2772
|
+
const agent = new Agent({
|
|
2773
|
+
identity: "I am {{name}}",
|
|
2774
|
+
context: { name: "HelperBot" },
|
|
2775
|
+
});
|
|
2776
|
+
```
|
|
2777
|
+
|
|
2778
|
+
**Function Templates:**
|
|
2779
|
+
|
|
2780
|
+
For more complex logic, you can provide a function that receives the `TemplateContext` and returns a string (or a `Promise<string>` for async operations).
|
|
2781
|
+
|
|
2782
|
+
```typescript
|
|
2783
|
+
const agent = new Agent({
|
|
2784
|
+
identity: ({ context }) => `I am here to help, ${context.user.name}`,
|
|
2785
|
+
context: { user: { name: "Alice" } },
|
|
2786
|
+
});
|
|
2787
|
+
```
|
|
2788
|
+
|
|
2789
|
+
#### `render(template, params)`
|
|
2790
|
+
|
|
2791
|
+
An internal async utility that resolves a `Template` to a string. You won't typically call this directly, but it powers the dynamic content generation throughout the framework.
|
|
2792
|
+
|
|
2793
|
+
**Supported in (Dynamic/Personalized):**
|
|
2794
|
+
|
|
2795
|
+
- **Agent**: `identity`
|
|
2796
|
+
- **Terms**: `name`, `description`, `synonyms`
|
|
2797
|
+
- **Guidelines**: `condition`, `action`
|
|
2798
|
+
- **Routes**: `conditions`, `rules`, `prohibitions`
|
|
2799
|
+
- **Steps/Transitions**: `prompt`, `condition`
|
|
2800
|
+
|
|
2801
|
+
**Not supported in (Static/Predictable):**
|
|
2802
|
+
|
|
2803
|
+
- Agent `name`, `goal`, `description`
|
|
2804
|
+
- Route `title`, `description`
|
|
2805
|
+
- Step `description`
|
|
2806
|
+
|
|
2807
|
+
**Example:**
|
|
2808
|
+
|
|
2809
|
+
```typescript
|
|
2810
|
+
const agent = new Agent({
|
|
2811
|
+
name: "Assistant", // Static
|
|
2812
|
+
identity: ({ context }) =>
|
|
2813
|
+
`I am here to help you, ${context.user.firstName}.`, // Dynamic
|
|
2814
|
+
context: {
|
|
2815
|
+
user: { firstName: "Alice", age: 30 },
|
|
2816
|
+
},
|
|
2817
|
+
});
|
|
2818
|
+
|
|
2819
|
+
agent.createGuideline({
|
|
2820
|
+
condition: ({ context }) => context.user.age > 18, // Dynamic condition
|
|
2821
|
+
action:
|
|
2822
|
+
"Be helpful to {{user.firstName}} and consider their age in responses", // Dynamic action
|
|
2823
|
+
});
|
|
2185
2824
|
```
|
|
2186
2825
|
|
|
2187
2826
|
---
|