@falai/agent 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/README.md +21 -74
  2. package/dist/cjs/core/Agent.d.ts +22 -29
  3. package/dist/cjs/core/Agent.d.ts.map +1 -1
  4. package/dist/cjs/core/Agent.js +465 -275
  5. package/dist/cjs/core/Agent.js.map +1 -1
  6. package/dist/cjs/core/Events.d.ts +10 -1
  7. package/dist/cjs/core/Events.d.ts.map +1 -1
  8. package/dist/cjs/core/Events.js +3 -2
  9. package/dist/cjs/core/Events.js.map +1 -1
  10. package/dist/cjs/core/PersistenceManager.d.ts +19 -0
  11. package/dist/cjs/core/PersistenceManager.d.ts.map +1 -1
  12. package/dist/cjs/core/PersistenceManager.js +57 -0
  13. package/dist/cjs/core/PersistenceManager.js.map +1 -1
  14. package/dist/cjs/core/PromptComposer.d.ts +24 -0
  15. package/dist/cjs/core/PromptComposer.d.ts.map +1 -0
  16. package/dist/cjs/core/PromptComposer.js +127 -0
  17. package/dist/cjs/core/PromptComposer.js.map +1 -0
  18. package/dist/cjs/core/ResponseEngine.d.ts +19 -0
  19. package/dist/cjs/core/ResponseEngine.d.ts.map +1 -0
  20. package/dist/cjs/core/ResponseEngine.js +51 -0
  21. package/dist/cjs/core/ResponseEngine.js.map +1 -0
  22. package/dist/cjs/core/Route.d.ts +18 -12
  23. package/dist/cjs/core/Route.d.ts.map +1 -1
  24. package/dist/cjs/core/Route.js +15 -9
  25. package/dist/cjs/core/Route.js.map +1 -1
  26. package/dist/cjs/core/RoutingEngine.d.ts +38 -0
  27. package/dist/cjs/core/RoutingEngine.d.ts.map +1 -0
  28. package/dist/cjs/core/RoutingEngine.js +110 -0
  29. package/dist/cjs/core/RoutingEngine.js.map +1 -0
  30. package/dist/cjs/core/State.d.ts +15 -4
  31. package/dist/cjs/core/State.d.ts.map +1 -1
  32. package/dist/cjs/core/State.js +21 -2
  33. package/dist/cjs/core/State.js.map +1 -1
  34. package/dist/cjs/core/ToolExecutor.d.ts +29 -0
  35. package/dist/cjs/core/ToolExecutor.d.ts.map +1 -0
  36. package/dist/cjs/core/ToolExecutor.js +73 -0
  37. package/dist/cjs/core/ToolExecutor.js.map +1 -0
  38. package/dist/cjs/core/Transition.d.ts +5 -5
  39. package/dist/cjs/core/Transition.d.ts.map +1 -1
  40. package/dist/cjs/core/Transition.js.map +1 -1
  41. package/dist/cjs/index.d.ts +6 -8
  42. package/dist/cjs/index.d.ts.map +1 -1
  43. package/dist/cjs/index.js +8 -10
  44. package/dist/cjs/index.js.map +1 -1
  45. package/dist/cjs/providers/AnthropicProvider.d.ts.map +1 -1
  46. package/dist/cjs/providers/AnthropicProvider.js +10 -13
  47. package/dist/cjs/providers/AnthropicProvider.js.map +1 -1
  48. package/dist/cjs/providers/GeminiProvider.d.ts.map +1 -1
  49. package/dist/cjs/providers/GeminiProvider.js +12 -8
  50. package/dist/cjs/providers/GeminiProvider.js.map +1 -1
  51. package/dist/cjs/providers/OpenAIProvider.d.ts.map +1 -1
  52. package/dist/cjs/providers/OpenAIProvider.js +10 -53
  53. package/dist/cjs/providers/OpenAIProvider.js.map +1 -1
  54. package/dist/cjs/providers/OpenRouterProvider.d.ts.map +1 -1
  55. package/dist/cjs/providers/OpenRouterProvider.js +10 -53
  56. package/dist/cjs/providers/OpenRouterProvider.js.map +1 -1
  57. package/dist/cjs/types/agent.d.ts +13 -9
  58. package/dist/cjs/types/agent.d.ts.map +1 -1
  59. package/dist/cjs/types/ai.d.ts +8 -2
  60. package/dist/cjs/types/ai.d.ts.map +1 -1
  61. package/dist/cjs/types/history.d.ts +8 -0
  62. package/dist/cjs/types/history.d.ts.map +1 -1
  63. package/dist/cjs/types/index.d.ts +0 -3
  64. package/dist/cjs/types/index.d.ts.map +1 -1
  65. package/dist/cjs/types/index.js +1 -3
  66. package/dist/cjs/types/index.js.map +1 -1
  67. package/dist/cjs/types/route.d.ts +39 -4
  68. package/dist/cjs/types/route.d.ts.map +1 -1
  69. package/dist/cjs/types/routing.d.ts +16 -0
  70. package/dist/cjs/types/routing.d.ts.map +1 -0
  71. package/dist/cjs/types/routing.js +3 -0
  72. package/dist/cjs/types/routing.js.map +1 -0
  73. package/dist/cjs/types/schema.d.ts +22 -0
  74. package/dist/cjs/types/schema.d.ts.map +1 -0
  75. package/dist/cjs/types/schema.js +3 -0
  76. package/dist/cjs/types/schema.js.map +1 -0
  77. package/dist/cjs/types/session.d.ts +72 -0
  78. package/dist/cjs/types/session.d.ts.map +1 -0
  79. package/dist/cjs/types/session.js +140 -0
  80. package/dist/cjs/types/session.js.map +1 -0
  81. package/dist/cjs/types/tool.d.ts +11 -5
  82. package/dist/cjs/types/tool.d.ts.map +1 -1
  83. package/dist/cjs/utils/id.d.ts +0 -5
  84. package/dist/cjs/utils/id.d.ts.map +1 -1
  85. package/dist/cjs/utils/id.js +0 -10
  86. package/dist/cjs/utils/id.js.map +1 -1
  87. package/dist/cjs/utils/schema.d.ts +17 -0
  88. package/dist/cjs/utils/schema.d.ts.map +1 -0
  89. package/dist/cjs/utils/schema.js +32 -0
  90. package/dist/cjs/utils/schema.js.map +1 -0
  91. package/dist/core/Agent.d.ts +22 -29
  92. package/dist/core/Agent.d.ts.map +1 -1
  93. package/dist/core/Agent.js +465 -275
  94. package/dist/core/Agent.js.map +1 -1
  95. package/dist/core/Events.d.ts +10 -1
  96. package/dist/core/Events.d.ts.map +1 -1
  97. package/dist/core/Events.js +3 -2
  98. package/dist/core/Events.js.map +1 -1
  99. package/dist/core/PersistenceManager.d.ts +19 -0
  100. package/dist/core/PersistenceManager.d.ts.map +1 -1
  101. package/dist/core/PersistenceManager.js +57 -0
  102. package/dist/core/PersistenceManager.js.map +1 -1
  103. package/dist/core/PromptComposer.d.ts +24 -0
  104. package/dist/core/PromptComposer.d.ts.map +1 -0
  105. package/dist/core/PromptComposer.js +123 -0
  106. package/dist/core/PromptComposer.js.map +1 -0
  107. package/dist/core/ResponseEngine.d.ts +19 -0
  108. package/dist/core/ResponseEngine.d.ts.map +1 -0
  109. package/dist/core/ResponseEngine.js +47 -0
  110. package/dist/core/ResponseEngine.js.map +1 -0
  111. package/dist/core/Route.d.ts +18 -12
  112. package/dist/core/Route.d.ts.map +1 -1
  113. package/dist/core/Route.js +15 -9
  114. package/dist/core/Route.js.map +1 -1
  115. package/dist/core/RoutingEngine.d.ts +38 -0
  116. package/dist/core/RoutingEngine.d.ts.map +1 -0
  117. package/dist/core/RoutingEngine.js +106 -0
  118. package/dist/core/RoutingEngine.js.map +1 -0
  119. package/dist/core/State.d.ts +15 -4
  120. package/dist/core/State.d.ts.map +1 -1
  121. package/dist/core/State.js +21 -2
  122. package/dist/core/State.js.map +1 -1
  123. package/dist/core/ToolExecutor.d.ts +29 -0
  124. package/dist/core/ToolExecutor.d.ts.map +1 -0
  125. package/dist/core/ToolExecutor.js +69 -0
  126. package/dist/core/ToolExecutor.js.map +1 -0
  127. package/dist/core/Transition.d.ts +5 -5
  128. package/dist/core/Transition.d.ts.map +1 -1
  129. package/dist/core/Transition.js.map +1 -1
  130. package/dist/index.d.ts +6 -8
  131. package/dist/index.d.ts.map +1 -1
  132. package/dist/index.js +3 -5
  133. package/dist/index.js.map +1 -1
  134. package/dist/providers/AnthropicProvider.d.ts.map +1 -1
  135. package/dist/providers/AnthropicProvider.js +10 -13
  136. package/dist/providers/AnthropicProvider.js.map +1 -1
  137. package/dist/providers/GeminiProvider.d.ts.map +1 -1
  138. package/dist/providers/GeminiProvider.js +12 -8
  139. package/dist/providers/GeminiProvider.js.map +1 -1
  140. package/dist/providers/OpenAIProvider.d.ts.map +1 -1
  141. package/dist/providers/OpenAIProvider.js +10 -53
  142. package/dist/providers/OpenAIProvider.js.map +1 -1
  143. package/dist/providers/OpenRouterProvider.d.ts.map +1 -1
  144. package/dist/providers/OpenRouterProvider.js +10 -53
  145. package/dist/providers/OpenRouterProvider.js.map +1 -1
  146. package/dist/types/agent.d.ts +13 -9
  147. package/dist/types/agent.d.ts.map +1 -1
  148. package/dist/types/ai.d.ts +8 -2
  149. package/dist/types/ai.d.ts.map +1 -1
  150. package/dist/types/history.d.ts +8 -0
  151. package/dist/types/history.d.ts.map +1 -1
  152. package/dist/types/index.d.ts +0 -3
  153. package/dist/types/index.d.ts.map +1 -1
  154. package/dist/types/index.js +0 -1
  155. package/dist/types/index.js.map +1 -1
  156. package/dist/types/route.d.ts +39 -4
  157. package/dist/types/route.d.ts.map +1 -1
  158. package/dist/types/routing.d.ts +16 -0
  159. package/dist/types/routing.d.ts.map +1 -0
  160. package/dist/types/routing.js +2 -0
  161. package/dist/types/routing.js.map +1 -0
  162. package/dist/types/schema.d.ts +22 -0
  163. package/dist/types/schema.d.ts.map +1 -0
  164. package/dist/types/schema.js +2 -0
  165. package/dist/types/schema.js.map +1 -0
  166. package/dist/types/session.d.ts +72 -0
  167. package/dist/types/session.d.ts.map +1 -0
  168. package/dist/types/session.js +132 -0
  169. package/dist/types/session.js.map +1 -0
  170. package/dist/types/tool.d.ts +11 -5
  171. package/dist/types/tool.d.ts.map +1 -1
  172. package/dist/utils/id.d.ts +0 -5
  173. package/dist/utils/id.d.ts.map +1 -1
  174. package/dist/utils/id.js +0 -9
  175. package/dist/utils/id.js.map +1 -1
  176. package/dist/utils/schema.d.ts +17 -0
  177. package/dist/utils/schema.d.ts.map +1 -0
  178. package/dist/utils/schema.js +27 -0
  179. package/dist/utils/schema.js.map +1 -0
  180. package/docs/ADAPTERS.md +83 -3
  181. package/docs/API_REFERENCE.md +95 -104
  182. package/docs/ARCHITECTURE.md +284 -286
  183. package/docs/CONSTRUCTOR_OPTIONS.md +192 -135
  184. package/docs/CONTEXT_MANAGEMENT.md +311 -28
  185. package/docs/CONTRIBUTING.md +1 -1
  186. package/docs/DOMAINS.md +61 -0
  187. package/docs/GETTING_STARTED.md +177 -88
  188. package/docs/PERSISTENCE.md +170 -23
  189. package/docs/README.md +7 -10
  190. package/examples/business-onboarding.ts +21 -9
  191. package/examples/company-qna-agent.ts +508 -0
  192. package/examples/declarative-agent.ts +143 -26
  193. package/examples/domain-scoping.ts +31 -10
  194. package/examples/extracted-data-modification.ts +415 -0
  195. package/examples/healthcare-agent.ts +194 -90
  196. package/examples/openai-agent.ts +67 -25
  197. package/examples/opensearch-persistence.ts +455 -151
  198. package/examples/persistent-onboarding.ts +162 -96
  199. package/examples/prisma-persistence.ts +371 -125
  200. package/examples/redis-persistence.ts +393 -23
  201. package/examples/rules-prohibitions.ts +32 -11
  202. package/examples/streaming-agent.ts +61 -13
  203. package/examples/travel-agent.ts +266 -133
  204. package/package.json +1 -1
  205. package/src/core/Agent.ts +679 -332
  206. package/src/core/Events.ts +12 -2
  207. package/src/core/PersistenceManager.ts +83 -0
  208. package/src/core/PromptComposer.ts +143 -0
  209. package/src/core/ResponseEngine.ts +82 -0
  210. package/src/core/Route.ts +32 -17
  211. package/src/core/RoutingEngine.ts +165 -0
  212. package/src/core/State.ts +55 -15
  213. package/src/core/ToolExecutor.ts +117 -0
  214. package/src/core/Transition.ts +5 -5
  215. package/src/index.ts +12 -21
  216. package/src/providers/AnthropicProvider.ts +10 -13
  217. package/src/providers/GeminiProvider.ts +12 -8
  218. package/src/providers/OpenAIProvider.ts +10 -56
  219. package/src/providers/OpenRouterProvider.ts +10 -56
  220. package/src/types/agent.ts +16 -10
  221. package/src/types/ai.ts +6 -2
  222. package/src/types/history.ts +8 -0
  223. package/src/types/index.ts +0 -11
  224. package/src/types/route.ts +41 -5
  225. package/src/types/routing.ts +18 -0
  226. package/src/types/schema.ts +23 -0
  227. package/src/types/session.ts +207 -0
  228. package/src/types/tool.ts +29 -7
  229. package/src/utils/id.ts +0 -10
  230. package/src/utils/schema.ts +32 -0
  231. package/dist/cjs/core/ConditionEvaluator.d.ts +0 -72
  232. package/dist/cjs/core/ConditionEvaluator.d.ts.map +0 -1
  233. package/dist/cjs/core/ConditionEvaluator.js +0 -272
  234. package/dist/cjs/core/ConditionEvaluator.js.map +0 -1
  235. package/dist/cjs/core/Observation.d.ts +0 -24
  236. package/dist/cjs/core/Observation.d.ts.map +0 -1
  237. package/dist/cjs/core/Observation.js +0 -39
  238. package/dist/cjs/core/Observation.js.map +0 -1
  239. package/dist/cjs/core/PreparationEngine.d.ts +0 -105
  240. package/dist/cjs/core/PreparationEngine.d.ts.map +0 -1
  241. package/dist/cjs/core/PreparationEngine.js +0 -320
  242. package/dist/cjs/core/PreparationEngine.js.map +0 -1
  243. package/dist/cjs/core/PromptBuilder.d.ts +0 -136
  244. package/dist/cjs/core/PromptBuilder.d.ts.map +0 -1
  245. package/dist/cjs/core/PromptBuilder.js +0 -421
  246. package/dist/cjs/core/PromptBuilder.js.map +0 -1
  247. package/dist/cjs/types/observation.d.ts +0 -27
  248. package/dist/cjs/types/observation.d.ts.map +0 -1
  249. package/dist/cjs/types/observation.js +0 -6
  250. package/dist/cjs/types/observation.js.map +0 -1
  251. package/dist/cjs/types/prompt.d.ts +0 -46
  252. package/dist/cjs/types/prompt.d.ts.map +0 -1
  253. package/dist/cjs/types/prompt.js +0 -19
  254. package/dist/cjs/types/prompt.js.map +0 -1
  255. package/dist/core/ConditionEvaluator.d.ts +0 -72
  256. package/dist/core/ConditionEvaluator.d.ts.map +0 -1
  257. package/dist/core/ConditionEvaluator.js +0 -268
  258. package/dist/core/ConditionEvaluator.js.map +0 -1
  259. package/dist/core/Observation.d.ts +0 -24
  260. package/dist/core/Observation.d.ts.map +0 -1
  261. package/dist/core/Observation.js +0 -35
  262. package/dist/core/Observation.js.map +0 -1
  263. package/dist/core/PreparationEngine.d.ts +0 -105
  264. package/dist/core/PreparationEngine.d.ts.map +0 -1
  265. package/dist/core/PreparationEngine.js +0 -316
  266. package/dist/core/PreparationEngine.js.map +0 -1
  267. package/dist/core/PromptBuilder.d.ts +0 -136
  268. package/dist/core/PromptBuilder.d.ts.map +0 -1
  269. package/dist/core/PromptBuilder.js +0 -417
  270. package/dist/core/PromptBuilder.js.map +0 -1
  271. package/dist/types/observation.d.ts +0 -27
  272. package/dist/types/observation.d.ts.map +0 -1
  273. package/dist/types/observation.js +0 -5
  274. package/dist/types/observation.js.map +0 -1
  275. package/dist/types/prompt.d.ts +0 -46
  276. package/dist/types/prompt.d.ts.map +0 -1
  277. package/dist/types/prompt.js +0 -16
  278. package/dist/types/prompt.js.map +0 -1
  279. package/docs/STRUCTURE.md +0 -58
  280. package/src/core/ConditionEvaluator.ts +0 -381
  281. package/src/core/Observation.ts +0 -47
  282. package/src/core/PreparationEngine.ts +0 -500
  283. package/src/core/PromptBuilder.ts +0 -617
  284. package/src/types/observation.ts +0 -29
  285. package/src/types/prompt.ts +0 -49
