@falai/agent 0.9.0-alpha-1 → 0.9.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 (217) hide show
  1. package/README.md +34 -22
  2. package/dist/cjs/src/core/Agent.d.ts +77 -59
  3. package/dist/cjs/src/core/Agent.d.ts.map +1 -1
  4. package/dist/cjs/src/core/Agent.js +284 -1060
  5. package/dist/cjs/src/core/Agent.js.map +1 -1
  6. package/dist/cjs/src/core/PersistenceManager.d.ts.map +1 -1
  7. package/dist/cjs/src/core/PersistenceManager.js +48 -25
  8. package/dist/cjs/src/core/PersistenceManager.js.map +1 -1
  9. package/dist/cjs/src/core/PromptComposer.d.ts +1 -1
  10. package/dist/cjs/src/core/PromptComposer.d.ts.map +1 -1
  11. package/dist/cjs/src/core/PromptComposer.js.map +1 -1
  12. package/dist/cjs/src/core/ResponseEngine.d.ts +13 -12
  13. package/dist/cjs/src/core/ResponseEngine.d.ts.map +1 -1
  14. package/dist/cjs/src/core/ResponseEngine.js +4 -4
  15. package/dist/cjs/src/core/ResponseEngine.js.map +1 -1
  16. package/dist/cjs/src/core/ResponseModal.d.ts +205 -0
  17. package/dist/cjs/src/core/ResponseModal.d.ts.map +1 -0
  18. package/dist/cjs/src/core/ResponseModal.js +1328 -0
  19. package/dist/cjs/src/core/ResponseModal.js.map +1 -0
  20. package/dist/cjs/src/core/ResponsePipeline.d.ts +66 -38
  21. package/dist/cjs/src/core/ResponsePipeline.d.ts.map +1 -1
  22. package/dist/cjs/src/core/ResponsePipeline.js +72 -4
  23. package/dist/cjs/src/core/ResponsePipeline.js.map +1 -1
  24. package/dist/cjs/src/core/Route.d.ts +24 -5
  25. package/dist/cjs/src/core/Route.d.ts.map +1 -1
  26. package/dist/cjs/src/core/Route.js +45 -1
  27. package/dist/cjs/src/core/Route.js.map +1 -1
  28. package/dist/cjs/src/core/RoutingEngine.d.ts +31 -6
  29. package/dist/cjs/src/core/RoutingEngine.d.ts.map +1 -1
  30. package/dist/cjs/src/core/RoutingEngine.js +113 -9
  31. package/dist/cjs/src/core/RoutingEngine.js.map +1 -1
  32. package/dist/cjs/src/core/SessionManager.d.ts +14 -4
  33. package/dist/cjs/src/core/SessionManager.d.ts.map +1 -1
  34. package/dist/cjs/src/core/SessionManager.js +25 -5
  35. package/dist/cjs/src/core/SessionManager.js.map +1 -1
  36. package/dist/cjs/src/core/Step.d.ts +10 -10
  37. package/dist/cjs/src/core/Step.d.ts.map +1 -1
  38. package/dist/cjs/src/core/Step.js.map +1 -1
  39. package/dist/cjs/src/core/ToolExecutor.d.ts +4 -2
  40. package/dist/cjs/src/core/ToolExecutor.d.ts.map +1 -1
  41. package/dist/cjs/src/core/ToolExecutor.js +13 -3
  42. package/dist/cjs/src/core/ToolExecutor.js.map +1 -1
  43. package/dist/cjs/src/index.d.ts +3 -1
  44. package/dist/cjs/src/index.d.ts.map +1 -1
  45. package/dist/cjs/src/index.js +7 -1
  46. package/dist/cjs/src/index.js.map +1 -1
  47. package/dist/cjs/src/types/agent.d.ts +42 -21
  48. package/dist/cjs/src/types/agent.d.ts.map +1 -1
  49. package/dist/cjs/src/types/agent.js.map +1 -1
  50. package/dist/cjs/src/types/ai.d.ts +1 -1
  51. package/dist/cjs/src/types/ai.d.ts.map +1 -1
  52. package/dist/cjs/src/types/index.d.ts +1 -1
  53. package/dist/cjs/src/types/index.d.ts.map +1 -1
  54. package/dist/cjs/src/types/index.js.map +1 -1
  55. package/dist/cjs/src/types/persistence.d.ts +0 -1
  56. package/dist/cjs/src/types/persistence.d.ts.map +1 -1
  57. package/dist/cjs/src/types/route.d.ts +22 -16
  58. package/dist/cjs/src/types/route.d.ts.map +1 -1
  59. package/dist/cjs/src/types/session.d.ts +6 -11
  60. package/dist/cjs/src/types/session.d.ts.map +1 -1
  61. package/dist/cjs/src/types/tool.d.ts +12 -6
  62. package/dist/cjs/src/types/tool.d.ts.map +1 -1
  63. package/dist/cjs/src/utils/clone.d.ts.map +1 -1
  64. package/dist/cjs/src/utils/clone.js +0 -4
  65. package/dist/cjs/src/utils/clone.js.map +1 -1
  66. package/dist/cjs/src/utils/history.d.ts +30 -1
  67. package/dist/cjs/src/utils/history.d.ts.map +1 -1
  68. package/dist/cjs/src/utils/history.js +169 -23
  69. package/dist/cjs/src/utils/history.js.map +1 -1
  70. package/dist/cjs/src/utils/index.d.ts +1 -1
  71. package/dist/cjs/src/utils/index.d.ts.map +1 -1
  72. package/dist/cjs/src/utils/index.js +5 -1
  73. package/dist/cjs/src/utils/index.js.map +1 -1
  74. package/dist/cjs/src/utils/session.d.ts +2 -2
  75. package/dist/cjs/src/utils/session.d.ts.map +1 -1
  76. package/dist/cjs/src/utils/session.js +6 -26
  77. package/dist/cjs/src/utils/session.js.map +1 -1
  78. package/dist/src/core/Agent.d.ts +77 -59
  79. package/dist/src/core/Agent.d.ts.map +1 -1
  80. package/dist/src/core/Agent.js +285 -1061
  81. package/dist/src/core/Agent.js.map +1 -1
  82. package/dist/src/core/PersistenceManager.d.ts.map +1 -1
  83. package/dist/src/core/PersistenceManager.js +48 -25
  84. package/dist/src/core/PersistenceManager.js.map +1 -1
  85. package/dist/src/core/PromptComposer.d.ts +1 -1
  86. package/dist/src/core/PromptComposer.d.ts.map +1 -1
  87. package/dist/src/core/PromptComposer.js.map +1 -1
  88. package/dist/src/core/ResponseEngine.d.ts +13 -12
  89. package/dist/src/core/ResponseEngine.d.ts.map +1 -1
  90. package/dist/src/core/ResponseEngine.js +4 -4
  91. package/dist/src/core/ResponseEngine.js.map +1 -1
  92. package/dist/src/core/ResponseModal.d.ts +205 -0
  93. package/dist/src/core/ResponseModal.d.ts.map +1 -0
  94. package/dist/src/core/ResponseModal.js +1323 -0
  95. package/dist/src/core/ResponseModal.js.map +1 -0
  96. package/dist/src/core/ResponsePipeline.d.ts +66 -38
  97. package/dist/src/core/ResponsePipeline.d.ts.map +1 -1
  98. package/dist/src/core/ResponsePipeline.js +72 -4
  99. package/dist/src/core/ResponsePipeline.js.map +1 -1
  100. package/dist/src/core/Route.d.ts +24 -5
  101. package/dist/src/core/Route.d.ts.map +1 -1
  102. package/dist/src/core/Route.js +45 -1
  103. package/dist/src/core/Route.js.map +1 -1
  104. package/dist/src/core/RoutingEngine.d.ts +31 -6
  105. package/dist/src/core/RoutingEngine.d.ts.map +1 -1
  106. package/dist/src/core/RoutingEngine.js +113 -9
  107. package/dist/src/core/RoutingEngine.js.map +1 -1
  108. package/dist/src/core/SessionManager.d.ts +14 -4
  109. package/dist/src/core/SessionManager.d.ts.map +1 -1
  110. package/dist/src/core/SessionManager.js +25 -5
  111. package/dist/src/core/SessionManager.js.map +1 -1
  112. package/dist/src/core/Step.d.ts +10 -10
  113. package/dist/src/core/Step.d.ts.map +1 -1
  114. package/dist/src/core/Step.js.map +1 -1
  115. package/dist/src/core/ToolExecutor.d.ts +4 -2
  116. package/dist/src/core/ToolExecutor.d.ts.map +1 -1
  117. package/dist/src/core/ToolExecutor.js +13 -3
  118. package/dist/src/core/ToolExecutor.js.map +1 -1
  119. package/dist/src/index.d.ts +3 -1
  120. package/dist/src/index.d.ts.map +1 -1
  121. package/dist/src/index.js +2 -1
  122. package/dist/src/index.js.map +1 -1
  123. package/dist/src/types/agent.d.ts +42 -21
  124. package/dist/src/types/agent.d.ts.map +1 -1
  125. package/dist/src/types/agent.js.map +1 -1
  126. package/dist/src/types/ai.d.ts +1 -1
  127. package/dist/src/types/ai.d.ts.map +1 -1
  128. package/dist/src/types/index.d.ts +1 -1
  129. package/dist/src/types/index.d.ts.map +1 -1
  130. package/dist/src/types/index.js.map +1 -1
  131. package/dist/src/types/persistence.d.ts +0 -1
  132. package/dist/src/types/persistence.d.ts.map +1 -1
  133. package/dist/src/types/route.d.ts +22 -16
  134. package/dist/src/types/route.d.ts.map +1 -1
  135. package/dist/src/types/session.d.ts +6 -11
  136. package/dist/src/types/session.d.ts.map +1 -1
  137. package/dist/src/types/tool.d.ts +12 -6
  138. package/dist/src/types/tool.d.ts.map +1 -1
  139. package/dist/src/utils/clone.d.ts.map +1 -1
  140. package/dist/src/utils/clone.js +0 -4
  141. package/dist/src/utils/clone.js.map +1 -1
  142. package/dist/src/utils/history.d.ts +30 -1
  143. package/dist/src/utils/history.d.ts.map +1 -1
  144. package/dist/src/utils/history.js +165 -23
  145. package/dist/src/utils/history.js.map +1 -1
  146. package/dist/src/utils/index.d.ts +1 -1
  147. package/dist/src/utils/index.d.ts.map +1 -1
  148. package/dist/src/utils/index.js +1 -1
  149. package/dist/src/utils/index.js.map +1 -1
  150. package/dist/src/utils/session.d.ts +2 -2
  151. package/dist/src/utils/session.d.ts.map +1 -1
  152. package/dist/src/utils/session.js +6 -26
  153. package/dist/src/utils/session.js.map +1 -1
  154. package/docs/README.md +5 -4
  155. package/docs/api/README.md +195 -4
  156. package/docs/api/overview.md +232 -13
  157. package/docs/core/agent/README.md +162 -17
  158. package/docs/core/agent/context-management.md +39 -15
  159. package/docs/core/agent/session-management.md +49 -16
  160. package/docs/core/ai-integration/prompt-composition.md +38 -14
  161. package/docs/core/ai-integration/response-processing.md +28 -17
  162. package/docs/core/conversation-flows/data-collection.md +103 -25
  163. package/docs/core/conversation-flows/route-dsl.md +45 -22
  164. package/docs/core/conversation-flows/routes.md +74 -18
  165. package/docs/core/conversation-flows/step-transitions.md +3 -3
  166. package/docs/core/conversation-flows/steps.md +39 -15
  167. package/docs/core/routing/intelligent-routing.md +18 -9
  168. package/docs/core/tools/tool-definition.md +8 -8
  169. package/docs/core/tools/tool-execution.md +26 -26
  170. package/docs/core/tools/tool-scoping.md +5 -5
  171. package/docs/guides/getting-started/README.md +54 -32
  172. package/docs/guides/migration/README.md +72 -0
  173. package/docs/guides/migration/response-modal-refactor.md +518 -0
  174. package/examples/advanced-patterns/knowledge-based-agent.ts +37 -28
  175. package/examples/advanced-patterns/persistent-onboarding.ts +70 -41
  176. package/examples/advanced-patterns/route-lifecycle-hooks.ts +28 -2
  177. package/examples/advanced-patterns/streaming-responses.ts +197 -119
  178. package/examples/ai-providers/anthropic-integration.ts +40 -33
  179. package/examples/ai-providers/openai-integration.ts +25 -25
  180. package/examples/conversation-flows/completion-transitions.ts +36 -32
  181. package/examples/core-concepts/basic-agent.ts +76 -78
  182. package/examples/core-concepts/modern-streaming-api.ts +309 -0
  183. package/examples/core-concepts/schema-driven-extraction.ts +20 -16
  184. package/examples/core-concepts/session-management.ts +65 -53
  185. package/examples/integrations/database-integration.ts +49 -34
  186. package/examples/integrations/healthcare-integration.ts +96 -91
  187. package/examples/integrations/search-integration.ts +79 -82
  188. package/examples/integrations/server-session-management.ts +25 -17
  189. package/examples/persistence/database-persistence.ts +61 -45
  190. package/examples/persistence/memory-sessions.ts +52 -63
  191. package/examples/persistence/redis-persistence.ts +81 -95
  192. package/examples/tools/basic-tools.ts +73 -62
  193. package/examples/tools/data-enrichment-tools.ts +52 -44
  194. package/package.json +1 -1
  195. package/src/core/Agent.ts +396 -1499
  196. package/src/core/PersistenceManager.ts +51 -27
  197. package/src/core/PromptComposer.ts +1 -1
  198. package/src/core/ResponseEngine.ts +21 -19
  199. package/src/core/ResponseModal.ts +1722 -0
  200. package/src/core/ResponsePipeline.ts +175 -60
  201. package/src/core/Route.ts +58 -6
  202. package/src/core/RoutingEngine.ts +174 -27
  203. package/src/core/SessionManager.ts +32 -8
  204. package/src/core/Step.ts +20 -12
  205. package/src/core/ToolExecutor.ts +19 -5
  206. package/src/index.ts +11 -0
  207. package/src/types/agent.ts +47 -23
  208. package/src/types/ai.ts +1 -1
  209. package/src/types/index.ts +2 -0
  210. package/src/types/persistence.ts +0 -1
  211. package/src/types/route.ts +22 -16
  212. package/src/types/session.ts +6 -12
  213. package/src/types/tool.ts +15 -9
  214. package/src/utils/clone.ts +6 -8
  215. package/src/utils/history.ts +190 -27
  216. package/src/utils/index.ts +4 -0
  217. package/src/utils/session.ts +6 -31
