@falai/agent 0.9.0-alpha-1 → 0.9.0-alpha-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/README.md +34 -22
  2. package/dist/cjs/src/core/Agent.d.ts +52 -24
  3. package/dist/cjs/src/core/Agent.d.ts.map +1 -1
  4. package/dist/cjs/src/core/Agent.js +266 -39
  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/ResponsePipeline.d.ts +66 -38
  17. package/dist/cjs/src/core/ResponsePipeline.d.ts.map +1 -1
  18. package/dist/cjs/src/core/ResponsePipeline.js +71 -3
  19. package/dist/cjs/src/core/ResponsePipeline.js.map +1 -1
  20. package/dist/cjs/src/core/Route.d.ts +24 -5
  21. package/dist/cjs/src/core/Route.d.ts.map +1 -1
  22. package/dist/cjs/src/core/Route.js +45 -1
  23. package/dist/cjs/src/core/Route.js.map +1 -1
  24. package/dist/cjs/src/core/RoutingEngine.d.ts +31 -6
  25. package/dist/cjs/src/core/RoutingEngine.d.ts.map +1 -1
  26. package/dist/cjs/src/core/RoutingEngine.js +113 -9
  27. package/dist/cjs/src/core/RoutingEngine.js.map +1 -1
  28. package/dist/cjs/src/core/SessionManager.d.ts +14 -4
  29. package/dist/cjs/src/core/SessionManager.d.ts.map +1 -1
  30. package/dist/cjs/src/core/SessionManager.js +25 -5
  31. package/dist/cjs/src/core/SessionManager.js.map +1 -1
  32. package/dist/cjs/src/core/Step.d.ts +10 -10
  33. package/dist/cjs/src/core/Step.d.ts.map +1 -1
  34. package/dist/cjs/src/core/Step.js.map +1 -1
  35. package/dist/cjs/src/core/ToolExecutor.d.ts +4 -2
  36. package/dist/cjs/src/core/ToolExecutor.d.ts.map +1 -1
  37. package/dist/cjs/src/core/ToolExecutor.js +13 -3
  38. package/dist/cjs/src/core/ToolExecutor.js.map +1 -1
  39. package/dist/cjs/src/types/agent.d.ts +41 -21
  40. package/dist/cjs/src/types/agent.d.ts.map +1 -1
  41. package/dist/cjs/src/types/agent.js.map +1 -1
  42. package/dist/cjs/src/types/index.d.ts +1 -1
  43. package/dist/cjs/src/types/index.d.ts.map +1 -1
  44. package/dist/cjs/src/types/index.js.map +1 -1
  45. package/dist/cjs/src/types/persistence.d.ts +0 -1
  46. package/dist/cjs/src/types/persistence.d.ts.map +1 -1
  47. package/dist/cjs/src/types/route.d.ts +22 -16
  48. package/dist/cjs/src/types/route.d.ts.map +1 -1
  49. package/dist/cjs/src/types/session.d.ts +6 -11
  50. package/dist/cjs/src/types/session.d.ts.map +1 -1
  51. package/dist/cjs/src/types/tool.d.ts +12 -6
  52. package/dist/cjs/src/types/tool.d.ts.map +1 -1
  53. package/dist/cjs/src/utils/session.d.ts +2 -2
  54. package/dist/cjs/src/utils/session.d.ts.map +1 -1
  55. package/dist/cjs/src/utils/session.js +6 -26
  56. package/dist/cjs/src/utils/session.js.map +1 -1
  57. package/dist/src/core/Agent.d.ts +52 -24
  58. package/dist/src/core/Agent.d.ts.map +1 -1
  59. package/dist/src/core/Agent.js +266 -39
  60. package/dist/src/core/Agent.js.map +1 -1
  61. package/dist/src/core/PersistenceManager.d.ts.map +1 -1
  62. package/dist/src/core/PersistenceManager.js +48 -25
  63. package/dist/src/core/PersistenceManager.js.map +1 -1
  64. package/dist/src/core/PromptComposer.d.ts +1 -1
  65. package/dist/src/core/PromptComposer.d.ts.map +1 -1
  66. package/dist/src/core/PromptComposer.js.map +1 -1
  67. package/dist/src/core/ResponseEngine.d.ts +13 -12
  68. package/dist/src/core/ResponseEngine.d.ts.map +1 -1
  69. package/dist/src/core/ResponseEngine.js +4 -4
  70. package/dist/src/core/ResponseEngine.js.map +1 -1
  71. package/dist/src/core/ResponsePipeline.d.ts +66 -38
  72. package/dist/src/core/ResponsePipeline.d.ts.map +1 -1
  73. package/dist/src/core/ResponsePipeline.js +71 -3
  74. package/dist/src/core/ResponsePipeline.js.map +1 -1
  75. package/dist/src/core/Route.d.ts +24 -5
  76. package/dist/src/core/Route.d.ts.map +1 -1
  77. package/dist/src/core/Route.js +45 -1
  78. package/dist/src/core/Route.js.map +1 -1
  79. package/dist/src/core/RoutingEngine.d.ts +31 -6
  80. package/dist/src/core/RoutingEngine.d.ts.map +1 -1
  81. package/dist/src/core/RoutingEngine.js +113 -9
  82. package/dist/src/core/RoutingEngine.js.map +1 -1
  83. package/dist/src/core/SessionManager.d.ts +14 -4
  84. package/dist/src/core/SessionManager.d.ts.map +1 -1
  85. package/dist/src/core/SessionManager.js +25 -5
  86. package/dist/src/core/SessionManager.js.map +1 -1
  87. package/dist/src/core/Step.d.ts +10 -10
  88. package/dist/src/core/Step.d.ts.map +1 -1
  89. package/dist/src/core/Step.js.map +1 -1
  90. package/dist/src/core/ToolExecutor.d.ts +4 -2
  91. package/dist/src/core/ToolExecutor.d.ts.map +1 -1
  92. package/dist/src/core/ToolExecutor.js +13 -3
  93. package/dist/src/core/ToolExecutor.js.map +1 -1
  94. package/dist/src/types/agent.d.ts +41 -21
  95. package/dist/src/types/agent.d.ts.map +1 -1
  96. package/dist/src/types/agent.js.map +1 -1
  97. package/dist/src/types/index.d.ts +1 -1
  98. package/dist/src/types/index.d.ts.map +1 -1
  99. package/dist/src/types/index.js.map +1 -1
  100. package/dist/src/types/persistence.d.ts +0 -1
  101. package/dist/src/types/persistence.d.ts.map +1 -1
  102. package/dist/src/types/route.d.ts +22 -16
  103. package/dist/src/types/route.d.ts.map +1 -1
  104. package/dist/src/types/session.d.ts +6 -11
  105. package/dist/src/types/session.d.ts.map +1 -1
  106. package/dist/src/types/tool.d.ts +12 -6
  107. package/dist/src/types/tool.d.ts.map +1 -1
  108. package/dist/src/utils/session.d.ts +2 -2
  109. package/dist/src/utils/session.d.ts.map +1 -1
  110. package/dist/src/utils/session.js +6 -26
  111. package/dist/src/utils/session.js.map +1 -1
  112. package/docs/README.md +3 -3
  113. package/docs/api/README.md +35 -4
  114. package/docs/api/overview.md +166 -12
  115. package/docs/core/agent/README.md +162 -17
  116. package/docs/core/agent/context-management.md +39 -15
  117. package/docs/core/agent/session-management.md +49 -16
  118. package/docs/core/ai-integration/prompt-composition.md +38 -14
  119. package/docs/core/ai-integration/response-processing.md +28 -17
  120. package/docs/core/conversation-flows/data-collection.md +103 -25
  121. package/docs/core/conversation-flows/route-dsl.md +45 -22
  122. package/docs/core/conversation-flows/routes.md +74 -18
  123. package/docs/core/conversation-flows/step-transitions.md +3 -3
  124. package/docs/core/conversation-flows/steps.md +39 -15
  125. package/docs/core/routing/intelligent-routing.md +18 -9
  126. package/docs/core/tools/tool-definition.md +8 -8
  127. package/docs/core/tools/tool-execution.md +26 -26
  128. package/docs/core/tools/tool-scoping.md +5 -5
  129. package/docs/guides/getting-started/README.md +54 -32
  130. package/examples/advanced-patterns/knowledge-based-agent.ts +37 -28
  131. package/examples/advanced-patterns/persistent-onboarding.ts +70 -41
  132. package/examples/advanced-patterns/route-lifecycle-hooks.ts +28 -2
  133. package/examples/advanced-patterns/streaming-responses.ts +28 -23
  134. package/examples/ai-providers/anthropic-integration.ts +40 -33
  135. package/examples/ai-providers/openai-integration.ts +25 -25
  136. package/examples/conversation-flows/completion-transitions.ts +36 -32
  137. package/examples/core-concepts/basic-agent.ts +76 -78
  138. package/examples/core-concepts/schema-driven-extraction.ts +20 -16
  139. package/examples/core-concepts/session-management.ts +65 -53
  140. package/examples/integrations/database-integration.ts +49 -34
  141. package/examples/integrations/healthcare-integration.ts +96 -91
  142. package/examples/integrations/search-integration.ts +79 -82
  143. package/examples/integrations/server-session-management.ts +25 -17
  144. package/examples/persistence/database-persistence.ts +61 -45
  145. package/examples/persistence/memory-sessions.ts +52 -63
  146. package/examples/persistence/redis-persistence.ts +81 -95
  147. package/examples/tools/basic-tools.ts +73 -62
  148. package/examples/tools/data-enrichment-tools.ts +52 -44
  149. package/package.json +1 -1
  150. package/src/core/Agent.ts +418 -128
  151. package/src/core/PersistenceManager.ts +51 -27
  152. package/src/core/PromptComposer.ts +1 -1
  153. package/src/core/ResponseEngine.ts +21 -19
  154. package/src/core/ResponsePipeline.ts +174 -59
  155. package/src/core/Route.ts +58 -6
  156. package/src/core/RoutingEngine.ts +174 -27
  157. package/src/core/SessionManager.ts +32 -8
  158. package/src/core/Step.ts +20 -12
  159. package/src/core/ToolExecutor.ts +19 -5
  160. package/src/types/agent.ts +46 -23
  161. package/src/types/index.ts +2 -0
  162. package/src/types/persistence.ts +0 -1
  163. package/src/types/route.ts +22 -16
  164. package/src/types/session.ts +6 -12
  165. package/src/types/tool.ts +15 -9
  166. package/src/utils/session.ts +6 -31
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/utils/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIpC;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,SAAkB,EAClB,QAA0C;IAE1C,MAAM,EAAE,GACN,SAAS,IAAI,WAAW,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAE9E,OAAO;QACL,EAAE;QACF,IAAI,EAAE,EAAoB;QAC1B,WAAW,EAAE,EAAE;QACf,YAAY,EAAE,EAAE;QAChB,QAAQ,EAAE;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QACR,YAAY,EAAE,EAAE;QAChB,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE,EAAE;QACZ,iBAAiB,EAAE,SAAS;QAC5B,sBAAsB,EAAE,SAAS;KAClC,CAAC;IAEF,OAAO;QACL,EAAE,EAAE,SAAS;QACb,YAAY,EAAE,IAAI,CAAC,YAAY;YAC7B,CAAC,CAAC;gBACE,EAAE,EAAE,IAAI,CAAC,YAAY;gBACrB,KAAK,EAAE,aAAa,CAAC,iBAAiB,IAAI,IAAI,CAAC,YAAY;gBAC3D,SAAS,EAAE,IAAI,IAAI,EAAE;aACtB;YACH,CAAC,CAAC,SAAS;QACb,WAAW,EAAE,IAAI,CAAC,WAAW;YAC3B,CAAC,CAAC;gBACE,EAAE,EAAE,IAAI,CAAC,WAAW;gBACpB,WAAW,EAAE,aAAa,CAAC,sBAAsB,IAAI,SAAS;gBAC9D,SAAS,EAAE,IAAI,IAAI,EAAE;aACtB;YACH,CAAC,CAAC,SAAS;QACb,IAAI,EAAE,aAAa,CAAC,IAAI,IAAI,EAAE;QAC9B,YAAY,EAAE,aAAa,CAAC,YAAY,IAAI,EAAE;QAC9C,OAAO,EAAE,aAAa,CAAC,OAAO,IAAI,EAAE;QACpC,QAAQ,EAAE,aAAa,CAAC,QAAQ,IAAI,EAAE;KACvC,CAAC;AACJ,CAAC"}
package/docs/README.md CHANGED
@@ -35,7 +35,7 @@ Welcome to the `@falai/agent` documentation! This comprehensive framework enable
35
35
 
