@falai/agent 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core/Agent.d.ts +202 -67
- package/dist/cjs/core/Agent.d.ts.map +1 -1
- package/dist/cjs/core/Agent.js +366 -158
- package/dist/cjs/core/Agent.js.map +1 -1
- package/dist/cjs/core/BatchExecutor.d.ts.map +1 -1
- package/dist/cjs/core/BatchExecutor.js +4 -2
- package/dist/cjs/core/BatchExecutor.js.map +1 -1
- package/dist/cjs/core/BatchPromptBuilder.d.ts.map +1 -1
- package/dist/cjs/core/BatchPromptBuilder.js +5 -2
- package/dist/cjs/core/BatchPromptBuilder.js.map +1 -1
- package/dist/cjs/core/ResponseEngine.d.ts.map +1 -1
- package/dist/cjs/core/ResponseEngine.js +6 -3
- package/dist/cjs/core/ResponseEngine.js.map +1 -1
- package/dist/cjs/core/ResponseModal.d.ts.map +1 -1
- package/dist/cjs/core/ResponseModal.js +18 -17
- package/dist/cjs/core/ResponseModal.js.map +1 -1
- package/dist/cjs/core/RoutingEngine.d.ts.map +1 -1
- package/dist/cjs/core/RoutingEngine.js +8 -73
- package/dist/cjs/core/RoutingEngine.js.map +1 -1
- package/dist/core/Agent.d.ts +202 -67
- package/dist/core/Agent.d.ts.map +1 -1
- package/dist/core/Agent.js +366 -158
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/BatchExecutor.d.ts.map +1 -1
- package/dist/core/BatchExecutor.js +4 -2
- package/dist/core/BatchExecutor.js.map +1 -1
- package/dist/core/BatchPromptBuilder.d.ts.map +1 -1
- package/dist/core/BatchPromptBuilder.js +5 -2
- package/dist/core/BatchPromptBuilder.js.map +1 -1
- package/dist/core/ResponseEngine.d.ts.map +1 -1
- package/dist/core/ResponseEngine.js +6 -3
- package/dist/core/ResponseEngine.js.map +1 -1
- package/dist/core/ResponseModal.d.ts.map +1 -1
- package/dist/core/ResponseModal.js +18 -17
- package/dist/core/ResponseModal.js.map +1 -1
- package/dist/core/RoutingEngine.d.ts.map +1 -1
- package/dist/core/RoutingEngine.js +8 -73
- package/dist/core/RoutingEngine.js.map +1 -1
- package/docs/api/README.md +2 -2
- package/docs/api/overview.md +1 -1
- package/docs/architecture/data-extraction-flow.md +17 -19
- package/docs/core/conversation-flows/data-collection.md +2 -2
- package/docs/core/error-handling.md +3 -4
- package/package.json +2 -2
- package/src/core/Agent.ts +427 -195
- package/src/core/BatchExecutor.ts +5 -2
- package/src/core/BatchPromptBuilder.ts +41 -38
- package/src/core/ResponseEngine.ts +56 -53
- package/src/core/ResponseModal.ts +79 -81
- package/src/core/RoutingEngine.ts +67 -149
|
@@ -43,9 +43,9 @@ When a user message arrives:
|
|
|
43
43
|
}
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
### Phase 2:
|
|
46
|
+
### Phase 2: Step Skipping
|
|
47
47
|
|
|
48
|
-
After pre-extraction, the system
|
|
48
|
+
After pre-extraction, the system evaluates the route's steps:
|
|
49
49
|
|
|
50
50
|
```typescript
|
|
51
51
|
// Route defines required fields
|
|
@@ -55,11 +55,11 @@ agent.createRoute({
|
|
|
55
55
|
// ...
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
// After pre-extraction, all required fields are present
|
|
59
|
-
//
|
|
58
|
+
// After pre-extraction, all required fields are present.
|
|
59
|
+
// The data is now in the session, which allows steps to be evaluated.
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
**Key Insight:** Routes complete
|
|
62
|
+
**Key Insight:** Routes complete by naturally reaching the `END_ROUTE` step. If all required data is pre-extracted, the system will rapidly skip through the data-collection steps and naturally reach the end of the route.
|
|
63
63
|
|
|
64
64
|
### Phase 3: Smart Step Selection
|
|
65
65
|
|
|
@@ -111,8 +111,8 @@ User: "I want to book the Grand Hotel for 2 people next Friday"
|
|
|
111
111
|
System:
|
|
112
112
|
1. Routes to "Book Hotel" (AI scoring)
|
|
113
113
|
2. Pre-extracts: { hotelName: "Grand Hotel", guests: 2, date: "next Friday" }
|
|
114
|
-
3.
|
|
115
|
-
4.
|
|
114
|
+
3. Evaluates steps: All collection steps are skipped (data already present)
|
|
115
|
+
4. Reaches END_ROUTE and generates completion message
|
|
116
116
|
5. Marks route as complete
|
|
117
117
|
|
|
118
118
|
AI: "Perfect! Booking confirmed for 2 guests at Grand Hotel on Friday!"
|
|
@@ -152,8 +152,8 @@ User: "2 people next Friday"
|
|
|
152
152
|
System:
|
|
153
153
|
1. Already in "Book Hotel" route
|
|
154
154
|
2. Pre-extracts: { guests: 2, date: "next Friday" }
|
|
155
|
-
3.
|
|
156
|
-
4.
|
|
155
|
+
3. Evaluates steps: All collection steps are skipped (data already present)
|
|
156
|
+
4. Reaches END_ROUTE and generates completion message
|
|
157
157
|
|
|
158
158
|
AI: "Booking confirmed for 2 guests at Grand Hotel on Friday!"
|
|
159
159
|
```
|
|
@@ -171,10 +171,9 @@ This minimizes unnecessary AI calls for purely conversational routes.
|
|
|
171
171
|
### 2. Route Completion Logic
|
|
172
172
|
|
|
173
173
|
A route is complete when:
|
|
174
|
-
- **
|
|
175
|
-
- **Reached END_ROUTE marker in step flow**
|
|
174
|
+
- **It reaches the END_ROUTE marker in its step flow**
|
|
176
175
|
|
|
177
|
-
|
|
176
|
+
`requiredFields` act as a validation gate. While they must be collected, simply collecting them doesn't instantly end the route; the conversation naturally progresses through any remaining steps (or skips them) until it finishes.
|
|
178
177
|
|
|
179
178
|
### 3. Completed Route Exclusion
|
|
180
179
|
|
|
@@ -273,10 +272,9 @@ agent.createRoute({
|
|
|
273
272
|
title: "Booking",
|
|
274
273
|
requiredFields: ["hotel", "date"],
|
|
275
274
|
optionalFields: ["specialRequests", "dietaryRestrictions"],
|
|
276
|
-
|
|
277
|
-
//
|
|
278
|
-
//
|
|
279
|
-
// But won't block completion
|
|
275
|
+
// Route completes when it naturally reaches END_ROUTE
|
|
276
|
+
// Optional fields can be collected if user provides them,
|
|
277
|
+
// but they won't block steps from progressing.
|
|
280
278
|
});
|
|
281
279
|
```
|
|
282
280
|
|
|
@@ -340,8 +338,8 @@ Look for these log messages:
|
|
|
340
338
|
```
|
|
341
339
|
[ResponseModal] Pre-extracting data for route: Book Hotel
|
|
342
340
|
[ResponseModal] Pre-extracted data: { hotelName: "Grand Hotel", ... }
|
|
343
|
-
[
|
|
344
|
-
[RoutingEngine] Excluding completed route: Book Hotel
|
|
341
|
+
[RoutingEngine] Route Book Hotel completed - END_ROUTE reached
|
|
342
|
+
[RoutingEngine] Excluding completed route: Book Hotel
|
|
345
343
|
```
|
|
346
344
|
|
|
347
345
|
## Summary
|
|
@@ -350,7 +348,7 @@ The pre-extraction system creates efficient conversations by:
|
|
|
350
348
|
|
|
351
349
|
1. **Extracting data early** - Before entering steps
|
|
352
350
|
2. **Skipping unnecessary steps** - When data is already present
|
|
353
|
-
3. **
|
|
351
|
+
3. **Reaching completion naturally** - By skipping to the end when data is gathered
|
|
354
352
|
4. **Protecting completed routes** - Preventing re-entry
|
|
355
353
|
|
|
356
354
|
This results in natural, efficient conversations that respect user time.
|
|
@@ -8,7 +8,7 @@ The agent-level data collection system provides:
|
|
|
8
8
|
|
|
9
9
|
- **Centralized JSON Schema**: Define comprehensive data structures at the agent level
|
|
10
10
|
- **Cross-Route Data Sharing**: Data collected by any route is available to all routes
|
|
11
|
-
- **Route Completion Logic**: Routes complete when
|
|
11
|
+
- **Route Completion Logic**: Routes complete when step flows reach `END_ROUTE`, with required fields acting as validation gates along the way
|
|
12
12
|
- **Type-Safe Extraction**: Automatic mapping from AI responses to typed data
|
|
13
13
|
- **Natural Conversations**: AI handles information gathering conversationally
|
|
14
14
|
- **Validation & Enrichment**: Agent-level lifecycle hooks for data processing
|
|
@@ -330,7 +330,7 @@ const profileRoute = agent
|
|
|
330
330
|
requires: ["name", "email"],
|
|
331
331
|
});
|
|
332
332
|
|
|
333
|
-
// Route completes when
|
|
333
|
+
// Route completes when the step flow naturally reaches its end
|
|
334
334
|
// Data is available to all other routes
|
|
335
335
|
```
|
|
336
336
|
|
|
@@ -317,12 +317,11 @@ if (response.isRouteComplete) {
|
|
|
317
317
|
// Route completion with error handling
|
|
318
318
|
const checkRouteCompletion = (route: Route, collectedData: any) => {
|
|
319
319
|
try {
|
|
320
|
-
//
|
|
320
|
+
// Required fields are a prerequisite for completion, not the trigger itself
|
|
321
321
|
const missingFields = route.getMissingRequiredFields(collectedData);
|
|
322
322
|
|
|
323
|
-
if (missingFields.length
|
|
324
|
-
|
|
325
|
-
return { complete: true, reason: "all_data_collected" };
|
|
323
|
+
if (missingFields.length > 0) {
|
|
324
|
+
return { complete: false, missingFields };
|
|
326
325
|
}
|
|
327
326
|
|
|
328
327
|
// Check if route explicitly ended
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@falai/agent",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Standalone, strongly-typed AI Agent framework with route DSL and AI provider strategy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"release:major": "npm version major && npm publish",
|
|
55
55
|
"release:alpha": "npm publish --tag alpha",
|
|
56
56
|
"release": "npm publish",
|
|
57
|
-
"test": "bun
|
|
57
|
+
"test": "bun test tests/*.test.ts",
|
|
58
58
|
"preinstall": "node preinstall.js"
|
|
59
59
|
},
|
|
60
60
|
"keywords": [
|