@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.
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,21 +1,21 @@
1
- # Session State & Data Management
1
+ # Session Step & Data Management
2
2
 
3
3
  ## Overview
4
4
 
5
- The `@falai/agent` framework provides **session state management** for tracking conversation progress, extracted data, and user intent across multiple turns. This enables sophisticated data-driven conversations with intelligent state progression.
5
+ The `@falai/agent` framework provides **session step management** for tracking conversation progress, collected data, and user intent across multiple turns. This enables sophisticated data-driven conversations with intelligent step progression.
6
6
 
7
7
  ---
8
8
 
9
- ## 🎯 Session State: The Foundation
9
+ ## 🎯 Session Step: The Foundation
10
10
 
11
- Session state tracks three key aspects of a conversation:
11
+ Session step tracks three key aspects of a conversation:
12
12
 
13
13
  1. **Current Route** - Which conversation flow the user is in
14
- 2. **Current State** - Where in the flow they currently are
15
- 3. **Extracted Data** - Structured data collected so far
14
+ 2. **Current Step** - Where in the flow they currently are
15
+ 3. **Collected data** - Structured data collected so far
16
16
 
17
17
  ```typescript
18
- import { createSession, SessionState } from "@falai/agent";
18
+ import { createSession, SessionStep } from "@falai/agent";
19
19
 
20
20
  // Define your data extraction type
21
21
  interface FlightData {
@@ -25,33 +25,33 @@ interface FlightData {
25
25
  cabinClass: "economy" | "business" | "first";
26
26
  }
27
27
 
28
- // Initialize session state
28
+ // Initialize session step
29
29
  let session = createSession<FlightData>();
30
30
 
31
31
  // Session starts empty
32
32
  console.log(session.currentRoute); // undefined
33
- console.log(session.currentState); // undefined
34
- console.log(session.extracted); // {}
33
+ console.log(session.currentStep); // undefined
34
+ console.log(session.data); // {}
35
35
 
36
36
  // Use in conversation
37
37
  const response = await agent.respond({ history, session });
38
38
 
39
- // Session updated with progress and extracted data
39
+ // Session updated with progress and collected data
40
40
  console.log(response.session?.currentRoute?.title); // "Book Flight"
41
- console.log(response.session?.currentState?.id); // "ask_destination"
42
- console.log(response.session?.extracted); // { destination: "Paris", ... }
41
+ console.log(response.session?.currentStep?.id); // "ask_destination"
42
+ console.log(response.session?.data); // { destination: "Paris", ... }
43
43
  ```
44
44
 
45
- **Benefits of Session State:**
45
+ **Benefits of Session Step:**
46
46
 
47
47
  - **Always-On Routing** - Users can change their mind mid-conversation
48
- - **Data Persistence** - Extracted data survives across turns
49
- - **Context Awareness** - Router sees current progress and extracted data
50
- - **State Recovery** - Resume conversations from any point
48
+ - **Data Persistence** - Collected data survives across turns
49
+ - **Context Awareness** - Router sees current progress and collected data
50
+ - **Step Recovery** - Resume conversations from any point
51
51
 
52
52
  ---
53
53
 
54
- ## 🔄 Session State Helpers
54
+ ## 🔄 Session Step Helpers
55
55
 
56
56
  ### Creating and Managing Sessions
57
57
 
@@ -59,9 +59,9 @@ console.log(response.session?.extracted); // { destination: "Paris", ... }
59
59
  import {
60
60
  createSession,
61
61
  enterRoute,
62
- enterState,
63
- mergeExtracted,
64
- type SessionState,
62
+ enterStep,
63
+ mergeData,
64
+ type SessionStep,
65
65
  } from "@falai/agent";
66
66
 
67
67
  // Create a new session
@@ -70,32 +70,32 @@ let session = createSession<FlightData>();
70
70
  // Enter a route (when routing decides to switch)
71
71
  session = enterRoute(session, "book_flight", "Book Flight");
72
72
 
