@falai/agent 0.6.9 → 0.7.0

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.
Files changed (231) hide show
  1. package/README.md +62 -59
  2. package/dist/adapters/MemoryAdapter.js +2 -2
  3. package/dist/adapters/MemoryAdapter.js.map +1 -1
  4. package/dist/adapters/MongoAdapter.js +2 -2
  5. package/dist/adapters/MongoAdapter.js.map +1 -1
  6. package/dist/adapters/OpenSearchAdapter.js +7 -7
  7. package/dist/adapters/OpenSearchAdapter.js.map +1 -1
  8. package/dist/adapters/PostgreSQLAdapter.js +9 -9
  9. package/dist/adapters/PostgreSQLAdapter.js.map +1 -1
  10. package/dist/adapters/PrismaAdapter.js +3 -3
  11. package/dist/adapters/PrismaAdapter.js.map +1 -1
  12. package/dist/adapters/RedisAdapter.js +2 -2
  13. package/dist/adapters/RedisAdapter.js.map +1 -1
  14. package/dist/adapters/SQLiteAdapter.d.ts +3 -3
  15. package/dist/adapters/SQLiteAdapter.d.ts.map +1 -1
  16. package/dist/adapters/SQLiteAdapter.js +11 -11
  17. package/dist/adapters/SQLiteAdapter.js.map +1 -1
  18. package/dist/adapters/index.d.ts +1 -1
  19. package/dist/adapters/index.d.ts.map +1 -1
  20. package/dist/cjs/adapters/MemoryAdapter.js +2 -2
  21. package/dist/cjs/adapters/MemoryAdapter.js.map +1 -1
  22. package/dist/cjs/adapters/MongoAdapter.js +2 -2
  23. package/dist/cjs/adapters/MongoAdapter.js.map +1 -1
  24. package/dist/cjs/adapters/OpenSearchAdapter.js +7 -7
  25. package/dist/cjs/adapters/OpenSearchAdapter.js.map +1 -1
  26. package/dist/cjs/adapters/PostgreSQLAdapter.js +9 -9
  27. package/dist/cjs/adapters/PostgreSQLAdapter.js.map +1 -1
  28. package/dist/cjs/adapters/PrismaAdapter.js +3 -3
  29. package/dist/cjs/adapters/PrismaAdapter.js.map +1 -1
  30. package/dist/cjs/adapters/RedisAdapter.js +2 -2
  31. package/dist/cjs/adapters/RedisAdapter.js.map +1 -1
  32. package/dist/cjs/adapters/SQLiteAdapter.d.ts +3 -3
  33. package/dist/cjs/adapters/SQLiteAdapter.d.ts.map +1 -1
  34. package/dist/cjs/adapters/SQLiteAdapter.js +11 -11
  35. package/dist/cjs/adapters/SQLiteAdapter.js.map +1 -1
  36. package/dist/cjs/adapters/index.d.ts +1 -1
  37. package/dist/cjs/adapters/index.d.ts.map +1 -1
  38. package/dist/cjs/constants/index.d.ts +4 -4
  39. package/dist/cjs/constants/index.js +5 -5
  40. package/dist/cjs/core/Agent.d.ts +22 -22
  41. package/dist/cjs/core/Agent.d.ts.map +1 -1
  42. package/dist/cjs/core/Agent.js +160 -152
  43. package/dist/cjs/core/Agent.js.map +1 -1
  44. package/dist/cjs/core/Events.d.ts +6 -6
  45. package/dist/cjs/core/Events.d.ts.map +1 -1
  46. package/dist/cjs/core/PersistenceManager.d.ts +13 -13
  47. package/dist/cjs/core/PersistenceManager.d.ts.map +1 -1
  48. package/dist/cjs/core/PersistenceManager.js +24 -24
  49. package/dist/cjs/core/PersistenceManager.js.map +1 -1
  50. package/dist/cjs/core/ResponseEngine.d.ts +3 -8
  51. package/dist/cjs/core/ResponseEngine.d.ts.map +1 -1
  52. package/dist/cjs/core/ResponseEngine.js +8 -8
  53. package/dist/cjs/core/ResponseEngine.js.map +1 -1
  54. package/dist/cjs/core/Route.d.ts +17 -17
  55. package/dist/cjs/core/Route.d.ts.map +1 -1
  56. package/dist/cjs/core/Route.js +33 -33
  57. package/dist/cjs/core/Route.js.map +1 -1
  58. package/dist/cjs/core/RoutingEngine.d.ts +30 -30
  59. package/dist/cjs/core/RoutingEngine.d.ts.map +1 -1
  60. package/dist/cjs/core/RoutingEngine.js +192 -192
  61. package/dist/cjs/core/RoutingEngine.js.map +1 -1
  62. package/dist/cjs/core/Step.d.ts +72 -0
  63. package/dist/cjs/core/Step.d.ts.map +1 -0
  64. package/dist/cjs/core/Step.js +150 -0
  65. package/dist/cjs/core/Step.js.map +1 -0
  66. package/dist/cjs/core/ToolExecutor.d.ts +5 -5
  67. package/dist/cjs/core/ToolExecutor.d.ts.map +1 -1
  68. package/dist/cjs/core/ToolExecutor.js +8 -8
  69. package/dist/cjs/core/ToolExecutor.js.map +1 -1
  70. package/dist/cjs/core/Transition.d.ts +14 -14
  71. package/dist/cjs/core/Transition.d.ts.map +1 -1
  72. package/dist/cjs/core/Transition.js +48 -19
  73. package/dist/cjs/core/Transition.js.map +1 -1
  74. package/dist/cjs/index.d.ts +7 -7
  75. package/dist/cjs/index.d.ts.map +1 -1
  76. package/dist/cjs/index.js +8 -8
  77. package/dist/cjs/index.js.map +1 -1
  78. package/dist/cjs/types/agent.d.ts +8 -8
  79. package/dist/cjs/types/agent.d.ts.map +1 -1
  80. package/dist/cjs/types/ai.d.ts +2 -2
  81. package/dist/cjs/types/ai.d.ts.map +1 -1
  82. package/dist/cjs/types/history.d.ts +3 -3
  83. package/dist/cjs/types/history.d.ts.map +1 -1
  84. package/dist/cjs/types/index.d.ts +1 -1
  85. package/dist/cjs/types/index.d.ts.map +1 -1
  86. package/dist/cjs/types/persistence.d.ts +5 -5
  87. package/dist/cjs/types/persistence.d.ts.map +1 -1
  88. package/dist/cjs/types/route.d.ts +57 -52
  89. package/dist/cjs/types/route.d.ts.map +1 -1
  90. package/dist/cjs/types/session.d.ts +27 -27
  91. package/dist/cjs/types/session.d.ts.map +1 -1
  92. package/dist/cjs/types/session.js +48 -50
  93. package/dist/cjs/types/session.js.map +1 -1
  94. package/dist/cjs/types/tool.d.ts +13 -13
  95. package/dist/cjs/types/tool.d.ts.map +1 -1
  96. package/dist/cjs/utils/id.d.ts +8 -3
  97. package/dist/cjs/utils/id.d.ts.map +1 -1
  98. package/dist/cjs/utils/id.js +16 -7
  99. package/dist/cjs/utils/id.js.map +1 -1
  100. package/dist/constants/index.d.ts +4 -4
  101. package/dist/constants/index.js +4 -4
  102. package/dist/core/Agent.d.ts +22 -22
  103. package/dist/core/Agent.d.ts.map +1 -1
  104. package/dist/core/Agent.js +162 -154
  105. package/dist/core/Agent.js.map +1 -1
  106. package/dist/core/Events.d.ts +6 -6
  107. package/dist/core/Events.d.ts.map +1 -1
  108. package/dist/core/PersistenceManager.d.ts +13 -13
  109. package/dist/core/PersistenceManager.d.ts.map +1 -1
  110. package/dist/core/PersistenceManager.js +25 -25
  111. package/dist/core/PersistenceManager.js.map +1 -1
  112. package/dist/core/ResponseEngine.d.ts +3 -8
  113. package/dist/core/ResponseEngine.d.ts.map +1 -1
  114. package/dist/core/ResponseEngine.js +8 -8
  115. package/dist/core/ResponseEngine.js.map +1 -1
  116. package/dist/core/Route.d.ts +17 -17
  117. package/dist/core/Route.d.ts.map +1 -1
  118. package/dist/core/Route.js +33 -33
  119. package/dist/core/Route.js.map +1 -1
  120. package/dist/core/RoutingEngine.d.ts +30 -30
  121. package/dist/core/RoutingEngine.d.ts.map +1 -1
  122. package/dist/core/RoutingEngine.js +193 -193
  123. package/dist/core/RoutingEngine.js.map +1 -1
  124. package/dist/core/Step.d.ts +72 -0
  125. package/dist/core/Step.d.ts.map +1 -0
  126. package/dist/core/Step.js +146 -0
  127. package/dist/core/Step.js.map +1 -0
  128. package/dist/core/ToolExecutor.d.ts +5 -5
  129. package/dist/core/ToolExecutor.d.ts.map +1 -1
  130. package/dist/core/ToolExecutor.js +8 -8
  131. package/dist/core/ToolExecutor.js.map +1 -1
  132. package/dist/core/Transition.d.ts +14 -14
  133. package/dist/core/Transition.d.ts.map +1 -1
  134. package/dist/core/Transition.js +48 -19
  135. package/dist/core/Transition.js.map +1 -1
  136. package/dist/index.d.ts +7 -7
  137. package/dist/index.d.ts.map +1 -1
  138. package/dist/index.js +4 -4
  139. package/dist/index.js.map +1 -1
  140. package/dist/types/agent.d.ts +8 -8
  141. package/dist/types/agent.d.ts.map +1 -1
  142. package/dist/types/ai.d.ts +2 -2
  143. package/dist/types/ai.d.ts.map +1 -1
  144. package/dist/types/history.d.ts +3 -3
  145. package/dist/types/history.d.ts.map +1 -1
  146. package/dist/types/index.d.ts +1 -1
  147. package/dist/types/index.d.ts.map +1 -1
  148. package/dist/types/persistence.d.ts +5 -5
  149. package/dist/types/persistence.d.ts.map +1 -1
  150. package/dist/types/route.d.ts +57 -52
  151. package/dist/types/route.d.ts.map +1 -1
  152. package/dist/types/session.d.ts +27 -27
  153. package/dist/types/session.d.ts.map +1 -1
  154. package/dist/types/session.js +44 -46
  155. package/dist/types/session.js.map +1 -1
  156. package/dist/types/tool.d.ts +13 -13
  157. package/dist/types/tool.d.ts.map +1 -1
  158. package/dist/utils/id.d.ts +8 -3
  159. package/dist/utils/id.d.ts.map +1 -1
  160. package/dist/utils/id.js +14 -6
  161. package/dist/utils/id.js.map +1 -1
  162. package/docs/ADAPTERS.md +21 -21
  163. package/docs/AGENT.md +57 -55
  164. package/docs/API_REFERENCE.md +218 -220
  165. package/docs/ARCHITECTURE.md +99 -104
  166. package/docs/CONTEXT_MANAGEMENT.md +81 -88
  167. package/docs/DOCS.md +18 -18
  168. package/docs/DOMAINS.md +16 -16
  169. package/docs/EXAMPLES.md +43 -43
  170. package/docs/GETTING_STARTED.md +60 -63
  171. package/docs/PERSISTENCE.md +66 -70
  172. package/docs/PROVIDERS.md +2 -2
  173. package/docs/README.md +6 -6
  174. package/docs/ROUTES.md +218 -220
  175. package/docs/STEPS.md +883 -0
  176. package/examples/business-onboarding.ts +84 -81
  177. package/examples/company-qna-agent.ts +68 -67
  178. package/examples/custom-database-persistence.ts +87 -89
  179. package/examples/declarative-agent.ts +32 -32
  180. package/examples/domain-scoping.ts +18 -18
  181. package/examples/extracted-data-modification.ts +92 -97
  182. package/examples/healthcare-agent.ts +89 -91
  183. package/examples/openai-agent.ts +29 -32
  184. package/examples/opensearch-persistence.ts +43 -45
  185. package/examples/persistent-onboarding.ts +65 -66
  186. package/examples/prisma-persistence.ts +108 -112
  187. package/examples/prisma-schema.example.prisma +3 -3
  188. package/examples/redis-persistence.ts +67 -73
  189. package/examples/route-transitions.ts +71 -47
  190. package/examples/rules-prohibitions.ts +28 -28
  191. package/examples/streaming-agent.ts +24 -24
  192. package/examples/travel-agent.ts +94 -109
  193. package/package.json +1 -1
  194. package/src/adapters/MemoryAdapter.ts +3 -3
  195. package/src/adapters/MongoAdapter.ts +3 -3
  196. package/src/adapters/OpenSearchAdapter.ts +8 -8
  197. package/src/adapters/PostgreSQLAdapter.ts +10 -10
  198. package/src/adapters/PrismaAdapter.ts +4 -4
  199. package/src/adapters/RedisAdapter.ts +3 -3
  200. package/src/adapters/SQLiteAdapter.ts +15 -15
  201. package/src/adapters/index.ts +1 -1
  202. package/src/constants/index.ts +4 -4
  203. package/src/core/Agent.ts +210 -206
  204. package/src/core/Events.ts +12 -12
  205. package/src/core/PersistenceManager.ts +32 -36
  206. package/src/core/ResponseEngine.ts +11 -17
  207. package/src/core/Route.ts +55 -49
  208. package/src/core/RoutingEngine.ts +244 -252
  209. package/src/core/Step.ts +197 -0
  210. package/src/core/ToolExecutor.ts +11 -11
  211. package/src/core/Transition.ts +72 -26
  212. package/src/index.ts +8 -8
  213. package/src/types/agent.ts +8 -8
  214. package/src/types/ai.ts +2 -2
  215. package/src/types/history.ts +3 -3
  216. package/src/types/index.ts +1 -1
  217. package/src/types/persistence.ts +6 -6
  218. package/src/types/route.ts +77 -61
  219. package/src/types/session.ts +75 -78
  220. package/src/types/tool.ts +17 -17
  221. package/src/utils/id.ts +15 -6
  222. package/dist/cjs/core/State.d.ts +0 -72
  223. package/dist/cjs/core/State.d.ts.map +0 -1
  224. package/dist/cjs/core/State.js +0 -148
  225. package/dist/cjs/core/State.js.map +0 -1
  226. package/dist/core/State.d.ts +0 -72
  227. package/dist/core/State.d.ts.map +0 -1
  228. package/dist/core/State.js +0 -144
  229. package/dist/core/State.js.map +0 -1
  230. package/docs/STATES.md +0 -888
  231. package/src/core/State.ts +0 -212