36
36
  - **[Routes](./core/conversation-flows/routes.md)** - Route definition, lifecycle & completion
37
37
  - **[Steps](./core/conversation-flows/steps.md)** - Step configuration, data collection & validation
38
- - **[Data Collection](./core/conversation-flows/data-collection.md)** - Schema-driven data extraction
38
+ - **[Data Collection](./core/conversation-flows/data-collection.md)** - Agent-level schema-driven data extraction
39
39
 
40
40
  #### AI Integration
41
41
 
@@ -74,7 +74,7 @@ Welcome to the `@falai/agent` documentation! This comprehensive framework enable
74
74
  → See [Route DSL](./core/conversation-flows/route-dsl.md), [Intelligent Routing](./core/routing/intelligent-routing.md), and [Step Transitions](./core/conversation-flows/step-transitions.md)
75
75
 
76
76
  **🎯 Collecting structured data?**
77
- → Learn [Data Collection](./core/conversation-flows/data-collection.md) and [Schema-Driven Extraction](../examples/core-concepts/schema-driven-extraction.ts)
77
+ → Learn [Agent-Level Data Collection](./core/conversation-flows/data-collection.md) and [Schema-Driven Extraction](../examples/core-concepts/schema-driven-extraction.ts)
78
78
 
79
79
  **🔧 Working with tools?**
