graphai 0.4.2 → 0.4.3

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 (92) hide show
  1. package/README.md +7 -77
  2. package/lib/experimental_agents/array_agents/push_agent.d.ts +1 -1
  3. package/lib/experimental_agents/array_agents/push_agent.js +1 -1
  4. package/lib/experimental_agents/array_agents/shift_agent.d.ts +1 -1
  5. package/lib/experimental_agents/array_agents/shift_agent.js +1 -1
  6. package/lib/experimental_agents/data_agents/property_filter_agent.d.ts +45 -0
  7. package/lib/experimental_agents/data_agents/property_filter_agent.js +28 -4
  8. package/lib/experimental_agents/embedding_agent.d.ts +1 -1
  9. package/lib/experimental_agents/embedding_agent.js +1 -1
  10. package/lib/experimental_agents/graph_agents/map_agent.d.ts +1 -1
  11. package/lib/experimental_agents/graph_agents/map_agent.js +1 -1
  12. package/lib/experimental_agents/graph_agents/nested_agent.d.ts +1 -1
  13. package/lib/experimental_agents/graph_agents/nested_agent.js +1 -1
  14. package/lib/experimental_agents/graph_agents/packages.d.ts +2 -1
  15. package/lib/experimental_agents/graph_agents/packages.js +3 -1
  16. package/lib/experimental_agents/graph_agents/vanilla.d.ts +2 -1
  17. package/lib/experimental_agents/graph_agents/vanilla.js +3 -1
  18. package/lib/experimental_agents/graph_agents/worker_agent.d.ts +39 -0
  19. package/lib/experimental_agents/graph_agents/worker_agent.js +111 -0
  20. package/lib/experimental_agents/index.d.ts +1 -2
  21. package/lib/experimental_agents/index.js +1 -3
  22. package/lib/experimental_agents/input_agents/text_input_agent.d.ts +8 -1
  23. package/lib/experimental_agents/input_agents/text_input_agent.js +9 -2
  24. package/lib/experimental_agents/llm_agents/anthropic_agent.d.ts +34 -0
  25. package/lib/experimental_agents/llm_agents/anthropic_agent.js +47 -0
  26. package/lib/experimental_agents/llm_agents/groq_agent.d.ts +5 -3
  27. package/lib/experimental_agents/llm_agents/groq_agent.js +6 -4
  28. package/lib/experimental_agents/llm_agents/index.d.ts +2 -2
  29. package/lib/experimental_agents/llm_agents/index.js +3 -3
  30. package/lib/experimental_agents/llm_agents/openai_agent.d.ts +8 -0
  31. package/lib/experimental_agents/llm_agents/openai_agent.js +13 -2
  32. package/lib/experimental_agents/llm_agents/packages.d.ts +2 -2
  33. package/lib/experimental_agents/llm_agents/packages.js +3 -3
  34. package/lib/experimental_agents/llm_agents/slashgpt_agent.d.ts +2 -0
  35. package/lib/experimental_agents/llm_agents/slashgpt_agent.js +2 -0
  36. package/lib/experimental_agents/matrix_agents/dot_product_agent.d.ts +1 -1
  37. package/lib/experimental_agents/matrix_agents/dot_product_agent.js +1 -1
  38. package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +1 -1
  39. package/lib/experimental_agents/matrix_agents/sort_by_values_agent.js +1 -1
  40. package/lib/experimental_agents/service_agents/fetch_agent.js +1 -1
  41. package/lib/experimental_agents/service_agents/wikipedia.js +1 -1
  42. package/lib/experimental_agents/sleeper_agents/sleeper_agent.d.ts +1 -1
  43. package/lib/experimental_agents/sleeper_agents/sleeper_agent.js +1 -1
  44. package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.d.ts +1 -1
  45. package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.js +1 -1
  46. package/lib/experimental_agents/string_agents/json_parser_agent.d.ts +38 -0
  47. package/lib/experimental_agents/string_agents/json_parser_agent.js +39 -0
  48. package/lib/experimental_agents/string_agents/packages.d.ts +2 -1
  49. package/lib/experimental_agents/string_agents/packages.js +3 -1
  50. package/lib/experimental_agents/string_agents/string_splitter_agent.js +1 -1
  51. package/lib/experimental_agents/string_agents/string_template_agent.d.ts +9 -7
  52. package/lib/experimental_agents/string_agents/string_template_agent.js +4 -1
  53. package/lib/experimental_agents/string_agents/vanilla.d.ts +2 -1
  54. package/lib/experimental_agents/string_agents/vanilla.js +3 -1
  55. package/lib/experimental_agents/test_agents/bypass_agent.js +1 -1
  56. package/lib/experimental_agents/test_agents/copy2array_agent.js +1 -1
  57. package/lib/experimental_agents/test_agents/copy_message_agent.js +1 -1
  58. package/lib/experimental_agents/test_agents/counting_agent.js +1 -1
  59. package/lib/experimental_agents/test_agents/echo_agent.js +13 -2
  60. package/lib/experimental_agents/test_agents/merge_node_id_agent.js +1 -1
  61. package/lib/experimental_agents/test_agents/stream_mock_agent.js +9 -2
  62. package/lib/experimental_agents/vanilla.d.ts +1 -2
  63. package/lib/experimental_agents/vanilla.js +1 -3
  64. package/lib/graphai.d.ts +5 -5
  65. package/lib/graphai.js +9 -9
  66. package/lib/index.d.ts +2 -1
  67. package/lib/index.js +3 -1
  68. package/lib/node.d.ts +2 -1
  69. package/lib/node.js +37 -11
  70. package/lib/transaction_log.d.ts +1 -0
  71. package/lib/transaction_log.js +2 -0
  72. package/lib/type.d.ts +11 -6
  73. package/lib/utils/runner.d.ts +2 -0
  74. package/lib/utils/runner.js +20 -0
  75. package/lib/utils/test_agents.d.ts +2 -2
  76. package/lib/utils/test_utils.d.ts +1 -17
  77. package/lib/utils/test_utils.js +3 -21
  78. package/lib/utils/utils.d.ts +2 -0
  79. package/lib/utils/utils.js +45 -1
  80. package/lib/validators/agent_validator.js +2 -1
  81. package/lib/validators/common.d.ts +3 -0
  82. package/lib/validators/common.js +10 -1
  83. package/lib/validators/computed_node_validator.js +1 -1
  84. package/lib/validators/graph_data_validator.js +9 -9
  85. package/lib/validators/nodeValidator.js +3 -2
  86. package/lib/validators/relation_validator.js +6 -5
  87. package/lib/validators/static_node_validator.js +1 -1
  88. package/package.json +3 -4
  89. package/lib/experimental_agents/function_agent.d.ts +0 -42
  90. package/lib/experimental_agents/function_agent.js +0 -40
  91. package/lib/experimental_agents/llm_agents/groq_stream_agent.d.ts +0 -42
  92. package/lib/experimental_agents/llm_agents/groq_stream_agent.js +0 -84
