@falai/agent 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/cjs/core/Agent.d.ts +202 -67
  2. package/dist/cjs/core/Agent.d.ts.map +1 -1
  3. package/dist/cjs/core/Agent.js +366 -158
  4. package/dist/cjs/core/Agent.js.map +1 -1
  5. package/dist/cjs/core/BatchExecutor.d.ts.map +1 -1
  6. package/dist/cjs/core/BatchExecutor.js +4 -2
  7. package/dist/cjs/core/BatchExecutor.js.map +1 -1
  8. package/dist/cjs/core/BatchPromptBuilder.d.ts.map +1 -1
  9. package/dist/cjs/core/BatchPromptBuilder.js +5 -2
  10. package/dist/cjs/core/BatchPromptBuilder.js.map +1 -1
  11. package/dist/cjs/core/ResponseEngine.d.ts.map +1 -1
  12. package/dist/cjs/core/ResponseEngine.js +6 -3
  13. package/dist/cjs/core/ResponseEngine.js.map +1 -1
  14. package/dist/cjs/core/ResponseModal.d.ts.map +1 -1
  15. package/dist/cjs/core/ResponseModal.js +18 -17
  16. package/dist/cjs/core/ResponseModal.js.map +1 -1
  17. package/dist/cjs/core/RoutingEngine.d.ts.map +1 -1
  18. package/dist/cjs/core/RoutingEngine.js +8 -73
  19. package/dist/cjs/core/RoutingEngine.js.map +1 -1
  20. package/dist/core/Agent.d.ts +202 -67
  21. package/dist/core/Agent.d.ts.map +1 -1
  22. package/dist/core/Agent.js +366 -158
  23. package/dist/core/Agent.js.map +1 -1
  24. package/dist/core/BatchExecutor.d.ts.map +1 -1
  25. package/dist/core/BatchExecutor.js +4 -2
  26. package/dist/core/BatchExecutor.js.map +1 -1
  27. package/dist/core/BatchPromptBuilder.d.ts.map +1 -1
  28. package/dist/core/BatchPromptBuilder.js +5 -2
  29. package/dist/core/BatchPromptBuilder.js.map +1 -1
  30. package/dist/core/ResponseEngine.d.ts.map +1 -1
  31. package/dist/core/ResponseEngine.js +6 -3
  32. package/dist/core/ResponseEngine.js.map +1 -1
  33. package/dist/core/ResponseModal.d.ts.map +1 -1
  34. package/dist/core/ResponseModal.js +18 -17
  35. package/dist/core/ResponseModal.js.map +1 -1
  36. package/dist/core/RoutingEngine.d.ts.map +1 -1
  37. package/dist/core/RoutingEngine.js +8 -73
  38. package/dist/core/RoutingEngine.js.map +1 -1
  39. package/docs/api/README.md +2 -2
  40. package/docs/api/overview.md +1 -1
  41. package/docs/architecture/data-extraction-flow.md +17 -19
  42. package/docs/core/conversation-flows/data-collection.md +2 -2
  43. package/docs/core/error-handling.md +3 -4
  44. package/package.json +2 -2
  45. package/src/core/Agent.ts +427 -195
  46. package/src/core/BatchExecutor.ts +5 -2
  47. package/src/core/BatchPromptBuilder.ts +41 -38
  48. package/src/core/ResponseEngine.ts +56 -53
  49. package/src/core/ResponseModal.ts +79 -81
  50. package/src/core/RoutingEngine.ts +67 -149
@@ -4,6 +4,7 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Agent = void 0;
7
+ const types_1 = require("../types");
7
8
  const utils_1 = require("../utils");
8
9
  const Route_1 = require("./Route");
9
10
  const PersistenceManager_1 = require("./PersistenceManager");