80
80
  → See [Tool Definition](./core/tools/tool-definition.md), [Tool Execution](./core/tools/tool-execution.md), and [Tool Scoping](./core/tools/tool-scoping.md)
@@ -89,7 +89,7 @@ Welcome to the `@falai/agent` documentation! This comprehensive framework enable
89
89
 
90
90
  - **Agent Architecture**: [Agent](./core/agent/README.md) | [Context](./core/agent/context-management.md) | [Sessions](./core/agent/session-management.md)
91
91
  - **AI Routing System**: [Intelligent Routing](./core/routing/intelligent-routing.md) | [Route DSL](./core/conversation-flows/route-dsl.md) | [Step Transitions](./core/conversation-flows/step-transitions.md)
92
- - **Conversation Flows**: [Routes](./core/conversation-flows/routes.md) | [Steps](./core/conversation-flows/steps.md) | [Data Collection](./core/conversation-flows/data-collection.md)
92
+ - **Conversation Flows**: [Routes](./core/conversation-flows/routes.md) | [Steps](./core/conversation-flows/steps.md) | [Agent-Level Data Collection](./core/conversation-flows/data-collection.md)
93
93
  - **AI Integration**: [Providers](./core/ai-integration/providers.md) | [Prompts](./core/ai-integration/prompt-composition.md) | [Responses](./core/ai-integration/response-processing.md)