@@ -24,76 +24,144 @@ interface AgentOptions<TContext = unknown> {
24
24
  goal?: string;
25
25
  context?: TContext;
26
26
 
27
+ // Context provider for always-fresh context
28
+ contextProvider?: () => Promise<TContext> | TContext;
29
+
27
30
  // Configuration
28
- maxEngineIterations?: number;
29
31
  compositionMode?: CompositionMode;
30
32
 
31
- // Declarative initialization (NEW!)
33
+ // Enhanced lifecycle hooks
34
+ hooks?: {
35
+ beforeRespond?: (currentContext: TContext) => Promise<TContext> | TContext;
36
+ onContextUpdate?: (
37
+ newContext: TContext,
38
+ previousContext: TContext
39
+ ) => Promise<void> | void;
40
+ onExtractedUpdate?: (
41
+ extracted: Record<string, unknown>,
42
+ previousExtracted: Record<string, unknown>
43
+ ) => Promise<Record<string, unknown>> | Record<string, unknown>;
44
+ };
45
+
46
+ // Declarative initialization
32
47
  terms?: Term[];
33
48
  guidelines?: Guideline[];
34
49
  capabilities?: Capability[];
35
50
  routes?: RouteOptions[];
36
- observations?: ObservationOptions[];
37
51
  }
