@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.
- package/README.md +34 -22
- package/dist/cjs/src/core/Agent.d.ts +52 -24
- package/dist/cjs/src/core/Agent.d.ts.map +1 -1
- package/dist/cjs/src/core/Agent.js +266 -39
- package/dist/cjs/src/core/Agent.js.map +1 -1
- package/dist/cjs/src/core/PersistenceManager.d.ts.map +1 -1
- package/dist/cjs/src/core/PersistenceManager.js +48 -25
- package/dist/cjs/src/core/PersistenceManager.js.map +1 -1
- package/dist/cjs/src/core/PromptComposer.d.ts +1 -1
- package/dist/cjs/src/core/PromptComposer.d.ts.map +1 -1
- package/dist/cjs/src/core/PromptComposer.js.map +1 -1
- package/dist/cjs/src/core/ResponseEngine.d.ts +13 -12
- package/dist/cjs/src/core/ResponseEngine.d.ts.map +1 -1
- package/dist/cjs/src/core/ResponseEngine.js +4 -4
- package/dist/cjs/src/core/ResponseEngine.js.map +1 -1
- package/dist/cjs/src/core/ResponsePipeline.d.ts +66 -38
- package/dist/cjs/src/core/ResponsePipeline.d.ts.map +1 -1
- package/dist/cjs/src/core/ResponsePipeline.js +71 -3
- package/dist/cjs/src/core/ResponsePipeline.js.map +1 -1
- package/dist/cjs/src/core/Route.d.ts +24 -5
- package/dist/cjs/src/core/Route.d.ts.map +1 -1
- package/dist/cjs/src/core/Route.js +45 -1
- package/dist/cjs/src/core/Route.js.map +1 -1
- package/dist/cjs/src/core/RoutingEngine.d.ts +31 -6
- package/dist/cjs/src/core/RoutingEngine.d.ts.map +1 -1
- package/dist/cjs/src/core/RoutingEngine.js +113 -9
- package/dist/cjs/src/core/RoutingEngine.js.map +1 -1
- package/dist/cjs/src/core/SessionManager.d.ts +14 -4
- package/dist/cjs/src/core/SessionManager.d.ts.map +1 -1
- package/dist/cjs/src/core/SessionManager.js +25 -5
- package/dist/cjs/src/core/SessionManager.js.map +1 -1
- package/dist/cjs/src/core/Step.d.ts +10 -10
- package/dist/cjs/src/core/Step.d.ts.map +1 -1
- package/dist/cjs/src/core/Step.js.map +1 -1
- package/dist/cjs/src/core/ToolExecutor.d.ts +4 -2
- package/dist/cjs/src/core/ToolExecutor.d.ts.map +1 -1
- package/dist/cjs/src/core/ToolExecutor.js +13 -3
- package/dist/cjs/src/core/ToolExecutor.js.map +1 -1
- package/dist/cjs/src/types/agent.d.ts +41 -21
- package/dist/cjs/src/types/agent.d.ts.map +1 -1
- package/dist/cjs/src/types/agent.js.map +1 -1
- package/dist/cjs/src/types/index.d.ts +1 -1
- package/dist/cjs/src/types/index.d.ts.map +1 -1
- package/dist/cjs/src/types/index.js.map +1 -1
- package/dist/cjs/src/types/persistence.d.ts +0 -1
- package/dist/cjs/src/types/persistence.d.ts.map +1 -1
- package/dist/cjs/src/types/route.d.ts +22 -16
- package/dist/cjs/src/types/route.d.ts.map +1 -1
- package/dist/cjs/src/types/session.d.ts +6 -11
- package/dist/cjs/src/types/session.d.ts.map +1 -1
- package/dist/cjs/src/types/tool.d.ts +12 -6
- package/dist/cjs/src/types/tool.d.ts.map +1 -1
- package/dist/cjs/src/utils/session.d.ts +2 -2
- package/dist/cjs/src/utils/session.d.ts.map +1 -1
- package/dist/cjs/src/utils/session.js +6 -26
- package/dist/cjs/src/utils/session.js.map +1 -1
- package/dist/src/core/Agent.d.ts +52 -24
- package/dist/src/core/Agent.d.ts.map +1 -1
- package/dist/src/core/Agent.js +266 -39
- package/dist/src/core/Agent.js.map +1 -1
- package/dist/src/core/PersistenceManager.d.ts.map +1 -1
- package/dist/src/core/PersistenceManager.js +48 -25
- package/dist/src/core/PersistenceManager.js.map +1 -1
- package/dist/src/core/PromptComposer.d.ts +1 -1
- package/dist/src/core/PromptComposer.d.ts.map +1 -1
- package/dist/src/core/PromptComposer.js.map +1 -1
- package/dist/src/core/ResponseEngine.d.ts +13 -12
- package/dist/src/core/ResponseEngine.d.ts.map +1 -1
- package/dist/src/core/ResponseEngine.js +4 -4
- package/dist/src/core/ResponseEngine.js.map +1 -1
- package/dist/src/core/ResponsePipeline.d.ts +66 -38
- package/dist/src/core/ResponsePipeline.d.ts.map +1 -1
- package/dist/src/core/ResponsePipeline.js +71 -3
- package/dist/src/core/ResponsePipeline.js.map +1 -1
- package/dist/src/core/Route.d.ts +24 -5
- package/dist/src/core/Route.d.ts.map +1 -1
- package/dist/src/core/Route.js +45 -1
- package/dist/src/core/Route.js.map +1 -1
- package/dist/src/core/RoutingEngine.d.ts +31 -6
- package/dist/src/core/RoutingEngine.d.ts.map +1 -1
- package/dist/src/core/RoutingEngine.js +113 -9
- package/dist/src/core/RoutingEngine.js.map +1 -1
- package/dist/src/core/SessionManager.d.ts +14 -4
- package/dist/src/core/SessionManager.d.ts.map +1 -1
- package/dist/src/core/SessionManager.js +25 -5
- package/dist/src/core/SessionManager.js.map +1 -1
- package/dist/src/core/Step.d.ts +10 -10
- package/dist/src/core/Step.d.ts.map +1 -1
- package/dist/src/core/Step.js.map +1 -1
- package/dist/src/core/ToolExecutor.d.ts +4 -2
- package/dist/src/core/ToolExecutor.d.ts.map +1 -1
- package/dist/src/core/ToolExecutor.js +13 -3
- package/dist/src/core/ToolExecutor.js.map +1 -1
- package/dist/src/types/agent.d.ts +41 -21
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/agent.js.map +1 -1
- package/dist/src/types/index.d.ts +1 -1
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/persistence.d.ts +0 -1
- package/dist/src/types/persistence.d.ts.map +1 -1
- package/dist/src/types/route.d.ts +22 -16
- package/dist/src/types/route.d.ts.map +1 -1
- package/dist/src/types/session.d.ts +6 -11
- package/dist/src/types/session.d.ts.map +1 -1
- package/dist/src/types/tool.d.ts +12 -6
- package/dist/src/types/tool.d.ts.map +1 -1
- package/dist/src/utils/session.d.ts +2 -2
- package/dist/src/utils/session.d.ts.map +1 -1
- package/dist/src/utils/session.js +6 -26
- package/dist/src/utils/session.js.map +1 -1
- package/docs/README.md +3 -3
- package/docs/api/README.md +35 -4
- package/docs/api/overview.md +166 -12
- package/docs/core/agent/README.md +162 -17
- package/docs/core/agent/context-management.md +39 -15
- package/docs/core/agent/session-management.md +49 -16
- package/docs/core/ai-integration/prompt-composition.md +38 -14
- package/docs/core/ai-integration/response-processing.md +28 -17
- package/docs/core/conversation-flows/data-collection.md +103 -25
- package/docs/core/conversation-flows/route-dsl.md +45 -22
- package/docs/core/conversation-flows/routes.md +74 -18
- package/docs/core/conversation-flows/step-transitions.md +3 -3
- package/docs/core/conversation-flows/steps.md +39 -15
- package/docs/core/routing/intelligent-routing.md +18 -9
- package/docs/core/tools/tool-definition.md +8 -8
- package/docs/core/tools/tool-execution.md +26 -26
- package/docs/core/tools/tool-scoping.md +5 -5
- package/docs/guides/getting-started/README.md +54 -32
- package/examples/advanced-patterns/knowledge-based-agent.ts +37 -28
- package/examples/advanced-patterns/persistent-onboarding.ts +70 -41
- package/examples/advanced-patterns/route-lifecycle-hooks.ts +28 -2
- package/examples/advanced-patterns/streaming-responses.ts +28 -23
- package/examples/ai-providers/anthropic-integration.ts +40 -33
- package/examples/ai-providers/openai-integration.ts +25 -25
- package/examples/conversation-flows/completion-transitions.ts +36 -32
- package/examples/core-concepts/basic-agent.ts +76 -78
- package/examples/core-concepts/schema-driven-extraction.ts +20 -16
- package/examples/core-concepts/session-management.ts +65 -53
- package/examples/integrations/database-integration.ts +49 -34
- package/examples/integrations/healthcare-integration.ts +96 -91
- package/examples/integrations/search-integration.ts +79 -82
- package/examples/integrations/server-session-management.ts +25 -17
- package/examples/persistence/database-persistence.ts +61 -45
- package/examples/persistence/memory-sessions.ts +52 -63
- package/examples/persistence/redis-persistence.ts +81 -95
- package/examples/tools/basic-tools.ts +73 -62
- package/examples/tools/data-enrichment-tools.ts +52 -44
- package/package.json +1 -1
- package/src/core/Agent.ts +418 -128
- package/src/core/PersistenceManager.ts +51 -27
- package/src/core/PromptComposer.ts +1 -1
- package/src/core/ResponseEngine.ts +21 -19
- package/src/core/ResponsePipeline.ts +174 -59
- package/src/core/Route.ts +58 -6
- package/src/core/RoutingEngine.ts +174 -27
- package/src/core/SessionManager.ts +32 -8
- package/src/core/Step.ts +20 -12
- package/src/core/ToolExecutor.ts +19 -5
- package/src/types/agent.ts +46 -23
- package/src/types/index.ts +2 -0
- package/src/types/persistence.ts +0 -1
- package/src/types/route.ts +22 -16
- package/src/types/session.ts +6 -12
- package/src/types/tool.ts +15 -9
- 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
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/utils/session.ts"],"names":[],"mappings":"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"}
|
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)** -
|
|
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)
|
package/docs/api/README.md
CHANGED
|
@@ -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
|
|
package/docs/api/overview.md
CHANGED
|
@@ -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
|
|
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
|
|
47
|
+
createRoute(options: RouteOptions<TContext, TData>): Route<TContext, TData>
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
Creates a new conversation route with the
|
|
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
|
|
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
|
-
|
|
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,
|
|
578
|
-
routes?: RouteOptions<TContext,
|
|
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
|
-
|
|
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**:
|
|
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
|
-
|
|
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.
|
|
114
|
-
data.
|
|
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: ["
|
|
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: ["
|
|
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: ["
|
|
405
|
+
collect: ["customerName", "email"], // Collects into agent-level data
|
|
366
406
|
},
|
|
367
407
|
})
|
|
368
408
|
.nextStep({
|
|
369
|
-
prompt: "I understand you need help
|
|
370
|
-
|
|
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()); //
|
|
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
|
|