94
94
  - **Tools & Execution**: [Tool Definition](./core/tools/tool-definition.md) | [Tool Execution](./core/tools/tool-execution.md) | [Tool Scoping](./core/tools/tool-scoping.md)
95
95
  - **Persistence**: [Session Storage](./core/persistence/session-storage.md) | [Adapters](./core/persistence/adapters.md)
@@ -17,14 +17,14 @@ Complete API documentation for `@falai/agent`. This framework provides a strongl
17
17
 
18
18
  ## Core Classes
19
19
 
20
- ### `Agent<TContext>`
20
+ ### `Agent<TContext, TData>`
21
21
 
22
- Main agent class for managing conversational AI.
22
+ Main agent class for managing conversational AI with agent-level data collection.
23
23
 
24
24
  #### Constructor
25
25
 
26
26
  ```typescript
27
- new Agent<TContext>(options: AgentOptions<TContext>)
27
+ new Agent<TContext, TData>(options: AgentOptions<TContext, TData>)
28
28
  ```
29
29
 
30
30
  See [Agent](./AGENT.md) for full details.
@@ -33,7 +33,38 @@ See [Agent](./AGENT.md) for full details.
33
33
 
34
34
  ##### `createRoute(options: RouteOptions): Route`
35
35
 
36
- Creates a new conversation route.
36
+ Creates a new conversation route with required fields specification.
37
+
38
+ ##### `getCollectedData(): Partial<TData>`
39
+
40
+ Gets the current agent-level collected data.
41
+
42
+ ```typescript
43
+ const data = agent.getCollectedData();
44
+ console.log(data); // { customerName: "John", email: "john@example.com" }
45
+ ```
46
+
47
+ ##### `updateCollectedData(updates: Partial<TData>): Promise<void>`
48
+
49
+ Updates agent-level collected data and triggers validation.
50
+
51
+ ```typescript
52
+ await agent.updateCollectedData({
53
+ customerId: "CUST-12345",
54
+ priority: "high"
55
+ });
56
+ ```
57
+
58
+ ##### `validateData(data: Partial<TData>): ValidationResult`
59
+
60
+ Validates data against the agent-level schema.
61
+
62
+ ```typescript
63
+ const validation = agent.validateData({ email: "invalid-email" });
64
+ if (!validation.valid) {
65
+ console.log(validation.errors); // Detailed validation errors
66
+ }
67
+ ```
37
68
 
38
69
  ##### `createTerm(term: Term): this`
39
70
 
@@ -23,12 +23,12 @@ Complete API documentation for `@falai/agent`. This framework provides a strongl
23
23
 
24
24
  ### Agent
25
25
 
26
- The central orchestrator class that manages conversation flow, routing, and tool execution.
26
+ The central orchestrator class that manages conversation flow, routing, tool execution, and agent-level data collection.
27
27
 
28
28
  #### Constructor
29
29
 
30
30
  ```typescript
31
- new Agent<TContext = unknown>(options: AgentOptions<TContext>)
31
+ new Agent<TContext = unknown, TData = unknown>(options: AgentOptions<TContext, TData>)
32
32
  ```
33
33
 
34
34
  #### Properties
@@ -44,10 +44,10 @@ new Agent<TContext = unknown>(options: AgentOptions<TContext>)
44
44
  ##### Route Management
45
45
 
46
46
  ```typescript
47
- createRoute<TData = unknown>(options: RouteOptions<TContext, TData>): Route<TContext, TData>
47
+ createRoute(options: RouteOptions<TContext, TData>): Route<TContext, TData>
48
48
  ```
49
49
 
50
- Creates a new conversation route with the specified options.
50
+ Creates a new conversation route with required fields specification that references the agent-level schema.
51
51
 
52
52
  ##### Context Management
53
53
 
@@ -63,6 +63,26 @@ getContext(): Promise<TContext | undefined>
63
63
 
64
64
  Gets current context, fetching from provider if configured.
65
65
 
