@ai.ntellect/core 0.7.14 → 0.8.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 (98) hide show
  1. package/dist/graph/event-manager.d.ts +9 -1
  2. package/dist/graph/event-manager.d.ts.map +1 -1
  3. package/dist/graph/event-manager.js +115 -37
  4. package/dist/graph/event-manager.js.map +1 -1
  5. package/dist/graph/index.d.ts +20 -1
  6. package/dist/graph/index.d.ts.map +1 -1
  7. package/dist/graph/index.js +59 -10
  8. package/dist/graph/index.js.map +1 -1
  9. package/dist/graph/node.d.ts +0 -24
  10. package/dist/graph/node.d.ts.map +1 -1
  11. package/dist/graph/node.js +2 -71
  12. package/dist/graph/node.js.map +1 -1
  13. package/dist/graph/observer.d.ts +6 -87
  14. package/dist/graph/observer.d.ts.map +1 -1
  15. package/dist/graph/observer.js +3 -116
  16. package/dist/graph/observer.js.map +1 -1
  17. package/dist/index.d.ts +1 -6
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -6
  20. package/dist/index.js.map +1 -1
  21. package/dist/interfaces/index.d.ts +10 -1
  22. package/dist/interfaces/index.d.ts.map +1 -1
  23. package/dist/interfaces/index.js.map +1 -1
  24. package/dist/modules/agent/agent.d.ts +35 -0
  25. package/dist/modules/agent/agent.d.ts.map +1 -0
  26. package/dist/modules/agent/agent.js +106 -0
  27. package/dist/modules/agent/agent.js.map +1 -0
  28. package/dist/modules/agent/base/executor.d.ts +51 -0
  29. package/dist/modules/agent/base/executor.d.ts.map +1 -0
  30. package/dist/modules/agent/base/executor.js +66 -0
  31. package/dist/modules/agent/base/executor.js.map +1 -0
  32. package/dist/modules/agent/base/index.d.ts +30 -0
  33. package/dist/modules/agent/base/index.d.ts.map +1 -0
  34. package/dist/modules/agent/base/index.js +100 -0
  35. package/dist/modules/agent/base/index.js.map +1 -0
  36. package/dist/modules/agent/generic-assistant.d.ts +20 -0
  37. package/dist/modules/agent/generic-assistant.d.ts.map +1 -0
  38. package/dist/modules/agent/generic-assistant.js +89 -0
  39. package/dist/modules/agent/generic-assistant.js.map +1 -0
  40. package/dist/modules/agent/generic-executor.d.ts +57 -0
  41. package/dist/modules/agent/generic-executor.d.ts.map +1 -0
  42. package/dist/modules/agent/generic-executor.js +200 -0
  43. package/dist/modules/agent/generic-executor.js.map +1 -0
  44. package/dist/modules/agent/llm-factory.d.ts +19 -0
  45. package/dist/modules/agent/llm-factory.d.ts.map +1 -0
  46. package/dist/modules/agent/llm-factory.js +56 -0
  47. package/dist/modules/agent/llm-factory.js.map +1 -0
  48. package/dist/modules/agent/prompt-builder.d.ts +35 -0
  49. package/dist/modules/agent/prompt-builder.d.ts.map +1 -0
  50. package/dist/modules/agent/prompt-builder.js +76 -0
  51. package/dist/modules/agent/prompt-builder.js.map +1 -0
  52. package/dist/modules/memory/adapters/in-memory/index.d.ts.map +1 -1
  53. package/dist/modules/memory/adapters/in-memory/index.js +4 -3
  54. package/dist/modules/memory/adapters/in-memory/index.js.map +1 -1
  55. package/dist/modules/memory/adapters/meilisearch/index.d.ts.map +1 -1
  56. package/dist/modules/memory/adapters/meilisearch/index.js +7 -4
  57. package/dist/modules/memory/adapters/meilisearch/index.js.map +1 -1
  58. package/dist/modules/memory/adapters/redis/index.d.ts.map +1 -1
  59. package/dist/modules/memory/adapters/redis/index.js +2 -1
  60. package/dist/modules/memory/adapters/redis/index.js.map +1 -1
  61. package/dist/modules/nlp/engine.d.ts +126 -0
  62. package/dist/modules/nlp/engine.d.ts.map +1 -0
  63. package/dist/modules/nlp/engine.js +300 -0
  64. package/dist/modules/nlp/engine.js.map +1 -0
  65. package/dist/modules/nlp/index.d.ts +27 -0
  66. package/dist/modules/nlp/index.d.ts.map +1 -0
  67. package/dist/modules/nlp/index.js +56 -0
  68. package/dist/modules/nlp/index.js.map +1 -0
  69. package/dist/types/agent.d.ts +233 -0
  70. package/dist/types/agent.d.ts.map +1 -0
  71. package/dist/types/agent.js +29 -0
  72. package/dist/types/agent.js.map +1 -0
  73. package/dist/types/index.d.ts +72 -18
  74. package/dist/types/index.d.ts.map +1 -1
  75. package/dist/utils/generate-action-schema.d.ts.map +1 -1
  76. package/graph/event-manager.ts +135 -42
  77. package/graph/index.ts +57 -4
  78. package/graph/node.ts +2 -104
  79. package/graph/observer.ts +9 -215
  80. package/index.ts +2 -7
  81. package/interfaces/index.ts +12 -0
  82. package/modules/agent/agent.ts +108 -0
  83. package/modules/agent/base/executor.ts +100 -0
  84. package/modules/agent/base/index.ts +99 -0
  85. package/modules/agent/generic-assistant.ts +90 -0
  86. package/modules/agent/generic-executor.ts +259 -0
  87. package/modules/agent/llm-factory.ts +47 -0
  88. package/modules/agent/prompt-builder.ts +78 -0
  89. package/modules/memory/adapters/in-memory/index.ts +4 -3
  90. package/modules/memory/adapters/meilisearch/index.ts +7 -4
  91. package/modules/memory/adapters/redis/index.ts +2 -1
  92. package/modules/nlp/engine.ts +325 -0
  93. package/modules/nlp/index.ts +45 -0
  94. package/package.json +5 -2
  95. package/test/graph/index.test.ts +6 -4
  96. package/test/graph/node.test.ts +18 -14
  97. package/types/agent.ts +174 -0
  98. package/types/index.ts +74 -18
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../../modules/agent/agent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA8C;AAC9C,6CAI2B;AAC3B,iCAAmC;AACnC,yDAAqD;AAErD;;;;;;;;;;;GAWG;AACH,MAAa,KAAK;IAIhB;;;OAGG;IACH,YAAY,MAAmB;QAC7B,MAAM,KAAK,GAAG,IAAI,gBAAS,CAAC;YAC1B,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,SAAS,EAAE,MAAM,CAAC,SAAS;SAC5B,CAAC,CAA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7B,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;wBAC3C,OAAO,CAAC,SAAS,GAAG,SAAS,SAAS,KAAK,IAAI,CAAC,SAAS,CACvD,OAAO,CAAC,OAAO,CAChB,EAAE,CAAC;wBACJ,MAAM,IAAI,CAAC,QAAQ,CAAC,cAAc,CAChC,OAAO,CAAC,OAAO,EACf,OAAkC,CACnC,CAAC;oBACJ,CAAC,CAAA;oBACD,IAAI,EAAE,CAAC,SAAS,CAAC;iBAClB;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACU,OAAO,CAAC,KAAa;;YAChC,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE;gBAChD,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE;gBACrB,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,EAAE;aACb,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,EAA6B,CAAC;QAC/D,CAAC;KAAA;CACF;AAtFD,sBAsFC"}
@@ -0,0 +1,51 @@
1
+ import { BaseAgent } from ".";
2
+ import { GraphFlow } from "../../../graph";
3
+ import { ActionSchema, AgentContext, DecisionOutput } from "../../../types/agent";
4
+ /**
5
+ * Abstract base class for agent executors that handle action execution
6
+ * @abstract
7
+ * @class AgentExecutor
8
+ */
9
+ export declare abstract class AgentExecutor {
10
+ protected agent: BaseAgent;
11
+ protected availableGraphs: Map<string, GraphFlow<any>>;
12
+ /**
13
+ * Creates an instance of AgentExecutor
14
+ * @param {BaseAgent} agent - The agent instance this executor is tied to
15
+ * @param {GraphFlow<any>[]} graphs - Array of available graph flows that can be executed
16
+ */
17
+ constructor(agent: BaseAgent, graphs: GraphFlow<any>[]);
18
+ /**
19
+ * Makes a decision based on the current context
20
+ * @abstract
21
+ * @param {any} context - The context to base the decision on
22
+ * @returns {Promise<DecisionOutput>} The decision output containing actions and response
23
+ */
24
+ abstract makeDecision(context: any): Promise<DecisionOutput>;
25
+ /**
26
+ * Executes a list of actions in the given context
27
+ * @param {ActionSchema[]} actions - Array of actions to execute
28
+ * @param {AgentContext} context - The context in which to execute the actions
29
+ * @returns {Promise<void>}
30
+ */
31
+ executeActions(actions: ActionSchema[], context: AgentContext): Promise<void>;
32
+ /**
33
+ * Prepares the input parameters for an action
34
+ * @private
35
+ * @param {Array<{name: string, value: any}>} parameters - Array of parameter objects
36
+ * @returns {Record<string, any>} Object with parameter names as keys and their values
37
+ */
38
+ private prepareActionInputs;
39
+ /**
40
+ * Executes multiple workflows with their respective inputs
41
+ * @protected
42
+ * @abstract
43
+ * @param {GraphFlow<any>[]} workflows - Array of workflows to execute
44
+ * @param {string[]} startNodes - Array of starting node names for each workflow
45
+ * @param {any[]} inputs - Array of inputs for each workflow
46
+ * @param {AgentContext} context - The context in which to execute the workflows
47
+ * @returns {Promise<void>}
48
+ */
49
+ protected abstract executeWorkflows(workflows: GraphFlow<any>[], startNodes: string[], inputs: any[], context: AgentContext): Promise<void>;
50
+ }
51
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../../modules/agent/base/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,cAAc,EACf,MAAM,sBAAsB,CAAC;AAE9B;;;;GAIG;AACH,8BAAsB,aAAa;IACjC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAEvD;;;;OAIG;gBACS,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE;IAKtD;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC;IAE5D;;;;;OAKG;IACG,cAAc,CAClB,OAAO,EAAE,YAAY,EAAE,EACvB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC;IAwBhB;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;;;;;;;;OASG;IACH,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CACjC,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,EAC3B,UAAU,EAAE,MAAM,EAAE,EACpB,MAAM,EAAE,GAAG,EAAE,EACb,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC;CACjB"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AgentExecutor = void 0;
13
+ /**
14
+ * Abstract base class for agent executors that handle action execution
15
+ * @abstract
16
+ * @class AgentExecutor
17
+ */
18
+ class AgentExecutor {
19
+ /**
20
+ * Creates an instance of AgentExecutor
21
+ * @param {BaseAgent} agent - The agent instance this executor is tied to
22
+ * @param {GraphFlow<any>[]} graphs - Array of available graph flows that can be executed
23
+ */
24
+ constructor(agent, graphs) {
25
+ this.agent = agent;
26
+ this.availableGraphs = new Map(graphs.map((g) => [g.name, g]));
27
+ }
28
+ /**
29
+ * Executes a list of actions in the given context
30
+ * @param {ActionSchema[]} actions - Array of actions to execute
31
+ * @param {AgentContext} context - The context in which to execute the actions
32
+ * @returns {Promise<void>}
33
+ */
34
+ executeActions(actions, context) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const workflowsToExecute = [];
37
+ const startNodes = [];
38
+ const inputs = [];
39
+ for (const action of actions) {
40
+ const workflow = this.availableGraphs.get(action.name);
41
+ if (!workflow)
42
+ continue;
43
+ workflowsToExecute.push(workflow);
44
+ startNodes.push(workflow.getNodes()[0].name);
45
+ inputs.push(this.prepareActionInputs(action.parameters));
46
+ }
47
+ if (workflowsToExecute.length > 0) {
48
+ yield this.executeWorkflows(workflowsToExecute, startNodes, inputs, context);
49
+ }
50
+ });
51
+ }
52
+ /**
53
+ * Prepares the input parameters for an action
54
+ * @private
55
+ * @param {Array<{name: string, value: any}>} parameters - Array of parameter objects
56
+ * @returns {Record<string, any>} Object with parameter names as keys and their values
57
+ */
58
+ prepareActionInputs(parameters) {
59
+ return parameters.reduce((acc, param) => {
60
+ acc[param.name] = param.value;
61
+ return acc;
62
+ }, {});
63
+ }
64
+ }
65
+ exports.AgentExecutor = AgentExecutor;
66
+ //# sourceMappingURL=executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../modules/agent/base/executor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAQA;;;;GAIG;AACH,MAAsB,aAAa;IAIjC;;;;OAIG;IACH,YAAY,KAAgB,EAAE,MAAwB;QACpD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,CAAC;IAUD;;;;;OAKG;IACG,cAAc,CAClB,OAAuB,EACvB,OAAqB;;YAErB,MAAM,kBAAkB,GAAqB,EAAE,CAAC;YAChD,MAAM,UAAU,GAAa,EAAE,CAAC;YAChC,MAAM,MAAM,GAAU,EAAE,CAAC;YAEzB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACvD,IAAI,CAAC,QAAQ;oBAAE,SAAS;gBAExB,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAClC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAC7C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;YAC3D,CAAC;YAED,IAAI,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,CAAC,gBAAgB,CACzB,kBAAkB,EAClB,UAAU,EACV,MAAM,EACN,OAAO,CACR,CAAC;YACJ,CAAC;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACK,mBAAmB,CACzB,UAA+C;QAE/C,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACtC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;YAC9B,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAyB,CAAC,CAAC;IAChC,CAAC;CAkBF;AAtFD,sCAsFC"}
@@ -0,0 +1,30 @@
1
+ import { AgentConfig } from "@/types/agent";
2
+ import { BaseMemoryType } from "../../../types";
3
+ /**
4
+ * Base agent class that handles role, goal, and personality management
5
+ * @class BaseAgent
6
+ */
7
+ export declare class BaseAgent {
8
+ private config;
9
+ private memory?;
10
+ constructor(config: AgentConfig);
11
+ execute(context: any, inputs?: any): Promise<any>;
12
+ private storeInMemory;
13
+ recall(query: string): Promise<BaseMemoryType[]>;
14
+ /**
15
+ * Get the agent's role - what function/job it performs
16
+ * @returns {string} The agent's role
17
+ */
18
+ getRole(): string;
19
+ /**
20
+ * Get the agent's goal - what it tries to achieve
21
+ * @returns {string} The agent's goal
22
+ */
23
+ getGoal(): string;
24
+ /**
25
+ * Get the agent's backstory - its personality and behavioral traits
26
+ * @returns {string} The agent's backstory
27
+ */
28
+ getBackstory(): string;
29
+ }
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../modules/agent/base/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,MAAM,CAAC,CAAS;gBAEZ,MAAM,EAAE,WAAW;IAKzB,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;YAmCzC,aAAa;IAcd,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAS7D;;;OAGG;IACI,OAAO,IAAI,MAAM;IAIxB;;;OAGG;IACI,OAAO,IAAI,MAAM;IAIxB;;;OAGG;IACI,YAAY,IAAI,MAAM;CAG9B"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BaseAgent = void 0;
13
+ /**
14
+ * Base agent class that handles role, goal, and personality management
15
+ * @class BaseAgent
16
+ */
17
+ class BaseAgent {
18
+ constructor(config) {
19
+ this.config = config;
20
+ this.memory = config.memory;
21
+ }
22
+ execute(context, inputs) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ // Log execution if verbose
25
+ if (this.config.verbose) {
26
+ console.log(`Agent ${this.config.role} executing...`);
27
+ console.log("Context:", context);
28
+ console.log("Inputs:", inputs);
29
+ }
30
+ // Store context in memory if available
31
+ if (this.memory) {
32
+ yield this.storeInMemory({
33
+ type: "execution",
34
+ content: JSON.stringify({ context, inputs }),
35
+ metadata: {
36
+ role: this.config.role,
37
+ timestamp: new Date().toISOString(),
38
+ },
39
+ });
40
+ }
41
+ // Execute tools if available
42
+ if (this.config.tools) {
43
+ for (const tool of this.config.tools) {
44
+ try {
45
+ const result = yield tool.execute(context, inputs);
46
+ context = Object.assign(Object.assign({}, context), result);
47
+ }
48
+ catch (error) {
49
+ console.error(`Tool execution failed:`, error);
50
+ }
51
+ }
52
+ }
53
+ return context;
54
+ });
55
+ }
56
+ storeInMemory(data) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ if (!this.memory)
59
+ return;
60
+ return this.memory.createMemory({
61
+ content: data.content,
62
+ metadata: data.metadata,
63
+ roomId: "default",
64
+ });
65
+ });
66
+ }
67
+ recall(query) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ if (!this.memory)
70
+ return [];
71
+ return this.memory.getMemoryByIndex(query, {
72
+ roomId: "default",
73
+ limit: 10,
74
+ });
75
+ });
76
+ }
77
+ /**
78
+ * Get the agent's role - what function/job it performs
79
+ * @returns {string} The agent's role
80
+ */
81
+ getRole() {
82
+ return this.config.role;
83
+ }
84
+ /**
85
+ * Get the agent's goal - what it tries to achieve
86
+ * @returns {string} The agent's goal
87
+ */
88
+ getGoal() {
89
+ return this.config.goal;
90
+ }
91
+ /**
92
+ * Get the agent's backstory - its personality and behavioral traits
93
+ * @returns {string} The agent's backstory
94
+ */
95
+ getBackstory() {
96
+ return this.config.backstory;
97
+ }
98
+ }
99
+ exports.BaseAgent = BaseAgent;
100
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../modules/agent/base/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA;;;GAGG;AACH,MAAa,SAAS;IAIpB,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAEK,OAAO,CAAC,OAAY,EAAE,MAAY;;YACtC,2BAA2B;YAC3B,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,IAAI,eAAe,CAAC,CAAC;gBACtD,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;gBACjC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YACjC,CAAC;YAED,uCAAuC;YACvC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAChB,MAAM,IAAI,CAAC,aAAa,CAAC;oBACvB,IAAI,EAAE,WAAW;oBACjB,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;oBAC5C,QAAQ,EAAE;wBACR,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;wBACtB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;qBACpC;iBACF,CAAC,CAAC;YACL,CAAC;YAED,6BAA6B;YAC7B,IAAI,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@@ -0,0 +1,20 @@
1
+ import { AgentConfig, AgentContext } from "../../types/agent";
2
+ /**
3
+ * A generic assistant that can be configured with different roles, goals, and personalities
4
+ * @class Agent
5
+ * @example
6
+ * const assistant = new Agent({
7
+ * role: "Email Assistant",
8
+ * goal: "Help users send emails efficiently",
9
+ * backstory: "I am a professional and friendly assistant who specializes in email communication",
10
+ * llmConfig: { provider: "openai", model: "gpt-4" }
11
+ * });
12
+ */
13
+ export declare class Agent {
14
+ private executor;
15
+ private workflow;
16
+ constructor(config: AgentConfig);
17
+ private setupWorkflow;
18
+ process(input: string): Promise<AgentContext>;
19
+ }
20
+ //# sourceMappingURL=generic-assistant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic-assistant.d.ts","sourceRoot":"","sources":["../../../modules/agent/generic-assistant.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,YAAY,EAEb,MAAM,mBAAmB,CAAC;AAI3B;;;;;;;;;;GAUG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,QAAQ,CAAuC;gBAE3C,MAAM,EAAE,WAAW;IAkB/B,OAAO,CAAC,aAAa;IAsCR,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAS3D"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Agent = void 0;
13
+ const index_1 = require("../../graph/index");
14
+ const agent_1 = require("../../types/agent");
15
+ const base_1 = require("./base");
16
+ const generic_executor_1 = require("./generic-executor");
17
+ /**
18
+ * A generic assistant that can be configured with different roles, goals, and personalities
19
+ * @class Agent
20
+ * @example
21
+ * const assistant = new Agent({
22
+ * role: "Email Assistant",
23
+ * goal: "Help users send emails efficiently",
24
+ * backstory: "I am a professional and friendly assistant who specializes in email communication",
25
+ * llmConfig: { provider: "openai", model: "gpt-4" }
26
+ * });
27
+ */
28
+ class Agent {
29
+ constructor(config) {
30
+ const agent = new base_1.BaseAgent({
31
+ role: config.role,
32
+ goal: config.goal,
33
+ backstory: config.backstory,
34
+ tools: config.tools,
35
+ memory: config.memory,
36
+ llmConfig: config.llmConfig,
37
+ });
38
+ this.executor = new generic_executor_1.GenericExecutor(agent, config.tools, {
39
+ llmConfig: config.llmConfig,
40
+ verbose: config.verbose,
41
+ });
42
+ this.workflow = this.setupWorkflow();
43
+ }
44
+ setupWorkflow() {
45
+ return new index_1.GraphFlow("assistant", {
46
+ name: "assistant",
47
+ schema: agent_1.AgentContextSchema,
48
+ context: {
49
+ input: { raw: "" },
50
+ actions: [],
51
+ response: "",
52
+ executedActions: [],
53
+ },
54
+ nodes: [
55
+ {
56
+ name: "process",
57
+ execute: (context) => __awaiter(this, void 0, void 0, function* () {
58
+ const agentContext = context;
59
+ const decision = yield this.executor.makeDecision(agentContext);
60
+ context.actions = decision.actions;
61
+ context.response = decision.response;
62
+ }),
63
+ next: (context) => (context.actions.length > 0 ? ["execute"] : []),
64
+ },
65
+ {
66
+ name: "execute",
67
+ execute: (context) => __awaiter(this, void 0, void 0, function* () {
68
+ console.log(`Executing actions:`);
69
+ console.log(context.actions);
70
+ yield this.executor.executeActions(context.actions, context);
71
+ }),
72
+ next: ["process"],
73
+ },
74
+ ],
75
+ });
76
+ }
77
+ process(input) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ yield this.workflow.execute("process", undefined, {
80
+ input: { raw: input },
81
+ actions: [],
82
+ response: "",
83
+ });
84
+ return this.workflow.getContext();
85
+ });
86
+ }
87
+ }
88
+ exports.Agent = Agent;
89
+ //# sourceMappingURL=generic-assistant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic-assistant.js","sourceRoot":"","sources":["../../../modules/agent/generic-assistant.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA8C;AAC9C,6CAI2B;AAC3B,iCAAmC;AACnC,yDAAqD;AAErD;;;;;;;;;;GAUG;AACH,MAAa,KAAK;IAIhB,YAAY,MAAmB;QAC7B,MAAM,KAAK,GAAG,IAAI,gBAAS,CAAC;YAC1B,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,SAAS,EAAE,MAAM,CAAC,SAAS;SAC5B,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,IAAI,kCAAe,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE;YACvD,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;IACvC,CAAC;IAEO,aAAa;QACnB,OAAO,IAAI,iBAAS,CAAC,WAAW,EAAE;YAChC,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,0BAAkB;YAC1B,OAAO,EAAE;gBACP,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;gBAClB,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,EAAE;gBACZ,eAAe,EAAE,EAAE;aACpB;YACD,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,SAAS;oBACf,OAAO,EAAE,CAAO,OAAO,E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Agent } from "./base";
4
+ import { AgentExecutor } from "./base/executor";
5
+ /**
6
+ * Generic executor that handles the interaction between the agent and LLM
7
+ * Uses a structured prompt format:
8
+ * - ROLE: The function/job the agent performs
9
+ * - GOAL: The specific objective to achieve
10
+ * - BACKSTORY: The personality and behavior traits
11
+ * - CONTEXT: Current knowledge and state
12
+ * - AVAILABLE ACTIONS: What the agent can do
13
+ * - INSTRUCTIONS: How to process and respond
14
+ * @class GenericExecutor
15
+ * @extends {AgentExecutor}
16
+ */
17
+ export declare class GenericExecutor extends AgentExecutor {
18
+ private verbose;
19
+ private llm;
20
+ /**
21
+ * Creates an instance of GenericExecutor
22
+ * @param {BaseAgent} agent - The agent instance this executor is tied to
23
+ * @param {GraphFlow<any>[]} graphs - Array of available graph flows
24
+ * @param {ExecutorConfig} config - Configuration for the executor
25
+ */
26
+ constructor(agent: BaseAgent, graphs: GraphFlow<any>[], config: ExecutorConfig);
27
+ /**
28
+ * Logs a message with a specific type if verbose mode is enabled
29
+ * @private
30
+ * @param {"info" | "success" | "warning" | "error" | "thinking"} type - The type of log message
31
+ * @param {string} message - The message to log
32
+ */
33
+ private log;
34
+ /**
35
+ * Generates a string representation of the available action schemas
36
+ * @private
37
+ * @returns {string} Formatted string containing all available actions and their parameters
38
+ */
39
+ protected generateActionSchema(): string;
40
+ /**
41
+ * Makes a decision based on the current context using the LLM
42
+ * @param {AgentContext} context - The context to base the decision on
43
+ * @returns {Promise<DecisionOutput>} The decision output containing actions and response
44
+ */
45
+ makeDecision(context: AgentContext): Promise<DecisionOutput>;
46
+ /**
47
+ * Executes multiple workflows with their respective inputs
48
+ * @protected
49
+ * @param {GraphFlow<any>[]} workflows - Array of workflows to execute
50
+ * @param {string[]} startNodes - Array of starting node names for each workflow
51
+ * @param {any[]} inputs - Array of inputs for each workflow
52
+ * @param {AgentContext} context - The context in which to execute the workflows
53
+ * @returns {Promise<void>}
54
+ */
55
+ protected executeWorkflows(workflows: GraphFlow<any>[], startNodes: string[], inputs: any[], context: AgentContext): Promise<void>;
56
+ }
57
+ //# sourceMappingURL=generic-executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic-executor.d.ts","sourceRoot":"","sources":["../../../modules/agent/generic-executor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAEL,YAAY,EACZ,cAAc,EACd,cAAc,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD;;;;;;;;;;;GAWG;AACH,qBAAa,eAAgB,SAAQ,aAAa;IAChD,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,GAAG,CAA0C;IAErD;;;;;OAKG;gBAED,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,EACxB,MAAM,EAAE,cAAc;IAOxB;;;;;OAKG;IACH,OAAO,CAAC,GAAG;IAiBX;;;;OAIG;IACH,SAAS,CAAC,oBAAoB,IAAI,MAAM;IAyBxC;;;;OAIG;IACG,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IAgGlE;;;;;;;;OAQG;cACa,gBAAgB,CAC9B,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,EAC3B,UAAU,EAAE,MAAM,EAAE,EACpB,MAAM,EAAE,GAAG,EAAE,EACb,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC;CA6CjB"}
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.GenericExecutor = void 0;
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const zod_1 = require("zod");
18
+ const executor_1 = require("./base/executor");
19
+ const llm_factory_1 = require("./llm-factory");
20
+ /**
21
+ * Generic executor that handles the interaction between the agent and LLM
22
+ * Uses a structured prompt format:
23
+ * - ROLE: The function/job the agent performs
24
+ * - GOAL: The specific objective to achieve
25
+ * - BACKSTORY: The personality and behavior traits
26
+ * - CONTEXT: Current knowledge and state
27
+ * - AVAILABLE ACTIONS: What the agent can do
28
+ * - INSTRUCTIONS: How to process and respond
29
+ * @class GenericExecutor
30
+ * @extends {AgentExecutor}
31
+ */
32
+ class GenericExecutor extends executor_1.AgentExecutor {
33
+ /**
34
+ * Creates an instance of GenericExecutor
35
+ * @param {BaseAgent} agent - The agent instance this executor is tied to
36
+ * @param {GraphFlow<any>[]} graphs - Array of available graph flows
37
+ * @param {ExecutorConfig} config - Configuration for the executor
38
+ */
39
+ constructor(agent, graphs, config) {
40
+ var _a;
41
+ super(agent, graphs);
42
+ this.verbose = (_a = config.verbose) !== null && _a !== void 0 ? _a : true;
43
+ this.llm = llm_factory_1.LLMFactory.createLLM(config.llmConfig);
44
+ }
45
+ /**
46
+ * Logs a message with a specific type if verbose mode is enabled
47
+ * @private
48
+ * @param {"info" | "success" | "warning" | "error" | "thinking"} type - The type of log message
49
+ * @param {string} message - The message to log
50
+ */
51
+ log(type, message) {
52
+ if (!this.verbose)
53
+ return;
54
+ const prefix = {
55
+ info: chalk_1.default.blue("ℹ"),
56
+ success: chalk_1.default.green("✓"),
57
+ warning: chalk_1.default.yellow("⚠"),
58
+ error: chalk_1.default.red("✖"),
59
+ thinking: chalk_1.default.magenta("🤔"),
60
+ }[type];
61
+ console.log(`${prefix} ${message}`);
62
+ }
63
+ /**
64
+ * Generates a string representation of the available action schemas
65
+ * @private
66
+ * @returns {string} Formatted string containing all available actions and their parameters
67
+ */
68
+ generateActionSchema() {
69
+ return Array.from(this.availableGraphs.values())
70
+ .map((graph) => {
71
+ const schema = graph.getSchema();
72
+ const schemaDescription = Object.entries(schema.shape)
73
+ .map(([key, value]) => {
74
+ const zodValue = value;
75
+ return ` - ${key}: ${zodValue.description || zodValue._def.typeName}`;
76
+ })
77
+ .join("\n");
78
+ return `${graph.name}:
79
+ Parameters:
80
+ ${schemaDescription}
81
+ Available Operations:
82
+ ${graph
83
+ .getNodes()
84
+ .map((n) => ` - ${n.name}`)
85
+ .join("\n")}`;
86
+ })
87
+ .join("\n\n");
88
+ }
89
+ /**
90
+ * Makes a decision based on the current context using the LLM
91
+ * @param {AgentContext} context - The context to base the decision on
92
+ * @returns {Promise<DecisionOutput>} The decision output containing actions and response
93
+ */
94
+ makeDecision(context) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ var _a;
97
+ this.log("thinking", chalk_1.default.dim("Analyzing context and available actions..."));
98
+ const memories = yield this.agent.recall(context.input.raw);
99
+ if (memories.length > 0) {
100
+ this.log("info", chalk_1.default.dim("Retrieved relevant memories:"));
101
+ memories.forEach((m) => this.log("info", chalk_1.default.dim(`- ${m.content}`)));
102
+ context.knowledge =
103
+ (context.knowledge || "") +
104
+ "\n" +
105
+ memories.map((m) => m.content).join("\n");
106
+ }
107
+ const systemPrompt = `
108
+ ## ROLE
109
+ ${this.agent.getRole()}
110
+
111
+ ## GOAL
112
+ ${this.agent.getGoal()}
113
+
114
+ ## BACKSTORY
115
+ ${this.agent.getBackstory()}
116
+
117
+ ## RECENT ACTIONS
118
+ ${context.knowledge ? `${context.knowledge}\n` : "None"}
119
+
120
+ ## AVAILABLE ACTIONS
121
+ ${this.generateActionSchema()}
122
+
123
+ ## INSTRUCTIONS
124
+ - Analyze the user input and what you have done (if no action is needed, just return an empty array)
125
+ - Choose appropriate actions based on their parameters
126
+ - Structure parameters according to the action's schema
127
+ - Look at the goal and the actions you have done, if you have achieved the goal, STOP
128
+ `;
129
+ this.log("info", chalk_1.default.dim("Generating response..."));
130
+ const result = yield this.llm.generate({
131
+ system: systemPrompt,
132
+ user: `User input: ${context.input.raw}
133
+ Actions you have already done: ${((_a = context.executedActions) === null || _a === void 0 ? void 0 : _a.map((a) => `\n- ${a.name} => ${JSON.stringify(a.result)}`).join("")) || "None"}`,
134
+ }, zod_1.z.object({
135
+ actions: zod_1.z.array(zod_1.z.object({
136
+ name: zod_1.z.string(),
137
+ parameters: zod_1.z.array(zod_1.z.object({
138
+ name: zod_1.z.string(),
139
+ value: zod_1.z.any(),
140
+ })),
141
+ })),
142
+ response: zod_1.z.string(),
143
+ }));
144
+ if (result.object.actions.length > 0) {
145
+ this.log("success", chalk_1.default.green("Decided to take actions:"));
146
+ result.object.actions.forEach((action) => {
147
+ this.log("info", chalk_1.default.cyan(`Action: ${action.name}`));
148
+ action.parameters.forEach((param) => {
149
+ this.log("info", chalk_1.default.dim(` - ${param.name}: ${JSON.stringify(param.value)}`));
150
+ });
151
+ });
152
+ }
153
+ else {
154
+ this.log("info", chalk_1.default.yellow("No actions needed"));
155
+ }
156
+ this.log("success", chalk_1.default.green(`Response: ${result.object.response}`));
157
+ return {
158
+ actions: result.object.actions,
159
+ response: result.object.response,
160
+ };
161
+ });
162
+ }
163
+ /**
164
+ * Executes multiple workflows with their respective inputs
165
+ * @protected
166
+ * @param {GraphFlow<any>[]} workflows - Array of workflows to execute
167
+ * @param {string[]} startNodes - Array of starting node names for each workflow
168
+ * @param {any[]} inputs - Array of inputs for each workflow
169
+ * @param {AgentContext} context - The context in which to execute the workflows
170
+ * @returns {Promise<void>}
171
+ */
172
+ executeWorkflows(workflows, startNodes, inputs, context) {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ this.log("info", chalk_1.default.cyan("Executing workflows:"));
175
+ for (let i = 0; i < workflows.length; i++) {
176
+ const workflow = workflows[i];
177
+ const startNode = startNodes[i];
178
+ const input = inputs[i];
179
+ this.log("info", chalk_1.default.dim(`Executing workflow ${workflow.name} starting at node ${startNode}`));
180
+ this.log("info", chalk_1.default.dim(`Input parameters: ${JSON.stringify(input, null, 2)}`));
181
+ // Initialize workflow context with input
182
+ const workflowContext = Object.assign(Object.assign({}, workflow.getContext()), input);
183
+ // Execute with merged context
184
+ const result = yield workflow.execute(startNode, undefined, workflowContext);
185
+ this.log("success", chalk_1.default.green(`Workflow ${workflow.name} completed`));
186
+ this.log("info", chalk_1.default.dim(`Result: ${JSON.stringify(result, null, 2)}`));
187
+ if (context.executedActions) {
188
+ context.executedActions.push({
189
+ name: workflow.name,
190
+ result: result,
191
+ timestamp: new Date().toISOString(),
192
+ isExecuted: true,
193
+ });
194
+ }
195
+ }
196
+ });
197
+ }
198
+ }
199
+ exports.GenericExecutor = GenericExecutor;
200
+ //# sourceMappingURL=generic-executor.js.map