@@ -18,7 +18,7 @@ Tools are created as objects implementing the `Tool` interface:
18
18
  ```typescript
19
19
  import { Tool } from "@falai/agent";
20
20
 
21
- const weatherTool: Tool<unknown, [], string, WeatherData> = {
21
+ const weatherTool: Tool<unknown, WeatherData, [], string> = {
22
22
  id: "get_weather",
23
23
  name: "Weather Forecast", // Human-readable name shown to AI models
24
24
  description: "Get current weather and forecast for a location",
@@ -48,7 +48,7 @@ const weatherTool: Tool<unknown, [], string, WeatherData> = {
48
48
  The optional `name` field provides a human-readable name for the tool that is displayed to AI models. When provided, this name takes precedence over the `id` field in AI provider interactions:
49
49
 
50
50
  ```typescript
51
- const calculatorTool: Tool<unknown, [], string, CalcData> = {
51
+ const calculatorTool: Tool<unknown, CalcData, [], string> = {
52
52
  id: "math_calculator", // Internal identifier
53
53
  name: "Math Calculator", // Display name for AI models
54
54
  description: "Perform mathematical calculations",
@@ -68,7 +68,7 @@ const calculatorTool: Tool<unknown, [], string, CalcData> = {
68
68
  Tool parameters are defined using JSON Schema:
69
69
 
70
70
  ```typescript
71
- const searchTool: Tool<unknown, [], string, SearchData> = {
71
+ const searchTool: Tool<unknown, SearchData, [], string> = {
72
72
  id: "web_search",
73
73
  name: "Web Search Engine",
74
74
  description: "Search the web for information",
@@ -110,7 +110,7 @@ Tools receive execution context including:
110
110
  - **Route information** - Current route and step details
111
111
 
112
112
  ```typescript
113
- const userProfileTool: Tool<unknown, [], string, UserData> = {
113
+ const userProfileTool: Tool<unknown, UserData, [], string> = {
114
114
  id: "get_user_profile",
115
115
  description: "Retrieve user profile information",
116
116
  parameters: {
@@ -159,7 +159,7 @@ interface ToolResult {
159
159
  Tools can modify conversation context:
160
160
 
161
161
  ```typescript
162
- const locationTool: Tool<unknown, [], string, LocationData> = {
162
+ const locationTool: Tool<unknown, LocationData, [], string> = {
163
163
  id: "set_location",
164
164
  description: "Update the user's location in context",
165
165
  parameters: {
@@ -187,7 +187,7 @@ const locationTool: Tool<unknown, [], string, LocationData> = {
187
187
  Tools can update session data collected during conversation:
188
188
 
189
189
  ```typescript
190
- const validationTool: Tool<unknown, [], string, BookingData> = {
190
+ const validationTool: Tool<unknown, BookingData, [], string> = {
191
191
  id: "validate_booking",
192
192
  description: "Validate booking information and update session data",
193
193
  parameters: {
@@ -223,7 +223,7 @@ const validationTool: Tool<unknown, [], string, BookingData> = {
223
223
  Tools should handle errors gracefully:
224
224
 
225
225
  ```typescript
226
- const apiTool: Tool<unknown, [], string, ApiData> = {
226
+ const apiTool: Tool<unknown, ApiData, [], string> = {
227
227
  id: "call_external_api",
228
228
  description: "Call an external API endpoint",
229
229
  parameters: {
@@ -303,7 +303,7 @@ When multiple tools with the same name exist, priority is:
303
303
  Tools support async operations and Promises:
304
304
 
305
305
  ```typescript
306
- const asyncTool: Tool<unknown, [], string, ProcessingData> = {
306
+ const asyncTool: Tool<unknown, ProcessingData, [], string> = {
307
307
  id: "process_data",
308
308
  description: "Process data asynchronously with heavy computation",
309
309
  parameters: {
@@ -17,7 +17,7 @@ The tool execution system provides:
17
17
  ### Basic Tool Structure
18
18
 
19
19
  ```typescript
20
- interface Tool<TContext, TArgs extends unknown[], TResult, TData> {
20
+ interface Tool<TContext, TData, TArgs extends unknown[], TResult> {
21
21
  id: string;
22
22
  name?: string; // Human-readable name shown to AI models
23
23
  description: string;
@@ -32,7 +32,7 @@ interface Tool<TContext, TArgs extends unknown[], TResult, TData> {
32
32
  import { Tool } from "@falai/agent";
33
33
 
34
34
  // Simple data retrieval tool
35
- const getWeather: Tool<unknown, [], string, WeatherData> = {
35
+ const getWeather: Tool<unknown, WeatherData, [], string> = {
36
36
  id: "get_weather",
37
37
  name: "Weather Checker",
38
38
  description: "Get current weather for a location",
@@ -56,7 +56,7 @@ const getWeather: Tool<unknown, [], string, WeatherData> = {
56
56
  };
57
57
 
58
58
  // Data modification tool
59
- const updateUserProfile: Tool<unknown, [], string, ProfileData> = {
59
+ const updateUserProfile: Tool<unknown, ProfileData, [], string> = {
60
60
  id: "update_profile",
61
61
  name: "Profile Updater",
62
62
  description: "Update user profile information",
@@ -136,9 +136,9 @@ Tools can modify agent context:
136
136
  ```typescript
137
137
  const locationTracker: Tool<
138
138
  { currentLocation?: string; locationHistory?: string[] },
139
+ { location: string },
139
140
  [],
140
- string,
141
- { location: string }
141
+ string
142
142
  > = {
143
143
  id: "track_location",
144
144
  description: "Track and update location information",
@@ -169,9 +169,9 @@ Tools can access current context:
169
169
  ```typescript
170
170
  const contextualTool: Tool<
171
171
  { userName?: string; currentLocation?: string },
172
+ {},
172
173
  [],
173
- string,
174
- {}
174
+ string
175
175
  > = {
176
176
  id: "personalized_greeting",
177
177
  description: "Generate personalized greeting based on context",
@@ -196,7 +196,7 @@ const contextualTool: Tool<
196
196
  Tools can modify session-collected data:
197
197
 
198
198
  ```typescript
199
- const dataEnrichmentTool: Tool<{}, [], string, { email?: string }> = {
199
+ const dataEnrichmentTool: Tool<{}, { email?: string }, [], string> = {
200
200
  id: "enrich_user_data",
201
201
  description: "Enrich user profile with additional information",
202
202
  handler: async ({ data }) => {
@@ -221,7 +221,7 @@ const dataEnrichmentTool: Tool<{}, [], string, { email?: string }> = {
221
221
  ### Validation Integration
222
222
 
223
223
  ```typescript
224
- const validatingTool: Tool<{}, [], string, any> = {
224
+ const validatingTool: Tool<{}, any, [], string> = {
225
225
  id: "validate_and_save",
226
226
  description: "Validate collected data and save to database",
227
227
  handler: async ({ data }) => {
@@ -362,9 +362,9 @@ while (hasToolCalls && toolLoopCount < MAX_TOOL_LOOPS) {
362
362
  ```typescript
363
363
  const robustTool: Tool<
364
364
  { lastApiCall?: string; errorCount?: number },
365
+ { endpoint: string },
365
366
  [],
366
- string,
367
- { endpoint: string }
367
+ string
368
368
  > = {
369
369
  id: "api_call",
370
370
  description: "Make external API call with error handling",
@@ -400,9 +400,9 @@ const robustTool: Tool<
400
400
  ```typescript
401
401
  const fallbackTool: Tool<
402
402
  { searchFallbackUsed?: boolean },
403
+ { query: string },
403
404
  [],
404
- string,
405
- { query: string }
405
+ string
406
406
  > = {
407
407
  id: "fallback_search",
408
408
  description: "Search with automatic fallback mechanisms",
@@ -452,9 +452,9 @@ let toolState = { conversationId: null };
452
452
 
453
453
  const conversationalTool: Tool<
454
454
  { conversationState?: any; lastMessage?: string },
455
+ { message: string },
455
456
  [],
456
- string,
457
- { message: string }
457
+ string
458
458
  > = {
459
459
  id: "continue_conversation",
460
460
  description: "Continue multi-turn conversation with state management",
@@ -493,9 +493,9 @@ Tools that set up data for other tools:
493
493
  ```typescript
494
494
  const setupTool: Tool<
495
495
  { activeWorkflowId?: string; workflowType?: string; workflowStep?: number },
496
+ { workflowType: string },
496
497
  [],
497
- string,
498
- { workflowType: string }
498
+ string
499
499
  > = {
500
500
  id: "setup_workflow",
501
501
  description: "Initialize a new workflow process",
@@ -526,9 +526,9 @@ const setupTool: Tool<
526
526
 
527
527
  const stepTool: Tool<
528
528
  { activeWorkflowId?: string; workflowStep?: number; lastStepResult?: any },
529
+ {},
529
530
  [],
530
- string,
531
- {}
531
+ string
532
532
  > = {
533
533
  id: "execute_workflow_step",
534
534
  description: "Execute the next step in active workflow",
@@ -559,7 +559,7 @@ const stepTool: Tool<
559
559
 
560
560
  ```typescript
561
561
  // Cache expensive operations
562
- const cachedTool: Tool<{ lastCacheHit?: boolean }, [], any, { key: string }> = {
562
+ const cachedTool: Tool<{ lastCacheHit?: boolean }, { key: string }, [], any> = {
563
563
  id: "cached_data_lookup",
564
564
  description: "Lookup data with caching for performance",
565
565
  parameters: {
@@ -592,9 +592,9 @@ const cachedTool: Tool<{ lastCacheHit?: boolean }, [], any, { key: string }> = {
592
592
  ```typescript
593
593
  const batchTool: Tool<
594
594
  {},
595
+ { items: string[]; processedItems?: any[]; batchCompletedAt?: string },
595
596
  [],
596
- string,
597
- { items: string[]; processedItems?: any[]; batchCompletedAt?: string }
597
+ string
598
598
  > = {
599
599
  id: "batch_process",
600
600
  description: "Process multiple items in a single batch operation",
@@ -629,7 +629,7 @@ const batchTool: Tool<
629
629
  ### Tool Permissions
630
630
 
631
631
  ```typescript
632
- const secureTool: Tool<{ userRole?: string }, [], any, { action: string }> = {
632
+ const secureTool: Tool<{ userRole?: string }, { action: string }, [], any> = {
633
633
  id: "admin_action",
634
634
  description: "Perform administrative actions with permission checks",
635
635
  parameters: {
@@ -662,9 +662,9 @@ const secureTool: Tool<{ userRole?: string }, [], any, { action: string }> = {
662
662
  ```typescript
663
663
  const validatedTool: Tool<
664
664
  { userId?: string; userRole?: string },
665
+ { userId: string; updates: any },
665
666
  [],
666
- any,
667
- { userId: string; updates: any }
667
+ any
668
668
  > = {
669
669
  id: "user_update",
670
670
  description: "Update user data with validation and permission checks",
@@ -717,7 +717,7 @@ const agent = new Agent({
717
717
  ### Performance Monitoring
718
718
 
719
719
  ```typescript
720
- const monitoredTool: Tool<{}, [], any, { args: any }> = {
720
+ const monitoredTool: Tool<{}, { args: any }, [], any> = {
721
721
  id: "monitored_operation",
722
722
  description: "Execute operation with performance monitoring",
723
723
  parameters: {
@@ -214,7 +214,7 @@ const secureTool = {
214
214
  ```typescript
215
215
  import { Tool } from "@falai/agent";
216
216
 
217
- const contextSecureTool: Tool<SecureContext, [], UserData> = {
217
+ const contextSecureTool: Tool<SecureContext, UserData, [], any> = {
218
218
  id: "user_data_access",
219
219
  description: "Access user data with security checks",
220
220
  parameters: {
@@ -415,9 +415,9 @@ class ToolRegistry {
415
415
  ```typescript
416
416
  const multiTenantTool: Tool<
417
417
  { tenantId: string },
418
+ { query: string },
418
419
  [],
419
- string,
420
- { query: string }
420
+ string
421
421
  > = {
422
422
  id: "tenant_search",
423
423
  description: "Search within tenant's data scope",
@@ -472,7 +472,7 @@ const timeSensitiveTool = {
472
472
  ### Usage-Based Limiting
473
473
 
474
474
  ```typescript
475
- const limitedTool: Tool<{ userId: string }, [args: any], string, any> = {
475
+ const limitedTool: Tool<{ userId: string }, any, [args: any], string> = {
476
476
  id: "premium_feature",
477
477
  description: "Execute premium feature with usage limits",
478
478
  parameters: {
@@ -528,7 +528,7 @@ const agent = new Agent({
528
528
  ### Access Audit Logging
529
529
 
530
530
  ```typescript
531
- const auditedTool: Tool<{ userId: string }, [args: any], string, any> = {
531
+ const auditedTool: Tool<{ userId: string }, any, [args: any], string> = {
532
532
  id: "sensitive_operation",
533
533
  description: "Perform sensitive operation with audit logging",
534
534
  parameters: {
@@ -128,7 +128,7 @@ interface BookingData {
128
128
  }
129
129
  ```
130
130
 
131
- ### Create a Schema-Driven Route
131
+ ### Create an Agent with Centralized Data Schema
132
132
 
133
133
  ```typescript
134
134
  import { Agent, GeminiProvider, type Tool } from "@falai/agent";
@@ -154,53 +154,66 @@ const checkAvailability: Tool<{}, [], string, BookingData> = {
154
154
  },
155
155
  };
156
156
 
157
- // Create agent
158
- const agent = new Agent({
157
+ // Create agent with centralized data schema
158
+ const agent = new Agent<{}, BookingData>({
159
159
  name: "TravelAgent",
160
160
  provider: new GeminiProvider({
161
161
  apiKey: process.env.GEMINI_API_KEY!,
162
162
  }),
163
- });
164
-
165
- // Data collection schema
166
- const bookingSchema = {
167
- type: "object",
168
- properties: {
169
- destination: { type: "string", description: "Travel destination" },
170
- travelDate: { type: "string", description: "Travel date" },
171
- travelers: { type: "number", minimum: 1, maximum: 10 },
172
- budget: { type: "number", description: "Budget in USD" },
163
+
164
+ // Agent-level schema defines all possible data fields
165
+ schema: {
166
+ type: "object",
167
+ properties: {
168
+ destination: { type: "string", description: "Travel destination" },
169
+ travelDate: { type: "string", description: "Travel date" },
170
+ travelers: { type: "number", minimum: 1, maximum: 10 },
171
+ budget: { type: "number", description: "Budget in USD" },
172
+ },
173
+ required: ["destination", "travelers"],
173
174
  },
174
- required: ["destination", "travelers"],
175
- } as const;
175
+
176
+ // Agent-level tools available to all routes
177
+ tools: [checkAvailability],
178
+
179
+ // Agent-level data validation and enrichment
180
+ hooks: {
181
+ onDataUpdate: async (data, previousData) => {
182
+ // Auto-set budget range based on travelers
183
+ if (data.travelers && !data.budget) {
184
+ data.budget = data.travelers * 500; // Default $500 per person
185
+ }
186
+ return data;
187
+ }
188
+ }
189
+ });
176
190
 
177
- // Create route with schema
178
- const bookingRoute = agent.createRoute<BookingData>({
191
+ // Routes specify required fields instead of schemas
192
+ const bookingRoute = agent.createRoute({
179
193
  title: "Travel Booking",
180
194
  description: "Help users book travel",
181
- schema: bookingSchema,
182
195
  conditions: ["User wants to book travel"],
196
+ requiredFields: ["destination", "travelDate", "travelers"], // Required for completion
197
+ optionalFields: ["budget"], // Nice to have but not required
198
+
183
199
  initialStep: {
184
200
  prompt: "I'd love to help you book a trip! Where would you like to go?",
185
201
  collect: ["destination"],
186
202
  },
187
203
  });
188
204
 
189
- // Add tool to route
190
- bookingRoute.createTool(checkAvailability);
191
-
192
- // Build conversation flow
205
+ // Build conversation flow with agent-level data awareness
193
206
  const askDate = bookingRoute.initialStep.nextStep({
194
207
  prompt: "When would you like to travel?",
195
208
  collect: ["travelDate"],
196
- requires: ["destination"],
197
- skipIf: (data) => !!data.travelDate,
209
+ requires: ["destination"], // Must have destination from agent data
210
+ skipIf: (data) => !!data.travelDate, // Skip if already collected
198
211
  });
199
212
 
200
213
  const askTravelers = askDate.nextStep({
201
214
  prompt: "How many people are traveling?",
202
215
  collect: ["travelers"],
203
- requires: ["destination"],
216
+ requires: ["destination"], // Prerequisites from agent data
204
217
  skipIf: (data) => data.travelers !== undefined,
205
218
  });
206
219
 
@@ -213,22 +226,27 @@ const askBudget = askTravelers.nextStep({
213
226
 
214
227
  const checkAndBook = askBudget.nextStep({
215
228
  prompt: "Let me check availability for your trip.",
216
- tool: checkAvailability,
217
- requires: ["destination", "travelers"],
229
+ tool: checkAvailability, // Tool accesses complete agent data
230
+ requires: ["destination", "travelers"], // Minimum data needed
218
231
  });
219
232
  ```
220
233
 
221
- ### Test the Data-Driven Agent
234
+ ### Test the Agent-Level Data Collection
222
235
 
223
236
  ```typescript
224
237
  async function testBookingAgent() {
225
- // Create agent with automatic session management
226
- const sessionAgent = new Agent({
238
+ // Create agent with automatic session management and agent-level schema
239
+ const sessionAgent = new Agent<{}, BookingData>({
227
240
  name: "TravelAgent",
228
241
  provider: new GeminiProvider({
229
242
  apiKey: process.env.GEMINI_API_KEY!,
230
243
  }),
231
244
  sessionId: "user-alice", // Automatically manages this session
245
+
246
+ // Same agent-level schema and configuration
247
+ schema: agent.schema,
248
+ tools: agent.tools,
249
+ hooks: agent.hooks
232
250
  });
233
251
 
234
252
  // Copy the route to the session agent
@@ -238,13 +256,17 @@ async function testBookingAgent() {
238
256
  const response1 = await sessionAgent.respond("I want to go to Paris");
239
257
 
240
258
  console.log("Bot:", response1.message);
241
- console.log("Collected:", sessionAgent.session.getData<BookingData>());
259
+ console.log("Agent data:", sessionAgent.getCollectedData()); // Agent-level data access
242
260
 
243
261
  // User provides more details - session automatically maintained
244
262
  const response2 = await sessionAgent.respond("Next Friday, 2 people, $2000 budget");
245
263
 
246
264
  console.log("Bot:", response2.message);
247
- console.log("Final data:", sessionAgent.session.getData<BookingData>());
265
+ console.log("Final agent data:", sessionAgent.getCollectedData());
266
+
267
+ // Check route completion
268
+ console.log("Route complete:", bookingRoute.isComplete(sessionAgent.getCollectedData()));
269
+ console.log("Progress:", Math.round(bookingRoute.getCompletionProgress(sessionAgent.getCollectedData()) * 100) + "%");
248
270
  }
249
271
 
250
272
  testBookingAgent();
@@ -0,0 +1,72 @@
1
+ # Migration Guides
2
+
3
+ This directory contains migration guides for major changes and updates to the `@falai/agent` framework.
4
+
5
+ ## Available Migration Guides
6
+
7
+ ### [ResponseModal Refactor Migration Guide](./response-modal-refactor.md)
8
+
9
+ **Latest Update** - Comprehensive guide for migrating to the new ResponseModal architecture.
10
+
11
+ **What's New:**
12
+ - 🚀 **Modern Streaming API**: Simple `agent.stream('message')` interface
13
+ - 🏗️ **Better Architecture**: Separated response logic from Agent class
14
+ - 🔄 **Full Backward Compatibility**: All existing code continues to work
15
+ - ⚡ **Performance Improvements**: Unified response logic and optimizations
16
+
17
+ **Key Benefits:**
18
+ - Automatic session management with `stream()` API
19
+ - Simplified streaming interface compared to `respondStream()`
20
+ - Better error handling with `ResponseGenerationError`
21
+ - Improved maintainability and testability
22
+
23
+ **Migration Status:**
24
+ - ✅ **Backward Compatible**: No breaking changes
25
+ - ✅ **Gradual Migration**: Adopt new APIs at your own pace
26
+ - ✅ **Production Ready**: New APIs are fully tested and stable
27
+
28
+ ---
29
+
30
+ ## Migration Philosophy
31
+
32
+ Our migration approach prioritizes:
33
+
34
+ 1. **🔄 Backward Compatibility**: Existing code continues to work without changes
35
+ 2. **📈 Gradual Adoption**: New features can be adopted incrementally
36
+ 3. **📚 Clear Documentation**: Comprehensive guides with examples
37
+ 4. **🛠️ Developer Experience**: Improved APIs that are easier to use
38
+ 5. **⚡ Performance**: Better performance without breaking existing functionality
39
+
40
+ ## Getting Help
41
+
42
+ - **📖 Documentation**: Each migration guide includes detailed examples and comparisons
43
+ - **💡 Examples**: Check the [examples directory](../../../examples/) for updated code samples
44
+ - **🐛 Issues**: Report migration issues on [GitHub Issues](https://github.com/falai-dev/agent/issues)
45
+ - **💬 Discussions**: Ask questions in [GitHub Discussions](https://github.com/falai-dev/agent/discussions)
46
+
47
+ ## Best Practices
48
+
49
+ ### Before Migrating
50
+
51
+ 1. **Read the migration guide** thoroughly
52
+ 2. **Test in development** before applying to production
53
+ 3. **Review examples** to understand new patterns
54
+ 4. **Check for breaking changes** (though we avoid them when possible)
55
+
56
+ ### During Migration
57
+
58
+ 1. **Migrate gradually** - don't change everything at once
59
+ 2. **Keep existing code working** while adopting new APIs
60
+ 3. **Test thoroughly** after each migration step
61
+ 4. **Monitor performance** to ensure improvements
62
+
63
+ ### After Migration
64
+
65
+ 1. **Update documentation** to reflect new patterns
66
+ 2. **Train team members** on new APIs and best practices
67
+ 3. **Monitor for issues** and report any problems
68
+ 4. **Share feedback** to help improve future migrations
69
+
70
+ ---
71
+
72
+ **Stay Updated**: Watch the repository for new migration guides and updates.