66
+ ##### Agent-Level Data Management
67
+
68
+ ```typescript
69
+ getCollectedData(): Partial<TData>
70
+ ```
71
+
72
+ Gets the current agent-level collected data.
73
+
74
+ ```typescript
75
+ updateCollectedData(updates: Partial<TData>): Promise<void>
76
+ ```
77
+
78
+ Updates agent-level collected data and triggers validation and lifecycle hooks.
79
+
80
+ ```typescript
81
+ validateData(data: Partial<TData>): ValidationResult
82
+ ```
83
+
84
+ Validates data against the agent-level schema, returning detailed validation results.
85
+
66
86
  ##### Response Generation
67
87
 
68
88
  ```typescript
@@ -150,7 +170,7 @@ hasPersistence(): boolean
150
170
 
151
171
  ### Route
152
172
 
153
- Represents a conversational journey with structured steps and data collection.
173
+ Represents a conversational journey with required fields specification and steps that collect data into the agent-level schema.
154
174
 
155
175
  #### Constructor
156
176
 
@@ -177,6 +197,26 @@ getStep(stepId: string): Step<TContext, TData> | undefined
177
197
  getAllSteps(): Step<TContext, TData>[]
178
198
  ```
179
199
 
200
+ ##### Route Completion Logic
201
+
202
+ ```typescript
203
+ isComplete(data: Partial<TData>): boolean
204
+ ```
205
+
206
+ Checks if the route is complete based on agent-level data.
207
+
208
+ ```typescript
209
+ getMissingRequiredFields(data: Partial<TData>): (keyof TData)[]
210
+ ```
211
+
212
+ Returns the fields still needed for route completion.
213
+
214
+ ```typescript
215
+ getCompletionProgress(data: Partial<TData>): number
216
+ ```
217
+
218
+ Returns completion progress as a number between 0 and 1.
219
+
180
220
  ##### Data Collection
181
221
 
182
222
  ```typescript
@@ -559,23 +599,28 @@ getSnapshot(): { sessions: SessionData[]; messages: MessageData[] }
559
599
  ### Core Types
560
600
 
561
601
  ```typescript