@@ -39,14 +40,14 @@ class RouteConfigurationError extends Error {
39
40
  class Agent {
40
41
  constructor(options) {
41
42
  this.options = options;
42
- this.terms = [];
43
- this.guidelines = [];
44
- this.tools = [];
45
- this.routes = [];
46
- this.agentRules = [];
47
- this.agentProhibitions = [];
48
- this.knowledgeBase = {};
49
- this.collectedData = {};
43
+ this._terms = [];
44
+ this._guidelines = [];
45
+ this._tools = [];
46
+ this._routes = [];
47
+ this._rules = [];
48
+ this._prohibitions = [];
49
+ this._knowledgeBase = {};
50
+ this._collectedData = {};
50
51
  // Set log level based on debug option
51
52
  if (options.debug) {
52
53
  utils_1.logger.setLevel(utils_1.LoggerLevel.DEBUG);
@@ -57,31 +58,31 @@ class Agent {
57
58
  }
58
59
  // Initialize and validate agent-level schema if provided
59
60
  if (options.schema) {
60
- this.schema = options.schema;
61
- this.validateSchema(this.schema);
61
+ this._schema = options.schema;
62
+ this.validateSchema(this._schema);
62
63
  utils_1.logger.debug("[Agent] Agent-level schema initialized and validated");
63
64
  }
64
65
  // Initialize context if provided
65
- this.context = options.context;
66
+ this._context = options.context;
66
67
  // Initialize collected data with initial data if provided
67
68
  if (options.initialData) {
68
- if (this.schema) {
69
+ if (this._schema) {
69
70
  const validation = this.validateData(options.initialData);
70
71
  if (!validation.valid) {
71
72
  throw new Error(`Initial data validation failed: ${validation.errors.map(e => e.message).join(', ')}`);
72
73
  }
73
74
  }
74
- this.collectedData = { ...options.initialData };
75
- utils_1.logger.debug("[Agent] Initial data set:", this.collectedData);
75
+ this._collectedData = { ...options.initialData };
76
+ utils_1.logger.debug("[Agent] Initial data set:", this._collectedData);
76
77
  }
77
78
  // Initialize current session if provided
78
- this.currentSession = options.session;
79
+ this._currentSession = options.session;
79
80
  // Initialize routing engine
80
- this.routingEngine = new RoutingEngine_1.RoutingEngine({
81
+ this._routingEngine = new RoutingEngine_1.RoutingEngine({
81
82
  routeSwitchMargin: options.routeSwitchMargin,
82
83
  });
83
84
  // Initialize ResponseModal for handling all response generation
84
- this.responseModal = new ResponseModal_1.ResponseModal(this);
85
+ this._responseModal = new ResponseModal_1.ResponseModal(this);
85
86
  // Initialize persistence if configured
86
87
  if (options.persistence) {
87
88
  try {
@@ -95,7 +96,7 @@ class Agent {
95
96
  if (!options.persistence.adapter.messageRepository) {
96
97
  throw new Error("Persistence adapter must provide a messageRepository");
97
98
  }
98
- this.persistenceManager = new PersistenceManager_1.PersistenceManager(options.persistence);
99
+ this._persistenceManager = new PersistenceManager_1.PersistenceManager(options.persistence);
99
100
  // Initialize the adapter if it has an initialize method
100
101
  if (options.persistence.adapter.initialize) {
101
102
  options.persistence.adapter.initialize().catch((error) => {
@@ -127,10 +128,10 @@ class Agent {
127
128
  }
128
129
  // Initialize agent-level rules and prohibitions
129
130
  if (options.rules) {
130
- this.agentRules = [...options.rules];
131
+ this._rules = [...options.rules];
131
132
  }
132
133
  if (options.prohibitions) {
133
- this.agentProhibitions = [...options.prohibitions];
134
+ this._prohibitions = [...options.prohibitions];
134
135
  }
135
136
  if (options.routes) {
136
137
  options.routes.forEach((routeOptions) => {
@@ -139,10 +140,10 @@ class Agent {
139
140
  }
140
141
  // Initialize knowledge base
141
142
  if (options.knowledgeBase) {
142
- this.knowledgeBase = { ...options.knowledgeBase };
143
+ this._knowledgeBase = { ...options.knowledgeBase };
143
144
  }
144
145
  // Initialize session manager with reference to this agent for bidirectional sync
145
- this.session = new SessionManager_1.SessionManager(this.persistenceManager, this);
146
+ this.session = new SessionManager_1.SessionManager(this._persistenceManager, this);
146
147
  // Initialize tool manager with proper type inference
147
148
  this.tool = new ToolManager_1.ToolManager(this);
148
149
  // Store sessionId for later use in getOrCreate calls
@@ -152,8 +153,8 @@ class Agent {
152
153
  this.session.getOrCreate(options.sessionId).then((session) => {
153
154
  // Sync session data to agent collected data
154
155
  if (session.data && Object.keys(session.data).length > 0) {
155
- this.collectedData = { ...session.data };
156
- utils_1.logger.debug("[Agent] Synced session data to collected data:", this.collectedData);
156
+ this._collectedData = { ...session.data };
157
+ utils_1.logger.debug("[Agent] Synced session data to collected data:", this._collectedData);
157
158
  }
158
159
  }).catch((err) => {
159
160
  utils_1.logger.error("Failed to start session", err);
@@ -183,16 +184,16 @@ class Agent {
183
184
  * Validate data against the agent-level schema
184
185
  */
185
186
  validateData(data) {
186
- if (!this.schema) {
187
+ if (!this._schema) {
187
188
  // No schema defined, consider all data valid
188
189
  return { valid: true, errors: [], warnings: [] };
189
190
  }
190
191
  const errors = [];
191
192
  const warnings = [];
192
193
  // Basic validation - check if provided fields exist in schema
193
- if (this.schema.properties) {
194
+ if (this._schema.properties) {
194
195
  for (const [key, value] of Object.entries(data)) {
195
- if (!(key in this.schema.properties)) {
196
+ if (!(key in this._schema.properties)) {
196
197
  errors.push({
197
198
  field: key,
198
199
  value,
@@ -203,8 +204,8 @@ class Agent {
203
204
  }
204
205
  }
205
206
  // Check required fields if specified
206
- if (this.schema.required && Array.isArray(this.schema.required)) {
207
- for (const requiredField of this.schema.required) {
207
+ if (this._schema.required && Array.isArray(this._schema.required)) {
208
+ for (const requiredField of this._schema.required) {
208
209
  if (!(requiredField in data) || data[requiredField] === undefined) {
209
210
  warnings.push({
210
211
  field: requiredField,
@@ -227,11 +228,11 @@ class Agent {
227
228
  * @returns true if field exists in schema or no schema is defined, false otherwise
228
229
  */
229
230
  isValidSchemaField(field) {
230
- if (!this.schema || !this.schema.properties) {
231
+ if (!this._schema || !this._schema.properties) {
231
232
  // No schema defined, consider all fields valid
232
233
  return true;
233
234
  }
234
- return field in this.schema.properties;
235
+ return field in this._schema.properties;
235
236
  }
236
237
  /**
237
238
  * Get the current collected data
@@ -239,7 +240,7 @@ class Agent {
239
240
  getCollectedData() {
240
241
  // Ensure agent collected data is synced with session
241
242
  this.syncSessionDataToCollectedData();
242
- return { ...this.collectedData };
243
+ return { ...this._collectedData };
243
244
  }
244
245
  /**
245
246
  * Update collected data with validation
@@ -257,80 +258,366 @@ class Agent {
257
258
  utils_1.logger.warn(`[Agent] Data validation warnings: ${warningMessages}`);
258
259
  }
259
260
  // Merge updates with current data
260
- const previousData = { ...this.collectedData };
261
- this.collectedData = {
262
- ...this.collectedData,
261
+ const previousData = { ...this._collectedData };
262
+ this._collectedData = {
263
+ ...this._collectedData,
263
264
  ...updates
264
265
  };
265
266
  // Trigger agent-level lifecycle hook if configured
266
267
  if (this.options.hooks?.onDataUpdate) {
267
- this.collectedData = await this.options.hooks.onDataUpdate(this.collectedData, previousData);
268
+ this._collectedData = await this.options.hooks.onDataUpdate(this._collectedData, previousData);
268
269
  }
269
270
  // Update current session if it exists to keep it in sync
270
- if (this.currentSession) {
271
- this.currentSession = (0, utils_1.mergeCollected)(this.currentSession, this.collectedData);
271
+ if (this._currentSession) {
272
+ this._currentSession = (0, utils_1.mergeCollected)(this._currentSession, this._collectedData);
272
273
  }
273
274
  // Also update the session manager's session data (avoid circular call)
274
275
  const sessionManagerSession = this.session.current;
275
276
  if (sessionManagerSession) {
276
- sessionManagerSession.data = { ...this.collectedData };
277
+ sessionManagerSession.data = { ...this._collectedData };
277
278
  sessionManagerSession.metadata.lastUpdatedAt = new Date();
278
279
  }
279
280
  utils_1.logger.debug("[Agent] Collected data updated:", updates);
280
281
  }
282
+ // ---------------------------------------------------------------------------
283
+ // Property accessors (get / set)
284
+ // ---------------------------------------------------------------------------
281
285
  /**
282
286
  * Get agent name
283
287
  */
284
288
  get name() {
285
289
  return this.options.name;
286
290
  }
291
+ /**
292
+ * Set agent name
293
+ */
294
+ set name(value) {
295
+ this.options.name = value;
296
+ }
287
297
  /**
288
298
  * Get agent description
289
299
  */
290
300
  get description() {
291
301
  return this.options.description;
292
302
  }
303
+ /**
304
+ * Set agent description
305
+ */
306
+ set description(value) {
307
+ this.options.description = value;
308
+ }
293
309
  /**
294
310
  * Get agent goal
295
311
  */
296
312
  get goal() {
297
313
  return this.options.goal;
298
314
  }
315
+ /**
316
+ * Set agent goal
317
+ */
318
+ set goal(value) {
319
+ this.options.goal = value;
320
+ }
299
321
  /**
300
322
  * Get agent identity
301
323
  */
302
324
  get identity() {
303
325
  return this.options.identity;
304
326
  }
327
+ /**
328
+ * Set agent identity
329
+ */
330
+ set identity(value) {
331
+ this.options.identity = value;
332
+ }
333
+ /**
334
+ * Get agent personality
335
+ */
336
+ get personality() {
337
+ return this.options.personality;
338
+ }
339
+ /**
340
+ * Set agent personality
341
+ */
342
+ set personality(value) {
343
+ this.options.personality = value;
344
+ }
345
+ /**
346
+ * Get whether debug mode is enabled
347
+ */
348
+ get debug() {
349
+ return this.options.debug ?? false;
350
+ }
351
+ /**
352
+ * Set debug mode (also updates logger level)
353
+ */
354
+ set debug(value) {
355
+ this.options.debug = value;
356
+ utils_1.logger.setLevel(value ? utils_1.LoggerLevel.DEBUG : utils_1.LoggerLevel.INFO);
357
+ }
358
+ /**
359
+ * Get the AI provider
360
+ */
361
+ get provider() {
362
+ return this.options.provider;
363
+ }
364
+ /**
365
+ * Set the AI provider
366
+ */
367
+ set provider(value) {
368
+ this.options.provider = value;
369
+ }
370
+ /**
371
+ * Get the composition mode
372
+ */
373
+ get compositionMode() {
374
+ return this.options.compositionMode ?? types_1.CompositionMode.FLUID;
375
+ }
376
+ /**
377
+ * Set the composition mode
378
+ */
379
+ set compositionMode(value) {
380
+ this.options.compositionMode = value;
381
+ }
382
+ /**
383
+ * Get the route switch margin
384
+ * @default 15
385
+ */
386
+ get routeSwitchMargin() {
387
+ return this.options.routeSwitchMargin ?? 15;
388
+ }
389
+ /**
390
+ * Set the route switch margin
391
+ */
392
+ set routeSwitchMargin(value) {
393
+ this.options.routeSwitchMargin = value;
394
+ }
395
+ /**
396
+ * Get the maximum steps per batch
397
+ * @default 1
398
+ */
399
+ get maxStepsPerBatch() {
400
+ return this.options.maxStepsPerBatch ?? 1;
401
+ }
402
+ /**
403
+ * Set the maximum steps per batch
404
+ */
405
+ set maxStepsPerBatch(value) {
406
+ this.options.maxStepsPerBatch = value;
407
+ }
408
+ /**
409
+ * Get all terms
410
+ */
411
+ get terms() {
412
+ return [...this._terms];
413
+ }
414
+ /**
415
+ * Get all guidelines
416
+ */
417
+ get guidelines() {
418
+ return [...this._guidelines];
419
+ }
420
+ /**
421
+ * Get all tools
422
+ */
423
+ get tools() {
424
+ return [...this._tools];
425
+ }
426
+ /**
427
+ * Get all routes
428
+ */
429
+ get routes() {
430
+ return [...this._routes];
431
+ }
432
+ /**
433
+ * Get agent-level rules
434
+ */
435
+ get rules() {
436
+ return [...this._rules];
437
+ }
438
+ /**
439
+ * Set agent-level rules
440
+ */
441
+ set rules(value) {
442
+ this._rules = [...value];
443
+ }
444
+ /**
445
+ * Get agent-level prohibitions
446
+ */
447
+ get prohibitions() {
448
+ return [...this._prohibitions];
449
+ }
450
+ /**
451
+ * Set agent-level prohibitions
452
+ */
453
+ set prohibitions(value) {
454
+ this._prohibitions = [...value];
455
+ }
456
+ /**
457
+ * Get current schema
458
+ */
459
+ get schema() {
460
+ return this._schema;
461
+ }
462
+ /**
463
+ * Set schema (validates structure)
464
+ */
465
+ set schema(value) {
466
+ if (value) {
467
+ this.validateSchema(value);
468
+ }
469
+ this._schema = value;
470
+ }
471
+ /**
472
+ * Get the agent's knowledge base
473
+ */
474
+ get knowledgeBase() {
475
+ return { ...this._knowledgeBase };
476
+ }
477
+ /**
478
+ * Set the agent's knowledge base
479
+ */
480
+ set knowledgeBase(value) {
481
+ this._knowledgeBase = { ...value };
482
+ }
483
+ /**
484
+ * Get the current session (if set)
485
+ */
486
+ get currentSession() {
487
+ return this._currentSession;
488
+ }
489
+ /**
490
+ * Set the current session for convenience methods
491
+ * Set to undefined to clear the current session
492
+ */
493
+ set currentSession(value) {
494
+ this._currentSession = value;
495
+ }
496
+ // ---------------------------------------------------------------------------
497
+ // Deprecated method-based accessors (for backward compatibility)
498
+ // ---------------------------------------------------------------------------
499
+ /**
500
+ * Get all terms
501
+ * @deprecated Use `agent.terms` instead
502
+ */
503
+ getTerms() {
504
+ return this.terms;
505
+ }
506
+ /**
507
+ * Get all tools
508
+ * @deprecated Use `agent.tools` instead
509
+ */
510
+ getTools() {
511
+ return this.tools;
512
+ }
513
+ /**
514
+ * Get all guidelines
515
+ * @deprecated Use `agent.guidelines` instead
516
+ */
517
+ getGuidelines() {
518
+ return this.guidelines;
519
+ }
520
+ /**
521
+ * Get all routes
522
+ * @deprecated Use `agent.routes` instead
523
+ */
524
+ getRoutes() {
525
+ return this.routes;
526
+ }
527
+ /**
528
+ * Get agent-level rules
529
+ * @deprecated Use `agent.rules` instead
530
+ */
531
+ getRules() {
532
+ return this.rules;
533
+ }
534
+ /**
535
+ * Get agent-level prohibitions
536
+ * @deprecated Use `agent.prohibitions` instead
537
+ */
538
+ getProhibitions() {
539
+ return this.prohibitions;
540
+ }
541
+ /**
542
+ * Get current schema
543
+ * @deprecated Use `agent.schema` instead
544
+ */
545
+ getSchema() {
546
+ return this.schema;
547
+ }
548
+ /**
549
+ * Get the agent's knowledge base
550
+ * @deprecated Use `agent.knowledgeBase` instead
551
+ */
552
+ getKnowledgeBase() {
553
+ return this.knowledgeBase;
554
+ }
555
+ /**
556
+ * Get the current session (if set)
557
+ * @deprecated Use `agent.currentSession` instead
558
+ */
559
+ getCurrentSession() {
560
+ return this.currentSession;
561
+ }
562
+ /**
563
+ * Set the current session for convenience methods
564
+ * @deprecated Use `agent.currentSession = session` instead
565
+ * @param session - Session step to use for subsequent calls
566
+ */
567
+ setCurrentSession(session) {
568
+ this.currentSession = session;
569
+ }
570
+ /**
571
+ * Clear the current session
572
+ * @deprecated Use `agent.currentSession = undefined` instead
573
+ */
574
+ clearCurrentSession() {
575
+ this._currentSession = undefined;
576
+ }
577
+ /**
578
+ * Get the persistence manager (if configured)
579
+ */
580
+ getPersistenceManager() {
581
+ return this._persistenceManager;
582
+ }
583
+ /**
584
+ * Check if persistence is enabled
585
+ */
586
+ hasPersistence() {
587
+ return this._persistenceManager !== undefined;
588
+ }
589
+ // ---------------------------------------------------------------------------
590
+ // Core methods
591
+ // ---------------------------------------------------------------------------
305
592
  /**
306
593
  * Create a new route (journey) using agent-level data type
307
594
  */
308
595
  createRoute(options) {
309
596
  // Validate that requiredFields exist in agent schema
310
- if (options.requiredFields && this.schema?.properties) {
311
- const invalidRequiredFields = options.requiredFields.filter(field => !(String(field) in this.schema.properties));
597
+ if (options.requiredFields && this._schema?.properties) {
598
+ const invalidRequiredFields = options.requiredFields.filter(field => !(String(field) in this._schema.properties));
312
599
  if (invalidRequiredFields.length > 0) {
313
600
  throw new RouteConfigurationError(options.title, invalidRequiredFields.map(f => String(f)), `Invalid required fields in route '${options.title}': ${invalidRequiredFields.join(', ')}. ` +
314
- `Must be valid keys from agent schema. Available fields: ${Object.keys(this.schema.properties).join(', ')}.`);
601
+ `Must be valid keys from agent schema. Available fields: ${Object.keys(this._schema.properties).join(', ')}.`);
315
602
  }
316
603
  }
317
604
  // Validate that optionalFields exist in agent schema
318
- if (options.optionalFields && this.schema?.properties) {
319
- const invalidOptionalFields = options.optionalFields.filter(field => !(String(field) in this.schema.properties));
605
+ if (options.optionalFields && this._schema?.properties) {
606
+ const invalidOptionalFields = options.optionalFields.filter(field => !(String(field) in this._schema.properties));
320
607
  if (invalidOptionalFields.length > 0) {
321
608
  throw new RouteConfigurationError(options.title, invalidOptionalFields.map(f => String(f)), `Invalid optional fields in route '${options.title}': ${invalidOptionalFields.join(', ')}. ` +
322
- `Must be valid keys from agent schema. Available fields: ${Object.keys(this.schema.properties).join(', ')}.`);
609
+ `Must be valid keys from agent schema. Available fields: ${Object.keys(this._schema.properties).join(', ')}.`);
323
610
  }
324
611
  }
325
612
  const route = new Route_1.Route(options, this);
326
- this.routes.push(route);
613
+ this._routes.push(route);
327
614
  return route;
328
615
  }
329
616
  /**
330
617
  * Create a domain term for the glossary
331
618
  */
332
619
  createTerm(term) {
333
- this.terms.push(term);
620
+ this._terms.push(term);
334
621
  return this;
335
622
  }
336
623
  /**
@@ -339,10 +626,10 @@ class Agent {
339
626
  createGuideline(guideline) {
340
627
  const guidelineWithId = {
341
628
  ...guideline,
342
- id: guideline.id || `guideline_${this.guidelines.length}`,
629
+ id: guideline.id || `guideline_${this._guidelines.length}`,
343
630
  enabled: guideline.enabled !== false, // Default to true
344
631
  };
345
- this.guidelines.push(guidelineWithId);
632
+ this._guidelines.push(guidelineWithId);
346
633
  return this;
347
634
  }
348
635
  /**
@@ -356,7 +643,7 @@ class Agent {
356
643
  throw new Error('Invalid tool: must have id and handler properties');
357
644
  }
358
645
  // Add directly to agent's tools array, preserving the TResult type
359
- this.tools.push(tool);
646
+ this._tools.push(tool);
360
647
  utils_1.logger.debug(`[Agent] Added tool to agent scope: ${tool.id}`);
361
648
  return this;
362
649
  }
@@ -370,7 +657,7 @@ class Agent {
370
657
  if (!tool || !tool.id || !tool.handler) {
371
658
  throw new Error('Invalid tool: must have id and handler properties');
372
659
  }
373
- this.tools.push(tool);
660
+ this._tools.push(tool);
374
661
  utils_1.logger.debug(`[Agent] Created tool (legacy): ${tool.id}`);
375
662
  return this;
376
663
  }
@@ -384,7 +671,7 @@ class Agent {
384
671
  if (!tool || !tool.id || !tool.handler) {
385
672
  throw new Error(`Invalid tool in batch: must have id and handler properties (tool: ${tool?.id || 'unknown'})`);
386
673
  }
387
- this.tools.push(tool);
674
+ this._tools.push(tool);
388
675
  });
389
676
  utils_1.logger.debug(`[Agent] Registered ${tools.length} tools`);
390
677
  return this;
@@ -394,23 +681,23 @@ class Agent {
394
681
  * Triggers both agent-level and route-specific onContextUpdate lifecycle hooks if configured
395
682
  */
396
683
  async updateContext(updates) {
397
- const previousContext = this.context;
684
+ const previousContext = this._context;
398
685
  // Merge updates with current context
399
- this.context = {
400
- ...this.context,
686
+ this._context = {
687
+ ...this._context,
401
688
  ...updates,
402
689
  };
403
690
  // Trigger route-specific lifecycle hook if configured and session has current route
404
- if (this.currentSession?.currentRoute) {
405
- const currentRoute = this.routes.find((r) => r.id === this.currentSession.currentRoute?.id);
691
+ if (this._currentSession?.currentRoute) {
692
+ const currentRoute = this._routes.find((r) => r.id === this._currentSession.currentRoute?.id);
406
693
  if (currentRoute?.hooks?.onContextUpdate &&
407
694
  previousContext !== undefined) {
408
- await currentRoute.handleContextUpdate(this.context, previousContext);
695
+ await currentRoute.handleContextUpdate(this._context, previousContext);
409
696
  }
410
697
  }
411
698
  // Trigger agent-level lifecycle hook if configured
412
699
  if (this.options.hooks?.onContextUpdate && previousContext !== undefined) {
413
- await this.options.hooks.onContextUpdate(this.context, previousContext);
700
+ await this.options.hooks.onContextUpdate(this._context, previousContext);
414
701
  }
415
702
  }
416
703
  /**
@@ -427,7 +714,7 @@ class Agent {
427
714
  };
428
715
  // Trigger route-specific lifecycle hook if configured and session has a current route
429
716
  if (session.currentRoute) {
430
- const currentRoute = this.routes.find((r) => r.id === session.currentRoute?.id);
717
+ const currentRoute = this._routes.find((r) => r.id === session.currentRoute?.id);
431
718
  if (currentRoute?.hooks?.onDataUpdate) {
432
719
  newCollected = await currentRoute.handleDataUpdate(newCollected, previousCollected);
433
720
  }
@@ -437,7 +724,7 @@ class Agent {
437
724
  newCollected = (await this.options.hooks.onDataUpdate(newCollected, previousCollected));
438
725
  }
439
726
  // Update agent's collected data to stay in sync
440
- this.collectedData = { ...newCollected };
727
+ this._collectedData = { ...newCollected };
441
728
  // Return updated session
442
729
  return (0, utils_1.mergeCollected)(session, newCollected);
443
730
  }
@@ -450,33 +737,21 @@ class Agent {
450
737
  return await this.options.contextProvider();
451
738
  }
452
739
  // Otherwise return the stored context
453
- return this.context;
454
- }
455
- /**
456
- * Get current schema
457
- */
458
- getSchema() {
459
- return this.schema;
740
+ return this._context;
460
741
  }
461
742
  /**
462
743
  * Generate a response based on history and context as a stream
463
744
  */
464
745
  async *respondStream(params) {
465
746
  // Delegate to ResponseModal
466
- yield* this.responseModal.respondStream(params);
747
+ yield* this._responseModal.respondStream(params);
467
748
  }
468
749
  /**
469
750
  * Generate a response based on history and context
470
751
  */
471
752
  async respond(params) {
472
753
  // Delegate to ResponseModal
473
- return this.responseModal.respond(params);
474
- }
475
- /**
476
- * Get all routes
477
- */
478
- getRoutes() {
479
- return [...this.routes];
754
+ return this._responseModal.respond(params);
480
755
  }
481
756
  /**
482
757
  * Get agent options
@@ -490,7 +765,7 @@ class Agent {
490
765
  * @internal Used by ResponseModal
491
766
  */
492
767
  getRoutingEngine() {
493
- return this.routingEngine;
768
+ return this._routingEngine;
494
769
  }
495
770
  /**
496
771
  * Get the updateData method bound to this agent
@@ -499,36 +774,6 @@ class Agent {
499
774
  getUpdateDataMethod() {
500
775
  return this.updateData.bind(this);
501
776
  }
502
- /**
503
- * Get all terms
504
- */
505
- getTerms() {
506
- return [...this.terms];
507
- }
508
- /**
509
- * Get all tools
510
- */
511
- getTools() {
512
- return [...this.tools];
513
- }
514
- /**
515
- * Get all guidelines
516
- */
517
- getGuidelines() {
518
- return [...this.guidelines];
519
- }
520
- /**
521
- * Get agent-level rules
522
- */
523
- getRules() {
524
- return [...this.agentRules];
525
- }
526
- /**
527
- * Get agent-level prohibitions
528
- */
529
- getProhibitions() {
530
- return [...this.agentProhibitions];
531
- }
532
777
  /**
533
778
  * Evaluate and match active guidelines based on their conditions
534
779
  * Returns guidelines that should be active given the current context
@@ -537,7 +782,7 @@ class Agent {
537
782
  const templateContext = { context, session, history, data: session?.data };
538
783
  const evaluator = (0, utils_1.createConditionEvaluator)(templateContext);
539
784
  const matches = [];
540
- for (const guideline of this.guidelines) {
785
+ for (const guideline of this._guidelines) {
541
786
  // Skip disabled guidelines
542
787
  if (guideline.enabled === false) {
543
788
  continue;
@@ -569,37 +814,6 @@ class Agent {
569
814
  }
570
815
  return matches;
571
816
  }
572
- /**
573
- * Get the agent's knowledge base
574
- */
575
- getKnowledgeBase() {
576
- return { ...this.knowledgeBase };
577
- }
578
- /**
579
- * Get the persistence manager (if configured)
580
- */
581
- getPersistenceManager() {
582
- return this.persistenceManager;
583
- }
584
- /**
585
- * Check if persistence is enabled
586
- */
587
- hasPersistence() {
588
- return this.persistenceManager !== undefined;
589
- }
590
- /**
591
- * Set the current session for convenience methods
592
- * @param session - Session step to use for subsequent calls
593
- */
594
- setCurrentSession(session) {
595
- this.currentSession = session;
596
- }
597
- /**
598
- * Get the current session (if set)
599
- */
600
- getCurrentSession() {
601
- return this.currentSession;
602
- }
603
817
  /**
604
818
  * Execute a prepare or finalize function/tool
605
819
  * @internal Used by ResponseModal
@@ -650,12 +864,6 @@ class Agent {
650
864
  }
651
865
  }
652
866
  }
653
- /**
654
- * Clear the current session
655
- */
656
- clearCurrentSession() {
657
- this.currentSession = undefined;
658
- }
659
867
  /**
660
868
  * Sync session data to agent collected data
661
869
  * @internal Used to keep agent and session data in sync
@@ -663,8 +871,8 @@ class Agent {
663
871
  syncSessionDataToCollectedData() {
664
872
  const sessionData = this.session.getData();
665
873
  if (sessionData && Object.keys(sessionData).length > 0) {
666
- this.collectedData = { ...sessionData };
667
- utils_1.logger.debug("[Agent] Synced session data to collected data:", this.collectedData);
874
+ this._collectedData = { ...sessionData };
875
+ utils_1.logger.debug("[Agent] Synced session data to collected data:", this._collectedData);
668
876
  }
669
877
  }
670
878
  /**
@@ -676,10 +884,10 @@ class Agent {
676
884
  // Ensure agent collected data is synced with session
677
885
  this.syncSessionDataToCollectedData();
678
886
  // If we have a current session, use session data
679
- if (this.currentSession) {
887
+ if (this._currentSession) {
680
888
  // With agent-level data, all routes share the same data structure
681
889
  // No need for route-specific data access
682
- return (this.currentSession.data) || {};
890
+ return (this._currentSession.data) || {};
683
891
  }
684
892
  // Otherwise, return agent-level collected data
685
893
  return this.getCollectedData();
@@ -702,22 +910,22 @@ class Agent {
702
910
  * }
703
911
  */
704
912
  async nextStepRoute(routeIdOrTitle, session, condition, history) {
705
- const targetSession = session || this.currentSession;
913
+ const targetSession = session || this._currentSession;
706
914
  if (!targetSession) {
707
915
  throw new Error("No session provided and no current session available. Please provide a session to transition.");
708
916
  }
709
917
  // Find target route by ID or title
710
- const targetRoute = this.routes.find((r) => r.id === routeIdOrTitle || r.title === routeIdOrTitle);
918
+ const targetRoute = this._routes.find((r) => r.id === routeIdOrTitle || r.title === routeIdOrTitle);
711
919
  if (!targetRoute) {
712
- throw new Error(`Route not found: ${routeIdOrTitle}. Available routes: ${this.routes
920
+ throw new Error(`Route not found: ${routeIdOrTitle}. Available routes: ${this._routes
713
921
  .map((r) => r.title)
714
922
  .join(", ")}`);
715
923
  }
716
924
  const templateContext = (0, utils_1.createTemplateContext)({
717
- context: this.context,
925
+ context: this._context,
718
926
  session,
719
927
  history,
720
- data: this.currentSession?.data,
928
+ data: this._currentSession?.data,
721
929
  });
722
930
  const renderedCondition = await (0, utils_1.render)(condition, templateContext);
723
931
  const updatedSession = {
@@ -729,8 +937,8 @@ class Agent {
729
937
  },
730
938
  };
731
939
  // Update current session if using it
732
- if (!session && this.currentSession) {
733
- this.currentSession = updatedSession;
940
+ if (!session && this._currentSession) {
941
+ this._currentSession = updatedSession;
734
942
  }
735
943
  utils_1.logger.debug(`[Agent] Set pending transition to route: ${targetRoute.title}`);
736
944
  return updatedSession;
@@ -741,7 +949,7 @@ class Agent {
741
949
  */
742
950
  async chat(message, options) {
743
951
  // Delegate to ResponseModal.generate()
744
- return this.responseModal.generate(message, options);
952
+ return this._responseModal.generate(message, options);
745
953
  }
746
954
  /**
747
955
  * Modern streaming API - simple interface like chat() but returns a stream
@@ -749,7 +957,7 @@ class Agent {
749
957
  */
750
958
  async *stream(message, options) {
751
959
  // Delegate to ResponseModal with the same options structure as chat()
752
- yield* this.responseModal.stream(message, {
960
+ yield* this._responseModal.stream(message, {
753
961
  history: options?.history,
754
962
  contextOverride: options?.contextOverride,
755
963
  signal: options?.signal,