graphai 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -35
- 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 +28 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.js +38 -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_agents/dot_product_agent.d.ts +4 -0
- package/lib/experimental_agents/matrix_agents/dot_product_agent.js +24 -0
- package/lib/experimental_agents/matrix_agents/index.d.ts +2 -0
- package/lib/experimental_agents/matrix_agents/index.js +7 -0
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +6 -0
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.js +29 -0
- package/lib/experimental_agents/nested_agent.d.ts +1 -2
- package/lib/experimental_agents/nested_agent.js +24 -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 +39 -0
- package/lib/experimental_agents/string_agents/string_splitter_agent.js +64 -0
- package/lib/experimental_agents/string_agents/string_template_agent.d.ts +27 -0
- package/lib/experimental_agents/string_agents/string_template_agent.js +33 -0
- 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/copy2array_agent.d.ts +2 -0
- package/lib/experimental_agents/test_agents/copy2array_agent.js +9 -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/index.d.ts +6 -0
- package/lib/experimental_agents/test_agents/index.js +15 -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 +106 -115
- package/lib/index.d.ts +2 -0
- package/lib/node.d.ts +30 -25
- package/lib/node.js +131 -101
- 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/test_agents.d.ts +2 -0
- package/lib/utils/test_agents.js +20 -0
- package/lib/utils/test_utils.d.ts +12 -0
- package/lib/utils/test_utils.js +34 -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 +10 -14
- 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/experimental_agents/string_agent.js +0 -15
- package/lib/graphai_cli.d.ts +0 -2
- package/lib/graphai_cli.js +0 -37
- package/lib/log.d.ts +0 -6
- package/lib/log.js +0 -48
- package/lib/utils.d.ts +0 -7
- package/lib/utils.js +0 -13
package/README.md
CHANGED
|
@@ -2,45 +2,57 @@
|
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
GraphAI is an asynchronous data flow execution engine, which makes it easy to
|
|
5
|
+
GraphAI is an asynchronous data flow execution engine, which makes it easy to build *agentic* applications, which perform the orchestration of mutiple "AI agents".
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
*Agentic* applications need to make asynchronous API calls (such as OpenAI's chat-completion API, database query, web search, and etc.) multiple times and manage data dependencies among them, such as giving the answer from one LLM call to another LLM call as a prompt -- 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.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
GraphAI allows developers to describe dependencies among those API calls in a single data flow graph (either in YAML or JSON), create a GraphAI instance with that graph, and let it run. The GraphAI engine will take care of all the complexity of concurrent asynchronous calls, data dependency management, error handling, retries and logging.
|
|
10
|
+
|
|
11
|
+
Here is an example graph, which uses the Wikipedia as the data source and perform an in-memory RAG.
|
|
10
12
|
|
|
11
13
|
```YAML
|
|
12
|
-
agentId: sample
|
|
13
14
|
nodes:
|
|
14
|
-
|
|
15
|
+
source: // Input data to this RAG application
|
|
16
|
+
value:
|
|
17
|
+
name: Sam Bankman-Fried
|
|
18
|
+
query: describe the final sentence by the court for Sam Bank-Fried
|
|
19
|
+
wikipedia: // Retrieve data from Wikipedia。
|
|
20
|
+
agentId: wikipediaAgent
|
|
21
|
+
inputs: [source.name]
|
|
22
|
+
chunks: // Break the text from Wikipedia into chunks(2048 character each with 512 overlap)
|
|
23
|
+
agentId: stringSplitterAgent
|
|
24
|
+
inputs: [wikipedia]
|
|
25
|
+
chunkEmbeddings: // Get embedding vector of each chunk
|
|
26
|
+
agentId: stringEmbeddingsAgent
|
|
27
|
+
inputs: [chunks]
|
|
28
|
+
topicEmbedding: // Get embedding vector of the question
|
|
29
|
+
agentId: stringEmbeddingsAgent
|
|
30
|
+
inputs: [source.query]
|
|
31
|
+
similarities: // Calculate the cosine similarity of each chunk
|
|
32
|
+
agentId: dotProductAgent
|
|
33
|
+
inputs: [chunkEmbeddings, topicEmbedding]
|
|
34
|
+
sortedChunks: // Sort chunks based on the similarity
|
|
35
|
+
agentId: sortByValuesAgent
|
|
36
|
+
inputs: [chunks, similarities]
|
|
37
|
+
referenceText: // Concatenate chunks up to the token limit (5000)
|
|
38
|
+
agentId: tokenBoundStringsAgent
|
|
39
|
+
inputs: [sortedChunks]
|
|
15
40
|
params:
|
|
16
|
-
|
|
17
|
-
|
|
41
|
+
limit: 5000
|
|
42
|
+
prompt: // Generate a prompt with that reference text
|
|
43
|
+
agentId: stringTemplateAgent
|
|
44
|
+
inputs: [source, referenceText]
|
|
18
45
|
params:
|
|
19
|
-
|
|
20
|
-
|
|
46
|
+
template: |-
|
|
47
|
+
Using the following document, ${0}
|
|
48
|
+
${1}
|
|
49
|
+
query: // retrieves the answer from GPT3.5
|
|
50
|
+
agentId: slashGPTAgent
|
|
21
51
|
params:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
``` TypeScript
|
|
27
|
-
const sampleAgentFunction = async (context: AgentFunctionContext) => {
|
|
28
|
-
const {
|
|
29
|
-
nodeId, // taskA, taskB or taskC
|
|
30
|
-
params, // agent-specific parameters specified in the graph definition file
|
|
31
|
-
inputs // inputs from previous nodes
|
|
32
|
-
} = context;
|
|
33
|
-
// Agent-specific code (such as calling OpenAI's chat.completions API)
|
|
34
|
-
...
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
...
|
|
39
|
-
const file = fs.readFileSync(pathToYamlFile, "utf8");
|
|
40
|
-
const graphData = YAML.parse(file);
|
|
41
|
-
const graph = new GraphAI(graphData, { sample: sampleAgentFunction });
|
|
42
|
-
const results = await graph.run();
|
|
43
|
-
return results["taskC"];
|
|
52
|
+
manifest:
|
|
53
|
+
model: gpt-3.5-turbo
|
|
54
|
+
isResult: true // indicating this is the final result
|
|
55
|
+
inputs: [prompt]
|
|
44
56
|
```
|
|
45
57
|
|
|
46
58
|
## Background
|
|
@@ -115,7 +127,7 @@ Key principles:
|
|
|
115
127
|
|
|
116
128
|
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
129
|
|
|
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.
|
|
130
|
+
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
131
|
|
|
120
132
|
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
133
|
|
|
@@ -123,7 +135,6 @@ Connections between nodes will be established by references from one not to anot
|
|
|
123
135
|
|
|
124
136
|
- 'nodes': A list of node. Required.
|
|
125
137
|
- '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
138
|
- '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
139
|
|
|
129
140
|
```
|
|
@@ -171,6 +182,7 @@ A *computed node* have following properties.
|
|
|
171
182
|
|
|
172
183
|
- 'agentId': An **required** property, which specifies the id of the *agent function*.
|
|
173
184
|
- '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.
|
|
185
|
+
- '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
186
|
- '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
187
|
- '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
188
|
- 'params': An optional property to the associated agent function, which are agent specific.
|
|
@@ -178,7 +190,7 @@ A *computed node* have following properties.
|
|
|
178
190
|
|
|
179
191
|
A *static* node have following properties.
|
|
180
192
|
|
|
181
|
-
- 'value': An
|
|
193
|
+
- 'value': An **required** property, which specifies the initial value of this static node (equivalent to calling the injectValue method from outside).
|
|
182
194
|
- 'update': An optional property, which specifies the *data source* after each iteration.
|
|
183
195
|
|
|
184
196
|
## GraphAI class
|
|
@@ -209,7 +221,7 @@ Retrieves all transaction logs recorded during the execution of the graph.
|
|
|
209
221
|
|
|
210
222
|
Returns: An array of transaction logs detailing the execution states and outcomes of the nodes within the graph.
|
|
211
223
|
|
|
212
|
-
### ```
|
|
224
|
+
### ```injectValue(nodeId: string, result: ResultData): void```
|
|
213
225
|
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
226
|
|
|
215
227
|
- ```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,28 @@
|
|
|
1
|
+
import { AgentFunction } from "../../graphai";
|
|
2
|
+
export declare const dataObjectMergeTemplateAgent: AgentFunction;
|
|
3
|
+
declare const dataObjectMergeTemplateAgentInfo: {
|
|
4
|
+
name: string;
|
|
5
|
+
agent: AgentFunction;
|
|
6
|
+
mock: AgentFunction;
|
|
7
|
+
samples: {
|
|
8
|
+
inputs: ({
|
|
9
|
+
a: number;
|
|
10
|
+
b: number;
|
|
11
|
+
c?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
a: number;
|
|
14
|
+
b: number;
|
|
15
|
+
c: number;
|
|
16
|
+
})[];
|
|
17
|
+
params: {};
|
|
18
|
+
result: {
|
|
19
|
+
a: number;
|
|
20
|
+
b: number;
|
|
21
|
+
};
|
|
22
|
+
}[];
|
|
23
|
+
description: string;
|
|
24
|
+
author: string;
|
|
25
|
+
repository: string;
|
|
26
|
+
license: string;
|
|
27
|
+
};
|
|
28
|
+
export default dataObjectMergeTemplateAgentInfo;
|
|
@@ -0,0 +1,38 @@
|
|
|
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;
|
|
14
|
+
// for test and document
|
|
15
|
+
const sampleInputs = [
|
|
16
|
+
{ a: 1, b: 1 },
|
|
17
|
+
{ a: 2, b: 2 },
|
|
18
|
+
{ a: 3, b: 0, c: 5 },
|
|
19
|
+
];
|
|
20
|
+
const sampleParams = {};
|
|
21
|
+
const sampleResult = { a: 6, b: 3 };
|
|
22
|
+
const dataObjectMergeTemplateAgentInfo = {
|
|
23
|
+
name: "dataObjectMergeTemplateAgent",
|
|
24
|
+
agent: exports.dataObjectMergeTemplateAgent,
|
|
25
|
+
mock: exports.dataObjectMergeTemplateAgent,
|
|
26
|
+
samples: [
|
|
27
|
+
{
|
|
28
|
+
inputs: sampleInputs,
|
|
29
|
+
params: sampleParams,
|
|
30
|
+
result: sampleResult,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
description: "Merge object",
|
|
34
|
+
author: "Satoshi Nakajima",
|
|
35
|
+
repository: "https://github.com/receptron/graphai",
|
|
36
|
+
license: "MIT",
|
|
37
|
+
};
|
|
38
|
+
exports.default = dataObjectMergeTemplateAgentInfo;
|
|
@@ -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/receptron/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_agents";
|
|
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_agents"), 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,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortByValuesAgent = exports.dotProductAgent = void 0;
|
|
4
|
+
var dot_product_agent_1 = require("../../experimental_agents/matrix_agents/dot_product_agent");
|
|
5
|
+
Object.defineProperty(exports, "dotProductAgent", { enumerable: true, get: function () { return dot_product_agent_1.dotProductAgent; } });
|
|
6
|
+
var sort_by_values_agent_1 = require("../../experimental_agents/matrix_agents/sort_by_values_agent");
|
|
7
|
+
Object.defineProperty(exports, "sortByValuesAgent", { enumerable: true, get: function () { return sort_by_values_agent_1.sortByValuesAgent; } });
|