@falai/agent 0.3.0 → 0.3.10

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 (49) hide show
  1. package/README.md +158 -9
  2. package/dist/cjs/core/Agent.d.ts +12 -0
  3. package/dist/cjs/core/Agent.d.ts.map +1 -1
  4. package/dist/cjs/core/Agent.js +37 -1
  5. package/dist/cjs/core/Agent.js.map +1 -1
  6. package/dist/cjs/core/DomainRegistry.d.ts +10 -0
  7. package/dist/cjs/core/DomainRegistry.d.ts.map +1 -1
  8. package/dist/cjs/core/DomainRegistry.js +25 -0
  9. package/dist/cjs/core/DomainRegistry.js.map +1 -1
  10. package/dist/cjs/core/PromptBuilder.d.ts +9 -1
  11. package/dist/cjs/core/PromptBuilder.d.ts.map +1 -1
  12. package/dist/cjs/core/PromptBuilder.js +49 -2
  13. package/dist/cjs/core/PromptBuilder.js.map +1 -1
  14. package/dist/cjs/core/Route.d.ts +16 -0
  15. package/dist/cjs/core/Route.d.ts.map +1 -1
  16. package/dist/cjs/core/Route.js +22 -0
  17. package/dist/cjs/core/Route.js.map +1 -1
  18. package/dist/cjs/types/route.d.ts +6 -0
  19. package/dist/cjs/types/route.d.ts.map +1 -1
  20. package/dist/core/Agent.d.ts +12 -0
  21. package/dist/core/Agent.d.ts.map +1 -1
  22. package/dist/core/Agent.js +37 -1
  23. package/dist/core/Agent.js.map +1 -1
  24. package/dist/core/DomainRegistry.d.ts +10 -0
  25. package/dist/core/DomainRegistry.d.ts.map +1 -1
  26. package/dist/core/DomainRegistry.js +25 -0
  27. package/dist/core/DomainRegistry.js.map +1 -1
  28. package/dist/core/PromptBuilder.d.ts +9 -1
  29. package/dist/core/PromptBuilder.d.ts.map +1 -1
  30. package/dist/core/PromptBuilder.js +49 -2
  31. package/dist/core/PromptBuilder.js.map +1 -1
  32. package/dist/core/Route.d.ts +16 -0
  33. package/dist/core/Route.d.ts.map +1 -1
  34. package/dist/core/Route.js +22 -0
  35. package/dist/core/Route.js.map +1 -1
  36. package/dist/types/route.d.ts +6 -0
  37. package/dist/types/route.d.ts.map +1 -1
  38. package/docs/API_REFERENCE.md +99 -2
  39. package/docs/CONSTRUCTOR_OPTIONS.md +178 -37
  40. package/docs/GETTING_STARTED.md +10 -2
  41. package/examples/business-onboarding.ts +707 -0
  42. package/examples/domain-scoping.ts +266 -0
  43. package/examples/rules-prohibitions.ts +258 -0
  44. package/package.json +1 -1
  45. package/src/core/Agent.ts +46 -1
  46. package/src/core/DomainRegistry.ts +30 -0
  47. package/src/core/PromptBuilder.ts +70 -3
  48. package/src/core/Route.ts +28 -0
  49. package/src/types/route.ts +6 -0
@@ -26,6 +26,7 @@ export enum BuiltInSection {
26
26
  OBSERVATIONS = "observations",
27
27
  CAPABILITIES = "capabilities",
28
28
  ACTIVE_ROUTES = "active_routes",
29
+ DOMAINS = "domains",
29
30
  }
30
31
 
31
32
  /**
@@ -431,7 +432,14 @@ When you detect any of these situations, consider which route would be most appr
431
432
  * Add active routes information
432
433
  */
433
434
  addActiveRoutes(
434
- routes: Array<{ title: string; description?: string; conditions: string[] }>
435
+ routes: Array<{
436
+ title: string;
437
+ description?: string;
438
+ conditions: string[];
439
+ domains?: string[];
440
+ rules?: string[];
441
+ prohibitions?: string[];
442
+ }>
435
443
  ): this {
436
444
  if (routes.length > 0) {
437
445
  const routesString = routes
@@ -441,7 +449,29 @@ When you detect any of these situations, consider which route would be most appr
441
449
  ? `\n Triggered when: ${route.conditions.join(" OR ")}`
442
450
  : "";
443
451
  const desc = route.description ? `\n ${route.description}` : "";
444
- return `${i + 1}) ${route.title}${desc}${conditions}`;
452
+
453
+ let domainInfo = "";
454
+ if (route.domains !== undefined) {
455
+ if (route.domains.length === 0) {
456
+ domainInfo = "\n Available tools: None (conversation only)";
457
+ } else {
458
+ domainInfo = `\n Available tools: ${route.domains.join(", ")}`;
459
+ }
460
+ }
461
+
462
+ let rulesInfo = "";
463
+ if (route.rules && route.rules.length > 0) {
464
+ const rulesList = route.rules.map((r, idx) => `${idx + 1}. ${r}`).join("; ");
465
+ rulesInfo = `\n RULES: ${rulesList}`;
466
+ }
467
+
468
+ let prohibitionsInfo = "";
469
+ if (route.prohibitions && route.prohibitions.length > 0) {
470
+ const prohibitionsList = route.prohibitions.map((p, idx) => `${idx + 1}. ${p}`).join("; ");
471
+ prohibitionsInfo = `\n PROHIBITIONS: ${prohibitionsList}`;
472
+ }
473
+
474
+ return `${i + 1}) ${route.title}${desc}${conditions}${domainInfo}${rulesInfo}${prohibitionsInfo}`;
445
475
  })