@@ -1,19 +1,19 @@
1
1
  /**
2
2
  * Business Onboarding Example
3
- * Updated for v2 architecture with session state management and schema-first data extraction
3
+ * Updated for v2 architecture with session step management and schema-first data extraction
4
4
  *
5
5
  * Real-world example showing:
6
6
  * - Complex multi-step onboarding flow with schema-based data extraction
7
- * - Tools with enhanced context access for automatic state management
7
+ * - Tools with enhanced context access for automatic step management
8
8
  * - Lifecycle hooks for data validation and persistence
9
9
  * - Branching logic (physical vs online business) with skipIf conditions
10
- * - Code-based state progression instead of fuzzy conditions
10
+ * - Code-based step progression instead of fuzzy conditions
11
11
  */
12
12
 
13
13
  import {
14
14
  Agent,
15
15
  defineTool,
16
- END_STATE,
16
+ END_ROUTE,
17
17
  EventSource,
18
18
  createMessageEvent,
19
19
  OpenAIProvider,
@@ -32,7 +32,7 @@ interface BusinessInfo {
32
32
  interface LocationInfo {
33
33
  address?: string;
34
34
  city?: string;
35
- state?: string;
35
+ step?: string;
36
36
  hasPhysicalStore?: boolean;
37
37
  }
38
38
 
@@ -157,7 +157,7 @@ const saveProductsServices = defineTool<
157
157
  */
158
158
  const saveLocationInfo = defineTool<
159
159
  OnboardingContext,
160
- [address: string, city: string, state: string, hasPhysicalStore: boolean],
160
+ [address: string, city: string, step: string, hasPhysicalStore: boolean],
161
161
  boolean
162
162
  >(
163
163
  "save_location_info",
@@ -165,7 +165,7 @@ const saveLocationInfo = defineTool<
165
165
  toolContext: ToolContext<OnboardingContext>,
166
166
  address: string,
167
167
  city: string,
168
- state: string,
168
+ step: string,
169
169
  hasPhysicalStore: boolean
170
170
  ) => {
171
171
  return {
@@ -176,7 +176,7 @@ const saveLocationInfo = defineTool<
176
176
  location: {
177
177
  address,
178
178
  city,
179
- state,
179
+ step,
180
180
  hasPhysicalStore,
181
181
  },
182
182
  },
@@ -185,7 +185,7 @@ const saveLocationInfo = defineTool<
185
185
  },
186
186
  {
187
187
  description:
188
- "Save location information: full address, city, state, and physical store status",
188
+ "Save location information: full address, city, step, and physical store status",
189
189
  }
190
190
  );
191
191
 
@@ -339,7 +339,7 @@ const addConversationRoute = defineTool<
339
339
  /**
340
340
  * Get all collected data for review
341
341
  */
342
- const getCollectedData = defineTool<OnboardingContext, [], OnboardingData>(
342
+ const getData = defineTool<OnboardingContext, [], OnboardingData>(
343
343
  "get_collected_data",
344
344
  async (toolContext: ToolContext<OnboardingContext>) => {
345
345
  return { data: toolContext.context.collectedData };
@@ -417,19 +417,20 @@ async function createBusinessOnboardingAgent(
417
417
  title: "Business Onboarding",
418
418
  description: "Complete onboarding process to configure personalized routes",
419
419
  conditions: ["User is starting the onboarding process"],
420
- endState: {
421
- chatState: "🎉 Perfect! Setup complete! Your WhatsApp assistant is ready and will use all this information to automatically serve your customers. If you have any questions or need adjustments, just let me know!",
420
+ endStep: {
421
+ instructions:
422
+ "🎉 Perfect! Setup complete! Your WhatsApp assistant is ready and will use all this information to automatically serve your customers. If you have any questions or need adjustments, just let me know!",
422
423
  },
423
424
  });
424
425
 
425
426
  // ==================== Build the Flow ====================
426
427
 
427
428
  // For complex flows with branching, we use step-by-step approach
428
- // This makes it easier to reference states for branching logic
429
+ // This makes it easier to reference steps for branching logic
429
430
 
430
431
  // Step 0: Welcome
431
- const welcome = onboardingRoute.initialState.transitionTo({
432
- chatState: `Hello ${userName}! 👋 I'm your setup assistant. I'll help you configure your WhatsApp assistant by collecting practical information about your business. ${
432
+ const welcome = onboardingRoute.initialStep.nextStep({
433
+ instructions: `Hello ${userName}! 👋 I'm your setup assistant. I'll help you configure your WhatsApp assistant by collecting practical information about your business. ${
433
434
  initialData.business?.businessName
434
435
  ? `I see your company is "${initialData.business.businessName}".`
435
436
  : ""
@@ -437,8 +438,8 @@ async function createBusinessOnboardingAgent(
437
438
  });
438
439
 
439
440
  // Step 1: Business basics - Ask
440
- const askBusiness = welcome.transitionTo({
441
- chatState:
441
+ const askBusiness = welcome.nextStep({
442
+ instructions:
442
443
  initialData.business?.businessName &&
443
444
  initialData.business?.businessDescription &&
444
445
  initialData.business?.businessSector
@@ -449,119 +450,119 @@ async function createBusinessOnboardingAgent(
449
450
  });
450
451
 
451
452
  // Step 1: Business basics - Save
452
- const saveBusiness = askBusiness.transitionTo({
453
- toolState: saveBusinessInfo,
453
+ const saveBusiness = askBusiness.nextStep({
454
+ tool: saveBusinessInfo,
454
455
  condition: "User provided company name, sector, and description",
455
456
  });
456
457
 
457
458
  // Step 2: Products/Services - Ask
458
- const askProducts = saveBusiness.transitionTo({
459
- chatState:
459
+ const askProducts = saveBusiness.nextStep({
460
+ instructions:
460
461
  "Perfect! Now tell me: what are the main products or services you offer? And who is your target audience? (e.g., 'We sell women's clothing and accessories for women aged 25-45')",
461
462
  });
462
463
 
463
464
  // Step 2: Products/Services - Save
464
- const saveProducts = askProducts.transitionTo({
465
- toolState: saveProductsServices,
465
+ const saveProducts = askProducts.nextStep({
466
+ tool: saveProductsServices,
466
467
  condition: "User listed products/services and target audience",
467
468
  });
468
469
 
469
470
  // Step 3: Location - Branch point
470
- const askLocation = saveProducts.transitionTo({
471
- chatState:
471
+ const askLocation = saveProducts.nextStep({
472
+ instructions:
472
473
  "Great! Do you have a physical store or in-person service location? (answer 'yes' or 'no')",
473
474
  });
474
475
 
475
476
  // Step 3a: Physical store path
476
- const askPhysicalLocation = askLocation.transitionTo({
477
- chatState:
478
- "I see! Since you have a physical presence, I need the complete address (street, number, city, and state) and business hours. This is important for your assistant to inform customers. (e.g., 'José Silva Street, 123, São Paulo - SP - Mon to Fri: 9am to 6pm')",
477
+ const askPhysicalLocation = askLocation.nextStep({
478
+ instructions:
479
+ "I see! Since you have a physical presence, I need the complete address (street, number, city, and step) and business hours. This is important for your assistant to inform customers. (e.g., 'José Silva Street, 123, São Paulo - SP - Mon to Fri: 9am to 6pm')",
479
480
  condition: "User has a physical store",
480
481
  });
481
482
 
482
- const savePhysicalLocation = askPhysicalLocation.transitionTo({
483
- toolState: saveLocationInfo,
483
+ const savePhysicalLocation = askPhysicalLocation.nextStep({
484
+ tool: saveLocationInfo,
484
485
  condition: "User provided physical address",
485
486
  });
486
487
 
487
488
  // Step 3b: Online-only path
488
- const askOnlineLocation = askLocation.transitionTo({
489
- chatState:
489
+ const askOnlineLocation = askLocation.nextStep({
490
+ instructions:
490
491
  "Perfect! Since it's online only, please share your main website or social media where customers can find you? And what are your support hours? (e.g., 'www.example.com - 24/7 support' or 'Instagram @mycompany - Mon to Fri: 9am-6pm')",
491
492
  condition: "User does not have a physical store",
492
493
  });
493
494
 
494
- const saveOnlineLocation = askOnlineLocation.transitionTo({
495
- toolState: saveContactInfo,
495
+ const saveOnlineLocation = askOnlineLocation.nextStep({
496
+ tool: saveContactInfo,
496
497
  condition: "User provided website/social media and support hours",
497
498
  });
498
499
 
499
500
  // Step 4: Contact info (convergence point for physical stores)
500
- const askContact = savePhysicalLocation.transitionTo({
501
- chatState:
501
+ const askContact = savePhysicalLocation.nextStep({
502
+ instructions:
502
503
  "Do you also have a website or social media? If yes, which one? (if not, you can skip by saying 'I don't have one')",
503
504
  });
504
505
 
505
- const saveContact = askContact.transitionTo({
506
- toolState: saveContactInfo,
506
+ const saveContact = askContact.nextStep({
507
+ tool: saveContactInfo,
507
508
  condition: "User provided website/social media",
508
509
  });
509
510
 
510
511
  // Step 5: Payment info (convergence point from both paths)
511
- const askPayment = saveContact.transitionTo({
512
- chatState:
512
+ const askPayment = saveContact.nextStep({
513
+ instructions:
513
514
  "Now about payment: do you sell products/services that customers pay for? If yes, what payment methods do you accept? If you accept Pix, provide the key and type (CPF, CNPJ, email, phone). Do you offer installments? (e.g., 'Pix CPF: 12345678900, Credit card up to 12x, Bank slip' - or say 'not applicable' if you don't sell)",
514
515
  });
515
516
 
516
517
  // Also connect online path to payment
517
- saveOnlineLocation.transitionTo({ state: askPayment });
518
+ saveOnlineLocation.nextStep({ step: askPayment });
518
519
 
519
- const savePayment = askPayment.transitionTo({
520
- toolState: savePaymentInfo,
520
+ const savePayment = askPayment.nextStep({
521
+ tool: savePaymentInfo,
521
522
  condition: "User provided payment methods or said not applicable",
522
523
  });
523
524
 
524
525
  // Step 6: Suggest automatic routes
525
- const suggestRoutes = savePayment.transitionTo({
526
- chatState:
526
+ const suggestRoutes = savePayment.nextStep({
527
+ instructions:
527
528
  "Perfect! Now I'll create the essential routes. Based on what you told me, I'll automatically create:\n\n1. **Products and Services** - for when they ask what you offer\n2. **Pricing and Quotes** - for questions about prices\n3. **Payment Information** - payment methods and installments\n4. **Location and Contact** - address, website, and hours\n\nThese are the most important routes for any business. I'll create them automatically with the information you provided. Sound good?",
528
529
  });
529
530
 
530
- const createRoutes = suggestRoutes.transitionTo({
531
- toolState: addConversationRoute,
531
+ const createRoutes = suggestRoutes.nextStep({
532
+ tool: addConversationRoute,
532
533
  condition: "User approved automatic route creation",
533
534
  });
534
535
 
535
536
  // Step 7: Review collected data
536
- const reviewData = createRoutes.transitionTo({
537
- toolState: getCollectedData,
537
+ const reviewData = createRoutes.nextStep({
538
+ tool: getData,
538
539
  condition: "Routes created successfully",
539
540
  });
540
541
 
541
542
  // Step 8: Summary and options
542
- const summary = reviewData.transitionTo({
543
- chatState:
543
+ const summary = reviewData.nextStep({
544
+ instructions:
544
545
  "Done! ✅ I've configured everything:\n\n✓ Business information\n✓ Products/services and target audience\n✓ Location and contact\n✓ Payment methods\n✓ Essential conversation routes\n\nYour assistant is ready! It will use this information to automatically respond when customers ask. Do you want to add any custom routes or is everything good?",
545
546
  });
546
547
 
547
548
  // Step 9a: Add more routes
548
- const askCustomRoute = summary.transitionTo({
549
- chatState:
549
+ const askCustomRoute = summary.nextStep({
550
+ instructions:
550
551
  "Got it! Tell me about this additional route: what's the title, what kind of questions should it answer, and what keywords do customers use? (e.g., 'Warranty and Exchange - answers about warranty, exchange, and returns - keywords: warranty, exchange, return')",
551
552
  condition: "User wants to add more routes",
552
553
  });
553
554
 
554
- const saveCustomRoute = askCustomRoute.transitionTo({
555
- toolState: addConversationRoute,
555
+ const saveCustomRoute = askCustomRoute.nextStep({
556
+ tool: addConversationRoute,
556
557
  condition: "User provided custom route information",
557
558
  });
558
559
 
559
560
  // Loop back to summary after adding custom route
560
- saveCustomRoute.transitionTo({ state: summary });
561
+ saveCustomRoute.nextStep({ step: summary });
561
562
 
562
- // Step 9b: Final confirmation - transition to END_STATE (uses route-level endState)
563
- summary.transitionTo({
564
- state: END_STATE,
563
+ // Step 9b: Final confirmation - transition to END_ROUTE (uses route-level endStep)
564
+ summary.nextStep({
565
+ step: END_ROUTE,
565
566
  condition: "User confirmed everything is okay",
566
567
  });
567
568
 
@@ -576,19 +577,20 @@ async function createBusinessOnboardingAgent(
576
577
  steps: [
577
578
  {
578
579
  id: "ask_rating",
579
- chatState: "How would you rate your onboarding experience? (1-5 stars)",
580
+ instructions:
581
+ "How would you rate your onboarding experience? (1-5 stars)",
580
582
  },
581
583
  {
582
584
  id: "ask_liked_most",
583
- chatState: "What did you like most about the process?",
585
+ instructions: "What did you like most about the process?",
584
586
  },
585
587
  {
586
588
  id: "ask_improve",
587
- chatState: "Is there anything we could improve?",
589
+ instructions: "Is there anything we could improve?",
588
590
  },
589
591
  {
590
592
  id: "thank_you",
591
- chatState: "Thank you for your feedback! It helps us improve. 🙏",
593
+ instructions: "Thank you for your feedback! It helps us improve. 🙏",
592
594
  },
593
595
  ],
594
596
  });
@@ -598,26 +600,27 @@ async function createBusinessOnboardingAgent(
598
600
  title: "Manual Feedback Route",
599
601
  description: "Same flow using traditional chaining",
600
602
  conditions: ["User wants manual feedback flow"],
601
- endState: {
602
- chatState: "Thank you for your feedback! It helps us improve. 🙏",
603
+ endStep: {
604
+ instructions: "Thank you for your feedback! It helps us improve. 🙏",
603
605
  },
604
606
  });
605
607
 
606
- manualFeedbackRoute.initialState
607
- .transitionTo({
608
+ manualFeedbackRoute.initialStep
609
+ .nextStep({
608
610
  id: "ask_rating",
609
- chatState: "How would you rate your onboarding experience? (1-5 stars)",
611
+ instructions:
612
+ "How would you rate your onboarding experience? (1-5 stars)",
610
613
  })
611
- .transitionTo({
614
+ .nextStep({
612
615
  id: "ask_liked_most",
613
- chatState: "What did you like most about the process?",
616
+ instructions: "What did you like most about the process?",
614
617
  })
615
- .transitionTo({
618
+ .nextStep({
616
619
  id: "ask_improve",
617
- chatState: "Is there anything we could improve?",
620
+ instructions: "Is there anything we could improve?",
618
621
  condition: "User wants to provide feedback",
619
622
  })
620
- .transitionTo({ state: END_STATE }); // Uses route-level endState
623
+ .nextStep({ step: END_ROUTE }); // Uses route-level endStep
621
624
 
622
625
  // ==================== Global Guidelines ====================
623
626
 
@@ -632,7 +635,7 @@ async function createBusinessOnboardingAgent(
632
635
  id: "guideline_incomplete",
633
636
  condition: "User provides incomplete or very vague information",
634
637
  action:
635
- "Politely ask for the missing specific details. E.g., 'You mentioned the address, but what's the city and state?'",
638
+ "Politely ask for the missing specific details. E.g., 'You mentioned the address, but what's the city and step?'",
636
639
  })
637
640
  .createGuideline({
638
641
  id: "guideline_skip",
@@ -718,7 +721,7 @@ async function main() {
718
721
 
719
722
  // Generate response (requires valid API key)
720
723
  try {
721
- // Initialize session state for multi-turn conversation
724
+ // Initialize session step for multi-turn conversation
722
725
  let session = createSession<OnboardingData>();
723
726
  agent.setCurrentSession(session);
724
727
 
@@ -726,9 +729,9 @@ async function main() {
726
729
  console.log("Agent:", response.message);
727
730
  console.log("\nRoute:", response.session?.currentRoute?.title);
728
731
 
729
- // After the conversation, you can get the extracted data
730
- const extractedData = agent.getExtractedData<OnboardingData>();
731
- console.log("Extracted:", extractedData);
732
+ // After the conversation, you can get the collected data
733
+ const dataData = agent.getData<OnboardingData>();
734
+ console.log("Data:", dataData);
732
735
 
733
736
  // Update session with progress
734
737
  session = response.session!;
@@ -740,14 +743,14 @@ async function main() {
740
743
  if (response.isRouteComplete) {
741
744
  console.log("\n✅ Onboarding route complete!");
742
745
  // Here you would typically save the complete data to your database
743
- await processOnboardingData(agent.getExtractedData());
746
+ await processOnboardingData(agent.getData());
744
747
  } else {
745
748
  console.log("\n⏳ Onboarding route in progress...");
746
749
  }
747
750
 
748
- console.log("\n✅ Session state benefits:");
751
+ console.log("\n✅ Session step benefits:");
749
752
  console.log(" - Data extraction tracked across turns");
750
- console.log(" - State progression managed automatically");
753
+ console.log(" - Step progression managed automatically");
751
754
  console.log(" - Always-on routing respects intent changes");
752
755
  } catch (error: any) {
753
756
  console.log("\n(Skipping AI response - requires valid API key)");