@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
package/docs/EXAMPLES.md
CHANGED
|
@@ -13,9 +13,9 @@ Complete example demonstrating the new `onComplete` feature for seamless route t
|
|
|
13
13
|
- ✅ Hotel booking flow transitioning to feedback collection
|
|
14
14
|
- ✅ Three ways to define transitions (string, config, function)
|
|
15
15
|
- ✅ Automatic transition after route completion
|
|
16
|
-
- ✅ Manual transition control with `agent.
|
|
17
|
-
- ✅ Dynamic logic based on
|
|
18
|
-
- ✅ Pending transition tracking in session
|
|
16
|
+
- ✅ Manual transition control with `agent.nextStepRoute()`
|
|
17
|
+
- ✅ Dynamic logic based on collected data
|
|
18
|
+
- ✅ Pending transition tracking in session step
|
|
19
19
|
|
|
20
20
|
**Key concepts:** Route transitions, workflow chaining, feedback collection, onComplete handlers
|
|
21
21
|
|
|
@@ -27,13 +27,13 @@ const bookingRoute = agent.createRoute<BookingData>({
|
|
|
27
27
|
|
|
28
28
|
// Or with AI condition:
|
|
29
29
|
// onComplete: {
|
|
30
|
-
//
|
|
30
|
+
// nextStep: "Collect Feedback",
|
|
31
31
|
// condition: "if booking was successful"
|
|
32
32
|
// },
|
|
33
33
|
|
|
34
34
|
// Or with function logic:
|
|
35
35
|
// onComplete: (session) => {
|
|
36
|
-
// if (session.
|
|
36
|
+
// if (session.data?.guests > 5) {
|
|
37
37
|
// return "VIP Feedback";
|
|
38
38
|
// }
|
|
39
39
|
// return "Collect Feedback";
|
|
@@ -43,7 +43,7 @@ const bookingRoute = agent.createRoute<BookingData>({
|
|
|
43
43
|
// Feedback route automatically triggered after booking
|
|
44
44
|
const feedbackRoute = agent.createRoute<FeedbackData>({
|
|
45
45
|
title: "Collect Feedback",
|
|
46
|
-
// ...
|
|
46
|
+
// ... steps for collecting rating and comments
|
|
47
47
|
});
|
|
48
48
|
```
|
|
49
49
|
|
|
@@ -59,11 +59,11 @@ Comprehensive example showing declarative agent configuration:
|
|
|
59
59
|
|
|
60
60
|
- ✅ Full constructor-based setup
|
|
61
61
|
- ✅ Terms, guidelines, capabilities, routes defined upfront
|
|
62
|
-
- ✅ Session
|
|
63
|
-
- ✅ Custom IDs for routes,
|
|
62
|
+
- ✅ Session step management with data extraction
|
|
63
|
+
- ✅ Custom IDs for routes, steps, and tools
|
|
64
64
|
- ✅ Dynamic additions after construction
|
|
65
65
|
|
|
66
|
-
**Key concepts:** Declarative configuration, session
|
|
66
|
+
**Key concepts:** Declarative configuration, session step, data extraction schemas
|
|
67
67
|
|
|
68
68
|
```typescript
|
|
69
69
|
const agent = new Agent({
|
|
@@ -72,7 +72,7 @@ const agent = new Agent({
|
|
|
72
72
|
terms: [...],
|
|
73
73
|
guidelines: [...],
|
|
74
74
|
routes: [{
|
|
75
|
-
|
|
75
|
+
schema: { /* JSON Schema */ }
|
|
76
76
|
}]
|
|
77
77
|
});
|
|
78
78
|
```
|
|
@@ -89,7 +89,7 @@ Production-ready business onboarding with advanced patterns:
|
|
|
89
89
|
|
|
90
90
|
- ✅ Multi-step data collection flow
|
|
91
91
|
- ✅ Branching logic (physical vs online business)
|
|
92
|
-
- ✅ Tools with `contextUpdate` for automatic
|
|
92
|
+
- ✅ Tools with `contextUpdate` for automatic step management
|
|
93
93
|
- ✅ Both step-by-step and fluent chaining approaches
|
|
94
94
|
- ✅ Lifecycle hooks for persistence
|
|
95
95
|
- ✅ Dynamic route creation based on collected data
|
|
@@ -98,43 +98,43 @@ Production-ready business onboarding with advanced patterns:
|
|
|
98
98
|
|
|
99
99
|
```typescript
|
|
100
100
|
// Branching based on business type
|
|
101
|
-
const askPhysicalLocation = askLocation.
|
|
102
|
-
|
|
101
|
+
const askPhysicalLocation = askLocation.nextStep({
|
|
102
|
+
instructions: "Get physical store address",
|
|
103
103
|
condition: "User has a physical store",
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
const askOnlineLocation = askLocation.
|
|
107
|
-
|
|
106
|
+
const askOnlineLocation = askLocation.nextStep({
|
|
107
|
+
instructions: "Get website and online support hours",
|
|
108
108
|
condition: "User does not have a physical store",
|
|
109
109
|
});
|
|
110
110
|
```
|
|
111
111
|
|
|
112
112
|
### ✈️ [Travel Agent](../examples/travel-agent.ts)
|
|
113
113
|
|
|
114
|
-
**Perfect for:** Multi-route systems with session
|
|
114
|
+
**Perfect for:** Multi-route systems with session step
|
|
115
115
|
|
|
116
116
|
Complete travel booking system featuring:
|
|
117
117
|
|
|
118
118
|
- ✅ Multi-step flight booking flow
|
|
119
119
|
- ✅ Data extraction with JSON Schema
|
|
120
|
-
- ✅ Session
|
|
121
|
-
- ✅ Tools with data access via `
|
|
120
|
+
- ✅ Session step tracking across turns
|
|
121
|
+
- ✅ Tools with data access via `data` context
|
|
122
122
|
- ✅ Alternative flow handling (booking vs status check)
|
|
123
123
|
- ✅ Route-specific guidelines
|
|
124
124
|
- ✅ **NEW:** Automatic feedback collection after booking with `onComplete`
|
|
125
125
|
|
|
126
|
-
**Key concepts:** Session
|
|
126
|
+
**Key concepts:** Session step, data extraction, multiple routes, tool data access, route transitions
|
|
127
127
|
|
|
128
128
|
```typescript
|
|
129
129
|
const searchFlights = defineTool(
|
|
130
130
|
"search_flights",
|
|
131
|
-
async ({ context,
|
|
132
|
-
// Tool has access to
|
|
133
|
-
if (!
|
|
131
|
+
async ({ context, data }) => {
|
|
132
|
+
// Tool has access to data booking data
|
|
133
|
+
if (!data?.destination || !data?.departureDate) {
|
|
134
134
|
return { data: [] };
|
|
135
135
|
}
|
|
136
|
-
// Use
|
|
137
|
-
const flights = await searchAPI(
|
|
136
|
+
// Use collected data to search
|
|
137
|
+
const flights = await searchAPI(data);
|
|
138
138
|
return { data: flights };
|
|
139
139
|
}
|
|
140
140
|
);
|
|
@@ -169,7 +169,7 @@ Real-time streaming responses:
|
|
|
169
169
|
- ✅ Stream responses from all providers (Anthropic, OpenAI, Gemini, OpenRouter)
|
|
170
170
|
- ✅ Real-time text generation with `respondStream`
|
|
171
171
|
- ✅ Cancellable streams with AbortSignal
|
|
172
|
-
- ✅ Access route,
|
|
172
|
+
- ✅ Access route, step, and tool information in final chunk
|
|
173
173
|
- ✅ 5 comprehensive examples covering different use cases
|
|
174
174
|
|
|
175
175
|
**Key concepts:** Streaming, real-time UX, cancellation
|
|
@@ -180,7 +180,7 @@ for await (const chunk of agent.respondStream({ history })) {
|
|
|
180
180
|
|
|
181
181
|
if (chunk.done) {
|
|
182
182
|
console.log("Route:", chunk.route?.title);
|
|
183
|
-
console.log("
|
|
183
|
+
console.log("Data:", chunk.data);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
```
|
|
@@ -298,11 +298,11 @@ Full-text search and analytics-powered persistence:
|
|
|
298
298
|
|
|
299
299
|
**Perfect for:** Integrating with existing database schemas
|
|
300
300
|
|
|
301
|
-
Manual session
|
|
301
|
+
Manual session step management for existing schemas:
|
|
302
302
|
|
|
303
303
|
- ✅ Full control over database operations
|
|
304
304
|
- ✅ Works with any database (no adapter needed)
|
|
305
|
-
- ✅ Manual session
|
|
305
|
+
- ✅ Manual session step save/restore
|
|
306
306
|
- ✅ Perfect for integrating with existing schemas
|
|
307
307
|
- ✅ Complete example with validation hooks
|
|
308
308
|
|
|
@@ -310,13 +310,13 @@ Manual session state management for existing schemas:
|
|
|
310
310
|
|
|
311
311
|
---
|
|
312
312
|
|
|
313
|
-
## 🔧 Context &
|
|
313
|
+
## 🔧 Context & Step Management
|
|
314
314
|
|
|
315
315
|
### 💾 [Persistent Onboarding Agent](../examples/persistent-onboarding.ts)
|
|
316
316
|
|
|
317
317
|
**Perfect for:** Multi-turn conversations with persistence
|
|
318
318
|
|
|
319
|
-
Multi-turn conversation with
|
|
319
|
+
Multi-turn conversation with step persistence:
|
|
320
320
|
|
|
321
321
|
- ✅ Context lifecycle hooks for database integration
|
|
322
322
|
- ✅ Automatic persistence on context updates
|
|
@@ -339,27 +339,27 @@ const agent = new Agent({
|
|
|
339
339
|
});
|
|
340
340
|
```
|
|
341
341
|
|
|
342
|
-
### 🔄 [
|
|
342
|
+
### 🔄 [Collected data Modification](../examples/data-data-modification.ts)
|
|
343
343
|
|
|
344
344
|
**Perfect for:** Data validation and enrichment
|
|
345
345
|
|
|
346
|
-
Tools that validate and enrich
|
|
346
|
+
Tools that validate and enrich collected data:
|
|
347
347
|
|
|
348
|
-
- ✅ Tools can modify
|
|
348
|
+
- ✅ Tools can modify collected data with `dataUpdate`
|
|
349
349
|
- ✅ Data validation and enrichment patterns
|
|
350
350
|
- ✅ Flag-based conditional execution
|
|
351
351
|
- ✅ Error handling and data correction
|
|
352
352
|
- ✅ Multi-step data refinement
|
|
353
353
|
|
|
354
|
-
**Key concepts:** Data validation, enrichment,
|
|
354
|
+
**Key concepts:** Data validation, enrichment, dataUpdate, flags
|
|
355
355
|
|
|
356
356
|
```typescript
|
|
357
|
-
const validateEmail = defineTool("validate_email", async ({
|
|
358
|
-
const isValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(
|
|
357
|
+
const validateEmail = defineTool("validate_email", async ({ data }) => {
|
|
358
|
+
const isValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email);
|
|
359
359
|
return {
|
|
360
360
|
data: isValid,
|
|
361
|
-
|
|
362
|
-
emailValid: isValid, // Enrich
|
|
361
|
+
dataUpdate: {
|
|
362
|
+
emailValid: isValid, // Enrich collected data
|
|
363
363
|
},
|
|
364
364
|
};
|
|
365
365
|
});
|
|
@@ -397,16 +397,16 @@ See how different AI providers work:
|
|
|
397
397
|
|
|
398
398
|
### 📊 [Company Q&A Agent](../examples/company-qna-agent.ts)
|
|
399
399
|
|
|
400
|
-
**Perfect for:**
|
|
400
|
+
**Perfect for:** Stepless question-answering systems
|
|
401
401
|
|
|
402
402
|
Simple Q&A agent with knowledge base:
|
|
403
403
|
|
|
404
|
-
- ✅
|
|
404
|
+
- ✅ Stepless routes (no data extraction)
|
|
405
405
|
- ✅ Knowledge base integration
|
|
406
406
|
- ✅ Simple request-response pattern
|
|
407
407
|
- ✅ Perfect for FAQ bots
|
|
408
408
|
|
|
409
|
-
**Key concepts:**
|
|
409
|
+
**Key concepts:** Stepless routing, Q&A patterns
|
|
410
410
|
|
|
411
411
|
---
|
|
412
412
|
|
|
@@ -428,7 +428,7 @@ bun examples/travel-agent.ts
|
|
|
428
428
|
### Learning Path
|
|
429
429
|
|
|
430
430
|
1. **Start here:** [Declarative Agent](../examples/declarative-agent.ts) - Learn the basics
|
|
431
|
-
2. **Simple flow:** [Travel Agent](../examples/travel-agent.ts) - Session
|
|
431
|
+
2. **Simple flow:** [Travel Agent](../examples/travel-agent.ts) - Session step & extraction
|
|
432
432
|
3. **Complex flow:** [Business Onboarding](../examples/business-onboarding.ts) - Branching & lifecycle
|
|
433
433
|
4. **Add persistence:** [Prisma Persistence](../examples/prisma-persistence.ts) - Database integration
|
|
434
434
|
5. **Add security:** [Domain Scoping](../examples/domain-scoping.ts) - Tool isolation
|
|
@@ -438,7 +438,7 @@ bun examples/travel-agent.ts
|
|
|
438
438
|
| Example | Best For | Key Features |
|
|
439
439
|
| ------------------- | --------------- | --------------------------- |
|
|
440
440
|
| Declarative Agent | Learning basics | Full API coverage |
|
|
441
|
-
| Travel Agent | Session
|
|
441
|
+
| Travel Agent | Session step | Multi-turn conversations |
|
|
442
442
|
| Business Onboarding | Complex flows | Branching, lifecycle hooks |
|
|
443
443
|
| Healthcare Agent | Security | Data validation, compliance |
|
|
444
444
|
| Streaming Agent | Real-time UX | Streaming responses |
|
package/docs/GETTING_STARTED.md
CHANGED
|
@@ -86,7 +86,7 @@ const bookingRoute = agent.createRoute<FlightData>({
|
|
|
86
86
|
title: "Book Flight",
|
|
87
87
|
description: "Help user book a flight",
|
|
88
88
|
conditions: ["User wants to book a flight"],
|
|
89
|
-
|
|
89
|
+
schema: {
|
|
90
90
|
type: "object",
|
|
91
91
|
properties: {
|
|
92
92
|
destination: { type: "string" },
|
|
@@ -102,10 +102,10 @@ const bookingRoute = agent.createRoute<FlightData>({
|
|
|
102
102
|
},
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
// Initialize session
|
|
105
|
+
// Initialize session step
|
|
106
106
|
let session = createSession<FlightData>();
|
|
107
107
|
|
|
108
|
-
// Generate a response with session
|
|
108
|
+
// Generate a response with session step
|
|
109
109
|
const response = await agent.respond({
|
|
110
110
|
history: [
|
|
111
111
|
createMessageEvent(
|
|
@@ -118,7 +118,7 @@ const response = await agent.respond({
|
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
console.log("Agent:", response.message);
|
|
121
|
-
console.log("
|
|
121
|
+
console.log("Data:", response.session?.data);
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
### 3. Run It!
|
|
@@ -133,9 +133,9 @@ bun run index.ts
|
|
|
133
133
|
|
|
134
134
|
## Next Steps
|
|
135
135
|
|
|
136
|
-
### Add Session
|
|
136
|
+
### Add Session Step Management
|
|
137
137
|
|
|
138
|
-
Continue the conversation with
|
|
138
|
+
Continue the conversation with collected data:
|
|
139
139
|
|
|
140
140
|
```typescript
|
|
141
141
|
// Turn 2 - User provides more details
|
|
@@ -144,90 +144,87 @@ const response2 = await agent.respond({
|
|
|
144
144
|
createMessageEvent(EventSource.AI_AGENT, "Bot", response.message),
|
|
145
145
|
createMessageEvent(EventSource.CUSTOMER, "Alice", "Make it business class"),
|
|
146
146
|
],
|
|
147
|
-
session: response.session, // Pass previous session
|
|
147
|
+
session: response.session, // Pass previous session step
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
console.log("Agent:", response2.message);
|
|
151
|
-
console.log("Updated
|
|
151
|
+
console.log("Updated data:", response2.session?.data);
|
|
152
152
|
// Agent remembers destination and passengers, updates cabin class
|
|
153
153
|
```
|
|
154
154
|
|
|
155
155
|
### Create Tools with Data Access
|
|
156
156
|
|
|
157
|
-
Tools can access and modify
|
|
157
|
+
Tools can access and modify collected data:
|
|
158
158
|
|
|
159
159
|
```typescript
|
|
160
160
|
import { defineTool } from "@falai/agent";
|
|
161
161
|
|
|
162
162
|
const searchFlights = defineTool<MyContext, [], void, FlightData>(
|
|
163
163
|
"search_flights",
|
|
164
|
-
async ({ context,
|
|
165
|
-
// Access
|
|
166
|
-
if (!
|
|
164
|
+
async ({ context, data }) => {
|
|
165
|
+
// Access collected data directly
|
|
166
|
+
if (!data.destination || !data.departureDate) {
|
|
167
167
|
return { data: undefined };
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
// Search for flights and enrich
|
|
171
|
-
const flights = await searchFlightAPI(
|
|
172
|
-
extracted.destination,
|
|
173
|
-
extracted.departureDate
|
|
174
|
-
);
|
|
170
|
+
// Search for flights and enrich collected data
|
|
171
|
+
const flights = await searchFlightAPI(data.destination, data.departureDate);
|
|
175
172
|
|
|
176
173
|
return {
|
|
177
174
|
data: undefined,
|
|
178
175
|
contextUpdate: { availableFlights: flights },
|
|
179
|
-
|
|
180
|
-
destinationCode: await lookupAirportCode(
|
|
176
|
+
dataUpdate: {
|
|
177
|
+
destinationCode: await lookupAirportCode(data.destination),
|
|
181
178
|
},
|
|
182
179
|
};
|
|
183
180
|
},
|
|
184
|
-
{ description: "Search for available flights based on
|
|
181
|
+
{ description: "Search for available flights based on collected data" }
|
|
185
182
|
);
|
|
186
183
|
|
|
187
|
-
// Add tool to
|
|
188
|
-
const
|
|
189
|
-
.
|
|
190
|
-
|
|
191
|
-
|
|
184
|
+
// Add tool to step machine
|
|
185
|
+
const searchStep = bookingRoute.initialStep
|
|
186
|
+
.nextStep({
|
|
187
|
+
instructions: "Extract travel details",
|
|
188
|
+
collect: ["destination", "departureDate", "passengers"],
|
|
192
189
|
})
|
|
193
|
-
.
|
|
194
|
-
|
|
195
|
-
|
|
190
|
+
.nextStep({
|
|
191
|
+
tool: searchFlights,
|
|
192
|
+
requires: ["destination", "departureDate", "passengers"],
|
|
196
193
|
});
|
|
197
194
|
```
|
|
198
195
|
|
|
199
|
-
### Build Smart
|
|
196
|
+
### Build Smart Step Machines
|
|
200
197
|
|
|
201
198
|
Create intelligent flows with code-based logic:
|
|
202
199
|
|
|
203
200
|
```typescript
|
|
204
|
-
//
|
|
205
|
-
const askDestination = bookingRoute.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
skipIf: (
|
|
201
|
+
// Step machine with smart bypassing and data validation
|
|
202
|
+
const askDestination = bookingRoute.initialStep.nextStep({
|
|
203
|
+
instructions: "Ask where they want to fly",
|
|
204
|
+
collect: ["destination"],
|
|
205
|
+
skipIf: (data) => !!data.destination, // Skip if already have destination
|
|
209
206
|
});
|
|
210
207
|
|
|
211
|
-
const enrichDestination = askDestination.
|
|
212
|
-
|
|
213
|
-
|
|
208
|
+
const enrichDestination = askDestination.nextStep({
|
|
209
|
+
tool: searchFlights, // Tool executes automatically
|
|
210
|
+
requires: ["destination"], // Prerequisites
|
|
214
211
|
});
|
|
215
212
|
|
|
216
|
-
const askDates = enrichDestination.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
skipIf: (
|
|
220
|
-
|
|
213
|
+
const askDates = enrichDestination.nextStep({
|
|
214
|
+
instructions: "Ask about travel dates",
|
|
215
|
+
collect: ["departureDate"],
|
|
216
|
+
skipIf: (data) => !!data.departureDate,
|
|
217
|
+
requires: ["destination"], // Must have destination first
|
|
221
218
|
});
|
|
222
219
|
|
|
223
|
-
const askPassengers = askDates.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
skipIf: (
|
|
220
|
+
const askPassengers = askDates.nextStep({
|
|
221
|
+
instructions: "How many passengers?",
|
|
222
|
+
collect: ["passengers"],
|
|
223
|
+
skipIf: (data) => !!data.passengers,
|
|
227
224
|
});
|
|
228
225
|
|
|
229
|
-
const presentFlights = askPassengers.
|
|
230
|
-
|
|
226
|
+
const presentFlights = askPassengers.nextStep({
|
|
227
|
+
instructions: "Present available flights from search results",
|
|
231
228
|
});
|
|
232
229
|
```
|
|
233
230
|
|
|
@@ -284,12 +281,12 @@ if (user.isPremium) {
|
|
|
284
281
|
}
|
|
285
282
|
```
|
|
286
283
|
|
|
287
|
-
### Multi-Turn Conversations with Session
|
|
284
|
+
### Multi-Turn Conversations with Session Step
|
|
288
285
|
|
|
289
|
-
Track conversation progress and
|
|
286
|
+
Track conversation progress and collected data:
|
|
290
287
|
|
|
291
288
|
```typescript
|
|
292
|
-
import { createSession, enterRoute,
|
|
289
|
+
import { createSession, enterRoute, mergeData } from "@falai/agent";
|
|
293
290
|
|
|
294
291
|
// Initialize session
|
|
295
292
|
let session = createSession<FlightData>();
|
|
@@ -304,10 +301,10 @@ const history1 = [
|
|
|
304
301
|
];
|
|
305
302
|
|
|
306
303
|
const response1 = await agent.respond({ history: history1, session });
|
|
307
|
-
console.log("Turn 1 -
|
|
304
|
+
console.log("Turn 1 - Data:", response1.session?.data);
|
|
308
305
|
// { destination: "Paris", departureDate: "tomorrow", passengers: 2 }
|
|
309
306
|
|
|
310
|
-
session = response1.session!; // Update session with
|
|
307
|
+
session = response1.session!; // Update session with collected data
|
|
311
308
|
|
|
312
309
|
// Turn 2 - User changes their mind
|
|
313
310
|
const history2 = [
|
|
@@ -321,7 +318,7 @@ const history2 = [
|
|
|
321
318
|
];
|
|
322
319
|
|
|
323
320
|
const response2 = await agent.respond({ history: history2, session });
|
|
324
|
-
console.log("Turn 2 - Updated:", response2.session?.
|
|
321
|
+
console.log("Turn 2 - Updated:", response2.session?.data);
|
|
325
322
|
// { destination: "Tokyo", departureDate: "tomorrow", passengers: 2 }
|
|
326
323
|
|
|
327
324
|
session = response2.session!; // Router handled the route change
|
|
@@ -335,7 +332,7 @@ const response3 = await agent.respond({
|
|
|
335
332
|
],
|
|
336
333
|
session,
|
|
337
334
|
});
|
|
338
|
-
console.log("Turn 3 - Final:", response3.session?.
|
|
335
|
+
console.log("Turn 3 - Final:", response3.session?.data);
|
|
339
336
|
// { destination: "Tokyo", departureDate: "tomorrow", passengers: 2, cabinClass: "business" }
|
|
340
337
|
```
|
|
341
338
|
|
|
@@ -347,18 +344,18 @@ console.log("Turn 3 - Final:", response3.session?.extracted);
|
|
|
347
344
|
|
|
348
345
|
- **Use TypeScript** - Full type safety and IntelliSense throughout
|
|
349
346
|
- **Define extraction schemas** - Use JSON Schema for reliable data collection
|
|
350
|
-
- **Leverage session
|
|
351
|
-
- **Use code-based logic** - `skipIf` and `
|
|
352
|
-
- **Create type-safe routes** - Generic types for both context and
|
|
347
|
+
- **Leverage session step** - Track conversation progress across turns
|
|
348
|
+
- **Use code-based logic** - `skipIf` and `requires` for deterministic flow
|
|
349
|
+
- **Create type-safe routes** - Generic types for both context and collected data
|
|
353
350
|
- **Handle user changes** - Always-on routing respects "I changed my mind"
|
|
354
|
-
- **Add lifecycle hooks** - Validate and enrich
|
|
355
|
-
- **Mix
|
|
351
|
+
- **Add lifecycle hooks** - Validate and enrich collected data
|
|
352
|
+
- **Mix stepful & stepless** - Use appropriate patterns for each use case
|
|
356
353
|
|
|
357
354
|
### ❌ Don'ts
|
|
358
355
|
|
|
359
|
-
- **Don't use `any` types** - Define proper interfaces for context and
|
|
360
|
-
- **Don't rely on LLM conditions** - Use code (`skipIf`) for
|
|
361
|
-
- **Don't skip session management** - Pass session
|
|
356
|
+
- **Don't use `any` types** - Define proper interfaces for context and collected data
|
|
357
|
+
- **Don't rely on LLM conditions** - Use code (`skipIf`) for step logic
|
|
358
|
+
- **Don't skip session management** - Pass session step between turns
|
|
362
359
|
- **Don't forget error handling** - Wrap agent calls in try/catch
|
|
363
360
|
- **Don't ignore type errors** - Fix TypeScript issues for reliability
|
|
364
361
|
- **Don't create fuzzy logic** - Use explicit schemas over prompt-based parsing
|