562
- interface AgentOptions<TContext = unknown> {
602
+ interface AgentOptions<TContext = unknown, TData = unknown> {
563
603
  name: string;
564
604
  provider: AiProvider;
565
605
  description?: string;
566
606
  goal?: string;
567
- personality?: Template<TContext>;
568
- identity?: Template<TContext>;
607
+ personality?: Template<TContext, TData>;
608
+ identity?: Template<TContext, TData>;
569
609
  context?: TContext;
570
610
  contextProvider?: ContextProvider<TContext>;
571
- hooks?: ContextLifecycleHooks<TContext>;
611
+
612
+ // NEW: Agent-level data schema and initial data
613
+ schema?: StructuredSchema;
614
+ initialData?: Partial<TData>;
615
+
616
+ hooks?: ContextLifecycleHooks<TContext, TData>;
572
617
  debug?: boolean;
573
618
  session?: SessionState;
574
619
  persistence?: PersistenceConfig;
575
620
  terms?: Term<TContext>[];
576
621
  guidelines?: Guideline<TContext>[];
577
- tools?: Tool<TContext, unknown[], unknown, unknown>[];
578
- routes?: RouteOptions<TContext, unknown>[];
622
+ tools?: Tool<TContext, unknown[], unknown, TData>[];
623
+ routes?: RouteOptions<TContext, TData>[];
579
624
  knowledgeBase?: Record<string, unknown>;
580
625
  }
581
626
 
@@ -588,7 +633,14 @@ interface RouteOptions<TContext = unknown, TData = unknown> {
588
633
  conditions?: Template<TContext, TData>[];
589
634
  rules?: Template<TContext, TData>[];
590
635
  prohibitions?: Template<TContext, TData>[];
591
- schema?: StructuredSchema;
636
+
637
+ // NEW: Required fields for route completion (replaces schema)
638
+ requiredFields?: (keyof TData)[];
639
+ optionalFields?: (keyof TData)[];
640
+
641
+ // REMOVED: schema (now at agent level)
642
+ // schema?: StructuredSchema;
643
+
592
644
  initialData?: Partial<TData>;
593
645
  steps?: StepOptions<TContext, TData>[];
594
646
  initialStep?: Omit<StepOptions<TContext, TData>, "step">;
@@ -795,4 +847,106 @@ generateStepId(routeId: string, description?: string): string
795
847
  generateToolId(name: string): string
796
848
  ```
797
849
 
850
+ ## Agent-Level Data Collection Example
851
+
852
+ Here's a comprehensive example showing the new agent-level data collection architecture:
853
+
854
+ ```typescript
855
+ import { Agent, OpenAIProvider } from "@falai/agent";
856
+
857
+ // Define comprehensive agent-level data interface
858
+ interface CustomerServiceData {
859
+ // Customer identification
860
+ customerId?: string;
861
+ customerName?: string;
862
+ email?: string;
863
+ phone?: string;
864
+
865
+ // Issue tracking
866
+ issueType?: 'booking' | 'billing' | 'technical' | 'other';
867
+ issueDescription?: string;
868
+ priority?: 'low' | 'medium' | 'high';
869
+
870
+ // Feedback
871
+ rating?: number;
872
+ comments?: string;
873
+ recommendToFriend?: boolean;
874
+ }
875
+
876
+ // Create agent with centralized schema
877
+ const agent = new Agent<{}, CustomerServiceData>({
878
+ name: "Customer Service Agent",
879
+ provider: new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY, model: "gpt-4" }),
880
+
881
+ // Agent-level schema defines all possible data fields
882
+ schema: {
883
+ type: "object",
884
+ properties: {
885
+ customerId: { type: "string" },
886
+ customerName: { type: "string" },
887
+ email: { type: "string", format: "email" },
888
+ phone: { type: "string" },
889
+ issueType: { type: "string", enum: ["booking", "billing", "technical", "other"] },
890
+ issueDescription: { type: "string" },
891
+ priority: { type: "string", enum: ["low", "medium", "high"] },
892
+ rating: { type: "number", minimum: 1, maximum: 5 },
893
+ comments: { type: "string" },
894
+ recommendToFriend: { type: "boolean" }
895
+ }
896
+ },
897
+
898
+ // Agent-level data validation and enrichment
899
+ hooks: {
900
+ onDataUpdate: async (data, previousData) => {
901
+ // Auto-set priority based on issue type
902
+ if (data.issueType === 'billing' && !data.priority) {
903
+ data.priority = 'high';
904
+ }
905
+
906
+ // Enrich customer data
907
+ if (data.customerName && !data.customerId) {
908
+ data.customerId = await lookupCustomerId(data.customerName);
909
+ }
910
+
911
+ return data;
912
+ }
913
+ }
914
+ });
915
+
916
+ // Routes specify required fields instead of schemas
917
+ const supportRoute = agent.createRoute({
918
+ title: "Customer Support",
919
+ requiredFields: ["customerName", "email", "issueType", "issueDescription"],
920
+ optionalFields: ["phone", "priority"],
921
+
922
+ initialStep: {
923
+ prompt: "I'm here to help with your issue. Can you tell me your name and email?",
924
+ collect: ["customerName", "email"]
925
+ }
926
+ });
927
+
928
+ const feedbackRoute = agent.createRoute({
929
+ title: "Feedback Collection",
930
+ requiredFields: ["customerName", "email", "rating"],
931
+ optionalFields: ["comments", "recommendToFriend"],
932
+
933
+ initialStep: {
934
+ prompt: "I'd love to get your feedback. What's your name and email?",
935
+ collect: ["customerName", "email"]
936
+ }
937
+ });
938
+
939
+ // Cross-route data sharing example
940
+ const response1 = await agent.respond("Hi, I'm John Doe, email john@example.com, I have a billing issue");
941
+ // Agent data: { customerName: "John Doe", email: "john@example.com", issueType: "billing" }
942
+
943
+ const response2 = await agent.respond("Actually, I want to leave feedback instead. I'd rate you 5 stars.");
944
+ // Feedback route completes immediately: already has name, email, and now rating
945
+ // { customerName: "John Doe", email: "john@example.com", rating: 5 }
946
+
947
+ // Check route completion
948
+ console.log(feedbackRoute.isComplete(agent.getCollectedData())); // true
949
+ console.log(feedbackRoute.getCompletionProgress(agent.getCollectedData())); // 1.0
950
+ ```
951
+
798
952
  This API reference covers the complete @falai/agent framework. For more detailed examples and usage patterns, see the [examples directory](../../examples/) and [guides](../../docs/guides/).
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- The `Agent<TContext>` class is the central orchestrator of @falai/agent, providing a strongly-typed, context-aware AI agent framework with intelligent routing and schema-driven data collection.
5
+ The `Agent<TContext, TData>` class is the central orchestrator of @falai/agent, providing a strongly-typed, context-aware AI agent framework with intelligent routing and agent-level schema-driven data collection.
6
6
 
7
7
  ## Core Responsibilities
8
8
 
@@ -11,7 +11,7 @@ The `Agent<TContext>` class is the central orchestrator of @falai/agent, providi
11
11
  - **Context Lifecycle**: Dynamic context management with provider functions and lifecycle hooks
12
12
  - **Session Management**: Conversation state persistence and multi-turn dialogue support
13
13
  - **Tool Orchestration**: Hierarchical tool execution (agent → route → step level)
14
- - **Data Collection**: Schema-driven information extraction from natural conversations
14
+ - **Agent-Level Data Collection**: Centralized schema-driven information extraction shared across all routes
15
15
 
16
16
  ## Agent Configuration
17
17
 
@@ -43,7 +43,18 @@ interface CustomerContext {
43
43
  };
44
44
  }
45
45
 
46
- const agent = new Agent<CustomerContext>({
46
+ interface CustomerData {
47
+ customerName?: string;
48
+ email?: string;
49
+ phone?: string;
50
+ issueType?: 'booking' | 'billing' | 'technical' | 'other';
51
+ issueDescription?: string;
52
+ priority?: 'low' | 'medium' | 'high';
53
+ rating?: number;
54
+ comments?: string;
55
+ }
56
+
57
+ const agent = new Agent<CustomerContext, CustomerData>({
47
58
  // Identity
48
59
  name: "Premium Support Assistant",
49
60
  description: "24/7 AI support for premium customers",
@@ -56,6 +67,21 @@ const agent = new Agent<CustomerContext>({
56
67
  backupModels: ["gpt-4"],
57
68
  }),
58
69
 
70
+ // Agent-level data schema (NEW)
71
+ schema: {
72
+ type: "object",
73
+ properties: {
74
+ customerName: { type: "string" },
75
+ email: { type: "string", format: "email" },
76
+ phone: { type: "string" },
77
+ issueType: { type: "string", enum: ["booking", "billing", "technical", "other"] },
78
+ issueDescription: { type: "string" },
79
+ priority: { type: "string", enum: ["low", "medium", "high"] },
80
+ rating: { type: "number", minimum: 1, maximum: 5 },
81
+ comments: { type: "string" }
82
+ }
83
+ },
84
+
59
85
  // Static context (can be overridden by contextProvider)
60
86
  context: {
61
87
  userId: "anonymous",
@@ -102,16 +128,21 @@ const agent = new Agent<CustomerContext>({
102
128
  }
103
129
  },
104
130
 
105
- // Validate and enrich collected data
131
+ // Validate and enrich collected data (NEW: Agent-level data hooks)
106
132
  onDataUpdate: async (data, previousData) => {
107
- // Data validation
133
+ // Data validation against agent schema
108
134
  if (data.email && !isValidEmail(data.email)) {
109
135
  throw new Error("Invalid email format");
110
136
  }
111
137
 
112
- // Data enrichment
113
- if (data.userId && !data.userProfile) {
114
- data.userProfile = await db.getUserProfile(data.userId);
138
+ // Data enrichment using agent-level data
139
+ if (data.customerName && !data.customerId) {
140
+ data.customerId = await lookupCustomerId(data.customerName);
141
+ }
142
+
143
+ // Auto-set priority based on issue type
144
+ if (data.issueType === 'billing' && !data.priority) {
145
+ data.priority = 'high';
115
146
  }
116
147
 
117
148
  return data;
@@ -327,26 +358,33 @@ agent.session.clearHistory();
327
358
  ### Declarative Route Creation
328
359
 
329
360
  ```typescript