446
476
  .join("\n\n");
447
477
 
@@ -452,7 +482,11 @@ When you detect any of these situations, consider which route would be most appr
452
482
  {routes_string}
453
483
  ###
454
484
 
455
- These routes represent different paths the conversation can take. Choose the most appropriate route based on the user's needs.`,
485
+ These routes represent different paths the conversation can take. Choose the most appropriate route based on the user's needs.
486
+ IMPORTANT:
487
+ - If a route specifies available tools, you can ONLY call tools from those domains when following that route.
488
+ - If a route has RULES, you MUST follow them when you choose that route.
489
+ - If a route has PROHIBITIONS, you MUST NEVER do those things when you choose that route.`,
456
490
  { routes_string: routesString },
457
491
  SectionStatus.ACTIVE
458
492
  );
@@ -460,6 +494,39 @@ These routes represent different paths the conversation can take. Choose the mos
460
494
  return this;
461
495
  }
462
496
 
497
+ /**
498
+ * Add domains (tools) information
499
+ */
500
+ addDomains(
501
+ domains: Record<string, Record<string, unknown>>
502
+ ): this {
503
+ const domainNames = Object.keys(domains);
504
+ if (domainNames.length > 0) {
505
+ const domainsString = domainNames
506
+ .map((name, i) => {
507
+ const toolNames = Object.keys(domains[name]);
508
+ const tools = toolNames.join(", ");
509
+ return `${i + 1}) Domain "${name}": ${tools}`;
510
+ })
511
+ .join("\n");
512
+
513
+ this.addSection(
514
+ BuiltInSection.DOMAINS,
515
+ `Available tool domains:
516
+ ###
517
+ {domains_string}
518
+ ###
519
+
520
+ These are the tool domains registered in the system. Each domain contains specific tools/methods.
521
+ When calling tools, use the format: domain.toolName (e.g., "payment.processPayment").`,
522
+ { domains_string: domainsString },
523
+ SectionStatus.ACTIVE
524
+ );
525
+ }
526
+ return this;
527
+ }
528
+
529
+
463
530
  /**
464
531
  * Add JSON response schema instructions
465
532
  */
package/src/core/Route.ts CHANGED
@@ -16,6 +16,9 @@ export class Route<TContext = unknown> {
16
16
  public readonly title: string;
17
17
  public readonly description?: string;
18
18
  public readonly conditions: string[];
19
+ public readonly domains?: string[];
20
+ public readonly rules: string[];
21
+ public readonly prohibitions: string[];
19
22
  public readonly initialState: State<TContext>;
20
23
  private guidelines: Guideline[] = [];
21
24
 
@@ -25,6 +28,9 @@ export class Route<TContext = unknown> {
25
28
  this.title = options.title;
26
29
  this.description = options.description;
27
30
  this.conditions = options.conditions || [];
31
+ this.domains = options.domains;
32
+ this.rules = options.rules || ([] as string[]);
33
+ this.prohibitions = options.prohibitions || ([] as string[]);
28
34
  this.initialState = new State<TContext>(this.id, "Initial state");
29
35
 
30
36
  // Initialize guidelines from options
@@ -54,6 +60,28 @@ export class Route<TContext = unknown> {
54
60
  return [...this.guidelines];
55
61
  }
56
62
 
63
+ /**
64
+ * Get allowed domain names for this route
65
+ * @returns Array of domain names, or undefined if all domains are allowed
66
+ */
67
+ getDomains(): string[] | undefined {
68
+ return this.domains ? [...this.domains] : undefined;
69
+ }
70
+
71
+ /**
72
+ * Get rules for this route
73
+ */
74
+ getRules(): string[] {
75
+ return [...this.rules];
76
+ }
77
+
78
+ /**
79
+ * Get prohibitions for this route
80
+ */
81
+ getProhibitions(): string[] {
82
+ return [...this.prohibitions];
83
+ }
84
+
57
85
  /**
58
86
  * Get route reference
59
87
  */
@@ -41,6 +41,12 @@ export interface RouteOptions {
41
41
  conditions?: string[];
42
42
  /** Initial guidelines for this route */
43
43
  guidelines?: Guideline[];
44
+ /** Domain names that are allowed in this route (undefined = all domains) */
45
+ domains?: string[];
46
+ /** Absolute rules the agent must follow in this route */
47
+ rules?: string[];
48
+ /** Absolute prohibitions the agent must never do in this route */
49
+ prohibitions?: string[];
44
50
  }
45
51
 
46
52
  /**