38
52
  ```
39
53
 
40
- ### Example: Full Declarative Agent
54
+ ### Example: Data-Driven Agent with Session State
41
55
 
42
56
  ```typescript
43
- const agent = new Agent({
44
- name: 'SupportBot',
45
- description: 'Helpful customer support',
46
- goal: 'Resolve issues efficiently',
57
+ // Define your data extraction types
58
+ interface FlightData {
59
+ destination: string;
60
+ departureDate: string;
61
+ passengers: number;
62
+ cabinClass: "economy" | "business" | "first";
63
+ }
64
+
65
+ const agent = new Agent<FlightBookingContext>({
66
+ name: 'FlightBot',
67
+ description: 'Helpful flight booking assistant',
68
+ goal: 'Book flights efficiently',
47
69
  ai: new GeminiProvider({ apiKey: '...', model: '...' }),
48
- context: { userId: '123' },
49
70
 
71
+ // Static context
72
+ context: {
73
+ userId: '123',
74
+ availableFlights: [],
75
+ },
76
+
77
+ // Enhanced lifecycle hooks
78
+ hooks: {
79
+ // Refresh context before each response
80
+ beforeRespond: async (ctx) => {
81
+ const freshUser = await db.getUser(ctx.userId);
82
+ return { ...ctx, userCredits: freshUser.credits };
83
+ },
84
+
85
+ // Validate and enrich extracted data
86
+ onExtractedUpdate: async (extracted, previous) => {
87
+ // Normalize passenger count
88
+ if (extracted.passengers < 1) extracted.passengers = 1;
89
+ if (extracted.passengers > 9) extracted.passengers = 9;
90
+
91
+ // Auto-trigger flight search when we have enough data
92
+ if (extracted.destination && extracted.departureDate && extracted.passengers) {
93
+ extracted.shouldSearchFlights = true;
94
+ }
95
+
96
+ return extracted;
97
+ },
98
+ },
99
+
100
+ // Declarative routes with data extraction
101
+ routes: [
102
+ {
103
+ title: 'Book Flight',
104
+ description: 'Help user book a flight',
105
+ conditions: ['User wants to book a flight'],
106
+ gatherSchema: {
107
+ type: 'object',
108
+ properties: {
109
+ destination: { type: 'string' },
110
+ departureDate: { type: 'string' },
111
+ passengers: { type: 'number', minimum: 1, maximum: 9 },
112
+ cabinClass: {
113
+ type: 'string',
114
+ enum: ['economy', 'business', 'first'],
115
+ default: 'economy',
116
+ },
117
+ },
118
+ required: ['destination', 'departureDate', 'passengers'],
119
+ },
120
+ },
121
+ ],
122
+
123
+ // Domain glossary
50
124
  terms: [
51
125
  {
52
- name: 'SLA',
53
- description: 'Service Level Agreement',
54
- synonyms: ['response time'],
126
+ name: 'Premium Plan',
127
+ description: 'Our top-tier subscription at $99/month',
128
+ synonyms: ['pro plan', 'premium subscription'],
55
129
  },
56
130
  ],
57
131
 
132
+ // Behavioral guidelines
58
133
  guidelines: [
59
134
  {
60
- condition: 'User is frustrated',
61
- action: 'Show empathy and offer escalation',
62
- tags: ['support'],
135
+ action: 'Always be polite and professional',
63
136
  enabled: true,
64
137
  },
65
- ],
66
-
67
- capabilities: [
68
- { title: 'Ticket Management', description: 'Create and track tickets' },
69
- ],
70
-
71
- routes: [
72
138
  {
73
- title: 'Create Ticket',
74
- description: 'Help user create a support ticket',
75
- conditions: ['User wants to report an issue'],
76
- guidelines: [
77
- { condition: 'Issue is urgent', action: 'Prioritize immediately' },
78
- ],
139
+ condition: 'User seems frustrated',
140
+ action: 'Apologize sincerely and offer to escalate to human support',
141
+ enabled: true,
79
142
  },
80
143
  ],
144
+ ],
81
145
 
82
- observations: [
83
- {
84
- description: 'User mentions problem but unclear what kind',
85
- routeRefs: ['Create Ticket', 'Check Ticket Status'], // By title!
86
- },
146
+ capabilities: [
147
+ { title: 'Ticket Management', description: 'Create and track tickets' },
87
148
  ],
88
149
  });
150
+
151
+ // Use with session state
152
+ let session = createSession<FlightData>();
153
+ const response = await agent.respond({ history, session });
154
+ console.log(response.session?.extracted); // Extracted flight data
89
155
  ```
90
156
 
157
+ ````
158
+
91
159
  ---
92
160
 
93
161
  ## 🛤️ Route Constructor Options
94
162
 
95
163
  ```typescript
96
- interface RouteOptions {
164
+ interface RouteOptions<TExtracted = unknown> {
97
165
  // Required
98
166
  title: string;
99
167
 
@@ -105,15 +173,28 @@ interface RouteOptions {
105
173
  domains?: string[]; // Restrict which domains are available in this route
106
174
  rules?: string[]; // Absolute rules the agent MUST follow
107
175
  prohibitions?: string[]; // Absolute prohibitions the agent MUST NEVER do
176
+
177
+ // NEW: Schema-first data extraction
178
+ gatherSchema?: {
179
+ type: "object";
180
+ properties: Record<string, any>;
181
+ required?: string[];
182
+ additionalProperties?: boolean;
183
+ };
184
+
185
+ // NEW: Pre-populate extracted data when entering route
186
+ initialData?: Partial<TExtracted>;
108
187
  }
109
- ```
188
+ ````
110
189
 
111
190
  **Domain Scoping:**
191
+
112
192
  - Use `domains` to limit which registered domains (tools/methods) can be accessed during this route
113
193
  - If `undefined` or omitted, all registered domains are available
114
194
  - Useful for security (preventing unauthorized tool calls) and performance (reducing AI decision space)
115
195
 
116
196
  **Rules & Prohibitions:**
197
+
117
198
  - **Rules**: Absolute requirements the agent must follow in this route (style, format, behavior)
118
199
  - **Prohibitions**: Things the agent must never do in this route
119
200
  - These override general guidelines if there's any conflict
@@ -124,23 +205,23 @@ interface RouteOptions {
124
205
 
125
206
  ```typescript
126
207
  const agent = new Agent({
127
- name: 'Bot',
208
+ name: "Bot",
128
209
  ai: provider,
129
210
  routes: [
130
211
  {
131
- title: 'Onboarding',
132
- description: 'Guide new users',
133
- conditions: ['User is new'],
212
+ title: "Onboarding",
213
+ description: "Guide new users",
214
+ conditions: ["User is new"],
134
215
  guidelines: [
135
216
  {
136
- condition: 'User skips a step',
217
+ condition: "User skips a step",
137
218
  action: "Gently remind them it's important",
138
- tags: ['onboarding'],
219
+ tags: ["onboarding"],
139
220
  },
140
221
  {
141
- condition: 'User seems confused',
142
- action: 'Offer a quick tutorial video',
143
- tags: ['help'],
222
+ condition: "User seems confused",
223
+ action: "Offer a quick tutorial video",
224
+ tags: ["help"],
144
225
  },
145
226
  ],
146
227
  },
@@ -152,7 +233,7 @@ const agent = new Agent({
152
233
 
153
234
  ```typescript
154
235
  // Register domains
155
- agent.addDomain('scraping', {
236
+ agent.addDomain("scraping", {
156
237
  scrapeSite: async (url: string) => {
157
238
  /* ... */
158
239
  },
@@ -161,7 +242,7 @@ agent.addDomain('scraping', {
161
242
  },
162
243
  });
163
244
 
164
- agent.addDomain('calendar', {
245
+ agent.addDomain("calendar", {
165
246
  scheduleEvent: async (date: Date, title: string) => {
166
247
  /* ... */
167
248
  },
@@ -170,7 +251,7 @@ agent.addDomain('calendar', {
170
251
  },
171
252
  });
172
253
 
173
- agent.addDomain('payment', {
254
+ agent.addDomain("payment", {
174
255
  processPayment: async (amount: number) => {
175
256
  /* ... */
176
257
  },
@@ -178,32 +259,32 @@ agent.addDomain('payment', {
178
259
 
179
260
  // Create routes with domain restrictions
180
261
  agent.createRoute({
181
- title: 'Data Collection',
182
- description: 'Collect and process web data',
183
- domains: ['scraping'], // ✅ Only scraping tools available
262
+ title: "Data Collection",
263
+ description: "Collect and process web data",
264
+ domains: ["scraping"], // ✅ Only scraping tools available
184
265
  });
185
266
 
186
267
  agent.createRoute({
187
- title: 'Schedule Meeting',
188
- description: 'Book appointments',
189
- domains: ['calendar'], // ✅ Only calendar tools available
268
+ title: "Schedule Meeting",
269
+ description: "Book appointments",
270
+ domains: ["calendar"], // ✅ Only calendar tools available
190
271
  });
191
272
 
192
273
  agent.createRoute({
193
- title: 'Checkout',
194
- description: 'Process purchase',
195
- domains: ['payment', 'calendar'], // ✅ Multiple domains allowed
274
+ title: "Checkout",
275
+ description: "Process purchase",
276
+ domains: ["payment", "calendar"], // ✅ Multiple domains allowed
196
277
  });
197
278
 
198
279
  agent.createRoute({
199
- title: 'FAQ Support',
200
- description: 'Answer general questions',
280
+ title: "FAQ Support",
281
+ description: "Answer general questions",
201
282
  domains: [], // ✅ No tools available (conversation only)
202
283
  });
203
284
 
204
285
  agent.createRoute({
205
- title: 'Admin Support',
206
- description: 'Administrative tasks',
286
+ title: "Admin Support",
287
+ description: "Administrative tasks",
207
288
  // domains not specified = all domains available (for demo purposes)
208
289
  });
209
290
  ```
@@ -213,61 +294,62 @@ agent.createRoute({
213
294
  ```typescript
214
295
  // WhatsApp support bot with different styles per route
215
296
  agent.createRoute({
216
- title: 'Customer Support',
217
- description: 'Help customers with issues',
297
+ title: "Customer Support",
298
+ description: "Help customers with issues",
218
299
  domains: [],
219
300
  rules: [
220
- 'Keep messages short (maximum 2 lines per message)',
221
- 'Use maximum 1 emoji per message',
222
- 'Always ask if the issue is resolved before ending',
223
- 'Professional but friendly tone'
301
+ "Keep messages short (maximum 2 lines per message)",
302
+ "Use maximum 1 emoji per message",
303
+ "Always ask if the issue is resolved before ending",
304
+ "Professional but friendly tone",
224
305
  ],
225
306
  prohibitions: [
226
- 'Never send messages longer than 3 paragraphs',
227
- 'Do not use slang or informal language',
228
- 'Never promise what you cannot deliver',
229
- 'Do not ask for sensitive information via chat'
230
- ]
307
+ "Never send messages longer than 3 paragraphs",
308
+ "Do not use slang or informal language",
309
+ "Never promise what you cannot deliver",
310
+ "Do not ask for sensitive information via chat",
311
+ ],
231
312
  });
232
313
 
233
314
  agent.createRoute({
234
- title: 'Sales Consultation',
235
- description: 'Help customer discover needs and present solutions',
236
- domains: ['calendar', 'analytics'],
315
+ title: "Sales Consultation",
316
+ description: "Help customer discover needs and present solutions",
317
+ domains: ["calendar", "analytics"],
237
318
  rules: [
238
- 'Ask open-ended questions to discover needs',
239
- 'Use storytelling when presenting solutions',
240
- 'Emoji only to reinforce positive emotions 😊',
241
- 'Always present value before mentioning price'
319
+ "Ask open-ended questions to discover needs",
320
+ "Use storytelling when presenting solutions",
321
+ "Emoji only to reinforce positive emotions 😊",
322
+ "Always present value before mentioning price",
242
323
  ],
243
324
  prohibitions: [
244
- 'Never talk about price before showing value',
245
- 'Do not pressure the customer',
246
- 'Avoid complex technical terms',
247
- 'Never send more than 2 messages in a row without customer response'
248
- ]
325
+ "Never talk about price before showing value",
326
+ "Do not pressure the customer",
327
+ "Avoid complex technical terms",
328
+ "Never send more than 2 messages in a row without customer response",
329
+ ],
249
330
  });
250
331
 
251
332
  agent.createRoute({
252
- title: 'Emergency Support',
253
- description: 'Handle urgent customer issues',
254
- domains: ['notifications', 'ticketing'],
333
+ title: "Emergency Support",
334
+ description: "Handle urgent customer issues",
335
+ domains: ["notifications", "ticketing"],
255
336
  rules: [
256
- 'Respond immediately and acknowledge urgency',
257
- 'Use clear, direct language',
258
- 'Provide concrete next steps',
259
- 'Set clear expectations on resolution time'
337
+ "Respond immediately and acknowledge urgency",
338
+ "Use clear, direct language",
339
+ "Provide concrete next steps",
340
+ "Set clear expectations on resolution time",
260
341
  ],
261
342
  prohibitions: [
262
- 'Never downplay the customer\'s concern',
263
- 'Do not use emojis',
343
+ "Never downplay the customer's concern",
344
+ "Do not use emojis",
264
345
  'Never say "calm down" or similar phrases',
265
- 'Do not transfer without explaining why'
266
- ]
346
+ "Do not transfer without explaining why",
347
+ ],
267
348
  });
268
349
  ```
269
350
 
270
351
  **How it works:**
352
+
271
353
  - Rules and prohibitions are automatically applied when the route is active
272
354
  - They override general guidelines if there's any conflict
273
355
  - Perfect for controlling communication style per context
@@ -275,16 +357,7 @@ agent.createRoute({
275
357
 
276
358
  ---
277
359
 
278
- ## 🔍 Observation Options
279
-
280
- ```typescript
281
- interface ObservationOptions {
282
- description: string;
283
- routeRefs?: string[]; // NEW! Reference routes by ID or title
284
- }
285
- ```
286
-
287
- ### Example: Observations with Route References
360
+ ### Example: With Route References
288
361
 
289
362
  ```typescript
290
363
  const agent = new Agent({
@@ -295,16 +368,6 @@ const agent = new Agent({
295
368
  { title: "Cancel Appointment", conditions: [...] },
296
369
  { title: "Reschedule Appointment", conditions: [...] }
297
370
  ],
298
- observations: [
299
- {
300
- description: "User mentions appointment but intent unclear",
301
- routeRefs: ["Schedule Appointment", "Reschedule Appointment"]
302
- },
303
- {
304
- description: "User wants to change something about their visit",
305
- routeRefs: ["Cancel Appointment", "Reschedule Appointment"]
306
- }
307
- ]
308
371
  });
309
372
  ```
310
373
 
@@ -316,15 +379,12 @@ All constructor options also have fluent methods that **return `this`** for chai
316
379
 
317
380
  ```typescript
318
381
  agent
319
- .createTerm({ name: 'API', description: '...' })
320
- .createGuideline({ condition: '...', action: '...' })
321
- .createCapability({ title: '...', description: '...' });
322
-
323
- const route = agent.createRoute({ title: '...' });
324
- route.createGuideline({ condition: '...', action: '...' });
382
+ .createTerm({ name: "API", description: "..." })
383
+ .createGuideline({ condition: "...", action: "..." })
384
+ .createCapability({ title: "...", description: "..." });
325
385
 
326
- const obs = agent.createObservation('User intent unclear');
327
- obs.disambiguate([route1, route2]);
386
+ const route = agent.createRoute({ title: "..." });
387
+ route.createGuideline({ condition: "...", action: "..." });
328
388
  ```
329
389
 
330
390
  ---
@@ -350,7 +410,7 @@ obs.disambiguate([route1, route2]);
350
410
  ```typescript
351
411
  // Start with static config
352
412
  const agent = new Agent({
353
- name: 'Bot',
413
+ name: "Bot",
354
414
  ai: provider,
355
415
  terms: loadTermsFromFile(),
356
416
  guidelines: loadGuidelinesFromDB(),
@@ -359,8 +419,8 @@ const agent = new Agent({
359
419
  // Add dynamic features
360
420
  if (user.isPremium) {
361
421
  agent.createGuideline({
362
- condition: 'User asks for priority support',
363
- action: 'Escalate immediately to premium team',
422
+ condition: "User asks for priority support",
423
+ action: "Escalate immediately to premium team",
364
424
  });
365
425
  }
366
426
  ```
@@ -369,15 +429,13 @@ if (user.isPremium) {
369
429
 
370
430
  ## 📊 Complete Comparison
371
431
 
372
- | Feature | Declarative (Constructor) | Fluent (Methods) |
373
- | -------------------- | ------------------------------------ | ------------------------------ |
374
- | **Terms** | `terms: Term[]` | `agent.createTerm(...)` |
375
- | **Guidelines** | `guidelines: Guideline[]` | `agent.createGuideline(...)` |
376
- | **Capabilities** | `capabilities: Capability[]` | `agent.createCapability(...)` |
377
- | **Routes** | `routes: RouteOptions[]` | `agent.createRoute(...)` |
378
- | **Route Guidelines** | `route.guidelines: Guideline[]` | `route.createGuideline(...)` |
379
- | **Observations** | `observations: ObservationOptions[]` | `agent.createObservation(...)` |
380
- | **Disambiguation** | `routeRefs: string[]` | `obs.disambiguate([...])` |
432
+ | Feature | Declarative (Constructor) | Fluent (Methods) |
433
+ | -------------------- | ------------------------------- | ----------------------------- |
434
+ | **Terms** | `terms: Term[]` | `agent.createTerm(...)` |
435
+ | **Guidelines** | `guidelines: Guideline[]` | `agent.createGuideline(...)` |
436
+ | **Capabilities** | `capabilities: Capability[]` | `agent.createCapability(...)` |
437
+ | **Routes** | `routes: RouteOptions[]` | `agent.createRoute(...)` |
438
+ | **Route Guidelines** | `route.guidelines: Guideline[]` | `route.createGuideline(...)` |
381
439
 
382
440
  ---
383
441
 
@@ -397,7 +455,6 @@ const agent = new Agent<MyContext>({
397
455
  guidelines?: Guideline[],
398
456
  capabilities?: Capability[],
399
457
  routes?: RouteOptions[], // Can include nested guidelines
400
- observations?: ObservationOptions[] // Can reference routes by title
401
458
  });
402
459
  ```
403
460