73
- // Enter a state (when progressing through the flow)
74
- session = enterState(session, "ask_destination", "Ask where they want to fly");
73
+ // Enter a step (when progressing through the flow)
74
+ session = enterStep(session, "ask_destination", "Ask where they want to fly");
75
75
 
76
- // Merge extracted data (when AI extracts new information)
77
- session = mergeExtracted(session, {
76
+ // Merge collected data (when AI extracts new information)
77
+ session = mergeData(session, {
78
78
  destination: "Paris",
79
79
  departureDate: "2025-10-15",
80
80
  passengers: 2,
81
81
  });
82
82
  ```
83
83
 
84
- ### Session State Structure
84
+ ### Session Step Structure
85
85
 
86
86
  ```typescript
87
- interface SessionState<TExtracted = unknown> {
87
+ interface SessionStep<TData = unknown> {
88
88
  currentRoute?: {
89
89
  id: string;
90
90
  title: string;
91
91
  enteredAt: Date;
92
92
  };
93
- currentState?: {
93
+ currentStep?: {
94
94
  id: string;
95
95
  description?: string;
96
96
  enteredAt: Date;
97
97
  };
98
- extracted: Partial<TExtracted>; // Data collected so far
98
+ data: Partial<TData>; // Data collected so far
99
99
  routeHistory: Array<{
100
100
  routeId: string;
101
101
  routeTitle: string;
@@ -125,25 +125,23 @@ const agent = new Agent({
125
125
  await saveUserData(newContext.userId, newContext);
126
126
  },
127
127
 
128
- // NEW: Validate and enrich extracted data
129
- onExtractedUpdate: async (extracted, previousExtracted) => {
128
+ // NEW: Validate and enrich collected data
129
+ onDataUpdate: async (data, previousData) => {
130
130
  // Normalize passenger count
131
- if (extracted.passengers < 1) extracted.passengers = 1;
132
- if (extracted.passengers > 9) extracted.passengers = 9;
131
+ if (data.passengers < 1) data.passengers = 1;
132
+ if (data.passengers > 9) data.passengers = 9;
133
133
 
134
134
  // Enrich with computed fields
135
- if (extracted.destination) {
136
- extracted.destinationCode = await lookupAirportCode(
137
- extracted.destination
138
- );
135
+ if (data.destination) {
136
+ data.destinationCode = await lookupAirportCode(data.destination);
139
137
  }
140
138
 
141
139
  // Auto-trigger actions
142
- if (hasAllRequiredData(extracted)) {
143
- extracted.shouldSearchFlights = true;
140
+ if (hasAllRequires(data)) {
141
+ data.shouldSearchFlights = true;
144
142
  }
145
143
 
146
- return extracted;
144
+ return data;
147
145
  },
148
146
  },
149
147
  });
@@ -165,7 +163,7 @@ const agent = new Agent({
165
163
 
166
164
  ## 📊 Data Extraction Pipeline
167
165
 
168
- Schema-first data extraction with intelligent state progression:
166
+ Schema-first data extraction with intelligent step progression:
169
167
 
170
168
  ### 1. Define Your Data Schema
171
169
 
@@ -182,7 +180,7 @@ interface FlightData {
182
180
 
183
181
  const route = agent.createRoute<FlightData>({
184
182
  title: "Book Flight",
185
- extractionSchema: {
183
+ schema: {
186
184
  type: "object",
187
185
  properties: {
188
186
  destination: { type: "string" },
@@ -202,65 +200,62 @@ const route = agent.createRoute<FlightData>({
202
200
  });
203
201
  ```
204
202
 
205
- ### 2. Create Smart State Machines
203
+ ### 2. Create Smart Step Machines
206
204
 
207
205
  ```typescript
208
- // State with code-based logic (no fuzzy LLM conditions!)
209
- const askDestination = route.initialState.transitionTo({
210
- chatState: "Ask where they want to fly",
211
- gather: ["destination"],
212
- skipIf: (extracted) => !!extracted.destination, // Skip if already have destination
206
+ // Step with code-based logic (no fuzzy LLM conditions!)
207
+ const askDestination = route.initialStep.nextStep({
208
+ instructions: "Ask where they want to fly",
209
+ collect: ["destination"],
210
+ skipIf: (data) => !!data.destination, // Skip if already have destination
213
211
  });
214
212
 
215
- const enrichDestination = askDestination.transitionTo({
216
- toolState: lookupAirportCode, // Tool executes automatically
217
- requiredData: ["destination"], // Prerequisites
213
+ const enrichDestination = askDestination.nextStep({
214
+ tool: lookupAirportCode, // Tool executes automatically
215
+ requires: ["destination"], // Prerequisites
218
216
  });
219
217
 
220
- const askDates = enrichDestination.transitionTo({
221
- chatState: "Ask about travel dates",
222
- gather: ["departureDate"],
223
- skipIf: (extracted) => !!extracted.departureDate,
224
- requiredData: ["destination"], // Must have destination first
218
+ const askDates = enrichDestination.nextStep({
219
+ instructions: "Ask about travel dates",
220
+ collect: ["departureDate"],
221
+ skipIf: (data) => !!data.departureDate,
222
+ requires: ["destination"], // Must have destination first
225
223
  });
226
224
 
227
- const validateDate = askDates.transitionTo({
228
- toolState: parseAndValidateDate,
229
- requiredData: ["departureDate"],
225
+ const validateDate = askDates.nextStep({
226
+ tool: parseAndValidateDate,
227
+ requires: ["departureDate"],
230
228
  });
231
229
 
232
- const askPassengers = validateDate.transitionTo({
233
- chatState: "How many passengers?",
234
- gather: ["passengers"],
235
- skipIf: (extracted) => !!extracted.passengers,
230
+ const askPassengers = validateDate.nextStep({
231
+ instructions: "How many passengers?",
232
+ collect: ["passengers"],
233
+ skipIf: (data) => !!data.passengers,
236
234
  });
237
235
 
238
- const searchFlights = askPassengers.transitionTo({
239
- toolState: searchFlightAPI,
236
+ const searchFlights = askPassengers.nextStep({
237
+ tool: searchFlightAPI,
240
238
  // Triggered when shouldSearchFlights flag is set by hook
241
239
  });
242
240
  ```
243
241
 
244
- ### 3. Tools Access Extracted Data
242
+ ### 3. Tools Access Collected data
245
243
 
246
244
  ```typescript
247
245
  const searchFlights = defineTool<Context, [], void, FlightData>(
248
246
  "search_flights",
249
- async ({ context, extracted }) => {
250
- // Access extracted data directly (no LLM extraction needed!)
251
- if (!extracted.destination || !extracted.departureDate) {
247
+ async ({ context, data }) => {
248
+ // Access collected data directly (no LLM extraction needed!)
249
+ if (!data.destination || !data.departureDate) {
252
250
  return { data: undefined };
253
251
  }
254
252
 
255
- const flights = await searchFlightAPI(
256
- extracted.destination,
257
- extracted.departureDate
258
- );
253
+ const flights = await searchFlightAPI(data.destination, data.departureDate);
259
254
 
260
255
  return {
261
256
  data: undefined,
262
257
  contextUpdate: { availableFlights: flights },
263
- extractedUpdate: {
258
+ dataUpdate: {
264
259
  shouldSearchFlights: false, // Clear the flag
265
260
  },
266
261
  };
@@ -274,24 +269,22 @@ const searchFlights = defineTool<Context, [], void, FlightData>(
274
269
  const agent = new Agent({
275
270
  // ... other options
276
271
  hooks: {
277
- onExtractedUpdate: async (extracted, previous) => {
272
+ onDataUpdate: async (data, previous) => {
278
273
  // Normalize data
279
- if (extracted.passengers < 1) extracted.passengers = 1;
280
- if (extracted.passengers > 9) extracted.passengers = 9;
274
+ if (data.passengers < 1) data.passengers = 1;
275
+ if (data.passengers > 9) data.passengers = 9;
281
276
 
282
277
  // Enrich data
283
- if (extracted.destination && !extracted.destinationCode) {
284
- extracted.destinationCode = await lookupAirportCode(
285
- extracted.destination
286
- );
278
+ if (data.destination && !data.destinationCode) {
279
+ data.destinationCode = await lookupAirportCode(data.destination);
287
280
  }
288
281
 
289
282
  // Auto-trigger actions
290
- if (hasAllRequiredData(extracted) && !extracted.shouldSearchFlights) {
291
- extracted.shouldSearchFlights = true;
283
+ if (hasAllRequires(data) && !data.shouldSearchFlights) {
284
+ data.shouldSearchFlights = true;
292
285
  }
293
286
 
294
- return extracted;
287
+ return data;
295
288
  },
296
289
  },
297
290
  });
@@ -329,8 +322,8 @@ const response2 = await agent.respond({
329
322
 
330
323
  // Router understands:
331
324
  // - Current route: "Book Flight"
332
- // - Current state: "ask_passengers"
333
- // - Extracted data: { destination: "Paris", departureDate: "tomorrow", passengers: 2 }
325
+ // - Current step: "ask_passengers"
326
+ // - Collected data: { destination: "Paris", departureDate: "tomorrow", passengers: 2 }
334
327
  // - User intent: "Tokyo instead" → switches to new destination
335
328
  ```
336
329
 
@@ -456,7 +449,7 @@ const agent = new Agent({
456
449
  **Difference from `beforeRespond`:**
457
450
 
458
451
  - `contextProvider`: **Replaces** the context entirely
459
- - `beforeRespond`: **Updates** the existing context (can access previous state)
452
+ - `beforeRespond`: **Updates** the existing context (can access previous step)
460
453
 
461
454
  ---
462
455
 
@@ -579,7 +572,7 @@ async function handleUserMessage(sessionId: string, message: string) {
579
572
 
580
573
  - **Cache agent instances** across requests (context gets stale)
581
574
  - **Mutate context directly** without using `updateContext()` or `contextUpdate`
582
- - **Rely on in-memory state** for multi-turn conversations
575
+ - **Rely on in-memory step** for multi-turn conversations
583
576
  - **Forget to handle** `onContextUpdate` failures (could lose data)
584
577
  - **Mix** `context` and `contextProvider` (will throw an error)
585
578
 
package/docs/DOCS.md CHANGED
@@ -12,7 +12,7 @@ Start here if you're new to the framework:
12
12
 
13
13
  Build your first AI agent in 5 minutes with step-by-step instructions.
14
14
 
15
- **Topics:** Installation, first agent, basic routes, data extraction, session state
15
+ **Topics:** Installation, first agent, basic routes, data extraction, session step
16
16
 
17
17
  ---
18
18
 
@@ -24,7 +24,7 @@ Essential guides for understanding how the framework works:
24
24
 
25
25
  Design principles, philosophy, and how the framework works under the hood.
26
26
 
27
- **Topics:** Schema-first extraction, session state, code-based logic, state machines, deterministic IDs
27
+ **Topics:** Schema-first extraction, session step, code-based logic, step machines, deterministic IDs
28
28
 
29
29
  ### [Agent](./AGENT.md)
30
30
 
@@ -34,9 +34,9 @@ Comprehensive guide to agent configuration patterns.
34
34
 
35
35
  ### [Context Management](./CONTEXT_MANAGEMENT.md)
36
36
 
37
- Session state, lifecycle hooks, and persistent conversations.
37
+ Session step, lifecycle hooks, and persistent conversations.
38
38
 
39
- **Topics:** Session state, lifecycle hooks, context updates, multi-turn conversations, persistence patterns
39
+ **Topics:** Session step, lifecycle hooks, context updates, multi-turn conversations, persistence patterns
40
40
 
41
41
  ---
42
42
 
@@ -48,19 +48,19 @@ Deep dives into specific features:
48
48
 
49
49
  Complete guide to creating and managing conversational routes.
50
50
 
51
- **Topics:** Route creation, initial state configuration, data extraction, sequential steps, security, branching logic
51
+ **Topics:** Route creation, initial step configuration, data extraction, sequential steps, security, branching logic
52
52
 
53
- ### [States Guide](./STATES.md)
53
+ ### [Steps Guide](./STEPS.md)
54
54
 
55
- Complete guide to creating and managing states in conversational flows.
55
+ Complete guide to creating and managing steps in conversational flows.
56
56
 
57
- **Topics:** State types, transitions, data gathering, state logic, skip conditions, configuration, advanced patterns
57
+ **Topics:** Step types, transitions, data collecting, step logic, skip conditions, configuration, advanced patterns
58
58
 
59
59
  ### [API Reference](./API_REFERENCE.md)
60
60
 
61
61
  Complete API documentation for all classes, methods, and types.
62
62
 
63
- **Topics:** Agent class, Route class, State class, defineTool, providers, all APIs
63
+ **Topics:** Agent class, Route class, Step class, defineTool, providers, all APIs
64
64
 
65
65
  ### [AI Providers](./PROVIDERS.md)
66
66
 
@@ -103,7 +103,7 @@ Comprehensive guide to all 15+ production-ready examples.
103
103
  Browse the `/examples` directory for runnable code:
104
104
 
105
105
  - [Business Onboarding](../examples/business-onboarding.ts) - Complex multi-step workflows
106
- - [Travel Agent](../examples/travel-agent.ts) - Session state & data extraction
106
+ - [Travel Agent](../examples/travel-agent.ts) - Session step & data extraction
107
107
  - [Healthcare Agent](../examples/healthcare-agent.ts) - Security & validation
108
108
  - [Streaming Agent](../examples/streaming-agent.ts) - Real-time responses
109
109
  - [Prisma Persistence](../examples/prisma-persistence.ts) - Database integration
@@ -140,7 +140,7 @@ Internal guide for maintainers on publishing releases.
140
140
  - **Understand the design** → [Architecture](./ARCHITECTURE.md)
141
141
  - **Configure my agent** → [Agent](./AGENT.md)
142
142
  - **Create conversational flows** → [Routes Guide](./ROUTES.md)
143
- - **Manage states** → [States Guide](./STATES.md)
143
+ - **Manage steps** → [Steps Guide](./STEPS.md)
144
144
  - **Persist conversations** → [Persistence Guide](./PERSISTENCE.md)
145
145
  - **Add tool security** → [Domain Organization](./DOMAINS.md)
146
146
  - **See real examples** → [Examples Guide](./EXAMPLES.md)
@@ -162,13 +162,13 @@ Internal guide for maintainers on publishing releases.
162
162
  - [Context Management](./CONTEXT_MANAGEMENT.md)
163
163
  - [Getting Started](./GETTING_STARTED.md)
164
164
 
165
- **Routes & State Machines:**
165
+ **Routes & Step Machines:**
166
166
 
167
167
  - [Routes Guide](./ROUTES.md) - Complete guide to routes
168
- - [States Guide](./STATES.md) - Complete guide to states
168
+ - [Steps Guide](./STEPS.md) - Complete guide to steps
169
169
  - [API Reference - Routes](./API_REFERENCE.md#route)
170
- - [API Reference - States](./API_REFERENCE.md#state)
171
- - [Architecture - State Machines](./ARCHITECTURE.md#state-machines)
170
+ - [API Reference - Steps](./API_REFERENCE.md#step)
171
+ - [Architecture - Step Machines](./ARCHITECTURE.md#step-machines)
172
172
  - [Examples - Complex Flows](./EXAMPLES.md#-real-world-applications)
173
173
 
174
174
  **Tools & Domains:**
@@ -180,13 +180,13 @@ Internal guide for maintainers on publishing releases.
180
180
  **Data Extraction:**
181
181
 
182
182
  - [Architecture - Schema-First](./ARCHITECTURE.md#schema-first-data-extraction)
183
- - [API Reference - extractionSchema](./API_REFERENCE.md#extractionschema)
183
+ - [API Reference - schema](./API_REFERENCE.md#schema)
184
184
  - [Examples - Travel Agent](./EXAMPLES.md#-travel-agent)
185
185
 
186
- **Session State:**
186
+ **Session Step:**
187
187
 
188
188
  - [Context Management](./CONTEXT_MANAGEMENT.md)
189
- - [Architecture - Session State](./ARCHITECTURE.md#session-state-management)
189
+ - [Architecture - Session Step](./ARCHITECTURE.md#session-step-management)
190
190
  - [API Reference - createSession](./API_REFERENCE.md#createsession)
191
191
 
192
192
  **Persistence:**
package/docs/DOMAINS.md CHANGED
@@ -45,9 +45,9 @@ const route = agent.createRoute({
45
45
  // No domains specified = all tools available
46
46
  });
47
47
 
48
- route.initialState
49
- .transitionTo({ toolState: saveName }) // ✅ Works
50
- .transitionTo({ toolState: saveEmail }); // ✅ Works
48
+ route.initialStep
49
+ .nextStep({ tool: saveName }) // ✅ Works
50
+ .nextStep({ tool: saveEmail }); // ✅ Works
51
51
  ```
52
52
 
53
53
  **Result**: Everything works. All tools can execute. Simple and easy!
@@ -96,17 +96,17 @@ const adminRoute = agent.createRoute({
96
96
  });
97
97
 
98
98
  // 3️⃣ Tools execute based on route restrictions
99
- onboardingRoute.initialState
100
- .transitionTo({ toolState: agent.domain.user.saveName }) // ✅ Allowed
101
- .transitionTo({ toolState: agent.domain.payment.processPayment }); // ❌ Blocked!
99
+ onboardingRoute.initialStep
100
+ .nextStep({ tool: agent.domain.user.saveName }) // ✅ Allowed
101
+ .nextStep({ tool: agent.domain.payment.processPayment }); // ❌ Blocked!
102
102
 
103
- checkoutRoute.initialState
104
- .transitionTo({ toolState: agent.domain.payment.processPayment }) // ✅ Allowed
105
- .transitionTo({ toolState: agent.domain.user.saveName }); // ❌ Blocked!
103
+ checkoutRoute.initialStep
104
+ .nextStep({ tool: agent.domain.payment.processPayment }) // ✅ Allowed
105
+ .nextStep({ tool: agent.domain.user.saveName }); // ❌ Blocked!
106
106
 
107
- adminRoute.initialState
108
- .transitionTo({ toolState: agent.domain.user.saveName }) // ✅ Allowed
109
- .transitionTo({ toolState: agent.domain.payment.processPayment }); // ✅ Allowed
107
+ adminRoute.initialStep
108
+ .nextStep({ tool: agent.domain.user.saveName }) // ✅ Allowed
109
+ .nextStep({ tool: agent.domain.payment.processPayment }); // ✅ Allowed
110
110
  ```
111
111
 
112
112
  **Result**: Tools are restricted by route. Security and isolation guaranteed!
@@ -638,7 +638,7 @@ const route = agent.createRoute({
638
638
  title: "Checkout",
639
639
  });
640
640
 
641
- route.initialState.transitionTo({ toolState: processPayment });
641
+ route.initialStep.nextStep({ tool: processPayment });
642
642
 
643
643
  // AFTER: With domains
644
644
  const agent = new Agent({
@@ -657,8 +657,8 @@ const route = agent.createRoute({
657
657
  });
658
658
 
659
659
  // Access via domain registry
660
- route.initialState.transitionTo({
661
- toolState: agent.domain.payment.processPayment,
660
+ route.initialStep.nextStep({
661
+ tool: agent.domain.payment.processPayment,
662
662
  });
663
663
  ```
664
664
 
@@ -705,7 +705,7 @@ if (allowedDomains !== undefined && tool.domainName) {
705
705
 
706
706
  ### What Gets Enforced
707
707
 
708
- ✅ **Tools in state machine transitions** (`toolState`)
708
+ ✅ **Tools in step machine transitions** (`tool`)
709
709
  ✅ **Multiple domain access** (route can allow several domains)
710
710
  ✅ **Empty array enforcement** (`domains: []` blocks all tools)
711
711
  ✅ **Undefined = all allowed** (backward compatible)