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/README.md
CHANGED
|
@@ -317,9 +317,12 @@ flowchart LR
|
|
|
317
317
|
```
|
|
318
318
|
### Conditional Flow
|
|
319
319
|
|
|
320
|
-
|
|
320
|
+
GraphAI provides mechanisms to control the flow of data based on certain conditions. This is achieved through the *if* and *anyInput* properties.
|
|
321
321
|
|
|
322
|
-
|
|
322
|
+
#### If Property
|
|
323
|
+
|
|
324
|
+
The *if* property allows you to specify a condition that must be met for the data to flow into a particular node. The condition is defined by a data source. If the value obtained from the specified *data source* is truthy (i.e., not null, undefined, 0, false, NaN, or an empty array/string), the node will be executed; otherwise, it will be skipped.
|
|
325
|
+
For example, the following node will only be executed if the *tool_calls* property of the message from the LLM contains a value:
|
|
323
326
|
|
|
324
327
|
```typescript
|
|
325
328
|
tool_calls: {
|
|
@@ -331,11 +334,13 @@ A sample code, [weather chat](https://github.com/receptron/graphai/blob/main/sam
|
|
|
331
334
|
// This graph is nested only for the readability.
|
|
332
335
|
```
|
|
333
336
|
|
|
334
|
-
|
|
337
|
+
It is recommended to use the *if* property in conjunction with nested graphs for better code readability and organization.
|
|
338
|
+
|
|
339
|
+
#### AnyInput Property
|
|
335
340
|
|
|
336
|
-
The *anyInput* property (boolean) allows
|
|
341
|
+
The *anyInput* property (boolean) allows you to merge multiple data flow paths into a single node. When set to *true*, the agent function associated with the node will be executed as soon as data becomes available from any of the specified input data sources.
|
|
337
342
|
|
|
338
|
-
|
|
343
|
+
This property is particularly useful when you want to continue the flow regardless of which path the data comes from. In the weather chat sample application, it is used to continue the chat iteration whether a tool was requested by the LLM or not:
|
|
339
344
|
|
|
340
345
|
```typescript
|
|
341
346
|
reducer: {
|
|
@@ -346,17 +351,31 @@ The [weather chat](https://github.com/receptron/graphai/blob/main/samples/sample
|
|
|
346
351
|
},
|
|
347
352
|
```
|
|
348
353
|
|
|
354
|
+
In this example, the "reducer" node will execute as soon as data is available from either the "no_tool_calls" or "tool_calls.messagesWithSecondRes" data source.
|
|
355
|
+
|
|
356
|
+
By combining the *if* and *anyInput* properties, you can create complex conditional flows that control the execution of nodes based on the availability and values of data from various sources. This flexibility allows you to build sophisticated data-driven applications with GraphAI.
|
|
357
|
+
|
|
349
358
|
## Concurrency
|
|
350
359
|
|
|
351
|
-
|
|
360
|
+
GraphAI supports concurrent execution of tasks, allowing you to leverage parallelism and improve performance. The level of concurrency can be controlled through the *concurrency* property at the top level of the graph definition.
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
concurrency: 16 # Maximum number of concurrent tasks
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
If the *concurrency* property is not specified, the default value of 8 is used.
|
|
367
|
+
|
|
368
|
+
### Concurrency and Nested Graphs
|
|
352
369
|
|
|
353
370
|
Since the task queue is shared between the parent graph and the children graph (uness the graph is running remotely), tasks created by the child graph will be bound by the same concurrency specified by the parent graph.
|
|
354
371
|
|
|
355
372
|
Since the task executing the nested graph will be in "running" state while tasks within the child graph are runnig, the concurrency limit will be incremented by one when we start running the child graph and restored when it is completed.
|
|
356
373
|
|
|
357
|
-
|
|
374
|
+
### Task Prioritization
|
|
375
|
+
|
|
376
|
+
By default, tasks are executed in a first-in, first-out (FIFO) order with a neutral priority (0). However, you can assign custom priorities to nodes using the *priority* property. Tasks associated with nodes that have a higher priority value will be executed before those with lower priorities.
|
|
358
377
|
|
|
359
|
-
|
|
378
|
+
Negative priority values are allowed, enabling you to fine-tune the execution order based on your application's requirements.
|
|
360
379
|
|
|
361
380
|
## GraphAI class
|
|
362
381
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.streamAgentFilterGenerator = void 0;
|
|
4
|
+
const streamAgentFilterGenerator = (callback) => {
|
|
5
|
+
const streamAgentFilter = async (context, next) => {
|
|
6
|
+
context.filterParams.streamTokenCallback = (data) => {
|
|
7
|
+
callback(context, data);
|
|
8
|
+
};
|
|
9
|
+
return next(context);
|
|
10
|
+
};
|
|
11
|
+
return streamAgentFilter;
|
|
12
|
+
};
|
|
13
|
+
exports.streamAgentFilterGenerator = streamAgentFilterGenerator;
|
|
@@ -5,6 +5,46 @@ declare const dataObjectMergeTemplateAgentInfo: {
|
|
|
5
5
|
agent: AgentFunction;
|
|
6
6
|
mock: AgentFunction;
|
|
7
7
|
samples: ({
|
|
8
|
+
inputs: ({
|
|
9
|
+
content1: string;
|
|
10
|
+
content2?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
content2: string;
|
|
13
|
+
content1?: undefined;
|
|
14
|
+
})[];
|
|
15
|
+
params: {};
|
|
16
|
+
result: {
|
|
17
|
+
content1: string;
|
|
18
|
+
content2: string;
|
|
19
|
+
content?: undefined;
|
|
20
|
+
a?: undefined;
|
|
21
|
+
b?: undefined;
|
|
22
|
+
};
|
|
23
|
+
} | {
|
|
24
|
+
inputs: {
|
|
25
|
+
content1: string;
|
|
26
|
+
}[];
|
|
27
|
+
params: {};
|
|
28
|
+
result: {
|
|
29
|
+
content1: string;
|
|
30
|
+
content2?: undefined;
|
|
31
|
+
content?: undefined;
|
|
32
|
+
a?: undefined;
|
|
33
|
+
b?: undefined;
|
|
34
|
+
};
|
|
35
|
+
} | {
|
|
36
|
+
inputs: {
|
|
37
|
+
content: string;
|
|
38
|
+
}[];
|
|
39
|
+
params: {};
|
|
40
|
+
result: {
|
|
41
|
+
content: string;
|
|
42
|
+
content1?: undefined;
|
|
43
|
+
content2?: undefined;
|
|
44
|
+
a?: undefined;
|
|
45
|
+
b?: undefined;
|
|
46
|
+
};
|
|
47
|
+
} | {
|
|
8
48
|
inputs: ({
|
|
9
49
|
a: number;
|
|
10
50
|
b: number;
|
|
@@ -72,6 +112,9 @@ declare const dataObjectMergeTemplateAgentInfo: {
|
|
|
72
112
|
};
|
|
73
113
|
};
|
|
74
114
|
};
|
|
115
|
+
content1?: undefined;
|
|
116
|
+
content2?: undefined;
|
|
117
|
+
content?: undefined;
|
|
75
118
|
};
|
|
76
119
|
})[];
|
|
77
120
|
description: string;
|
|
@@ -24,6 +24,28 @@ const dataObjectMergeTemplateAgentInfo = {
|
|
|
24
24
|
agent: exports.dataObjectMergeTemplateAgent,
|
|
25
25
|
mock: exports.dataObjectMergeTemplateAgent,
|
|
26
26
|
samples: [
|
|
27
|
+
{
|
|
28
|
+
inputs: [{ content1: "hello" }, { content2: "test" }],
|
|
29
|
+
params: {},
|
|
30
|
+
result: {
|
|
31
|
+
content1: "hello",
|
|
32
|
+
content2: "test",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
inputs: [{ content1: "hello" }],
|
|
37
|
+
params: {},
|
|
38
|
+
result: {
|
|
39
|
+
content1: "hello",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
inputs: [{ content: "hello1" }, { content: "hello2" }],
|
|
44
|
+
params: {},
|
|
45
|
+
result: {
|
|
46
|
+
content: "hello2",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
27
49
|
{
|
|
28
50
|
inputs: sampleInputs,
|
|
29
51
|
params: sampleParams,
|
|
@@ -21,6 +21,21 @@ const dataSumTemplateAgentInfo = {
|
|
|
21
21
|
params: sampleParams,
|
|
22
22
|
result: sampleResult,
|
|
23
23
|
},
|
|
24
|
+
{
|
|
25
|
+
inputs: [1],
|
|
26
|
+
params: {},
|
|
27
|
+
result: 1,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
inputs: [1, 2],
|
|
31
|
+
params: {},
|
|
32
|
+
result: 3,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
inputs: [1, 2, 3],
|
|
36
|
+
params: {},
|
|
37
|
+
result: 6,
|
|
38
|
+
},
|
|
24
39
|
],
|
|
25
40
|
description: "Returns the sum of input values",
|
|
26
41
|
category: ["data"],
|
|
@@ -2,55 +2,156 @@ import { AgentFunction } from "../../graphai";
|
|
|
2
2
|
export declare const propertyFilterAgent: AgentFunction<{
|
|
3
3
|
include?: Array<string>;
|
|
4
4
|
exclude?: Array<string>;
|
|
5
|
+
alter?: Record<string, Record<string, string>>;
|
|
6
|
+
inject?: Record<string, Record<string, any>>;
|
|
5
7
|
}>;
|
|
6
8
|
declare const propertyFilterAgentInfo: {
|
|
7
9
|
name: string;
|
|
8
10
|
agent: AgentFunction<{
|
|
9
11
|
include?: string[] | undefined;
|
|
10
12
|
exclude?: string[] | undefined;
|
|
13
|
+
alter?: Record<string, Record<string, string>> | undefined;
|
|
14
|
+
inject?: Record<string, Record<string, any>> | undefined;
|
|
11
15
|
}>;
|
|
12
16
|
mock: AgentFunction<{
|
|
13
17
|
include?: string[] | undefined;
|
|
14
18
|
exclude?: string[] | undefined;
|
|
19
|
+
alter?: Record<string, Record<string, string>> | undefined;
|
|
20
|
+
inject?: Record<string, Record<string, any>> | undefined;
|
|
15
21
|
}>;
|
|
16
22
|
samples: ({
|
|
17
|
-
inputs: {
|
|
23
|
+
inputs: (string | {
|
|
18
24
|
color: string;
|
|
19
25
|
model: string;
|
|
20
26
|
type: string;
|
|
21
27
|
maker: string;
|
|
22
28
|
range: number;
|
|
23
|
-
}[];
|
|
29
|
+
})[];
|
|
24
30
|
params: {
|
|
25
31
|
include: string[];
|
|
26
32
|
exclude?: undefined;
|
|
33
|
+
alter?: undefined;
|
|
34
|
+
inject?: undefined;
|
|
27
35
|
};
|
|
28
36
|
result: {
|
|
29
37
|
color: string;
|
|
30
38
|
model: string;
|
|
31
|
-
type?: undefined;
|
|
32
|
-
maker?: undefined;
|
|
33
|
-
range?: undefined;
|
|
34
39
|
};
|
|
35
40
|
} | {
|
|
36
|
-
inputs: {
|
|
41
|
+
inputs: (string | {
|
|
37
42
|
color: string;
|
|
38
43
|
model: string;
|
|
39
44
|
type: string;
|
|
40
45
|
maker: string;
|
|
41
46
|
range: number;
|
|
47
|
+
}[])[];
|
|
48
|
+
params: {
|
|
49
|
+
include: string[];
|
|
50
|
+
exclude?: undefined;
|
|
51
|
+
alter?: undefined;
|
|
52
|
+
inject?: undefined;
|
|
53
|
+
};
|
|
54
|
+
result: {
|
|
55
|
+
color: string;
|
|
56
|
+
model: string;
|
|
42
57
|
}[];
|
|
58
|
+
} | {
|
|
59
|
+
inputs: (string | {
|
|
60
|
+
color: string;
|
|
61
|
+
model: string;
|
|
62
|
+
type: string;
|
|
63
|
+
maker: string;
|
|
64
|
+
range: number;
|
|
65
|
+
}[])[];
|
|
43
66
|
params: {
|
|
44
67
|
exclude: string[];
|
|
45
68
|
include?: undefined;
|
|
69
|
+
alter?: undefined;
|
|
70
|
+
inject?: undefined;
|
|
46
71
|
};
|
|
47
72
|
result: {
|
|
48
73
|
type: string;
|
|
49
74
|
maker: string;
|
|
50
75
|
range: number;
|
|
51
|
-
|
|
52
|
-
|
|
76
|
+
}[];
|
|
77
|
+
} | {
|
|
78
|
+
inputs: (string | {
|
|
79
|
+
color: string;
|
|
80
|
+
model: string;
|
|
81
|
+
type: string;
|
|
82
|
+
maker: string;
|
|
83
|
+
range: number;
|
|
84
|
+
}[])[];
|
|
85
|
+
params: {
|
|
86
|
+
alter: {
|
|
87
|
+
color: {
|
|
88
|
+
red: string;
|
|
89
|
+
blue: string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
include?: undefined;
|
|
93
|
+
exclude?: undefined;
|
|
94
|
+
inject?: undefined;
|
|
53
95
|
};
|
|
96
|
+
result: {
|
|
97
|
+
color: string;
|
|
98
|
+
model: string;
|
|
99
|
+
type: string;
|
|
100
|
+
maker: string;
|
|
101
|
+
range: number;
|
|
102
|
+
}[];
|
|
103
|
+
} | {
|
|
104
|
+
inputs: (string | {
|
|
105
|
+
color: string;
|
|
106
|
+
model: string;
|
|
107
|
+
type: string;
|
|
108
|
+
maker: string;
|
|
109
|
+
range: number;
|
|
110
|
+
}[])[];
|
|
111
|
+
params: {
|
|
112
|
+
inject: {
|
|
113
|
+
maker: {
|
|
114
|
+
from: number;
|
|
115
|
+
index?: undefined;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
include?: undefined;
|
|
119
|
+
exclude?: undefined;
|
|
120
|
+
alter?: undefined;
|
|
121
|
+
};
|
|
122
|
+
result: {
|
|
123
|
+
color: string;
|
|
124
|
+
model: string;
|
|
125
|
+
type: string;
|
|
126
|
+
maker: string;
|
|
127
|
+
range: number;
|
|
128
|
+
}[];
|
|
129
|
+
} | {
|
|
130
|
+
inputs: (string | {
|
|
131
|
+
color: string;
|
|
132
|
+
model: string;
|
|
133
|
+
type: string;
|
|
134
|
+
maker: string;
|
|
135
|
+
range: number;
|
|
136
|
+
}[])[];
|
|
137
|
+
params: {
|
|
138
|
+
inject: {
|
|
139
|
+
maker: {
|
|
140
|
+
index: number;
|
|
141
|
+
from: number;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
include?: undefined;
|
|
145
|
+
exclude?: undefined;
|
|
146
|
+
alter?: undefined;
|
|
147
|
+
};
|
|
148
|
+
result: {
|
|
149
|
+
color: string;
|
|
150
|
+
model: string;
|
|
151
|
+
type: string;
|
|
152
|
+
maker: string;
|
|
153
|
+
range: number;
|
|
154
|
+
}[];
|
|
54
155
|
})[];
|
|
55
156
|
description: string;
|
|
56
157
|
category: string[];
|
|
@@ -1,40 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.propertyFilterAgent = void 0;
|
|
4
|
-
const applyFilter = (input, include, exclude) => {
|
|
4
|
+
const applyFilter = (input, index, inputs, include, exclude, alter, inject) => {
|
|
5
5
|
const propIds = include ? include : Object.keys(input);
|
|
6
6
|
const excludeSet = new Set(exclude ?? []);
|
|
7
7
|
return propIds.reduce((tmp, propId) => {
|
|
8
8
|
if (!excludeSet.has(propId)) {
|
|
9
|
-
|
|
9
|
+
const injection = inject && inject[propId];
|
|
10
|
+
const mapping = alter && alter[propId];
|
|
11
|
+
if (injection && (injection.index === undefined || injection.index === index)) {
|
|
12
|
+
tmp[propId] = inputs[injection.from];
|
|
13
|
+
}
|
|
14
|
+
else if (mapping && mapping[input[propId]]) {
|
|
15
|
+
tmp[propId] = mapping[input[propId]];
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
tmp[propId] = input[propId];
|
|
19
|
+
}
|
|
10
20
|
}
|
|
11
21
|
return tmp;
|
|
12
22
|
}, {});
|
|
13
23
|
};
|
|
14
24
|
const propertyFilterAgent = async ({ inputs, params }) => {
|
|
15
25
|
const [input] = inputs;
|
|
16
|
-
const { include, exclude } = params;
|
|
26
|
+
const { include, exclude, alter, inject } = params;
|
|
17
27
|
if (Array.isArray(input)) {
|
|
18
|
-
return input.map((item) => applyFilter(item, include, exclude));
|
|
28
|
+
return input.map((item, index) => applyFilter(item, index, inputs, include, exclude, alter, inject));
|
|
19
29
|
}
|
|
20
|
-
return applyFilter(input, include, exclude);
|
|
30
|
+
return applyFilter(input, 0, inputs, include, exclude, alter);
|
|
21
31
|
};
|
|
22
32
|
exports.propertyFilterAgent = propertyFilterAgent;
|
|
23
|
-
const
|
|
33
|
+
const testInputs = [
|
|
34
|
+
[
|
|
35
|
+
{ color: "red", model: "Model 3", type: "EV", maker: "Tesla", range: 300 },
|
|
36
|
+
{ color: "blue", model: "Model Y", type: "EV", maker: "Tesla", range: 400 },
|
|
37
|
+
],
|
|
38
|
+
"Tesla Motors",
|
|
39
|
+
];
|
|
24
40
|
const propertyFilterAgentInfo = {
|
|
25
41
|
name: "propertyFilterAgent",
|
|
26
42
|
agent: exports.propertyFilterAgent,
|
|
27
43
|
mock: exports.propertyFilterAgent,
|
|
28
44
|
samples: [
|
|
29
45
|
{
|
|
30
|
-
inputs,
|
|
46
|
+
inputs: [testInputs[0][0]],
|
|
31
47
|
params: { include: ["color", "model"] },
|
|
32
48
|
result: { color: "red", model: "Model 3" },
|
|
33
49
|
},
|
|
34
50
|
{
|
|
35
|
-
inputs,
|
|
51
|
+
inputs: testInputs,
|
|
52
|
+
params: { include: ["color", "model"] },
|
|
53
|
+
result: [
|
|
54
|
+
{ color: "red", model: "Model 3" },
|
|
55
|
+
{ color: "blue", model: "Model Y" },
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
inputs: testInputs,
|
|
36
60
|
params: { exclude: ["color", "model"] },
|
|
37
|
-
result:
|
|
61
|
+
result: [
|
|
62
|
+
{ type: "EV", maker: "Tesla", range: 300 },
|
|
63
|
+
{ type: "EV", maker: "Tesla", range: 400 },
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
inputs: testInputs,
|
|
68
|
+
params: { alter: { color: { red: "blue", blue: "red" } } },
|
|
69
|
+
result: [
|
|
70
|
+
{ color: "blue", model: "Model 3", type: "EV", maker: "Tesla", range: 300 },
|
|
71
|
+
{ color: "red", model: "Model Y", type: "EV", maker: "Tesla", range: 400 },
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
inputs: testInputs,
|
|
76
|
+
params: { inject: { maker: { from: 1 } } },
|
|
77
|
+
result: [
|
|
78
|
+
{ color: "red", model: "Model 3", type: "EV", maker: "Tesla Motors", range: 300 },
|
|
79
|
+
{ color: "blue", model: "Model Y", type: "EV", maker: "Tesla Motors", range: 400 },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
inputs: testInputs,
|
|
84
|
+
params: { inject: { maker: { index: 0, from: 1 } } },
|
|
85
|
+
result: [
|
|
86
|
+
{ color: "red", model: "Model 3", type: "EV", maker: "Tesla Motors", range: 300 },
|
|
87
|
+
{ color: "blue", model: "Model Y", type: "EV", maker: "Tesla", range: 400 },
|
|
88
|
+
],
|
|
38
89
|
},
|
|
39
90
|
],
|
|
40
91
|
description: "Filter properties based on property name either with 'include' or 'exclude'",
|
|
@@ -37,6 +37,19 @@ declare const totalAgentInfo: {
|
|
|
37
37
|
c: number;
|
|
38
38
|
d: number;
|
|
39
39
|
};
|
|
40
|
+
} | {
|
|
41
|
+
inputs: ({
|
|
42
|
+
a: number;
|
|
43
|
+
b?: undefined;
|
|
44
|
+
} | {
|
|
45
|
+
a: number;
|
|
46
|
+
b: number;
|
|
47
|
+
})[];
|
|
48
|
+
params: {};
|
|
49
|
+
result: {
|
|
50
|
+
a: number;
|
|
51
|
+
b: number;
|
|
52
|
+
};
|
|
40
53
|
})[];
|
|
41
54
|
description: string;
|
|
42
55
|
category: string[];
|
|
@@ -42,6 +42,35 @@ const totalAgentInfo = {
|
|
|
42
42
|
params: sample2Params,
|
|
43
43
|
result: sample2Result,
|
|
44
44
|
},
|
|
45
|
+
{
|
|
46
|
+
inputs: [{ a: 1 }],
|
|
47
|
+
params: {},
|
|
48
|
+
result: { a: 1 },
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
inputs: [{ a: 1 }, { a: 2 }],
|
|
52
|
+
params: {},
|
|
53
|
+
result: { a: 3 },
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
inputs: [{ a: 1 }, { a: 2 }, { a: 3 }],
|
|
57
|
+
params: {},
|
|
58
|
+
result: { a: 6 },
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
inputs: [
|
|
62
|
+
{ a: 1, b: 1 },
|
|
63
|
+
{ a: 2, b: 2 },
|
|
64
|
+
{ a: 3, b: 0 },
|
|
65
|
+
],
|
|
66
|
+
params: {},
|
|
67
|
+
result: { a: 6, b: 3 },
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
inputs: [{ a: 1 }, { a: 2, b: 2 }, { a: 3, b: 0 }],
|
|
71
|
+
params: {},
|
|
72
|
+
result: { a: 6, b: 2 },
|
|
73
|
+
},
|
|
45
74
|
],
|
|
46
75
|
description: "Returns the sum of input values",
|
|
47
76
|
category: ["data"],
|
|
@@ -4,7 +4,7 @@ exports.mapAgent = void 0;
|
|
|
4
4
|
const graphai_1 = require("../../graphai");
|
|
5
5
|
const utils_1 = require("../../utils/utils");
|
|
6
6
|
const nested_agent_1 = require("./nested_agent");
|
|
7
|
-
const mapAgent = async ({ params, inputs, agents, log, taskManager, graphData }) => {
|
|
7
|
+
const mapAgent = async ({ params, inputs, agents, log, taskManager, graphData, agentFilters }) => {
|
|
8
8
|
if (taskManager) {
|
|
9
9
|
const status = taskManager.getStatus();
|
|
10
10
|
(0, utils_1.assert)(status.concurrency > status.running, `mapAgent: Concurrency is too low: ${status.concurrency}`);
|
|
@@ -25,7 +25,7 @@ const mapAgent = async ({ params, inputs, agents, log, taskManager, graphData })
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
const graphs = input.map((data) => {
|
|
28
|
-
const graphAI = new graphai_1.GraphAI(nestedGraphData, agents || {}, { taskManager });
|
|
28
|
+
const graphAI = new graphai_1.GraphAI(nestedGraphData, agents || {}, { taskManager, agentFilters: agentFilters || [] });
|
|
29
29
|
// Only the first input will be mapped
|
|
30
30
|
injectionTo.forEach((injectToNodeId, index) => {
|
|
31
31
|
graphAI.injectValue(injectToNodeId, index === 0 ? data : inputs[index], "__mapAgent_inputs__");
|
|
@@ -21,27 +21,24 @@ const getNestedGraphData = (graphData, inputs) => {
|
|
|
21
21
|
return graphData;
|
|
22
22
|
};
|
|
23
23
|
exports.getNestedGraphData = getNestedGraphData;
|
|
24
|
-
const nestedAgent = async ({ params, inputs, agents, log, taskManager, graphData }) => {
|
|
24
|
+
const nestedAgent = async ({ params, inputs, agents, log, taskManager, graphData, agentFilters }) => {
|
|
25
25
|
if (taskManager) {
|
|
26
26
|
const status = taskManager.getStatus(false);
|
|
27
27
|
(0, utils_1.assert)(status.concurrency > status.running, `nestedAgent: Concurrency is too low: ${status.concurrency}`);
|
|
28
28
|
}
|
|
29
29
|
const nestedGraphData = (0, exports.getNestedGraphData)(graphData, inputs);
|
|
30
|
-
const injectionTo = params.injectionTo ??
|
|
31
|
-
|
|
32
|
-
return `$${index}`;
|
|
33
|
-
});
|
|
34
|
-
injectionTo.forEach((nodeId) => {
|
|
30
|
+
const injectionTo = params.injectionTo ?? inputs.map((__input, index) => `$${index}`);
|
|
31
|
+
injectionTo.forEach((nodeId, index) => {
|
|
35
32
|
if (nestedGraphData.nodes[nodeId] === undefined) {
|
|
36
33
|
// If the input node does not exist, automatically create a static node
|
|
37
|
-
nestedGraphData.nodes[nodeId] = { value:
|
|
34
|
+
nestedGraphData.nodes[nodeId] = { value: inputs[index] };
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// Otherwise, inject the proper data here (instead of calling injectTo method later)
|
|
38
|
+
nestedGraphData.nodes[nodeId]["value"] = inputs[index];
|
|
38
39
|
}
|
|
39
40
|
});
|
|
40
|
-
const graphAI = new graphai_1.GraphAI(nestedGraphData, agents || {}, { taskManager });
|
|
41
|
-
// Inject inputs to specified source nodes
|
|
42
|
-
injectionTo.forEach((injectToNodeId, index) => {
|
|
43
|
-
graphAI.injectValue(injectToNodeId, inputs[index]);
|
|
44
|
-
});
|
|
41
|
+
const graphAI = new graphai_1.GraphAI(nestedGraphData, agents || {}, { taskManager, agentFilters });
|
|
45
42
|
const results = await graphAI.run(false);
|
|
46
43
|
log?.push(...graphAI.transactionLogs());
|
|
47
44
|
return results;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AgentFunction } from "../../graphai";
|
|
2
|
+
import { Groq } from "groq-sdk";
|
|
3
|
+
export declare const groqStreamAgent: AgentFunction<{
|
|
4
|
+
model: string;
|
|
5
|
+
query?: string;
|
|
6
|
+
system?: string;
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
tools?: Groq.Chat.CompletionCreateParams.Tool[];
|
|
9
|
+
temperature?: number;
|
|
10
|
+
max_tokens?: number;
|
|
11
|
+
tool_choice?: Groq.Chat.CompletionCreateParams.ToolChoice;
|
|
12
|
+
}, any, string | Array<Groq.Chat.CompletionCreateParams.Message>>;
|
|
13
|
+
declare const groqStreamAgentInfo: {
|
|
14
|
+
name: string;
|
|
15
|
+
agent: AgentFunction<{
|
|
16
|
+
model: string;
|
|
17
|
+
query?: string | undefined;
|
|
18
|
+
system?: string | undefined;
|
|
19
|
+
verbose?: boolean | undefined;
|
|
20
|
+
tools?: Groq.Chat.Completions.CompletionCreateParams.Tool[] | undefined;
|
|
21
|
+
temperature?: number | undefined;
|
|
22
|
+
max_tokens?: number | undefined;
|
|
23
|
+
tool_choice?: Groq.Chat.Completions.CompletionCreateParams.ToolChoice | undefined;
|
|
24
|
+
}, any, string | Groq.Chat.Completions.CompletionCreateParams.Message[]>;
|
|
25
|
+
mock: AgentFunction<{
|
|
26
|
+
model: string;
|
|
27
|
+
query?: string | undefined;
|
|
28
|
+
system?: string | undefined;
|
|
29
|
+
verbose?: boolean | undefined;
|
|
30
|
+
tools?: Groq.Chat.Completions.CompletionCreateParams.Tool[] | undefined;
|
|
31
|
+
temperature?: number | undefined;
|
|
32
|
+
max_tokens?: number | undefined;
|
|
33
|
+
tool_choice?: Groq.Chat.Completions.CompletionCreateParams.ToolChoice | undefined;
|
|
34
|
+
}, any, string | Groq.Chat.Completions.CompletionCreateParams.Message[]>;
|
|
35
|
+
samples: never[];
|
|
36
|
+
description: string;
|
|
37
|
+
category: string[];
|
|
38
|
+
author: string;
|
|
39
|
+
repository: string;
|
|
40
|
+
license: string;
|
|
41
|
+
};
|
|
42
|
+
export default groqStreamAgentInfo;
|