@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
|
@@ -120,11 +120,37 @@ function createPersistentOnboardingAgent(sessionId: string) {
|
|
|
120
120
|
model: "models/gemini-2.5-flash",
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
// Define the onboarding schema
|
|
124
|
+
const onboardingSchema = {
|
|
125
|
+
type: "object",
|
|
126
|
+
properties: {
|
|
127
|
+
businessName: {
|
|
128
|
+
type: "string",
|
|
129
|
+
description: "Name of the business",
|
|
130
|
+
},
|
|
131
|
+
businessDescription: {
|
|
132
|
+
type: "string",
|
|
133
|
+
description: "Brief description of what the business does",
|
|
134
|
+
},
|
|
135
|
+
industry: {
|
|
136
|
+
type: "string",
|
|
137
|
+
description: "Industry the business operates in",
|
|
138
|
+
},
|
|
139
|
+
contactEmail: {
|
|
140
|
+
type: "string",
|
|
141
|
+
description: "Contact email for the business",
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
required: ["businessName", "businessDescription"],
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const agent = new Agent<OnboardingContext, OnboardingData>({
|
|
124
148
|
name: "OnboardingBot",
|
|
125
149
|
description: "A friendly assistant that helps businesses get started",
|
|
126
150
|
goal: "Collect business information efficiently while being conversational",
|
|
127
151
|
provider: provider,
|
|
152
|
+
// NEW: Agent-level schema
|
|
153
|
+
schema: onboardingSchema,
|
|
128
154
|
|
|
129
155
|
// Knowledge base with onboarding best practices
|
|
130
156
|
knowledgeBase: {
|
|
@@ -204,9 +230,9 @@ function createPersistentOnboardingAgent(sessionId: string) {
|
|
|
204
230
|
// OPTION 1: Using contextUpdate in return value
|
|
205
231
|
const saveBusinessInfo: Tool<
|
|
206
232
|
OnboardingContext,
|
|
233
|
+
OnboardingData,
|
|
207
234
|
unknown[],
|
|
208
|
-
unknown
|
|
209
|
-
OnboardingData
|
|
235
|
+
unknown
|
|
210
236
|
> = {
|
|
211
237
|
id: "save_business_info",
|
|
212
238
|
name: "Business Info Saver",
|
|
@@ -244,9 +270,9 @@ function createPersistentOnboardingAgent(sessionId: string) {
|
|
|
244
270
|
// OPTION 2: Using updateContext method directly
|
|
245
271
|
const saveIndustry: Tool<
|
|
246
272
|
OnboardingContext,
|
|
273
|
+
OnboardingData,
|
|
247
274
|
unknown[],
|
|
248
|
-
unknown
|
|
249
|
-
OnboardingData
|
|
275
|
+
unknown
|
|
250
276
|
> = {
|
|
251
277
|
id: "save_industry",
|
|
252
278
|
name: "Industry Classifier",
|
|
@@ -277,9 +303,9 @@ function createPersistentOnboardingAgent(sessionId: string) {
|
|
|
277
303
|
|
|
278
304
|
const saveContactEmail: Tool<
|
|
279
305
|
OnboardingContext,
|
|
306
|
+
OnboardingData,
|
|
280
307
|
unknown[],
|
|
281
|
-
unknown
|
|
282
|
-
OnboardingData
|
|
308
|
+
unknown
|
|
283
309
|
> = {
|
|
284
310
|
id: "save_contact_email",
|
|
285
311
|
name: "Contact Email Saver",
|
|
@@ -311,32 +337,14 @@ function createPersistentOnboardingAgent(sessionId: string) {
|
|
|
311
337
|
// ONBOARDING ROUTE WITH DATA EXTRACTION
|
|
312
338
|
// ============================================================================
|
|
313
339
|
|
|
314
|
-
const onboardingRoute = agent.createRoute
|
|
340
|
+
const onboardingRoute = agent.createRoute({
|
|
315
341
|
title: "Business Onboarding",
|
|
316
342
|
description: "Guide user through business information collection",
|
|
317
343
|
conditions: ["User is onboarding their business"],
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
type: "string",
|
|
323
|
-
description: "Name of the business",
|
|
324
|
-
},
|
|
325
|
-
businessDescription: {
|
|
326
|
-
type: "string",
|
|
327
|
-
description: "Brief description of what the business does",
|
|
328
|
-
},
|
|
329
|
-
industry: {
|
|
330
|
-
type: "string",
|
|
331
|
-
description: "Industry the business operates in",
|
|
332
|
-
},
|
|
333
|
-
contactEmail: {
|
|
334
|
-
type: "string",
|
|
335
|
-
description: "Contact email for the business",
|
|
336
|
-
},
|
|
337
|
-
},
|
|
338
|
-
required: ["businessName", "businessDescription"],
|
|
339
|
-
},
|
|
344
|
+
// NEW: Required fields for route completion
|
|
345
|
+
requiredFields: ["businessName", "businessDescription"],
|
|
346
|
+
// NEW: Optional fields that enhance the experience
|
|
347
|
+
optionalFields: ["industry", "contactEmail"],
|
|
340
348
|
endStep: {
|
|
341
349
|
prompt:
|
|
342
350
|
"Summarize all collected information warmly and confirm onboarding is complete",
|
|
@@ -428,10 +436,36 @@ function createOnboardingAgentWithProvider(sessionId: string) {
|
|
|
428
436
|
model: "models/gemini-2.5-flash",
|
|
429
437
|
});
|
|
430
438
|
|
|
431
|
-
|
|
439
|
+
// Define the onboarding schema
|
|
440
|
+
const onboardingSchema = {
|
|
441
|
+
type: "object",
|
|
442
|
+
properties: {
|
|
443
|
+
businessName: {
|
|
444
|
+
type: "string",
|
|
445
|
+
description: "Name of the business",
|
|
446
|
+
},
|
|
447
|
+
businessDescription: {
|
|
448
|
+
type: "string",
|
|
449
|
+
description: "Brief description of what the business does",
|
|
450
|
+
},
|
|
451
|
+
industry: {
|
|
452
|
+
type: "string",
|
|
453
|
+
description: "Industry the business operates in",
|
|
454
|
+
},
|
|
455
|
+
contactEmail: {
|
|
456
|
+
type: "string",
|
|
457
|
+
description: "Contact email for the business",
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
required: ["businessName", "businessDescription"],
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
const agent = new Agent<OnboardingContext, OnboardingData>({
|
|
432
464
|
name: "OnboardingBot",
|
|
433
465
|
description: "A friendly assistant that helps businesses get started",
|
|
434
466
|
provider: provider,
|
|
467
|
+
// NEW: Agent-level schema
|
|
468
|
+
schema: onboardingSchema,
|
|
435
469
|
|
|
436
470
|
// Context is always fetched fresh from database
|
|
437
471
|
contextProvider: () => {
|
|
@@ -499,7 +533,7 @@ async function main() {
|
|
|
499
533
|
});
|
|
500
534
|
|
|
501
535
|
console.log("🤖 Bot:", response1.message);
|
|
502
|
-
console.log("📊 Data after turn 1:", agent.session.getData
|
|
536
|
+
console.log("📊 Data after turn 1:", agent.session.getData());
|
|
503
537
|
console.log("📊 Route:", response1.session?.currentRoute?.title);
|
|
504
538
|
|
|
505
539
|
// Check route completion after turn 1
|
|
@@ -533,7 +567,7 @@ async function main() {
|
|
|
533
567
|
name: "Alice",
|
|
534
568
|
},
|
|
535
569
|
];
|
|
536
|
-
const response2 = await agent.respond({ history: history2
|
|
570
|
+
const response2 = await agent.respond({ history: history2 });
|
|
537
571
|
console.log("🤖 Bot:", response2.message);
|
|
538
572
|
console.log("📊 Data after turn 2:", response2.session?.data);
|
|
539
573
|
|
|
@@ -547,8 +581,6 @@ async function main() {
|
|
|
547
581
|
|
|
548
582
|
console.log();
|
|
549
583
|
|
|
550
|
-
// Update session again
|
|
551
|
-
session = response2.session!;
|
|
552
584
|
|
|
553
585
|
// Turn 3: User provides industry
|
|
554
586
|
console.log("📱 Turn 3: User provides industry");
|
|
@@ -564,7 +596,7 @@ async function main() {
|
|
|
564
596
|
name: "Alice",
|
|
565
597
|
},
|
|
566
598
|
];
|
|
567
|
-
const response3 = await agent.respond({ history: history3
|
|
599
|
+
const response3 = await agent.respond({ history: history3 });
|
|
568
600
|
console.log("🤖 Bot:", response3.message);
|
|
569
601
|
console.log("📊 Data after turn 3:", response3.session?.data);
|
|
570
602
|
|
|
@@ -578,9 +610,6 @@ async function main() {
|
|
|
578
610
|
|
|
579
611
|
console.log();
|
|
580
612
|
|
|
581
|
-
// Update session again
|
|
582
|
-
session = response3.session!;
|
|
583
|
-
|
|
584
613
|
// Turn 4: User provides contact email, completing the flow
|
|
585
614
|
console.log("📱 Turn 4: User provides contact email");
|
|
586
615
|
const history4 = [
|
|
@@ -595,7 +624,7 @@ async function main() {
|
|
|
595
624
|
name: "Alice",
|
|
596
625
|
},
|
|
597
626
|
];
|
|
598
|
-
const response4 = await agent.respond({ history: history4
|
|
627
|
+
const response4 = await agent.respond({ history: history4 });
|
|
599
628
|
console.log("🤖 Bot:", response4.message);
|
|
600
629
|
console.log("📊 Data after turn 4:", response4.session?.data);
|
|
601
630
|
|
|
@@ -603,7 +632,7 @@ async function main() {
|
|
|
603
632
|
if (response4.isRouteComplete) {
|
|
604
633
|
console.log("\n✅ Onboarding complete!");
|
|
605
634
|
await finalizeOnboarding(
|
|
606
|
-
agent.getData(
|
|
635
|
+
agent.getData() as unknown as OnboardingData
|
|
607
636
|
);
|
|
608
637
|
}
|
|
609
638
|
|
|
@@ -16,15 +16,39 @@ const provider = new OpenAIProvider({
|
|
|
16
16
|
model: "gpt-5",
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
+
// Define data schema for feedback collection
|
|
20
|
+
interface ServiceData {
|
|
21
|
+
feedbackRating?: number;
|
|
22
|
+
feedbackComments?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const serviceSchema = {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
feedbackRating: {
|
|
29
|
+
type: "number",
|
|
30
|
+
description: "Rating from 1-5",
|
|
31
|
+
minimum: 1,
|
|
32
|
+
maximum: 5,
|
|
33
|
+
},
|
|
34
|
+
feedbackComments: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "Additional feedback comments",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
19
41
|
/**
|
|
20
42
|
* Create a new agent instance with predefined routes and rules/prohibitions.
|
|
21
43
|
*/
|
|
22
|
-
const agent = new Agent({
|
|
44
|
+
const agent = new Agent<unknown, ServiceData>({
|
|
23
45
|
name: "CustomerServiceAgent",
|
|
24
46
|
description:
|
|
25
47
|
"A versatile customer service agent that adapts its behavior based on the conversation's context.",
|
|
26
48
|
goal: "Provide excellent customer service by following route-specific rules and prohibitions.",
|
|
27
49
|
provider,
|
|
50
|
+
// NEW: Agent-level schema
|
|
51
|
+
schema: serviceSchema,
|
|
28
52
|
debug: true,
|
|
29
53
|
|
|
30
54
|
// Knowledge base with customer service best practices
|
|
@@ -223,12 +247,14 @@ agent.createRoute({
|
|
|
223
247
|
* Demonstration function to show how the agent responds to different scenarios.
|
|
224
248
|
*/
|
|
225
249
|
async function demonstrateRulesAndProhibitions() {
|
|
226
|
-
const agent = new Agent({
|
|
250
|
+
const agent = new Agent<unknown, ServiceData>({
|
|
227
251
|
name: "CustomerServiceAgent",
|
|
228
252
|
description:
|
|
229
253
|
"A versatile customer service agent that adapts its behavior based on the conversation's context.",
|
|
230
254
|
goal: "Provide excellent customer service by following route-specific rules and prohibitions.",
|
|
231
255
|
provider,
|
|
256
|
+
// NEW: Agent-level schema
|
|
257
|
+
schema: serviceSchema,
|
|
232
258
|
debug: true,
|
|
233
259
|
});
|
|
234
260
|
|
|
@@ -36,7 +36,7 @@ async function streamingWithAnthropic() {
|
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
// Create agent
|
|
39
|
-
const agent = new Agent<ConversationContext>({
|
|
39
|
+
const agent = new Agent<ConversationContext, unknown>({
|
|
40
40
|
name: "StreamingAssistant",
|
|
41
41
|
description: "An AI assistant that streams responses in real-time",
|
|
42
42
|
goal: "Provide helpful information with streaming responses",
|
|
@@ -120,7 +120,7 @@ async function streamingWithOpenAI() {
|
|
|
120
120
|
},
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
-
const agent = new Agent<ConversationContext>({
|
|
123
|
+
const agent = new Agent<ConversationContext, unknown>({
|
|
124
124
|
name: "CreativeAssistant",
|
|
125
125
|
description: "A creative AI assistant",
|
|
126
126
|
context: {
|
|
@@ -185,7 +185,7 @@ async function streamingWithGemini() {
|
|
|
185
185
|
},
|
|
186
186
|
});
|
|
187
187
|
|
|
188
|
-
const agent = new Agent<ConversationContext>({
|
|
188
|
+
const agent = new Agent<ConversationContext, unknown>({
|
|
189
189
|
name: "AnalyticalAssistant",
|
|
190
190
|
description: "An analytical AI assistant",
|
|
191
191
|
context: {
|
|
@@ -247,7 +247,22 @@ async function streamingWithRoutes() {
|
|
|
247
247
|
model: "claude-sonnet-4-5",
|
|
248
248
|
});
|
|
249
249
|
|
|
250
|
-
|
|
250
|
+
// Define feedback data schema
|
|
251
|
+
interface FeedbackData {
|
|
252
|
+
rating: number;
|
|
253
|
+
comments: string;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const feedbackSchema = {
|
|
257
|
+
type: "object",
|
|
258
|
+
properties: {
|
|
259
|
+
rating: { type: "number", minimum: 1, maximum: 5 },
|
|
260
|
+
comments: { type: "string" },
|
|
261
|
+
},
|
|
262
|
+
required: ["rating"],
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const agent = new Agent<ConversationContext, FeedbackData>({
|
|
251
266
|
name: "SupportAgent",
|
|
252
267
|
description: "A customer support agent with conversation routes",
|
|
253
268
|
context: {
|
|
@@ -258,6 +273,8 @@ async function streamingWithRoutes() {
|
|
|
258
273
|
},
|
|
259
274
|
},
|
|
260
275
|
provider: provider,
|
|
276
|
+
// NEW: Agent-level schema
|
|
277
|
+
schema: feedbackSchema,
|
|
261
278
|
});
|
|
262
279
|
|
|
263
280
|
// Create a route
|
|
@@ -272,21 +289,14 @@ async function streamingWithRoutes() {
|
|
|
272
289
|
});
|
|
273
290
|
|
|
274
291
|
// Create a feedback route
|
|
275
|
-
agent.createRoute
|
|
276
|
-
rating: number;
|
|
277
|
-
comments: string;
|
|
278
|
-
}>({
|
|
292
|
+
agent.createRoute({
|
|
279
293
|
title: "Collect Feedback",
|
|
280
294
|
description: "Collect user feedback on their support experience",
|
|
281
295
|
conditions: ["User wants to provide feedback"],
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
comments: { type: "string" },
|
|
287
|
-
},
|
|
288
|
-
required: ["rating"],
|
|
289
|
-
},
|
|
296
|
+
// NEW: Required fields for route completion
|
|
297
|
+
requiredFields: ["rating"],
|
|
298
|
+
// NEW: Optional fields
|
|
299
|
+
optionalFields: ["comments"],
|
|
290
300
|
steps: [
|
|
291
301
|
{
|
|
292
302
|
prompt: "How would you rate your support experience from 1 to 5?",
|
|
@@ -339,12 +349,7 @@ async function streamingWithRoutes() {
|
|
|
339
349
|
if (chunk.isRouteComplete) {
|
|
340
350
|
console.log("\n✅ Route complete!");
|
|
341
351
|
if (chunk.session?.currentRoute?.title === "Collect Feedback") {
|
|
342
|
-
await logFeedback(
|
|
343
|
-
agent.session.getData() as {
|
|
344
|
-
rating: number;
|
|
345
|
-
comments: string;
|
|
346
|
-
}
|
|
347
|
-
);
|
|
352
|
+
await logFeedback(agent.session.getData() as FeedbackData);
|
|
348
353
|
}
|
|
349
354
|
}
|
|
350
355
|
|
|
@@ -364,7 +369,7 @@ async function streamingWithAbortSignal() {
|
|
|
364
369
|
model: "claude-sonnet-4-5",
|
|
365
370
|
});
|
|
366
371
|
|
|
367
|
-
const agent = new Agent<ConversationContext>({
|
|
372
|
+
const agent = new Agent<ConversationContext, unknown>({
|
|
368
373
|
name: "Assistant",
|
|
369
374
|
description: "An assistant that can be interrupted",
|
|
370
375
|
context: {
|
|
@@ -25,7 +25,7 @@ interface ResearchData {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// Research tool that Claude can use
|
|
28
|
-
const conductResearch: Tool<unknown, unknown[], unknown
|
|
28
|
+
const conductResearch: Tool<unknown, ResearchData, unknown[], unknown> = {
|
|
29
29
|
id: "conduct_research",
|
|
30
30
|
description: "Conduct comprehensive research on a given topic",
|
|
31
31
|
parameters: {
|
|
@@ -33,17 +33,16 @@ const conductResearch: Tool<unknown, unknown[], unknown, ResearchData> = {
|
|
|
33
33
|
properties: {},
|
|
34
34
|
},
|
|
35
35
|
handler: async ({ data }) => {
|
|
36
|
-
const researchData = data as Partial<ResearchData>;
|
|
37
36
|
console.log(
|
|
38
|
-
`Conducting ${
|
|
37
|
+
`Conducting ${data?.depth} research on: ${data?.topic}`
|
|
39
38
|
);
|
|
40
39
|
|
|
41
40
|
const researchId = `RES-${Date.now()}`;
|
|
42
41
|
|
|
43
42
|
// Simulate research process
|
|
44
43
|
const findings = {
|
|
45
|
-
overview: `Found ${
|
|
46
|
-
|
|
44
|
+
overview: `Found ${data?.sources || 3} sources about ${
|
|
45
|
+
data?.topic
|
|
47
46
|
}`,
|
|
48
47
|
key_points: [
|
|
49
48
|
"Latest developments in the field",
|
|
@@ -62,8 +61,36 @@ const conductResearch: Tool<unknown, unknown[], unknown, ResearchData> = {
|
|
|
62
61
|
},
|
|
63
62
|
};
|
|
64
63
|
|
|
64
|
+
// Define research schema
|
|
65
|
+
const researchSchema = {
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: {
|
|
68
|
+
topic: { type: "string", description: "The research topic" },
|
|
69
|
+
depth: {
|
|
70
|
+
type: "string",
|
|
71
|
+
enum: ["overview", "detailed", "comprehensive"],
|
|
72
|
+
default: "detailed",
|
|
73
|
+
},
|
|
74
|
+
sources: {
|
|
75
|
+
type: "number",
|
|
76
|
+
minimum: 1,
|
|
77
|
+
maximum: 20,
|
|
78
|
+
default: 5,
|
|
79
|
+
description: "Number of sources to analyze",
|
|
80
|
+
},
|
|
81
|
+
format: {
|
|
82
|
+
type: "string",
|
|
83
|
+
enum: ["summary", "bullet_points", "structured"],
|
|
84
|
+
default: "structured",
|
|
85
|
+
description: "Output format preference",
|
|
86
|
+
},
|
|
87
|
+
researchId: { type: "string" },
|
|
88
|
+
},
|
|
89
|
+
required: ["topic"],
|
|
90
|
+
};
|
|
91
|
+
|
|
65
92
|
// Create agent with Anthropic provider
|
|
66
|
-
const agent = new Agent({
|
|
93
|
+
const agent = new Agent<unknown, ResearchData>({
|
|
67
94
|
name: "ClaudeResearcher",
|
|
68
95
|
description: "A research assistant powered by Claude",
|
|
69
96
|
provider: new AnthropicProvider({
|
|
@@ -75,38 +102,18 @@ const agent = new Agent({
|
|
|
75
102
|
top_p: 0.9,
|
|
76
103
|
},
|
|
77
104
|
}),
|
|
105
|
+
// NEW: Agent-level schema
|
|
106
|
+
schema: researchSchema,
|
|
78
107
|
});
|
|
79
108
|
|
|
80
109
|
// Create research route
|
|
81
|
-
const researchRoute = agent.createRoute
|
|
110
|
+
const researchRoute = agent.createRoute({
|
|
82
111
|
title: "Research Assistant",
|
|
83
112
|
description: "Conduct research using Claude's analytical capabilities",
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
depth: {
|
|
89
|
-
type: "string",
|
|
90
|
-
enum: ["overview", "detailed", "comprehensive"],
|
|
91
|
-
default: "detailed",
|
|
92
|
-
},
|
|
93
|
-
sources: {
|
|
94
|
-
type: "number",
|
|
95
|
-
minimum: 1,
|
|
96
|
-
maximum: 20,
|
|
97
|
-
default: 5,
|
|
98
|
-
description: "Number of sources to analyze",
|
|
99
|
-
},
|
|
100
|
-
format: {
|
|
101
|
-
type: "string",
|
|
102
|
-
enum: ["summary", "bullet_points", "structured"],
|
|
103
|
-
default: "structured",
|
|
104
|
-
description: "Output format preference",
|
|
105
|
-
},
|
|
106
|
-
researchId: { type: "string" },
|
|
107
|
-
},
|
|
108
|
-
required: ["topic"],
|
|
109
|
-
},
|
|
113
|
+
// NEW: Required fields for route completion
|
|
114
|
+
requiredFields: ["topic"],
|
|
115
|
+
// NEW: Optional fields that enhance the experience
|
|
116
|
+
optionalFields: ["depth", "sources", "format", "researchId"],
|
|
110
117
|
identity: `You are Claude, an AI research assistant created by Anthropic.
|
|
111
118
|
You have access to extensive knowledge and can conduct thorough research.
|
|
112
119
|
Always be helpful, truthful, and provide well-reasoned analysis.`,
|
|
@@ -26,7 +26,7 @@ interface WeatherData {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
// Define a tool that can access collected data
|
|
29
|
-
const getWeather: Tool<CustomerContext, unknown[], unknown
|
|
29
|
+
const getWeather: Tool<CustomerContext, WeatherData, unknown[], unknown> = {
|
|
30
30
|
id: "get_weather",
|
|
31
31
|
description: "Get current weather for a location",
|
|
32
32
|
parameters: {
|
|
@@ -38,8 +38,7 @@ const getWeather: Tool<CustomerContext, unknown[], unknown, WeatherData> = {
|
|
|
38
38
|
},
|
|
39
39
|
handler: ({ data }, location) => {
|
|
40
40
|
// Use data location if available, otherwise use args
|
|
41
|
-
const
|
|
42
|
-
const finalLocation = weatherData?.location || location;
|
|
41
|
+
const finalLocation = data?.location || location;
|
|
43
42
|
|
|
44
43
|
// Simulate API call
|
|
45
44
|
return {
|
|
@@ -71,7 +70,7 @@ async function main() {
|
|
|
71
70
|
});
|
|
72
71
|
|
|
73
72
|
// Create agent with OpenAI
|
|
74
|
-
const agent = new Agent<CustomerContext>({
|
|
73
|
+
const agent = new Agent<CustomerContext, WeatherData>({
|
|
75
74
|
name: "Assistant",
|
|
76
75
|
description:
|
|
77
76
|
"A helpful AI assistant that can check weather and answer questions",
|
|
@@ -84,6 +83,25 @@ async function main() {
|
|
|
84
83
|
preferences: ["concise answers", "weather updates"],
|
|
85
84
|
},
|
|
86
85
|
provider: openaiProvider,
|
|
86
|
+
|
|
87
|
+
schema: {
|
|
88
|
+
type: "object",
|
|
89
|
+
properties: {
|
|
90
|
+
location: {
|
|
91
|
+
type: "string",
|
|
92
|
+
description: "City or location for weather check",
|
|
93
|
+
},
|
|
94
|
+
temperature: {
|
|
95
|
+
type: "number",
|
|
96
|
+
description: "Temperature in Fahrenheit",
|
|
97
|
+
},
|
|
98
|
+
condition: {
|
|
99
|
+
type: "string",
|
|
100
|
+
description: "Weather condition (sunny, cloudy, rainy, etc.)",
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
required: ["location"],
|
|
104
|
+
},
|
|
87
105
|
});
|
|
88
106
|
|
|
89
107
|
// Add domain knowledge
|
|
@@ -106,28 +124,10 @@ async function main() {
|
|
|
106
124
|
});
|
|
107
125
|
|
|
108
126
|
// Create weather route with data extraction schema
|
|
109
|
-
const weatherRoute = agent.createRoute
|
|
127
|
+
const weatherRoute = agent.createRoute({
|
|
110
128
|
title: "Check Weather",
|
|
111
129
|
description: "Help user check weather for a location",
|
|
112
130
|
conditions: ["User wants to know the weather"],
|
|
113
|
-
schema: {
|
|
114
|
-
type: "object",
|
|
115
|
-
properties: {
|
|
116
|
-
location: {
|
|
117
|
-
type: "string",
|
|
118
|
-
description: "City or location for weather check",
|
|
119
|
-
},
|
|
120
|
-
temperature: {
|
|
121
|
-
type: "number",
|
|
122
|
-
description: "Temperature in Fahrenheit",
|
|
123
|
-
},
|
|
124
|
-
condition: {
|
|
125
|
-
type: "string",
|
|
126
|
-
description: "Weather condition (sunny, cloudy, rainy, etc.)",
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
required: ["location"],
|
|
130
|
-
},
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
// Step 1: Collect location
|
|
@@ -180,14 +180,14 @@ async function main() {
|
|
|
180
180
|
console.log(` Customer: What's the weather like in San Francisco?`);
|
|
181
181
|
console.log(` Agent: ${response.message}`);
|
|
182
182
|
console.log(` Route: ${response.session?.currentRoute?.title}`);
|
|
183
|
-
console.log(` Data:`, agent.session.getData
|
|
183
|
+
console.log(` Data:`, agent.session.getData());
|
|
184
184
|
|
|
185
185
|
await agent.session.addMessage("assistant", response.message);
|
|
186
186
|
|
|
187
187
|
// Check for route completion
|
|
188
188
|
if (response.isRouteComplete) {
|
|
189
189
|
console.log("\n✅ Weather route complete!");
|
|
190
|
-
await logWeatherRequest(agent.session.getData
|
|
190
|
+
await logWeatherRequest(agent.session.getData());
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
console.log("\n✨ Session step benefits:");
|