graphai 0.3.0 → 0.3.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 +27 -8
- package/lib/experimental_agent_filters/stream.d.ts +2 -0
- package/lib/experimental_agent_filters/stream.js +13 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.d.ts +43 -0
- package/lib/experimental_agents/data_agents/data_object_merge_template_agent.js +22 -0
- package/lib/experimental_agents/data_agents/data_sum_template_agent.js +15 -0
- package/lib/experimental_agents/data_agents/property_filter_agent.d.ts +109 -8
- package/lib/experimental_agents/data_agents/property_filter_agent.js +60 -9
- package/lib/experimental_agents/data_agents/total_agent.d.ts +13 -0
- package/lib/experimental_agents/data_agents/total_agent.js +29 -0
- package/lib/experimental_agents/graph_agents/map_agent.js +2 -2
- package/lib/experimental_agents/graph_agents/nested_agent.js +9 -12
- package/lib/experimental_agents/llm_agents/groq_stream_agent.d.ts +42 -0
- package/lib/experimental_agents/llm_agents/groq_stream_agent.js +84 -0
- package/lib/experimental_agents/llm_agents/index.d.ts +2 -0
- package/lib/experimental_agents/llm_agents/index.js +2 -0
- package/lib/experimental_agents/llm_agents/openai_agent.d.ts +58 -0
- package/lib/experimental_agents/llm_agents/openai_agent.js +87 -0
- package/lib/experimental_agents/llm_agents/packages.d.ts +3 -1
- package/lib/experimental_agents/llm_agents/packages.js +5 -1
- package/lib/experimental_agents/llm_agents/slashgpt_agent.js +6 -2
- package/lib/experimental_agents/matrix_agents/dot_product_agent.d.ts +4 -4
- package/lib/experimental_agents/matrix_agents/dot_product_agent.js +15 -4
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +13 -1
- package/lib/experimental_agents/matrix_agents/sort_by_values_agent.js +20 -1
- package/lib/experimental_agents/service_agents/fetch_agent.js +1 -1
- package/lib/experimental_agents/service_agents/packages.d.ts +2 -1
- package/lib/experimental_agents/service_agents/packages.js +3 -1
- package/lib/experimental_agents/service_agents/wikipedia.d.ts +1 -0
- package/lib/experimental_agents/service_agents/wikipedia.js +1 -0
- package/lib/experimental_agents/test_agents/stream_mock_agent.js +6 -6
- package/lib/experimental_agents/token_agent.d.ts +11 -1
- package/lib/experimental_agents/token_agent.js +30 -1
- package/lib/graphai.d.ts +3 -3
- package/lib/graphai.js +16 -15
- package/lib/node.d.ts +2 -1
- package/lib/node.js +18 -11
- package/lib/task_manager.js +3 -6
- package/lib/transaction_log.d.ts +1 -1
- package/lib/transaction_log.js +2 -1
- package/lib/type.d.ts +7 -1
- package/lib/utils/test_agents.js +2 -0
- package/lib/utils/test_utils.js +2 -2
- package/lib/validators/agent_validator.js +1 -1
- package/lib/validators/common.js +1 -1
- package/lib/validators/nodeValidator.js +2 -2
- package/package.json +13 -12
package/lib/node.js
CHANGED
|
@@ -38,6 +38,7 @@ class ComputedNode extends Node {
|
|
|
38
38
|
this.isComputedNode = true;
|
|
39
39
|
this.graphId = graphId;
|
|
40
40
|
this.params = data.params ?? {};
|
|
41
|
+
this.filterParams = data.filterParams ?? {};
|
|
41
42
|
this.nestedGraph = data.graph;
|
|
42
43
|
if (typeof data.agent === "string") {
|
|
43
44
|
this.agentId = data.agent;
|
|
@@ -64,12 +65,13 @@ class ComputedNode extends Node {
|
|
|
64
65
|
this.dynamicParams = Object.keys(this.params).reduce((tmp, key) => {
|
|
65
66
|
const dataSource = (0, utils_2.parseNodeName)(this.params[key], graph.version < 0.3 ? 0.3 : graph.version);
|
|
66
67
|
if (dataSource.nodeId) {
|
|
68
|
+
(0, utils_2.assert)(!this.anyInput, "Dynamic params are not supported with anyInput");
|
|
67
69
|
tmp[key] = dataSource;
|
|
68
70
|
this.pendings.add(dataSource.nodeId);
|
|
69
71
|
}
|
|
70
72
|
return tmp;
|
|
71
73
|
}, {});
|
|
72
|
-
this.log.initForComputedNode(this);
|
|
74
|
+
this.log.initForComputedNode(this, graph);
|
|
73
75
|
}
|
|
74
76
|
getAgentId() {
|
|
75
77
|
return this.agentId ?? "__custom__function"; // only for display purpose in the log.
|
|
@@ -165,17 +167,20 @@ class ComputedNode extends Node {
|
|
|
165
167
|
}
|
|
166
168
|
return !agentFilter.agentIds && !agentFilter.nodeIds;
|
|
167
169
|
}
|
|
168
|
-
agentFilterHandler(context,
|
|
170
|
+
agentFilterHandler(context, agentFunction) {
|
|
169
171
|
let index = 0;
|
|
170
|
-
const next = (
|
|
172
|
+
const next = (innerContext) => {
|
|
171
173
|
const agentFilter = this.graph.agentFilters[index++];
|
|
172
174
|
if (agentFilter) {
|
|
173
175
|
if (this.shouldApplyAgentFilter(agentFilter)) {
|
|
174
|
-
|
|
176
|
+
if (agentFilter.filterParams) {
|
|
177
|
+
innerContext.filterParams = { ...agentFilter.filterParams, ...innerContext.filterParams };
|
|
178
|
+
}
|
|
179
|
+
return agentFilter.agent(innerContext, next);
|
|
175
180
|
}
|
|
176
|
-
return next(
|
|
181
|
+
return next(innerContext);
|
|
177
182
|
}
|
|
178
|
-
return
|
|
183
|
+
return agentFunction(innerContext);
|
|
179
184
|
};
|
|
180
185
|
return next(context);
|
|
181
186
|
}
|
|
@@ -196,7 +201,7 @@ class ComputedNode extends Node {
|
|
|
196
201
|
}, this.timeout);
|
|
197
202
|
}
|
|
198
203
|
try {
|
|
199
|
-
const
|
|
204
|
+
const agentFunction = this.agentFunction ?? this.graph.getAgentFunction(this.agentId);
|
|
200
205
|
const localLog = [];
|
|
201
206
|
const params = Object.keys(this.dynamicParams).reduce((tmp, key) => {
|
|
202
207
|
const [result] = this.graph.resultsOf([this.dynamicParams[key]]);
|
|
@@ -208,10 +213,12 @@ class ComputedNode extends Node {
|
|
|
208
213
|
inputs: previousResults,
|
|
209
214
|
debugInfo: {
|
|
210
215
|
nodeId: this.nodeId,
|
|
216
|
+
agentId: this.agentId,
|
|
211
217
|
retry: this.retryCount,
|
|
212
218
|
verbose: this.graph.verbose,
|
|
213
219
|
},
|
|
214
|
-
filterParams:
|
|
220
|
+
filterParams: this.filterParams,
|
|
221
|
+
agentFilters: this.graph.agentFilters,
|
|
215
222
|
log: localLog,
|
|
216
223
|
};
|
|
217
224
|
// NOTE: We use the existence of graph object in the agent-specific params to determine
|
|
@@ -220,9 +227,9 @@ class ComputedNode extends Node {
|
|
|
220
227
|
this.graph.taskManager.prepareForNesting();
|
|
221
228
|
context.taskManager = this.graph.taskManager;
|
|
222
229
|
context.graphData = this.nestedGraph;
|
|
223
|
-
context.agents = this.graph.
|
|
230
|
+
context.agents = this.graph.agentFunctionDictionary;
|
|
224
231
|
}
|
|
225
|
-
const result = await this.agentFilterHandler(context,
|
|
232
|
+
const result = await this.agentFilterHandler(context, agentFunction);
|
|
226
233
|
if (this.nestedGraph) {
|
|
227
234
|
this.graph.taskManager.restoreAfterNesting();
|
|
228
235
|
}
|
|
@@ -278,7 +285,7 @@ class StaticNode extends Node {
|
|
|
278
285
|
this.isStaticNode = true;
|
|
279
286
|
this.isComputedNode = false;
|
|
280
287
|
this.value = data.value;
|
|
281
|
-
this.update = data.update;
|
|
288
|
+
this.update = data.update ? (0, utils_2.parseNodeName)(data.update, graph.version) : undefined;
|
|
282
289
|
this.isResult = data.isResult ?? false;
|
|
283
290
|
}
|
|
284
291
|
injectValue(value, injectFrom) {
|
package/lib/task_manager.js
CHANGED
|
@@ -58,12 +58,9 @@ class TaskManager {
|
|
|
58
58
|
this.concurrency--;
|
|
59
59
|
}
|
|
60
60
|
getStatus(verbose = false) {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
queuedNodes: this.taskQueue.map((task) => task.node.nodeId),
|
|
65
|
-
}
|
|
66
|
-
: {};
|
|
61
|
+
const runningNodes = Array.from(this.runningNodes).map((node) => node.nodeId);
|
|
62
|
+
const queuedNodes = this.taskQueue.map((task) => task.node.nodeId);
|
|
63
|
+
const nodes = verbose ? { runningNodes, queuedNodes } : {};
|
|
67
64
|
return {
|
|
68
65
|
concurrency: this.concurrency,
|
|
69
66
|
queue: this.taskQueue.length,
|
package/lib/transaction_log.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class TransactionLog {
|
|
|
19
19
|
repeatCount?: number;
|
|
20
20
|
log?: TransactionLog[];
|
|
21
21
|
constructor(nodeId: string);
|
|
22
|
-
initForComputedNode(node: ComputedNode): void;
|
|
22
|
+
initForComputedNode(node: ComputedNode, graph: GraphAI): void;
|
|
23
23
|
onInjected(node: StaticNode, graph: GraphAI, injectFrom?: string): void;
|
|
24
24
|
onComplete(node: ComputedNode, graph: GraphAI, localLog: TransactionLog[]): void;
|
|
25
25
|
beforeExecute(node: ComputedNode, graph: GraphAI, transactionId: number, inputs: ResultData[]): void;
|
package/lib/transaction_log.js
CHANGED
|
@@ -7,9 +7,10 @@ class TransactionLog {
|
|
|
7
7
|
this.nodeId = nodeId;
|
|
8
8
|
this.state = type_1.NodeState.Waiting;
|
|
9
9
|
}
|
|
10
|
-
initForComputedNode(node) {
|
|
10
|
+
initForComputedNode(node, graph) {
|
|
11
11
|
this.agentId = node.getAgentId();
|
|
12
12
|
this.params = node.params;
|
|
13
|
+
graph.appendLog(this);
|
|
13
14
|
}
|
|
14
15
|
onInjected(node, graph, injectFrom) {
|
|
15
16
|
const isUpdating = "endTime" in this;
|
package/lib/type.d.ts
CHANGED
|
@@ -27,11 +27,13 @@ export type StaticNodeData = {
|
|
|
27
27
|
isResult?: boolean;
|
|
28
28
|
};
|
|
29
29
|
export type AgentNamelessFunction = (...param: any[]) => unknown;
|
|
30
|
+
export type AgentFilterParams = Record<string, any>;
|
|
30
31
|
export type ComputedNodeData = {
|
|
31
32
|
agent: string | AgentNamelessFunction;
|
|
32
33
|
inputs?: Array<any>;
|
|
33
34
|
anyInput?: boolean;
|
|
34
35
|
params?: NodeDataParams;
|
|
36
|
+
filterParams?: AgentFilterParams;
|
|
35
37
|
retry?: number;
|
|
36
38
|
timeout?: number;
|
|
37
39
|
if?: string;
|
|
@@ -59,11 +61,13 @@ export type AgentFunctionContext<ParamsType = DefaultParamsType, InputDataType =
|
|
|
59
61
|
verbose: boolean;
|
|
60
62
|
nodeId: string;
|
|
61
63
|
retry: number;
|
|
64
|
+
agentId?: string;
|
|
62
65
|
};
|
|
63
66
|
graphData?: GraphData | string;
|
|
64
67
|
agents?: AgentFunctionDictonary;
|
|
65
68
|
taskManager?: TaskManager;
|
|
66
|
-
filterParams:
|
|
69
|
+
filterParams: AgentFilterParams;
|
|
70
|
+
agentFilters?: AgentFilterInfo[];
|
|
67
71
|
log?: TransactionLog[];
|
|
68
72
|
};
|
|
69
73
|
export type AgentFunction<ParamsType = DefaultParamsType, ResultType = DefaultResultData, InputDataType = DefaultInputData> = (context: AgentFunctionContext<ParamsType, InputDataType>) => Promise<ResultData<ResultType>>;
|
|
@@ -73,6 +77,7 @@ export type AgentFilterInfo = {
|
|
|
73
77
|
agent: AgentFilterFunction;
|
|
74
78
|
agentIds?: string[];
|
|
75
79
|
nodeIds?: string[];
|
|
80
|
+
filterParams?: AgentFilterParams;
|
|
76
81
|
};
|
|
77
82
|
export type AgentFunctionDictonary = Record<string, AgentFunction<any, any, any>>;
|
|
78
83
|
export type AgentFunctionInfo = {
|
|
@@ -84,6 +89,7 @@ export type AgentFunctionInfo = {
|
|
|
84
89
|
params: DefaultParamsType;
|
|
85
90
|
result: any;
|
|
86
91
|
}[];
|
|
92
|
+
skipTest?: boolean;
|
|
87
93
|
description: string;
|
|
88
94
|
category: string[];
|
|
89
95
|
author: string;
|
package/lib/utils/test_agents.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultTestAgents = void 0;
|
|
4
4
|
const experimental_agents_1 = require("../experimental_agents");
|
|
5
|
+
const openai_agent_1 = require("../experimental_agents/llm_agents/openai_agent");
|
|
5
6
|
exports.defaultTestAgents = {
|
|
6
7
|
bypassAgent: experimental_agents_1.bypassAgent,
|
|
7
8
|
echoAgent: experimental_agents_1.echoAgent,
|
|
@@ -19,4 +20,5 @@ exports.defaultTestAgents = {
|
|
|
19
20
|
popAgent: experimental_agents_1.popAgent,
|
|
20
21
|
shiftAgent: experimental_agents_1.shiftAgent,
|
|
21
22
|
streamMockAgent: experimental_agents_1.streamMockAgent,
|
|
23
|
+
openAIMockAgent: openai_agent_1.openAIMockAgent,
|
|
22
24
|
};
|
package/lib/utils/test_utils.js
CHANGED
|
@@ -19,8 +19,8 @@ exports.defaultTestContext = {
|
|
|
19
19
|
};
|
|
20
20
|
// for agent
|
|
21
21
|
const agentTestRunner = async (agentInfo) => {
|
|
22
|
-
const { agent, samples } = agentInfo;
|
|
23
|
-
if (samples.length === 0) {
|
|
22
|
+
const { agent, samples, skipTest } = agentInfo;
|
|
23
|
+
if (samples.length === 0 || skipTest) {
|
|
24
24
|
console.log(`test ${agentInfo.name}: No test`);
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
@@ -4,7 +4,7 @@ exports.agentValidator = void 0;
|
|
|
4
4
|
const agentValidator = (graphAgentIds, agentIds) => {
|
|
5
5
|
graphAgentIds.forEach((agentId) => {
|
|
6
6
|
if (!agentIds.has(agentId)) {
|
|
7
|
-
throw new Error("Invalid
|
|
7
|
+
throw new Error("Invalid Agent : " + agentId + " is not in callbackDictonary.");
|
|
8
8
|
}
|
|
9
9
|
});
|
|
10
10
|
return true;
|
package/lib/validators/common.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.staticNodeAttributeKeys = exports.computedNodeAttributeKeys = exports.graphDataAttributeKeys = void 0;
|
|
4
4
|
exports.graphDataAttributeKeys = ["nodes", "concurrency", "agentId", "loop", "verbose", "version"];
|
|
5
|
-
exports.computedNodeAttributeKeys = ["inputs", "anyInput", "params", "retry", "timeout", "agent", "graph", "isResult", "priority", "if"];
|
|
5
|
+
exports.computedNodeAttributeKeys = ["inputs", "anyInput", "params", "retry", "timeout", "agent", "graph", "isResult", "priority", "if", "filterParams"];
|
|
6
6
|
exports.staticNodeAttributeKeys = ["value", "update", "isResult"];
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.nodeValidator = void 0;
|
|
4
4
|
const nodeValidator = (nodeData) => {
|
|
5
5
|
if (nodeData.agent && nodeData.value) {
|
|
6
|
-
throw new Error("Cannot set both
|
|
6
|
+
throw new Error("Cannot set both agent and value");
|
|
7
7
|
}
|
|
8
8
|
if (!("agent" in nodeData) && !("value" in nodeData)) {
|
|
9
|
-
throw new Error("Either
|
|
9
|
+
throw new Error("Either agent or value is required");
|
|
10
10
|
}
|
|
11
11
|
return true;
|
|
12
12
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphai",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Asynchronous data flow execution engine for agentic AI apps.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "rm -r lib/* && tsc && tsc-alias",
|
|
11
|
-
"eslint": "eslint
|
|
12
|
-
"format": "prettier --write '{src,tests,samples}/**/*.ts'
|
|
11
|
+
"eslint": "eslint",
|
|
12
|
+
"format": "prettier --write '{src,tests,samples}/**/*.ts'",
|
|
13
13
|
"test": "node --test -r tsconfig-paths/register --require ts-node/register ./tests/**/test_*.ts",
|
|
14
14
|
"http_test": "node --test -r tsconfig-paths/register --require ts-node/register ./tests/**/http_*.ts",
|
|
15
15
|
"b": "yarn run format && yarn run eslint && yarn run build",
|
|
@@ -28,26 +28,27 @@
|
|
|
28
28
|
"homepage": "https://github.com/receptron/graphai#readme",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@inquirer/prompts": "^5.0.0",
|
|
31
|
+
"@types/cors": "^2.8.17",
|
|
31
32
|
"@types/express": "^4.17.21",
|
|
32
|
-
"@types/node": "^20.
|
|
33
|
+
"@types/node": "^20.12.11",
|
|
33
34
|
"@types/xml2js": "^0.4.14",
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
35
|
-
"@typescript-eslint/parser": "^6.8.0",
|
|
36
35
|
"arxiv-api-ts": "^1.0.3",
|
|
36
|
+
"cors": "^2.8.5",
|
|
37
37
|
"deepmerge": "^4.3.1",
|
|
38
38
|
"dotenv": "^16.4.5",
|
|
39
|
-
"eslint": "^
|
|
40
|
-
"eslint-plugin-import": "^2.25.2",
|
|
39
|
+
"eslint": "^9.2.0",
|
|
41
40
|
"express": "^4.19.2",
|
|
41
|
+
"globals": "^15.2.0",
|
|
42
42
|
"groq-sdk": "^0.3.3",
|
|
43
43
|
"openai": "^4.12.4",
|
|
44
|
-
"prettier": "^3.
|
|
45
|
-
"slashgpt": "^0.0.
|
|
44
|
+
"prettier": "^3.2.5",
|
|
45
|
+
"slashgpt": "^0.0.9",
|
|
46
46
|
"tiktoken": "^1.0.14",
|
|
47
|
-
"ts-node": "^10.9.
|
|
47
|
+
"ts-node": "^10.9.2",
|
|
48
48
|
"tsc-alias": "^1.8.8",
|
|
49
49
|
"tsconfig-paths": "^4.2.0",
|
|
50
|
-
"typescript": "^5.
|
|
50
|
+
"typescript": "^5.4.5",
|
|
51
|
+
"typescript-eslint": "^7.8.0",
|
|
51
52
|
"wikipedia": "^2.1.2",
|
|
52
53
|
"xml2js": "^0.6.2",
|
|
53
54
|
"yaml": "^2.4.1"
|