package/README.md CHANGED
@@ -6,7 +6,7 @@ GraphAI is an asynchronous data flow execution engine, which allows developers t
6
6
 
7
7
  As Andrew Ng has described in his article, "[The batch: Issue 242](https://www.deeplearning.ai/the-batch/issue-242/)", better results can often be achieved by making multiple calls to a Large Language Model (LLM) and allowing it to incrementally build towards a higher-quality output. Dr. Ng refers to this approach as 'agentic workflows.'
8
8
 
9
- Such *agentic applications* need to make multiple asynchronous API calls (such as OpenAI's chat-completion API, database query, web search, and etc.) and manage data dependencies among them, such as giving the answer from one LLM call to another -- which will become quite difficult to manage in a traditional programing style as the complexity of the application increases, because of the asynchronous nature of those APIs.
9
+ Such *agentic applications* require making multiple asynchronous API calls (e.g., OpenAI's chat-completion API, database queries, web searches) and managing data dependencies among them. As the complexity of the application increases, managing these dependencies in a traditional programming style becomes challenging due to the asynchronous nature of the APIs.
10
10
 
11
11
  GraphAI allows developers to describe dependencies among those agents (asynchronous API calls) in a data flow graph in YAML or JSON, which is called *declarative data flow programming* . The GraphAI engine will take care of all the complexity of concurrent asynchronous calls, data dependency management, task priority management, map-reduce processing, error handling, retries and logging.
12
12
 
@@ -68,9 +68,9 @@ flowchart TD
68
68
  chunkEmbeddings --> similarities(similarities)
69
69
  topicEmbedding --> similarities
70
70
  similarities --> sortedChunks(sortedChunks)
71
- sortedChunks --> resourceText(resourceText)
71
+ sortedChunks --> referenceText(resourceText)
72
72
  source -- query --> prompt(prompt)
73
- resourceText --> prompt
73
+ referenceText --> prompt
74
74
  prompt --> query(query)
75
75
  ```
76
76
 
@@ -120,7 +120,7 @@ An *agent function* is a TypeScript function, which implements a particular *age
120
120
  There are additional optional parameters for developers of nested agents and agent filters.
121
121
 
122
122
  - *graphData*: an optional GraphData (for nested agents)
123
- - *agents*: AgentFunctionInfoDictonary (for nested agents)
123
+ - *agents*: AgentFunctionInfoDictionary (for nested agents)
124
124
  - *taskManager*: TaskManager (for nested agents)
125
125
  - *log*: TransactionLog[] (for nested agents)
126
126
  - *filterParams*: agent filter parameters (for agent filters)
@@ -377,77 +377,7 @@ By default, tasks are executed in a first-in, first-out (FIFO) order with a neut
377
377
 
378
378
  Negative priority values are allowed, enabling you to fine-tune the execution order based on your application's requirements.
379
379
 
380
- ## GraphAI class
380
+ ## References
381
381
 
382
- ### ```constructor(data: GraphData, callbackDictonary: AgentFunctionInfoDictonary)```
383
- Initializes a new instance of the GraphAI object with the specified graph data and a dictionary of callback functions.
384
-
385
- - ```data: GraphData```: The graph data including nodes and optional concurrency limit.
386
- - ```callbackDictonary: AgentFunctionInfoDictonary```: A dictionary mapping agent IDs to their respective callback functions info to be used for all nodes.
387
-
388
- ### ```async run(): Promise<ResultDataDictonary<ResultData>>```
389
- Executes the graph asynchronously, starting with nodes that have no dependencies or whose dependencies have been met. The method continues to execute nodes as their dependencies are satisfied until all nodes have been executed or an error occurs.
390
-
391
- Returns: A promise that resolves with the results of all executed nodes or rejects with the first encountered error.
392
-
393
- ### ```results(): ResultDataDictonary<ResultData>```
394
- Compiles and returns the results of all executed nodes in the graph.
395
-
396
- Returns: A dictionary mapping node IDs to their results. Only includes nodes that have completed execution and produced a result.
397
-
398
- ### ```errors(): Record<string, Error>```
399
- Compiles and returns the errors from all nodes that encountered an error during execution.
400
-
401
- Returns: A dictionary mapping node IDs to the errors they encountered. Only includes nodes that have executed and encountered an error. It does not include any errors which have been retried.
402
-
403
- ### ```transactionLogs(): Array<TransactionLog>```
404
- Retrieves all transaction logs recorded during the execution of the graph.
405
-
406
- Returns: An array of transaction logs detailing the execution states and outcomes of the nodes within the graph.
407
-
408
- ### ```injectValue(nodeId: string, result: ResultData): void```
409
- Injects a result into a specified node. This is used to manually set the result of a static node, allowing dependent nodes to proceed with execution.
410
-
411
- - ```nodeId: string```: The ID of the static node into which the result is to be injected.
412
- - ```result: ResultData```: The result to be injected into the specified node.
413
-
414
- ## Collaboration
415
-
416
- Step 1. Install git, node and yarn
417
-
418
- Step 2. Clone the project and install necessary node modules
419
-
420
- ```
421
- git clone git@github.com:receptron/graphai.git
422
- cd graphai
423
- yarn install
424
- ```
425
-
426
- Step 3. Set the environment variable OPENAI_API_KEY to your own key (=sk-...)
427
-
428
- You need to set ANTHROPIC_API_KEY as well, if you want to use Claude.
429
-
430
- Step 4. Run the test script
431
-
432
- Run the test
433
-
434
- ```
435
- npm run test
436
- ```
437
-
438
- Step 5. Run one of sample scripts
439
-
440
- ```
441
- npm run sample ./samples/home.ts
442
- ```
443
-
444
- Step 6. Write some code and send pull requests
445
-
446
- - Please run "yarn run format" before sending your pull request.
447
- - Please do not include any build files (files under /lib) to your pull reuquest.
448
-
449
- Key principles:
450
-
451
- 1. Keep the core (Node and GraphAI classes) small and simple.
452
- 2. Enhance the platform by adding 'agents' (plug ins).
453
- 3. Simple but effective test scripts make it easy to maintain.
382
+ - [Collaboration](./Collaboration.md)
383
+ - [API Document](./APIDocument.md)
@@ -24,7 +24,7 @@ declare const pushAgentInfo: {
24
24
  })[];
25
25
  })[];
26
26
  description: string;
27
- category: never[];
27
+ category: string[];
28
28
  author: string;
29
29
  repository: string;
30
30
  license: string;
@@ -33,7 +33,7 @@ const pushAgentInfo = {
33
33
  },
34
34
  ],
35
35
  description: "push Agent",
36
- category: [],
36
+ category: ["array"],
37
37
  author: "Receptron team",
38
38
  repository: "https://github.com/receptron/graphai",
39
39
  license: "MIT",
@@ -20,7 +20,7 @@ declare const shiftAgentInfo: {
20
20
  };
21
21
  })[];
22
22
  description: string;
23
- category: never[];
23
+ category: string[];
24
24
  author: string;
25
25
  repository: string;
26
26
  license: string;
@@ -31,7 +31,7 @@ const shiftAgentInfo = {
31
31
  },
32
32
  ],
33
33
  description: "shift Agent",
34
- category: [],
34
+ category: ["array"],
35
35
  author: "Receptron team",
36
36
  repository: "https://github.com/receptron/graphai",
37
37
  license: "MIT",
@@ -4,6 +4,7 @@ export declare const propertyFilterAgent: AgentFunction<{
4
4
  exclude?: Array<string>;
5
5
  alter?: Record<string, Record<string, string>>;
6
6
  inject?: Array<Record<string, any>>;
7
+ inspect?: Array<Record<string, any>>;
7
8
  swap?: Record<string, string>;
8
9
  }>;
9
10
  declare const propertyFilterAgentInfo: {
@@ -13,6 +14,7 @@ declare const propertyFilterAgentInfo: {
13
14
  exclude?: string[] | undefined;
14
15
  alter?: Record<string, Record<string, string>> | undefined;
15
16
  inject?: Record<string, any>[] | undefined;
17
+ inspect?: Record<string, any>[] | undefined;
16
18
  swap?: Record<string, string> | undefined;
17
19
  }>;
18
20
  mock: AgentFunction<{
@@ -20,6 +22,7 @@ declare const propertyFilterAgentInfo: {
20
22
  exclude?: string[] | undefined;
21
23
  alter?: Record<string, Record<string, string>> | undefined;
22
24
  inject?: Record<string, any>[] | undefined;
25
+ inspect?: Record<string, any>[] | undefined;
23
26
  swap?: Record<string, string> | undefined;
24
27
  }>;
25
28
  samples: ({
@@ -36,6 +39,7 @@ declare const propertyFilterAgentInfo: {
36
39
  alter?: undefined;
37
40
  inject?: undefined;
38
41
  swap?: undefined;
42
+ inspect?: undefined;
39
43
  };
40
44
  result: {
41
45
  color: string;
@@ -55,6 +59,7 @@ declare const propertyFilterAgentInfo: {
55
59
  alter?: undefined;
56
60
  inject?: undefined;
57
61
  swap?: undefined;
62
+ inspect?: undefined;
58
63
  };
59
64
  result: {
60
65
  color: string;
@@ -74,6 +79,7 @@ declare const propertyFilterAgentInfo: {
74
79
  alter?: undefined;
75
80
  inject?: undefined;
76
81
  swap?: undefined;
82
+ inspect?: undefined;
77
83
  };
78
84
  result: {
79
85
  type: string;
@@ -99,6 +105,7 @@ declare const propertyFilterAgentInfo: {
99
105
  exclude?: undefined;
100
106
  inject?: undefined;
101
107
  swap?: undefined;
108
+ inspect?: undefined;
102
109
  };
103
110
  result: {
104
111
  color: string;
@@ -124,6 +131,7 @@ declare const propertyFilterAgentInfo: {
124
131
  exclude?: undefined;
125
132
  alter?: undefined;
126
133
  swap?: undefined;
134
+ inspect?: undefined;
127
135
  };
128
136
  result: {
129
137
  color: string;
@@ -150,6 +158,7 @@ declare const propertyFilterAgentInfo: {
150
158
  exclude?: undefined;
151
159
  alter?: undefined;
152
160
  swap?: undefined;
161
+ inspect?: undefined;
153
162
  };
154
163
  result: {
155
164
  color: string;
@@ -174,6 +183,7 @@ declare const propertyFilterAgentInfo: {
174
183
  exclude?: undefined;
175
184
  alter?: undefined;
176
185
  inject?: undefined;
186
+ inspect?: undefined;
177
187
  };
178
188
  result: {
179
189
  color: string;
@@ -182,6 +192,41 @@ declare const propertyFilterAgentInfo: {
182
192
  maker: string;
183
193
  range: number;
184
194
  }[];
195
+ } | {
196
+ inputs: (string | {
197
+ color: string;
198
+ model: string;
199
+ type: string;
200
+ maker: string;
201
+ range: number;
202
+ }[])[];
203
+ params: {
204
+ inspect: ({
205
+ propId: string;
206
+ equal: string;
207
+ notEqual?: undefined;
208
+ from?: undefined;
209
+ } | {
210
+ propId: string;
211
+ notEqual: string;
212
+ from: number;
213
+ equal?: undefined;
214
+ })[];
215
+ include?: undefined;
216
+ exclude?: undefined;
217
+ alter?: undefined;
218
+ inject?: undefined;
219
+ swap?: undefined;
220
+ };
221
+ result: {
222
+ color: string;
223
+ model: string;
224
+ type: string;
225
+ maker: string;
226
+ range: number;
227
+ isTesla: boolean;
228
+ isGM: boolean;
229
+ }[];
185
230
  })[];
186
231
  description: string;
187
232
  category: string[];
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.propertyFilterAgent = void 0;
4
- const applyFilter = (input, index, inputs, include, exclude, alter, inject, swap) => {
4
+ const applyFilter = (input, index, inputs, include, exclude, alter, inject, swap, inspect) => {
5
5
  const propIds = include ? include : Object.keys(input);
6
6
  const excludeSet = new Set(exclude ?? []);
7
7
  const result = propIds.reduce((tmp, propId) => {
@@ -23,6 +23,17 @@ const applyFilter = (input, index, inputs, include, exclude, alter, inject, swap
23
23
  }
24
24
  });
25
25
  }
26
+ if (inspect) {
27
+ inspect.forEach((item) => {
28
+ const value = inputs[item.from ?? 1]; // default is inputs[1]
29
+ if (item.equal) {
30
+ result[item.propId] = item.equal === value;
31
+ }
32
+ else if (item.notEqual) {
33
+ result[item.propId] = item.notEqual !== value;
34
+ }
35
+ });
36
+ }
26
37
  if (swap) {
27
38
  Object.keys(swap).forEach((key) => {
28
39
  const tmp = result[key];
@@ -34,11 +45,11 @@ const applyFilter = (input, index, inputs, include, exclude, alter, inject, swap
34
45
  };
35
46
  const propertyFilterAgent = async ({ inputs, params }) => {
36
47
  const [input] = inputs;
37
- const { include, exclude, alter, inject, swap } = params;
48
+ const { include, exclude, alter, inject, swap, inspect } = params;
38
49
  if (Array.isArray(input)) {
39
- return input.map((item, index) => applyFilter(item, index, inputs, include, exclude, alter, inject, swap));
50
+ return input.map((item, index) => applyFilter(item, index, inputs, include, exclude, alter, inject, swap, inspect));
40
51
  }
41
- return applyFilter(input, 0, inputs, include, exclude, alter, inject, swap);
52
+ return applyFilter(input, 0, inputs, include, exclude, alter, inject, swap, inspect);
42
53
  };
43
54
  exports.propertyFilterAgent = propertyFilterAgent;
44
55
  const testInputs = [
@@ -106,6 +117,19 @@ const propertyFilterAgentInfo = {
106
117
  { color: "blue", model: "Tesla", type: "EV", maker: "Model Y", range: 400 },
107
118
  ],
108
119
  },
120
+ {
121
+ inputs: testInputs,
122
+ params: {
123
+ inspect: [
124
+ { propId: "isTesla", equal: "Tesla Motors" }, // from: 1 is implied
125
+ { propId: "isGM", notEqual: "Tesla Motors", from: 1 },
126
+ ],
127
+ },
128
+ result: [
129
+ { color: "red", model: "Model 3", type: "EV", maker: "Tesla", range: 300, isTesla: true, isGM: false },
130
+ { color: "blue", model: "Model Y", type: "EV", maker: "Tesla", range: 400, isTesla: true, isGM: false },
131
+ ],
132
+ },
109
133
  ],
110
134
  description: "Filter properties based on property name either with 'include' or 'exclude'",
111
135
  category: ["data"],
@@ -12,7 +12,7 @@ declare const stringEmbeddingsAgentInfo: {
12
12
  }, any, string | string[]>;
13
13
  samples: never[];
14
14
  description: string;
15
- category: never[];
15
+ category: string[];
16
16
  author: string;
17
17
  repository: string;
18
18
  license: string;
@@ -47,7 +47,7 @@ const stringEmbeddingsAgentInfo = {
47
47
  mock: exports.stringEmbeddingsAgent,
48
48
  samples: [],
49
49
  description: "Embeddings Agent",
50
- category: [],
50
+ category: ["embedding"],
51
51
  author: "Receptron team",
52
52
  repository: "https://github.com/receptron/graphai",
53
53
  license: "MIT",
@@ -15,7 +15,7 @@ declare const mapAgentInfo: {
15
15
  }, Record<string, any[]>, any>;
16
16
  samples: never[];
17
17
  description: string;
18
- category: never[];
18
+ category: string[];
19
19
  author: string;
20
20
  repository: string;
21
21
  license: string;
@@ -62,7 +62,7 @@ const mapAgentInfo = {
62
62
  mock: exports.mapAgent,
63
63
  samples: [],
64
64
  description: "Map Agent",
65
- category: [],
65
+ category: ["graph"],
66
66
  author: "Receptron team",
67
67
  repository: "https://github.com/receptron/graphai",
68
68
  license: "MIT",
@@ -14,7 +14,7 @@ declare const nestedAgentInfo: {
14
14
  }>;
15
15
  samples: never[];
16
16
  description: string;
17
- category: never[];
17
+ category: string[];
18
18
  author: string;
19
19
  repository: string;
20
20
  license: string;
@@ -50,7 +50,7 @@ const nestedAgentInfo = {
50
50
  mock: exports.nestedAgent,
51
51
  samples: [],
52
52
  description: "nested Agent",
53
- category: [],
53
+ category: ["graph"],
54
54
  author: "Receptron team",
55
55
  repository: "https://github.com/receptron/graphai",
56
56
  license: "MIT",
@@ -1,3 +1,4 @@
1
1
  import nestedAgent from "../../experimental_agents/graph_agents/nested_agent";
2
2
  import mapAgent from "../../experimental_agents/graph_agents/map_agent";
3
- export { nestedAgent, mapAgent };
3
+ import workerAgent from "../../experimental_agents/graph_agents/worker_agent";
4
+ export { nestedAgent, mapAgent, workerAgent };
@@ -3,8 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mapAgent = exports.nestedAgent = void 0;
6
+ exports.workerAgent = exports.mapAgent = exports.nestedAgent = void 0;
7
7
  const nested_agent_1 = __importDefault(require("../../experimental_agents/graph_agents/nested_agent"));
8
8
  exports.nestedAgent = nested_agent_1.default;
9
9
  const map_agent_1 = __importDefault(require("../../experimental_agents/graph_agents/map_agent"));
10
10
  exports.mapAgent = map_agent_1.default;
11
+ const worker_agent_1 = __importDefault(require("../../experimental_agents/graph_agents/worker_agent"));
12
+ exports.workerAgent = worker_agent_1.default;
@@ -1,3 +1,4 @@
1
1
  import nestedAgent from "../../experimental_agents/graph_agents/nested_agent";
2
2
  import mapAgent from "../../experimental_agents/graph_agents/map_agent";
3
- export { nestedAgent, mapAgent };
3
+ import workerAgent from "../../experimental_agents/graph_agents/worker_agent";
4
+ export { nestedAgent, mapAgent, workerAgent };
@@ -3,8 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mapAgent = exports.nestedAgent = void 0;
6
+ exports.workerAgent = exports.mapAgent = exports.nestedAgent = void 0;
7
7
  const nested_agent_1 = __importDefault(require("../../experimental_agents/graph_agents/nested_agent"));
8
8
  exports.nestedAgent = nested_agent_1.default;
9
9
  const map_agent_1 = __importDefault(require("../../experimental_agents/graph_agents/map_agent"));
10
10
  exports.mapAgent = map_agent_1.default;
11
+ const worker_agent_1 = __importDefault(require("../../experimental_agents/graph_agents/worker_agent"));
12
+ exports.workerAgent = worker_agent_1.default;
@@ -0,0 +1,39 @@
1
+ import { AgentFunction } from "../../index";
2
+ export declare const workerAgent: AgentFunction<{
3
+ namedInputs?: Array<string>;
4
+ }, any, any>;
5
+ declare const workerAgentInfo: {
6
+ name: string;
7
+ agent: AgentFunction<{
8
+ namedInputs?: string[] | undefined;
9
+ }, any, any>;
10
+ mock: AgentFunction<{
11
+ namedInputs?: string[] | undefined;
12
+ }, any, any>;
13
+ samples: {
14
+ inputs: string[];
15
+ params: {};
16
+ result: {
17
+ message: string;
18
+ };
19
+ graph: {
20
+ version: number;
21
+ nodes: {
22
+ source: {
23
+ value: string;
24
+ };
25
+ message: {
26
+ agent: string;
27
+ inputs: string[];
28
+ isResult: boolean;
29
+ };
30
+ };
31
+ };
32
+ }[];
33
+ description: string;
34
+ category: string[];
35
+ author: string;
36
+ repository: string;
37
+ license: string;
38
+ };
39
+ export default workerAgentInfo;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.workerAgent = void 0;
4
+ const index_1 = require("../../index");
5
+ const worker_threads_1 = require("worker_threads");
6
+ const experimental_agents_1 = require("../../experimental_agents");
7
+ const utils_1 = require("../../utils/utils");
8
+ const vanillaAgents = {
9
+ totalAgent: experimental_agents_1.totalAgent,
10
+ dataSumTemplateAgent: experimental_agents_1.dataSumTemplateAgent,
11
+ propertyFilterAgent: experimental_agents_1.propertyFilterAgent,
12
+ copyAgent: experimental_agents_1.copyAgent,
13
+ pushAgent: experimental_agents_1.pushAgent,
14
+ popAgent: experimental_agents_1.popAgent,
15
+ shiftAgent: experimental_agents_1.shiftAgent,
16
+ nestedAgent: experimental_agents_1.nestedAgent,
17
+ mapAgent: experimental_agents_1.mapAgent,
18
+ dotProductAgent: experimental_agents_1.dotProductAgent,
19
+ sortByValuesAgent: experimental_agents_1.sortByValuesAgent,
20
+ stringSplitterAgent: experimental_agents_1.stringSplitterAgent,
21
+ stringTemplateAgent: experimental_agents_1.stringTemplateAgent,
22
+ jsonParserAgent: experimental_agents_1.jsonParserAgent,
23
+ };
24
+ if (!worker_threads_1.isMainThread && worker_threads_1.parentPort) {
25
+ const port = worker_threads_1.parentPort;
26
+ port.on("message", async (data) => {
27
+ const { graphData } = data;
28
+ const graphAI = new index_1.GraphAI(graphData, vanillaAgents);
29
+ const result = await graphAI.run();
30
+ port.postMessage(result);
31
+ });
32
+ }
33
+ const workerAgent = async ({ inputs, params, /* agents, log, */ graphData }) => {
34
+ const namedInputs = params.namedInputs ?? inputs.map((__input, index) => `$${index}`);
35
+ (0, utils_1.assert)(!!graphData, "required");
36
+ (0, utils_1.assert)(typeof graphData === "object", "required");
37
+ namedInputs.forEach((nodeId, index) => {
38
+ if (graphData.nodes[nodeId] === undefined) {
39
+ // If the input node does not exist, automatically create a static node
40
+ graphData.nodes[nodeId] = { value: inputs[index] };
41
+ }
42
+ else {
43
+ // Otherwise, inject the proper data here (instead of calling injectTo method later)
44
+ graphData.nodes[nodeId]["value"] = inputs[index];
45
+ }
46
+ });
47
+ return new Promise((resolve, reject) => {
48
+ const worker = new worker_threads_1.Worker("./lib/experimental_agents/graph_agents/worker_agent.js");
49
+ worker.on("message", (result) => {
50
+ worker.terminate();
51
+ resolve(result);
52
+ });
53
+ worker.on("error", reject);
54
+ worker.on("exit", (code) => {
55
+ if (code !== 0)
56
+ reject(new Error(`Worker stopped with exit code ${code}`));
57
+ });
58
+ // copyAgent is required for test case
59
+ worker.postMessage({ graphData });
60
+ });
61
+ };
62
+ exports.workerAgent = workerAgent;
63
+ const workerAgentInfo = {
64
+ name: "workerAgent",
65
+ agent: exports.workerAgent,
66
+ mock: exports.workerAgent,
67
+ samples: [
68
+ {
69
+ inputs: [],
70
+ params: {},
71
+ result: { message: "May the force be with you" },
72
+ graph: {
73
+ version: 0.3,
74
+ nodes: {
75
+ source: {
76
+ value: "May the force be with you",
77
+ },
78
+ message: {
79
+ agent: "copyAgent",
80
+ inputs: [":source"],
81
+ isResult: true,
82
+ },
83
+ },
84
+ },
85
+ },
86
+ {
87
+ inputs: ["May the force be with you"],
88
+ params: {},
89
+ result: { message: "May the force be with you" },
90
+ graph: {
91
+ version: 0.3,
92
+ nodes: {
93
+ source: {
94
+ value: "TypeScript compiler fails without this node for some reason.",
95
+ },
96
+ message: {
97
+ agent: "copyAgent",
98
+ inputs: [":$0"],
99
+ isResult: true,
100
+ },
101
+ },
102
+ },
103
+ },
104
+ ],
105
+ description: "Map Agent",
106
+ category: ["graph"],
107
+ author: "Receptron team",
108
+ repository: "https://github.com/receptron/graphai",
109
+ license: "MIT",
110
+ };
111
+ exports.default = workerAgentInfo;
@@ -8,7 +8,6 @@ export * from "./sleeper_agents";
8
8
  export * from "./llm_agents";
9
9
  export * from "./service_agents";
10
10
  export * from "./input_agents";
11
- import functionAgent from "./function_agent";
12
11
  import stringEmbeddingsAgent from "./embedding_agent";
13
12
  import tokenBoundStringsAgent from "./token_agent";
14
- export { functionAgent, stringEmbeddingsAgent, tokenBoundStringsAgent };
13
+ export { stringEmbeddingsAgent, tokenBoundStringsAgent };
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.tokenBoundStringsAgent = exports.stringEmbeddingsAgent = exports.functionAgent = void 0;
20
+ exports.tokenBoundStringsAgent = exports.stringEmbeddingsAgent = void 0;
21
21
  __exportStar(require("./string_agents"), exports);
22
22
  __exportStar(require("./array_agents"), exports);
23
23
  __exportStar(require("./matrix_agents"), exports);
@@ -30,8 +30,6 @@ __exportStar(require("./llm_agents"), exports);
30
30
  __exportStar(require("./service_agents"), exports);
31
31
  __exportStar(require("./input_agents"), exports);
32
32
  // TODO sub folder
33
- const function_agent_1 = __importDefault(require("./function_agent"));
34
- exports.functionAgent = function_agent_1.default;
35
33
  const embedding_agent_1 = __importDefault(require("./embedding_agent"));
36
34
  exports.stringEmbeddingsAgent = embedding_agent_1.default;
37
35
  const token_agent_1 = __importDefault(require("./token_agent"));
@@ -16,7 +16,14 @@ declare const textInputAgentInfo: {
16
16
  }, string | {
17
17
  [x: string]: string;
18
18
  }>;
19
- samples: never[];
19
+ samples: {
20
+ inputs: never[];
21
+ params: {
22
+ message: string;
23
+ };
24
+ result: string;
25
+ }[];
26
+ skipTest: boolean;
20
27
  description: string;
21
28
  category: string[];
22
29
  author: string;
@@ -13,9 +13,16 @@ const textInputAgentInfo = {
13
13
  name: "textInputAgent",
14
14
  agent: exports.textInputAgent,
15
15
  mock: exports.textInputAgent,
16
- samples: [],
16
+ samples: [
17
+ {
18
+ inputs: [],
19
+ params: { message: "Enter your message to AI." },
20
+ result: "message from the user",
21
+ },
22
+ ],
23
+ skipTest: true,
17
24
  description: "Text Input Agent",
18
- category: ["array"],
25
+ category: ["input"],
19
26
  author: "Receptron team",
20
27
  repository: "https://github.com/receptron/graphai",
21
28
  license: "MIT",