graphai 0.1.0 → 0.1.1
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.
- package/README.md +7 -5
- package/lib/experimental_agents/array_agents/index.d.ts +3 -0
- package/lib/experimental_agents/array_agents/index.js +9 -0
- package/lib/experimental_agents/array_agents/pop_agent.d.ts +2 -0
- package/lib/experimental_agents/array_agents/pop_agent.js +15 -0
- package/lib/experimental_agents/array_agents/push_agent.d.ts +2 -0
- package/lib/experimental_agents/array_agents/push_agent.js +14 -0
- package/lib/experimental_agents/array_agents/shift_agent.d.ts +2 -0
- package/lib/experimental_agents/{array_agents.js → array_agents/shift_agent.js} +2 -17
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.d.ts +2 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.js +13 -0
- package/lib/experimental_agents/data_agents/data_sum_template_agent.d.ts +17 -0
- package/lib/experimental_agents/data_agents/data_sum_template_agent.js +30 -0
- package/lib/experimental_agents/data_agents/index.d.ts +3 -0
- package/lib/experimental_agents/data_agents/index.js +9 -0
- package/lib/experimental_agents/data_agents/total_agent.d.ts +46 -0
- package/lib/experimental_agents/data_agents/total_agent.js +51 -0
- package/lib/experimental_agents/embedding_agent.d.ts +6 -0
- package/lib/experimental_agents/embedding_agent.js +43 -0
- package/lib/experimental_agents/index.d.ts +8 -3
- package/lib/experimental_agents/index.js +8 -3
- package/lib/experimental_agents/map_agent.d.ts +4 -0
- package/lib/experimental_agents/map_agent.js +46 -0
- package/lib/experimental_agents/matrix_agent.d.ts +9 -0
- package/lib/experimental_agents/matrix_agent.js +50 -0
- package/lib/experimental_agents/nested_agent.d.ts +2 -2
- package/lib/experimental_agents/nested_agent.js +14 -8
- package/lib/experimental_agents/slashgpt_agent.d.ts +1 -1
- package/lib/experimental_agents/slashgpt_agent.js +2 -7
- package/lib/experimental_agents/sleeper_agents/index.d.ts +2 -0
- package/lib/experimental_agents/sleeper_agents/index.js +7 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.d.ts +5 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent.js +16 -0
- package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.d.ts +6 -0
- package/lib/experimental_agents/{sleeper_agent.js → sleeper_agents/sleeper_agent_debug.js} +4 -13
- package/lib/experimental_agents/string_agents/index.d.ts +2 -0
- package/lib/experimental_agents/string_agents/index.js +7 -0
- package/lib/experimental_agents/string_agents/string_splitter_agent.d.ts +7 -0
- package/lib/experimental_agents/string_agents/string_splitter_agent.js +24 -0
- package/lib/experimental_agents/string_agents/string_template_agent.d.ts +4 -0
- package/lib/experimental_agents/{string_agent.js → string_agents/string_template_agent.js} +2 -5
- package/lib/experimental_agents/test_agents/bypass_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/bypass_agent.js +10 -0
- package/lib/experimental_agents/test_agents/copy_message_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/copy_message_agent.js +11 -0
- package/lib/experimental_agents/test_agents/counting_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/counting_agent.js +11 -0
- package/lib/experimental_agents/test_agents/echo_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/echo_agent.js +7 -0
- package/lib/experimental_agents/test_agents/echo_fork_index_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/echo_fork_index_agent.js +7 -0
- package/lib/experimental_agents/test_agents/index.d.ts +5 -0
- package/lib/experimental_agents/test_agents/index.js +13 -0
- package/lib/experimental_agents/test_agents/merge_node_id_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/merge_node_id_agent.js +10 -0
- package/lib/experimental_agents/token_agent.d.ts +6 -0
- package/lib/experimental_agents/token_agent.js +33 -0
- package/lib/graphai.d.ts +23 -18
- package/lib/graphai.js +110 -115
- package/lib/index.d.ts +2 -0
- package/lib/log.d.ts +22 -6
- package/lib/log.js +45 -44
- package/lib/node.d.ts +31 -25
- package/lib/node.js +136 -97
- package/lib/task.d.ts +18 -0
- package/lib/task.js +63 -0
- package/lib/task_manager.d.ts +20 -0
- package/lib/task_manager.js +69 -0
- package/lib/transaction_log.d.ts +27 -0
- package/lib/transaction_log.js +56 -0
- package/lib/type.d.ts +45 -32
- package/lib/type.js +1 -0
- package/lib/utils/utils.d.ts +3 -1
- package/lib/utils/utils.js +17 -6
- package/lib/validator.d.ts +2 -0
- package/lib/validator.js +28 -0
- package/lib/validators/agent_validator.d.ts +1 -0
- package/lib/validators/agent_validator.js +12 -0
- package/lib/validators/common.d.ts +3 -0
- package/lib/validators/common.js +6 -0
- package/lib/validators/computed_node_validator.d.ts +2 -0
- package/lib/validators/computed_node_validator.js +13 -0
- package/lib/validators/graph_data_validator.d.ts +3 -0
- package/lib/validators/graph_data_validator.js +43 -0
- package/lib/validators/nodeValidator.d.ts +2 -0
- package/lib/validators/nodeValidator.js +13 -0
- package/lib/validators/relation_validator.d.ts +2 -0
- package/lib/validators/relation_validator.js +62 -0
- package/lib/validators/static_node_validator.d.ts +2 -0
- package/lib/validators/static_node_validator.js +13 -0
- package/package.json +3 -5
- package/lib/experimental_agents/array_agents.d.ts +0 -4
- package/lib/experimental_agents/data_agent.d.ts +0 -3
- package/lib/experimental_agents/data_agent.js +0 -25
- package/lib/experimental_agents/sleeper_agent.d.ts +0 -10
- package/lib/experimental_agents/string_agent.d.ts +0 -7
- package/lib/graphai_cli.d.ts +0 -2
- package/lib/graphai_cli.js +0 -37
- package/lib/utils.d.ts +0 -7
- package/lib/utils.js +0 -13
package/README.md
CHANGED
|
@@ -9,15 +9,17 @@ You just need to describe dependencies among those API calls in a single data fl
|
|
|
9
9
|
Here is an example:
|
|
10
10
|
|
|
11
11
|
```YAML
|
|
12
|
-
agentId: sample
|
|
13
12
|
nodes:
|
|
14
13
|
taskA:
|
|
14
|
+
agentId: sample
|
|
15
15
|
params:
|
|
16
16
|
// agent-specific parameters for taskA
|
|
17
17
|
taskB:
|
|
18
|
+
agentId: sample
|
|
18
19
|
params:
|
|
19
20
|
// agent-specific parameters for taskB
|
|
20
21
|
taskC:
|
|
22
|
+
agentId: sample
|
|
21
23
|
params:
|
|
22
24
|
// agent-specific parameters for taskC
|
|
23
25
|
inputs: [taskA, taskB]
|
|
@@ -115,7 +117,7 @@ Key principles:
|
|
|
115
117
|
|
|
116
118
|
A Data Flow Graph (DFG) is a JavaScript object, which defines the flow of data. It is typically described in YAML file and loaded at runtime.
|
|
117
119
|
|
|
118
|
-
A DFG consists of a collection of 'nodes', which contains a series of nested properties representing individual nodes in the data flow. Each node is identified by a unique key, *nodeId* (e.g., node1, node2) and can contain several predefined properties (params, inputs, retry, timeout, agentId, fork, value, update) that dictate the node's behavior and its relationship with other nodes.
|
|
120
|
+
A DFG consists of a collection of 'nodes', which contains a series of nested properties representing individual nodes in the data flow. Each node is identified by a unique key, *nodeId* (e.g., node1, node2) and can contain several predefined properties (params, inputs, anyInput, retry, timeout, agentId, fork, value, update) that dictate the node's behavior and its relationship with other nodes.
|
|
119
121
|
|
|
120
122
|
Connections between nodes will be established by references from one not to another, using either its "inputs" or "update" property. The values of those properties are *data sources*. A *data souce* is specified by either the nodeId (e.g., "node1"), or nodeId + propertyId ("node1.item").
|
|
121
123
|
|
|
@@ -123,7 +125,6 @@ Connections between nodes will be established by references from one not to anot
|
|
|
123
125
|
|
|
124
126
|
- 'nodes': A list of node. Required.
|
|
125
127
|
- 'concurrency': An optional property, which specifies the maximum number of concurrent operations (agent functions to be executed at the same time). The default is 8.
|
|
126
|
-
- 'agentId': An optional property, which specifies the default agent for all the nodes.
|
|
127
128
|
- 'loop': An optional property, which specifies if the graph needs to be executed multiple times. The loop is an JavaScript object, which has two optinoal properties. The *count* property specifies the number of times the graph needs to be executed and the *while* property specifies the condition required to contineu the loop in the form of node name (nodeId) or its property (nodeId.propId). Unlike JavaScript, an empty array will be treated as false.
|
|
128
129
|
|
|
129
130
|
```
|
|
@@ -171,6 +172,7 @@ A *computed node* have following properties.
|
|
|
171
172
|
|
|
172
173
|
- 'agentId': An **required** property, which specifies the id of the *agent function*.
|
|
173
174
|
- 'inputs': An optional list of *data sources* that the current node depends on. This establishes a flow where the current node can only be executed after the completion of the nodes listed under 'inputs'. If this list is empty, the associated *agent function* will be immediatley executed.
|
|
175
|
+
- 'anyInput': An optiona boolean flag, which indicates that the associated *agent function* will be called when at least one of input data became available. Otherwise, it will wait until all the data became available.
|
|
174
176
|
- 'retry': An optional number, which specifies the maximum number of retries to be made. If the last attempt fails, that return value will be recorded.
|
|
175
177
|
- 'timeout': An optional number, which specifies the maximum waittime in msec. If the associated agent function does not return the value in time, the "Timeout" error will be recorded and the returned value will be discarded.
|
|
176
178
|
- 'params': An optional property to the associated agent function, which are agent specific.
|
|
@@ -178,7 +180,7 @@ A *computed node* have following properties.
|
|
|
178
180
|
|
|
179
181
|
A *static* node have following properties.
|
|
180
182
|
|
|
181
|
-
- 'value': An
|
|
183
|
+
- 'value': An **required** property, which specifies the initial value of this static node (equivalent to calling the injectValue method from outside).
|
|
182
184
|
- 'update': An optional property, which specifies the *data source* after each iteration.
|
|
183
185
|
|
|
184
186
|
## GraphAI class
|
|
@@ -209,7 +211,7 @@ Retrieves all transaction logs recorded during the execution of the graph.
|
|
|
209
211
|
|
|
210
212
|
Returns: An array of transaction logs detailing the execution states and outcomes of the nodes within the graph.
|
|
211
213
|
|
|
212
|
-
### ```
|
|
214
|
+
### ```injectValue(nodeId: string, result: ResultData): void```
|
|
213
215
|
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.
|
|
214
216
|
|
|
215
217
|
- ```nodeId: string```: The ID of the static node into which the result is to be injected.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shiftAgent = exports.popAgent = exports.pushAgent = void 0;
|
|
4
|
+
var push_agent_1 = require("../../experimental_agents/array_agents/push_agent");
|
|
5
|
+
Object.defineProperty(exports, "pushAgent", { enumerable: true, get: function () { return push_agent_1.pushAgent; } });
|
|
6
|
+
var pop_agent_1 = require("../../experimental_agents/array_agents/pop_agent");
|
|
7
|
+
Object.defineProperty(exports, "popAgent", { enumerable: true, get: function () { return pop_agent_1.popAgent; } });
|
|
8
|
+
var shift_agent_1 = require("../../experimental_agents/array_agents/shift_agent");
|
|
9
|
+
Object.defineProperty(exports, "shiftAgent", { enumerable: true, get: function () { return shift_agent_1.shiftAgent; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.popAgent = void 0;
|
|
7
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
8
|
+
const popAgent = async (context) => {
|
|
9
|
+
const { inputs } = context;
|
|
10
|
+
const [array] = (0, deepmerge_1.default)({ inputs }, {}).inputs;
|
|
11
|
+
// TODO: Validation
|
|
12
|
+
const item = array.pop();
|
|
13
|
+
return { array, item };
|
|
14
|
+
};
|
|
15
|
+
exports.popAgent = popAgent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pushAgent = void 0;
|
|
7
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
8
|
+
const pushAgent = async ({ inputs }) => {
|
|
9
|
+
const [array, item] = (0, deepmerge_1.default)({ inputs }, {}).inputs;
|
|
10
|
+
// TODO: Validation
|
|
11
|
+
array.push(item);
|
|
12
|
+
return array;
|
|
13
|
+
};
|
|
14
|
+
exports.pushAgent = pushAgent;
|
|
@@ -3,27 +3,12 @@ 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.shiftAgent =
|
|
6
|
+
exports.shiftAgent = void 0;
|
|
7
7
|
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
8
|
-
const pushAgent = async ({ inputs }) => {
|
|
9
|
-
const [array, item] = (0, deepmerge_1.default)({ inputs }, {}).inputs;
|
|
10
|
-
// TODO: Validation
|
|
11
|
-
array.push(item);
|
|
12
|
-
return array;
|
|
13
|
-
};
|
|
14
|
-
exports.pushAgent = pushAgent;
|
|
15
|
-
const popAgent = async (context) => {
|
|
16
|
-
const { inputs } = context;
|
|
17
|
-
const [array] = (0, deepmerge_1.default)({ inputs }, {}).inputs;
|
|
18
|
-
// TODO: Varidation
|
|
19
|
-
const item = array.pop();
|
|
20
|
-
return { array, item };
|
|
21
|
-
};
|
|
22
|
-
exports.popAgent = popAgent;
|
|
23
8
|
const shiftAgent = async (context) => {
|
|
24
9
|
const { inputs } = context;
|
|
25
10
|
const [array] = (0, deepmerge_1.default)({ inputs }, {}).inputs;
|
|
26
|
-
// TODO:
|
|
11
|
+
// TODO: Validation
|
|
27
12
|
const item = array.shift();
|
|
28
13
|
return { array, item };
|
|
29
14
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.dataObjectMergeTemplateAgent = void 0;
|
|
7
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
8
|
+
const dataObjectMergeTemplateAgent = async ({ inputs }) => {
|
|
9
|
+
return inputs.reduce((tmp, input) => {
|
|
10
|
+
return (0, deepmerge_1.default)(tmp, input);
|
|
11
|
+
}, {});
|
|
12
|
+
};
|
|
13
|
+
exports.dataObjectMergeTemplateAgent = dataObjectMergeTemplateAgent;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AgentFunction } from "../../graphai";
|
|
2
|
+
export declare const dataSumTemplateAgent: AgentFunction<Record<string, any>, number, number>;
|
|
3
|
+
declare const dataSumTemplateAgentInfo: {
|
|
4
|
+
name: string;
|
|
5
|
+
agent: AgentFunction<Record<string, any>, number, number>;
|
|
6
|
+
mock: AgentFunction<Record<string, any>, number, number>;
|
|
7
|
+
samples: {
|
|
8
|
+
inputs: number[];
|
|
9
|
+
params: {};
|
|
10
|
+
result: number;
|
|
11
|
+
}[];
|
|
12
|
+
description: string;
|
|
13
|
+
author: string;
|
|
14
|
+
repository: string;
|
|
15
|
+
license: string;
|
|
16
|
+
};
|
|
17
|
+
export default dataSumTemplateAgentInfo;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dataSumTemplateAgent = void 0;
|
|
4
|
+
const dataSumTemplateAgent = async ({ inputs }) => {
|
|
5
|
+
return inputs.reduce((tmp, input) => {
|
|
6
|
+
return tmp + input;
|
|
7
|
+
}, 0);
|
|
8
|
+
};
|
|
9
|
+
exports.dataSumTemplateAgent = dataSumTemplateAgent;
|
|
10
|
+
// for test and document
|
|
11
|
+
const sampleInputs = [1, 2, 3];
|
|
12
|
+
const sampleParams = {};
|
|
13
|
+
const sampleResult = 6;
|
|
14
|
+
const dataSumTemplateAgentInfo = {
|
|
15
|
+
name: "dataSumTemplateAgent",
|
|
16
|
+
agent: exports.dataSumTemplateAgent,
|
|
17
|
+
mock: exports.dataSumTemplateAgent,
|
|
18
|
+
samples: [
|
|
19
|
+
{
|
|
20
|
+
inputs: sampleInputs,
|
|
21
|
+
params: sampleParams,
|
|
22
|
+
result: sampleResult,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
description: "Returns the sum of input values",
|
|
26
|
+
author: "Satoshi Nakajima",
|
|
27
|
+
repository: "https://github.com/snakajima/graphai",
|
|
28
|
+
license: "MIT",
|
|
29
|
+
};
|
|
30
|
+
exports.default = dataSumTemplateAgentInfo;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { totalAgent } from "../../experimental_agents/data_agents/total_agent";
|
|
2
|
+
export { dataObjectMergeTemplateAgent } from "../../experimental_agents/data_agents/data_object_merge_template_agent";
|
|
3
|
+
export { dataSumTemplateAgent } from "../../experimental_agents/data_agents/data_sum_template_agent";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dataSumTemplateAgent = exports.dataObjectMergeTemplateAgent = exports.totalAgent = void 0;
|
|
4
|
+
var total_agent_1 = require("../../experimental_agents/data_agents/total_agent");
|
|
5
|
+
Object.defineProperty(exports, "totalAgent", { enumerable: true, get: function () { return total_agent_1.totalAgent; } });
|
|
6
|
+
var data_object_merge_template_agent_1 = require("../../experimental_agents/data_agents/data_object_merge_template_agent");
|
|
7
|
+
Object.defineProperty(exports, "dataObjectMergeTemplateAgent", { enumerable: true, get: function () { return data_object_merge_template_agent_1.dataObjectMergeTemplateAgent; } });
|
|
8
|
+
var data_sum_template_agent_1 = require("../../experimental_agents/data_agents/data_sum_template_agent");
|
|
9
|
+
Object.defineProperty(exports, "dataSumTemplateAgent", { enumerable: true, get: function () { return data_sum_template_agent_1.dataSumTemplateAgent; } });
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AgentFunction } from "../../graphai";
|
|
2
|
+
export declare const totalAgent: AgentFunction<Record<never, never>, Record<string, number>>;
|
|
3
|
+
declare const totalAgentInfo: {
|
|
4
|
+
name: string;
|
|
5
|
+
agent: AgentFunction<Record<never, never>, Record<string, number>>;
|
|
6
|
+
mock: AgentFunction<Record<never, never>, Record<string, number>>;
|
|
7
|
+
samples: ({
|
|
8
|
+
inputs: {
|
|
9
|
+
a: number;
|
|
10
|
+
}[];
|
|
11
|
+
params: {};
|
|
12
|
+
result: {
|
|
13
|
+
a: number;
|
|
14
|
+
};
|
|
15
|
+
} | {
|
|
16
|
+
inputs: (({
|
|
17
|
+
a: number;
|
|
18
|
+
b: number;
|
|
19
|
+
c?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
c: number;
|
|
22
|
+
a?: undefined;
|
|
23
|
+
b?: undefined;
|
|
24
|
+
})[] | ({
|
|
25
|
+
a: number;
|
|
26
|
+
b: number;
|
|
27
|
+
d?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
d: number;
|
|
30
|
+
a?: undefined;
|
|
31
|
+
b?: undefined;
|
|
32
|
+
})[])[];
|
|
33
|
+
params: {};
|
|
34
|
+
result: {
|
|
35
|
+
a: number;
|
|
36
|
+
b: number;
|
|
37
|
+
c: number;
|
|
38
|
+
d: number;
|
|
39
|
+
};
|
|
40
|
+
})[];
|
|
41
|
+
description: string;
|
|
42
|
+
author: string;
|
|
43
|
+
repository: string;
|
|
44
|
+
license: string;
|
|
45
|
+
};
|
|
46
|
+
export default totalAgentInfo;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.totalAgent = void 0;
|
|
4
|
+
const totalAgent = async ({ inputs }) => {
|
|
5
|
+
return inputs.reduce((result, input) => {
|
|
6
|
+
const inputArray = Array.isArray(input) ? input : [input];
|
|
7
|
+
inputArray.forEach((innerInput) => {
|
|
8
|
+
Object.keys(innerInput).forEach((key) => {
|
|
9
|
+
const value = innerInput[key];
|
|
10
|
+
if (result[key]) {
|
|
11
|
+
result[key] += value;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
result[key] = value;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
return result;
|
|
19
|
+
}, {});
|
|
20
|
+
};
|
|
21
|
+
exports.totalAgent = totalAgent;
|
|
22
|
+
// for test and document
|
|
23
|
+
const sampleInputs = [{ a: 1 }, { a: 2 }, { a: 3 }];
|
|
24
|
+
const sampleParams = {};
|
|
25
|
+
const sampleResult = { a: 6 };
|
|
26
|
+
const sample2Inputs = [[{ a: 1, b: -1 }, { c: 10 }], [{ a: 2, b: -1 }], [{ a: 3, b: -2 }, { d: -10 }]];
|
|
27
|
+
const sample2Params = {};
|
|
28
|
+
const sample2Result = { a: 6, b: -4, c: 10, d: -10 };
|
|
29
|
+
//
|
|
30
|
+
const totalAgentInfo = {
|
|
31
|
+
name: "totalAgent",
|
|
32
|
+
agent: exports.totalAgent,
|
|
33
|
+
mock: exports.totalAgent,
|
|
34
|
+
samples: [
|
|
35
|
+
{
|
|
36
|
+
inputs: sampleInputs,
|
|
37
|
+
params: sampleParams,
|
|
38
|
+
result: sampleResult,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
inputs: sample2Inputs,
|
|
42
|
+
params: sample2Params,
|
|
43
|
+
result: sample2Result,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
description: "Returns the sum of input values",
|
|
47
|
+
author: "Satoshi Nakajima",
|
|
48
|
+
repository: "https://github.com/snakajima/graphai",
|
|
49
|
+
license: "MIT",
|
|
50
|
+
};
|
|
51
|
+
exports.default = totalAgentInfo;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringEmbeddingsAgent = void 0;
|
|
4
|
+
const defaultEmbeddingModel = "text-embedding-3-small";
|
|
5
|
+
const OpenAI_embedding_API = "https://api.openai.com/v1/embeddings";
|
|
6
|
+
// This agent retrieves embedding vectors for an array of strings using OpenAI's API
|
|
7
|
+
//
|
|
8
|
+
// Parameters:
|
|
9
|
+
// model: Specifies the model (default is "text-embedding-3-small")
|
|
10
|
+
// Inputs:
|
|
11
|
+
// inputs[0]: Array<string>
|
|
12
|
+
// Result:
|
|
13
|
+
// contents: Array<Array<number>>
|
|
14
|
+
//
|
|
15
|
+
const stringEmbeddingsAgent = async ({ params, inputs }) => {
|
|
16
|
+
const input = inputs[0];
|
|
17
|
+
const sources = Array.isArray(input) ? input : [input];
|
|
18
|
+
const apiKey = process.env.OPENAI_API_KEY;
|
|
19
|
+
if (!apiKey) {
|
|
20
|
+
throw new Error("OPENAI_API_KEY key is not set in environment variables.");
|
|
21
|
+
}
|
|
22
|
+
const headers = {
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
Authorization: `Bearer ${apiKey}`,
|
|
25
|
+
};
|
|
26
|
+
const response = await fetch(OpenAI_embedding_API, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: headers,
|
|
29
|
+
body: JSON.stringify({
|
|
30
|
+
input: sources,
|
|
31
|
+
model: params?.model ?? defaultEmbeddingModel,
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
const jsonResponse = await response.json();
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
37
|
+
}
|
|
38
|
+
const embeddings = jsonResponse.data.map((object) => {
|
|
39
|
+
return object.embedding;
|
|
40
|
+
});
|
|
41
|
+
return { contents: embeddings };
|
|
42
|
+
};
|
|
43
|
+
exports.stringEmbeddingsAgent = stringEmbeddingsAgent;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./string_agents";
|
|
2
2
|
export * from "./slashgpt_agent";
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
3
|
+
export * from "./sleeper_agents";
|
|
4
|
+
export * from "./data_agents";
|
|
5
5
|
export * from "./nested_agent";
|
|
6
6
|
export * from "./array_agents";
|
|
7
|
+
export * from "./embedding_agent";
|
|
8
|
+
export * from "./matrix_agent";
|
|
9
|
+
export * from "./token_agent";
|
|
10
|
+
export * from "./test_agents";
|
|
11
|
+
export * from "./map_agent";
|
|
@@ -14,9 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./string_agents"), exports);
|
|
18
18
|
__exportStar(require("./slashgpt_agent"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./
|
|
19
|
+
__exportStar(require("./sleeper_agents"), exports);
|
|
20
|
+
__exportStar(require("./data_agents"), exports);
|
|
21
21
|
__exportStar(require("./nested_agent"), exports);
|
|
22
22
|
__exportStar(require("./array_agents"), exports);
|
|
23
|
+
__exportStar(require("./embedding_agent"), exports);
|
|
24
|
+
__exportStar(require("./matrix_agent"), exports);
|
|
25
|
+
__exportStar(require("./token_agent"), exports);
|
|
26
|
+
__exportStar(require("./test_agents"), exports);
|
|
27
|
+
__exportStar(require("./map_agent"), exports);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapAgent = void 0;
|
|
4
|
+
const graphai_1 = require("../graphai");
|
|
5
|
+
const utils_1 = require("../utils/utils");
|
|
6
|
+
const mapAgent = async ({ params, inputs, agents, log, taskManager, graphData }) => {
|
|
7
|
+
if (taskManager) {
|
|
8
|
+
const status = taskManager.getStatus();
|
|
9
|
+
(0, utils_1.assert)(status.concurrency > status.running, `mapAgent: Concurrency is too low: ${status.concurrency}`);
|
|
10
|
+
}
|
|
11
|
+
(0, utils_1.assert)(graphData !== undefined, "mapAgent: graphData is required");
|
|
12
|
+
const input = Array.isArray(inputs[0]) ? inputs[0] : inputs;
|
|
13
|
+
const injectionTo = params.injectionTo ?? "$0";
|
|
14
|
+
if (graphData.nodes[injectionTo] === undefined) {
|
|
15
|
+
// If the input node does not exist, automatically create a static node
|
|
16
|
+
graphData.nodes[injectionTo] = { value: {} };
|
|
17
|
+
}
|
|
18
|
+
const graphs = input.map((data) => {
|
|
19
|
+
const graphAI = new graphai_1.GraphAI(graphData, agents || {}, taskManager);
|
|
20
|
+
graphAI.injectValue(injectionTo, data, "__mapAgent_inputs__");
|
|
21
|
+
return graphAI;
|
|
22
|
+
});
|
|
23
|
+
const runs = graphs.map((graph) => {
|
|
24
|
+
return graph.run(false);
|
|
25
|
+
});
|
|
26
|
+
const results = await Promise.all(runs);
|
|
27
|
+
const nodeIds = Object.keys(results[0]);
|
|
28
|
+
(0, utils_1.assert)(nodeIds.length > 0, "mapAgent: no return values (missing isResult)");
|
|
29
|
+
const compositeResult = nodeIds.reduce((tmp, nodeId) => {
|
|
30
|
+
tmp[nodeId] = results.map((result) => {
|
|
31
|
+
return result[nodeId];
|
|
32
|
+
});
|
|
33
|
+
return tmp;
|
|
34
|
+
}, {});
|
|
35
|
+
if (log) {
|
|
36
|
+
const logs = graphs.map((graph, index) => {
|
|
37
|
+
return graph.transactionLogs().map((log) => {
|
|
38
|
+
log.mapIndex = index;
|
|
39
|
+
return log;
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
log.push(...logs.flat());
|
|
43
|
+
}
|
|
44
|
+
return compositeResult;
|
|
45
|
+
};
|
|
46
|
+
exports.mapAgent = mapAgent;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AgentFunction } from "../graphai";
|
|
2
|
+
export declare const dotProductAgent: AgentFunction<Record<string, any>, {
|
|
3
|
+
contents: Array<number>;
|
|
4
|
+
}, Array<Array<number>>>;
|
|
5
|
+
export declare const sortByValuesAgent: AgentFunction<{
|
|
6
|
+
assendant?: boolean;
|
|
7
|
+
}, {
|
|
8
|
+
contents: Array<any>;
|
|
9
|
+
}, Array<any>>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortByValuesAgent = exports.dotProductAgent = void 0;
|
|
4
|
+
// This agent calculates the dot product of an array of vectors (A[]) and a vector (B),
|
|
5
|
+
// typically used to calculate cosine similarity of embedding vectors.
|
|
6
|
+
// Inputs:
|
|
7
|
+
// inputs[0]: Two dimentional array of numbers.
|
|
8
|
+
// inputs[1]: Two dimentional array of numbers (but the array size is 1 for the first dimention)
|
|
9
|
+
// Outputs:
|
|
10
|
+
// { contents: Array<number> } // array of docProduct of each vector (A[]) and vector B
|
|
11
|
+
const dotProductAgent = async ({ inputs }) => {
|
|
12
|
+
const embeddings = inputs[0];
|
|
13
|
+
const reference = inputs[1][0];
|
|
14
|
+
if (embeddings[0].length != reference.length) {
|
|
15
|
+
throw new Error("dotProduct: Length of vectors do not match.");
|
|
16
|
+
}
|
|
17
|
+
const contents = embeddings.map((embedding) => {
|
|
18
|
+
return embedding.reduce((dotProduct, value, index) => {
|
|
19
|
+
return dotProduct + value * reference[index];
|
|
20
|
+
}, 0);
|
|
21
|
+
});
|
|
22
|
+
return { contents };
|
|
23
|
+
};
|
|
24
|
+
exports.dotProductAgent = dotProductAgent;
|
|
25
|
+
// This agent returned a sorted array of one array (A) based on another array (B).
|
|
26
|
+
// The default sorting order is "decendant".
|
|
27
|
+
//
|
|
28
|
+
// Parameters:
|
|
29
|
+
// acendant: Specifies if the sorting order should be acendant. The default is "false" (decendant).
|
|
30
|
+
// Inputs:
|
|
31
|
+
// inputs[0]: Array<any>; // array to be sorted
|
|
32
|
+
// inputs[1]: Array<number>; // array of numbers for sorting
|
|
33
|
+
//
|
|
34
|
+
const sortByValuesAgent = async ({ params, inputs }) => {
|
|
35
|
+
const direction = params?.assendant ?? false ? -1 : 1;
|
|
36
|
+
const sources = inputs[0];
|
|
37
|
+
const values = inputs[1];
|
|
38
|
+
const joined = sources.map((item, index) => {
|
|
39
|
+
return { item, value: values[index] };
|
|
40
|
+
});
|
|
41
|
+
const contents = joined
|
|
42
|
+
.sort((a, b) => {
|
|
43
|
+
return (b.value - a.value) * direction;
|
|
44
|
+
})
|
|
45
|
+
.map((a) => {
|
|
46
|
+
return a.item;
|
|
47
|
+
});
|
|
48
|
+
return { contents };
|
|
49
|
+
};
|
|
50
|
+
exports.sortByValuesAgent = sortByValuesAgent;
|
|
@@ -2,19 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.nestedAgent = void 0;
|
|
4
4
|
const graphai_1 = require("../graphai");
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const utils_1 = require("../utils/utils");
|
|
6
|
+
const nestedAgent = async ({ params, inputs, agents, log, taskManager, graphData }) => {
|
|
7
|
+
if (taskManager) {
|
|
8
|
+
const status = taskManager.getStatus(false);
|
|
9
|
+
(0, utils_1.assert)(status.concurrency > status.running, `nestedAgent: Concurrency is too low: ${status.concurrency}`);
|
|
10
|
+
}
|
|
11
|
+
(0, utils_1.assert)(graphData !== undefined, "nestedAgent: graphData is required");
|
|
12
|
+
const graphAI = new graphai_1.GraphAI(graphData, agents || {}, taskManager);
|
|
7
13
|
try {
|
|
8
14
|
// Inject inputs to specified source nodes
|
|
9
|
-
(params.
|
|
10
|
-
|
|
15
|
+
(params.injectionTo ?? []).forEach((injectToNodeId, index) => {
|
|
16
|
+
graphAI.injectValue(injectToNodeId, inputs[index]);
|
|
11
17
|
});
|
|
12
|
-
const results = await
|
|
13
|
-
log
|
|
14
|
-
return results[params.
|
|
18
|
+
const results = await graphAI.run(true);
|
|
19
|
+
log?.push(...graphAI.transactionLogs());
|
|
20
|
+
return results[params.resultFrom];
|
|
15
21
|
}
|
|
16
22
|
catch (error) {
|
|
17
|
-
log
|
|
23
|
+
log?.push(...graphAI.transactionLogs());
|
|
18
24
|
if (error instanceof Error) {
|
|
19
25
|
console.log("Error:", error.message);
|
|
20
26
|
}
|
|
@@ -7,18 +7,13 @@ exports.slashGPTAgent = void 0;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const slashgpt_1 = require("slashgpt");
|
|
9
9
|
const config = new slashgpt_1.ChatConfig(path_1.default.resolve(__dirname));
|
|
10
|
-
const slashGPTAgent = async ({
|
|
10
|
+
const slashGPTAgent = async ({ params, inputs, debugInfo: { verbose, nodeId } }) => {
|
|
11
11
|
if (verbose) {
|
|
12
12
|
console.log("executing", nodeId, params);
|
|
13
13
|
}
|
|
14
14
|
const session = new slashgpt_1.ChatSession(config, params.manifest ?? {});
|
|
15
15
|
const query = params?.query ? [params.query] : [];
|
|
16
|
-
const contents = query.concat(inputs
|
|
17
|
-
if (typeof input === "string") {
|
|
18
|
-
return input;
|
|
19
|
-
}
|
|
20
|
-
return input.content;
|
|
21
|
-
}));
|
|
16
|
+
const contents = query.concat(inputs);
|
|
22
17
|
session.append_user_question(contents.join("\n"));
|
|
23
18
|
await session.call_loop(() => { });
|
|
24
19
|
const message = (() => {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sleeperAgentDebug = exports.sleeperAgent = void 0;
|
|
4
|
+
var sleeper_agent_1 = require("../../experimental_agents/sleeper_agents/sleeper_agent");
|
|
5
|
+
Object.defineProperty(exports, "sleeperAgent", { enumerable: true, get: function () { return sleeper_agent_1.sleeperAgent; } });
|
|
6
|
+
var sleeper_agent_debug_1 = require("../../experimental_agents/sleeper_agents/sleeper_agent_debug");
|
|
7
|
+
Object.defineProperty(exports, "sleeperAgentDebug", { enumerable: true, get: function () { return sleeper_agent_debug_1.sleeperAgentDebug; } });
|