330
- const agent = new Agent({
361
+ const agent = new Agent<CustomerContext, CustomerData>({
362
+ // Agent-level schema defines all possible data fields
363
+ schema: { /* comprehensive schema */ },
364
+
331
365
  routes: [
332
366
  {
333
367
  title: "Technical Support",
334
368
  description: "Help with technical issues",
335
369
  conditions: ["user reports technical problem"],
370
+ // NEW: Routes specify required fields instead of schemas
371
+ requiredFields: ["customerName", "email", "issueType", "issueDescription"],
372
+ optionalFields: ["phone", "priority"],
336
373
  initialStep: {
337
374
  prompt:
338
375
  "I understand you're having a technical issue. Can you describe what's happening?",
339
- collect: ["problem", "severity"],
376
+ collect: ["issueType", "issueDescription"], // Collects into agent-level data
340
377
  },
341
378
  },
342
379
  {
343
- title: "Billing Inquiry",
380
+ title: "Billing Inquiry",
344
381
  description: "Handle billing and payment questions",
345
382
  conditions: ["user asks about billing or payment"],
383
+ requiredFields: ["customerName", "email", "issueType"],
346
384
  initialStep: {
347
385
  prompt:
348
386
  "I'd be happy to help with your billing question. What can I assist with?",
349
- collect: ["billingIssue"],
387
+ collect: ["issueType"], // Maps to agent schema field
350
388
  },
351
389
  },
352
390
  ],
@@ -356,18 +394,21 @@ const agent = new Agent({
356
394
  ### Programmatic Route Creation
357
395
 
358
396
  ```typescript
359
- // Create routes dynamically
397
+ // Create routes dynamically with required fields
360
398
  const supportRoute = agent
361
399
  .createRoute({
362
400
  title: "Customer Support",
401
+ requiredFields: ["customerName", "email", "issueType"], // NEW: Required fields
402
+ optionalFields: ["phone"], // NEW: Optional fields
363
403
  initialStep: {
364
404
  prompt: "How can I help you today?",
365
- collect: ["intent"],
405
+ collect: ["customerName", "email"], // Collects into agent-level data
366
406
  },
367
407
  })
368
408
  .nextStep({
369
- prompt: "I understand you need help with {{intent}}",
370
- requires: ["intent"],
409
+ prompt: "I understand you need help, {{customerName}}. What type of issue are you experiencing?",
410
+ collect: ["issueType"],
411
+ requires: ["customerName", "email"], // Prerequisites from agent data
371
412
  });
372
413
 
373
414
  // Access created routes
@@ -404,6 +445,110 @@ const route = agent.createRoute({
404
445
  2. **Route-level tools**
405
446
  3. **Agent-level tools** (lowest priority)
406
447
 
448
+ ## Agent-Level Data Collection
449
+
450
+ ### Centralized Data Schema
451
+
452
+ The new architecture centralizes data collection at the agent level, allowing all routes to work with the same data structure:
453
+
454
+ ```typescript
455
+ interface ComprehensiveData {
456
+ // Customer identification
457
+ customerId?: string;
458
+ customerName?: string;
459
+ email?: string;
460
+ phone?: string;
461
+
462
+ // Issue tracking
463
+ issueType?: 'booking' | 'billing' | 'technical' | 'other';
464
+ issueDescription?: string;
465
+ priority?: 'low' | 'medium' | 'high';
466
+
467
+ // Feedback
468
+ rating?: number;
469
+ comments?: string;
470
+ recommendToFriend?: boolean;
471
+ }
472
+
473
+ const agent = new Agent<Context, ComprehensiveData>({
474
+ name: "Customer Service Agent",
475
+ schema: {
476
+ type: "object",
477
+ properties: {
478
+ customerId: { type: "string" },
479
+ customerName: { type: "string" },
480
+ email: { type: "string", format: "email" },
481
+ phone: { type: "string" },
482
+ issueType: { type: "string", enum: ["booking", "billing", "technical", "other"] },
483
+ issueDescription: { type: "string" },
484
+ priority: { type: "string", enum: ["low", "medium", "high"] },
485
+ rating: { type: "number", minimum: 1, maximum: 5 },
486
+ comments: { type: "string" },
487
+ recommendToFriend: { type: "boolean" }
488
+ }
489
+ }
490
+ });
491
+ ```
492
+
493
+ ### Route Completion Based on Required Fields
494
+
495
+ Routes now specify which fields they need to complete, enabling cross-route data sharing:
496
+
497
+ ```typescript
498
+ // Support route needs basic info + issue details
499
+ const supportRoute = agent.createRoute({
500
+ title: "Customer Support",
501
+ requiredFields: ["customerName", "email", "issueType", "issueDescription"],
502
+ optionalFields: ["phone", "priority"]
503
+ });
504
+
505
+ // Feedback route needs basic info + rating
506
+ const feedbackRoute = agent.createRoute({
507
+ title: "Feedback Collection",
508
+ requiredFields: ["customerName", "email", "rating"],
509
+ optionalFields: ["comments", "recommendToFriend"]
510
+ });
511
+
512
+ // Routes can complete when their required data is available,
513
+ // regardless of which route collected it
514
+ ```
515
+
516
+ ### Cross-Route Data Sharing
517
+
518
+ Data collected by any route is available to all other routes:
519
+
520
+ ```typescript
521
+ // User starts with support, provides name and email
522
+ const response1 = await agent.respond("I need help, my name is John Doe, email john@example.com");
523
+ // Agent data now contains: { customerName: "John Doe", email: "john@example.com" }
524
+
525
+ // User switches to feedback - already has 2/3 required fields
526
+ const response2 = await agent.respond("Actually, I want to leave feedback. I'd rate you 5 stars.");
527
+ // Feedback route completes immediately with: { customerName: "John Doe", email: "john@example.com", rating: 5 }
528
+ ```
529
+
530
+ ### Agent Data Management Methods
531
+
532
+ Access and update agent-level data programmatically:
533
+
534
+ ```typescript
535
+ // Get current collected data
536
+ const currentData = agent.getCollectedData();
537
+ console.log(currentData); // { customerName: "John", email: "john@example.com" }
538
+
539
+ // Update data programmatically
540
+ await agent.updateCollectedData({
541
+ customerId: "CUST-12345",
542
+ priority: "high"
543
+ });
544
+
545
+ // Validate data against schema
546
+ const validation = agent.validateData({ email: "invalid-email" });
547
+ if (!validation.valid) {
548
+ console.log(validation.errors); // Detailed validation errors
549
+ }
550
+ ```
551
+
407
552
  ## Response Generation
408
553
 
409
554
  ### Simple Response API
@@ -412,7 +557,7 @@ const route = agent.createRoute({
412
557
  // Simple message-based API (recommended)
413
558
  const response = await agent.respond("How do I reset my password?");
414
559
  console.log(response.message);
415
- console.log(agent.session.getData()); // Any collected data
560
+ console.log(agent.session.getData<CustomerData>()); // Agent-level collected data
416
561
  console.log(response.toolCalls); // Any tool calls made
417
562
  console.log(response.isRouteComplete); // Whether route finished
418
563