@falai/agent 0.6.8 → 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.
- package/README.md +62 -59
- package/dist/adapters/MemoryAdapter.js +2 -2
- package/dist/adapters/MemoryAdapter.js.map +1 -1
- package/dist/adapters/MongoAdapter.js +2 -2
- package/dist/adapters/MongoAdapter.js.map +1 -1
- package/dist/adapters/OpenSearchAdapter.js +7 -7
- package/dist/adapters/OpenSearchAdapter.js.map +1 -1
- package/dist/adapters/PostgreSQLAdapter.js +9 -9
- package/dist/adapters/PostgreSQLAdapter.js.map +1 -1
- package/dist/adapters/PrismaAdapter.js +3 -3
- package/dist/adapters/PrismaAdapter.js.map +1 -1
- package/dist/adapters/RedisAdapter.js +2 -2
- package/dist/adapters/RedisAdapter.js.map +1 -1
- package/dist/adapters/SQLiteAdapter.d.ts +3 -3
- package/dist/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/dist/adapters/SQLiteAdapter.js +11 -11
- package/dist/adapters/SQLiteAdapter.js.map +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/cjs/adapters/MemoryAdapter.js +2 -2
- package/dist/cjs/adapters/MemoryAdapter.js.map +1 -1
- package/dist/cjs/adapters/MongoAdapter.js +2 -2
- package/dist/cjs/adapters/MongoAdapter.js.map +1 -1
- package/dist/cjs/adapters/OpenSearchAdapter.js +7 -7
- package/dist/cjs/adapters/OpenSearchAdapter.js.map +1 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.js +9 -9
- package/dist/cjs/adapters/PostgreSQLAdapter.js.map +1 -1
- package/dist/cjs/adapters/PrismaAdapter.js +3 -3
- package/dist/cjs/adapters/PrismaAdapter.js.map +1 -1
- package/dist/cjs/adapters/RedisAdapter.js +2 -2
- package/dist/cjs/adapters/RedisAdapter.js.map +1 -1
- package/dist/cjs/adapters/SQLiteAdapter.d.ts +3 -3
- package/dist/cjs/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/dist/cjs/adapters/SQLiteAdapter.js +11 -11
- package/dist/cjs/adapters/SQLiteAdapter.js.map +1 -1
- package/dist/cjs/adapters/index.d.ts +1 -1
- package/dist/cjs/adapters/index.d.ts.map +1 -1
- package/dist/cjs/constants/index.d.ts +4 -4
- package/dist/cjs/constants/index.js +5 -5
- package/dist/cjs/core/Agent.d.ts +22 -22
- package/dist/cjs/core/Agent.d.ts.map +1 -1
- package/dist/cjs/core/Agent.js +160 -152
- package/dist/cjs/core/Agent.js.map +1 -1
- package/dist/cjs/core/Events.d.ts +6 -6
- package/dist/cjs/core/Events.d.ts.map +1 -1
- package/dist/cjs/core/PersistenceManager.d.ts +13 -13
- package/dist/cjs/core/PersistenceManager.d.ts.map +1 -1
- package/dist/cjs/core/PersistenceManager.js +24 -24
- package/dist/cjs/core/PersistenceManager.js.map +1 -1
- package/dist/cjs/core/ResponseEngine.d.ts +3 -8
- package/dist/cjs/core/ResponseEngine.d.ts.map +1 -1
- package/dist/cjs/core/ResponseEngine.js +8 -8
- package/dist/cjs/core/ResponseEngine.js.map +1 -1
- package/dist/cjs/core/Route.d.ts +17 -17
- package/dist/cjs/core/Route.d.ts.map +1 -1
- package/dist/cjs/core/Route.js +33 -33
- package/dist/cjs/core/Route.js.map +1 -1
- package/dist/cjs/core/RoutingEngine.d.ts +30 -30
- package/dist/cjs/core/RoutingEngine.d.ts.map +1 -1
- package/dist/cjs/core/RoutingEngine.js +192 -192
- package/dist/cjs/core/RoutingEngine.js.map +1 -1
- package/dist/cjs/core/Step.d.ts +72 -0
- package/dist/cjs/core/Step.d.ts.map +1 -0
- package/dist/cjs/core/Step.js +150 -0
- package/dist/cjs/core/Step.js.map +1 -0
- package/dist/cjs/core/ToolExecutor.d.ts +5 -5
- package/dist/cjs/core/ToolExecutor.d.ts.map +1 -1
- package/dist/cjs/core/ToolExecutor.js +8 -8
- package/dist/cjs/core/ToolExecutor.js.map +1 -1
- package/dist/cjs/core/Transition.d.ts +14 -14
- package/dist/cjs/core/Transition.d.ts.map +1 -1
- package/dist/cjs/core/Transition.js +48 -19
- package/dist/cjs/core/Transition.js.map +1 -1
- package/dist/cjs/index.d.ts +7 -7
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +8 -8
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/agent.d.ts +8 -8
- package/dist/cjs/types/agent.d.ts.map +1 -1
- package/dist/cjs/types/ai.d.ts +2 -2
- package/dist/cjs/types/ai.d.ts.map +1 -1
- package/dist/cjs/types/history.d.ts +3 -3
- package/dist/cjs/types/history.d.ts.map +1 -1
- package/dist/cjs/types/index.d.ts +1 -1
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/persistence.d.ts +5 -5
- package/dist/cjs/types/persistence.d.ts.map +1 -1
- package/dist/cjs/types/route.d.ts +57 -52
- package/dist/cjs/types/route.d.ts.map +1 -1
- package/dist/cjs/types/session.d.ts +27 -27
- package/dist/cjs/types/session.d.ts.map +1 -1
- package/dist/cjs/types/session.js +48 -50
- package/dist/cjs/types/session.js.map +1 -1
- package/dist/cjs/types/tool.d.ts +13 -13
- package/dist/cjs/types/tool.d.ts.map +1 -1
- package/dist/cjs/utils/id.d.ts +8 -3
- package/dist/cjs/utils/id.d.ts.map +1 -1
- package/dist/cjs/utils/id.js +16 -7
- package/dist/cjs/utils/id.js.map +1 -1
- package/dist/constants/index.d.ts +4 -4
- package/dist/constants/index.js +4 -4
- package/dist/core/Agent.d.ts +22 -22
- package/dist/core/Agent.d.ts.map +1 -1
- package/dist/core/Agent.js +162 -154
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/Events.d.ts +6 -6
- package/dist/core/Events.d.ts.map +1 -1
- package/dist/core/PersistenceManager.d.ts +13 -13
- package/dist/core/PersistenceManager.d.ts.map +1 -1
- package/dist/core/PersistenceManager.js +25 -25
- package/dist/core/PersistenceManager.js.map +1 -1
- package/dist/core/ResponseEngine.d.ts +3 -8
- package/dist/core/ResponseEngine.d.ts.map +1 -1
- package/dist/core/ResponseEngine.js +8 -8
- package/dist/core/ResponseEngine.js.map +1 -1
- package/dist/core/Route.d.ts +17 -17
- package/dist/core/Route.d.ts.map +1 -1
- package/dist/core/Route.js +33 -33
- package/dist/core/Route.js.map +1 -1
- package/dist/core/RoutingEngine.d.ts +30 -30
- package/dist/core/RoutingEngine.d.ts.map +1 -1
- package/dist/core/RoutingEngine.js +193 -193
- package/dist/core/RoutingEngine.js.map +1 -1
- package/dist/core/Step.d.ts +72 -0
- package/dist/core/Step.d.ts.map +1 -0
- package/dist/core/Step.js +146 -0
- package/dist/core/Step.js.map +1 -0
- package/dist/core/ToolExecutor.d.ts +5 -5
- package/dist/core/ToolExecutor.d.ts.map +1 -1
- package/dist/core/ToolExecutor.js +8 -8
- package/dist/core/ToolExecutor.js.map +1 -1
- package/dist/core/Transition.d.ts +14 -14
- package/dist/core/Transition.d.ts.map +1 -1
- package/dist/core/Transition.js +48 -19
- package/dist/core/Transition.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/types/agent.d.ts +8 -8
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/ai.d.ts +2 -2
- package/dist/types/ai.d.ts.map +1 -1
- package/dist/types/history.d.ts +3 -3
- package/dist/types/history.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/persistence.d.ts +5 -5
- package/dist/types/persistence.d.ts.map +1 -1
- package/dist/types/route.d.ts +57 -52
- package/dist/types/route.d.ts.map +1 -1
- package/dist/types/session.d.ts +27 -27
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types/session.js +44 -46
- package/dist/types/session.js.map +1 -1
- package/dist/types/tool.d.ts +13 -13
- package/dist/types/tool.d.ts.map +1 -1
- package/dist/utils/id.d.ts +8 -3
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +14 -6
- package/dist/utils/id.js.map +1 -1
- package/docs/ADAPTERS.md +21 -21
- package/docs/AGENT.md +57 -55
- package/docs/API_REFERENCE.md +218 -220
- package/docs/ARCHITECTURE.md +99 -104
- package/docs/CONTEXT_MANAGEMENT.md +81 -88
- package/docs/DOCS.md +18 -18
- package/docs/DOMAINS.md +16 -16
- package/docs/EXAMPLES.md +43 -43
- package/docs/GETTING_STARTED.md +60 -63
- package/docs/PERSISTENCE.md +66 -70
- package/docs/PROVIDERS.md +2 -2
- package/docs/README.md +6 -6
- package/docs/ROUTES.md +218 -220
- package/docs/STEPS.md +883 -0
- package/examples/business-onboarding.ts +84 -81
- package/examples/company-qna-agent.ts +68 -67
- package/examples/custom-database-persistence.ts +87 -89
- package/examples/declarative-agent.ts +32 -32
- package/examples/domain-scoping.ts +18 -18
- package/examples/extracted-data-modification.ts +92 -97
- package/examples/healthcare-agent.ts +89 -91
- package/examples/openai-agent.ts +29 -32
- package/examples/opensearch-persistence.ts +43 -45
- package/examples/persistent-onboarding.ts +65 -66
- package/examples/prisma-persistence.ts +108 -112
- package/examples/prisma-schema.example.prisma +3 -3
- package/examples/redis-persistence.ts +67 -73
- package/examples/route-transitions.ts +71 -47
- package/examples/rules-prohibitions.ts +28 -28
- package/examples/streaming-agent.ts +24 -24
- package/examples/travel-agent.ts +94 -109
- package/package.json +1 -1
- package/src/adapters/MemoryAdapter.ts +3 -3
- package/src/adapters/MongoAdapter.ts +3 -3
- package/src/adapters/OpenSearchAdapter.ts +8 -8
- package/src/adapters/PostgreSQLAdapter.ts +10 -10
- package/src/adapters/PrismaAdapter.ts +4 -4
- package/src/adapters/RedisAdapter.ts +3 -3
- package/src/adapters/SQLiteAdapter.ts +15 -15
- package/src/adapters/index.ts +1 -1
- package/src/constants/index.ts +4 -4
- package/src/core/Agent.ts +210 -206
- package/src/core/Events.ts +12 -12
- package/src/core/PersistenceManager.ts +32 -36
- package/src/core/ResponseEngine.ts +11 -17
- package/src/core/Route.ts +55 -49
- package/src/core/RoutingEngine.ts +244 -252
- package/src/core/Step.ts +197 -0
- package/src/core/ToolExecutor.ts +11 -11
- package/src/core/Transition.ts +72 -26
- package/src/index.ts +8 -8
- package/src/types/agent.ts +8 -8
- package/src/types/ai.ts +2 -2
- package/src/types/history.ts +3 -3
- package/src/types/index.ts +1 -1
- package/src/types/persistence.ts +6 -6
- package/src/types/route.ts +77 -61
- package/src/types/session.ts +75 -78
- package/src/types/tool.ts +17 -17
- package/src/utils/id.ts +15 -6
- package/dist/cjs/core/State.d.ts +0 -72
- package/dist/cjs/core/State.d.ts.map +0 -1
- package/dist/cjs/core/State.js +0 -148
- package/dist/cjs/core/State.js.map +0 -1
- package/dist/core/State.d.ts +0 -72
- package/dist/core/State.d.ts.map +0 -1
- package/dist/core/State.js +0 -144
- package/dist/core/State.js.map +0 -1
- package/docs/STATES.md +0 -888
- 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
|
|
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
|
|
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
|
|
10
|
+
* - Code-based step progression instead of fuzzy conditions
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {
|
|
14
14
|
Agent,
|
|
15
15
|
defineTool,
|
|
16
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
|
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
|
-
|
|
421
|
-
|
|
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
|
|
429
|
+
// This makes it easier to reference steps for branching logic
|
|
429
430
|
|
|
430
431
|
// Step 0: Welcome
|
|
431
|
-
const welcome = onboardingRoute.
|
|
432
|
-
|
|
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.
|
|
441
|
-
|
|
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.
|
|
453
|
-
|
|
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.
|
|
459
|
-
|
|
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.
|
|
465
|
-
|
|
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.
|
|
471
|
-
|
|
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.
|
|
477
|
-
|
|
478
|
-
"I see! Since you have a physical presence, I need the complete address (street, number, city, and
|
|
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.
|
|
483
|
-
|
|
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.
|
|
489
|
-
|
|
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.
|
|
495
|
-
|
|
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.
|
|
501
|
-
|
|
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.
|
|
506
|
-
|
|
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.
|
|
512
|
-
|
|
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.
|
|
518
|
+
saveOnlineLocation.nextStep({ step: askPayment });
|
|
518
519
|
|
|
519
|
-
const savePayment = askPayment.
|
|
520
|
-
|
|
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.
|
|
526
|
-
|
|
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.
|
|
531
|
-
|
|
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.
|
|
537
|
-
|
|
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.
|
|
543
|
-
|
|
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.
|
|
549
|
-
|
|
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.
|
|
555
|
-
|
|
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.
|
|
561
|
+
saveCustomRoute.nextStep({ step: summary });
|
|
561
562
|
|
|
562
|
-
// Step 9b: Final confirmation - transition to
|
|
563
|
-
summary.
|
|
564
|
-
|
|
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
|
-
|
|
580
|
+
instructions:
|
|
581
|
+
"How would you rate your onboarding experience? (1-5 stars)",
|
|
580
582
|
},
|
|
581
583
|
{
|
|
582
584
|
id: "ask_liked_most",
|
|
583
|
-
|
|
585
|
+
instructions: "What did you like most about the process?",
|
|
584
586
|
},
|
|
585
587
|
{
|
|
586
588
|
id: "ask_improve",
|
|
587
|
-
|
|
589
|
+
instructions: "Is there anything we could improve?",
|
|
588
590
|
},
|
|
589
591
|
{
|
|
590
592
|
id: "thank_you",
|
|
591
|
-
|
|
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
|
-
|
|
602
|
-
|
|
603
|
+
endStep: {
|
|
604
|
+
instructions: "Thank you for your feedback! It helps us improve. 🙏",
|
|
603
605
|
},
|
|
604
606
|
});
|
|
605
607
|
|
|
606
|
-
manualFeedbackRoute.
|
|
607
|
-
.
|
|
608
|
+
manualFeedbackRoute.initialStep
|
|
609
|
+
.nextStep({
|
|
608
610
|
id: "ask_rating",
|
|
609
|
-
|
|
611
|
+
instructions:
|
|
612
|
+
"How would you rate your onboarding experience? (1-5 stars)",
|
|
610
613
|
})
|
|
611
|
-
.
|
|
614
|
+
.nextStep({
|
|
612
615
|
id: "ask_liked_most",
|
|
613
|
-
|
|
616
|
+
instructions: "What did you like most about the process?",
|
|
614
617
|
})
|
|
615
|
-
.
|
|
618
|
+
.nextStep({
|
|
616
619
|
id: "ask_improve",
|
|
617
|
-
|
|
620
|
+
instructions: "Is there anything we could improve?",
|
|
618
621
|
condition: "User wants to provide feedback",
|
|
619
622
|
})
|
|
620
|
-
.
|
|
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
|
|
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
|
|
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
|
|
730
|
-
const
|
|
731
|
-
console.log("
|
|
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.
|
|
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
|
|
751
|
+
console.log("\n✅ Session step benefits:");
|
|
749
752
|
console.log(" - Data extraction tracked across turns");
|
|
750
|
-
console.log(" -
|
|
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)");
|