graphai 0.2.7 → 0.3.0
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 +130 -69
- package/lib/experimental_agents/data_agents/index.d.ts +0 -1
- package/lib/experimental_agents/data_agents/index.js +1 -3
- package/lib/experimental_agents/graph_agents/map_agent.js +1 -1
- package/lib/experimental_agents/graph_agents/nested_agent.js +7 -16
- package/lib/experimental_agents/index.d.ts +2 -8
- package/lib/experimental_agents/index.js +5 -8
- package/lib/experimental_agents/llm_agents/groq_agent.d.ts +22 -6
- package/lib/experimental_agents/llm_agents/groq_agent.js +51 -17
- package/lib/experimental_agents/llm_agents/packages.d.ts +2 -2
- package/lib/experimental_agents/llm_agents/packages.js +2 -2
- package/lib/experimental_agents/packages.d.ts +1 -0
- package/lib/experimental_agents/packages.js +1 -0
- package/lib/experimental_agents/service_agents/fetch_agent.d.ts +62 -0
- package/lib/experimental_agents/service_agents/fetch_agent.js +95 -0
- package/lib/experimental_agents/service_agents/index.d.ts +1 -1
- package/lib/experimental_agents/service_agents/index.js +3 -3
- package/lib/experimental_agents/service_agents/packages.d.ts +2 -0
- package/lib/experimental_agents/service_agents/packages.js +8 -0
- package/lib/experimental_agents/test_agents/echo_agent.js +4 -1
- package/lib/experimental_agents/vanilla.d.ts +8 -0
- package/lib/experimental_agents/vanilla.js +26 -0
- package/lib/graphai.d.ts +1 -1
- package/lib/graphai.js +6 -5
- package/lib/node.d.ts +2 -0
- package/lib/node.js +35 -5
- package/lib/transaction_log.d.ts +1 -0
- package/lib/transaction_log.js +5 -0
- package/lib/type.d.ts +8 -4
- package/lib/type.js +1 -0
- package/lib/utils/test_utils.d.ts +3 -1
- package/lib/utils/test_utils.js +19 -1
- package/lib/utils/utils.d.ts +1 -1
- package/lib/utils/utils.js +19 -1
- package/lib/validators/common.js +1 -1
- package/lib/validators/relation_validator.js +2 -2
- package/lib/vanilla_agents.d.ts +1 -0
- package/lib/vanilla_agents.js +17 -0
- package/package.json +1 -1
- package/lib/experimental_agents/service_agents/rss_agent.d.ts +0 -13
- package/lib/experimental_agents/service_agents/rss_agent.js +0 -29
package/README.md
CHANGED
|
@@ -21,42 +21,42 @@ nodes:
|
|
|
21
21
|
name: Sam Bankman-Fried
|
|
22
22
|
query: describe the final sentence by the court for Sam Bank-Fried
|
|
23
23
|
wikipedia: // Retrieve data from Wikipedia
|
|
24
|
-
|
|
25
|
-
inputs: [source.name]
|
|
24
|
+
agent: wikipediaAgent
|
|
25
|
+
inputs: [:source.name]
|
|
26
26
|
chunks: // Break the text from Wikipedia into chunks (2048 character each with 512 overlap)
|
|
27
|
-
|
|
28
|
-
inputs: [wikipedia]
|
|
27
|
+
agent: stringSplitterAgent
|
|
28
|
+
inputs: [:wikipedia]
|
|
29
29
|
chunkEmbeddings: // Get embedding vector of each chunk
|
|
30
|
-
|
|
31
|
-
inputs: [chunks]
|
|
30
|
+
agent: stringEmbeddingsAgent
|
|
31
|
+
inputs: [:chunks]
|
|
32
32
|
topicEmbedding: // Get embedding vector of the question
|
|
33
|
-
|
|
34
|
-
inputs: [source.query]
|
|
33
|
+
agent: stringEmbeddingsAgent
|
|
34
|
+
inputs: [:source.query]
|
|
35
35
|
similarities: // Calculate the cosine similarity of each chunk
|
|
36
|
-
|
|
37
|
-
inputs: [chunkEmbeddings, topicEmbedding]
|
|
36
|
+
agent: dotProductAgent
|
|
37
|
+
inputs: [:chunkEmbeddings, :topicEmbedding]
|
|
38
38
|
sortedChunks: // Sort chunks based on their similarities
|
|
39
|
-
|
|
40
|
-
inputs: [chunks, similarities]
|
|
39
|
+
agent: sortByValuesAgent
|
|
40
|
+
inputs: [:chunks, :similarities]
|
|
41
41
|
referenceText: // Concatenate chunks up to the token limit (5000)
|
|
42
|
-
|
|
43
|
-
inputs: [sortedChunks]
|
|
42
|
+
agent: tokenBoundStringsAgent
|
|
43
|
+
inputs: [:sortedChunks]
|
|
44
44
|
params:
|
|
45
45
|
limit: 5000
|
|
46
46
|
prompt: // Generate a prompt with that reference text
|
|
47
|
-
|
|
48
|
-
inputs: [source, referenceText]
|
|
47
|
+
agent: stringTemplateAgent
|
|
48
|
+
inputs: [:source, :referenceText]
|
|
49
49
|
params:
|
|
50
50
|
template: |-
|
|
51
51
|
Using the following document, ${0}
|
|
52
52
|
${1}
|
|
53
53
|
query: // retrieves the answer from GPT3.5
|
|
54
|
-
|
|
54
|
+
agent: slashGPTAgent
|
|
55
55
|
params:
|
|
56
56
|
manifest:
|
|
57
57
|
model: gpt-3.5-turbo
|
|
58
58
|
isResult: true // indicating this is the final result
|
|
59
|
-
inputs: [prompt]
|
|
59
|
+
inputs: [:prompt]
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
```mermaid
|
|
@@ -64,8 +64,8 @@ flowchart TD
|
|
|
64
64
|
source -- name --> wikipedia(wikipedia)
|
|
65
65
|
source -- query --> topicEmbedding(topicEmbedding)
|
|
66
66
|
wikipedia --> chunks(chunks)
|
|
67
|
-
chunks -->
|
|
68
|
-
|
|
67
|
+
chunks --> chunkEmbeddings(chunkEmbeddings)
|
|
68
|
+
chunkEmbeddings --> similarities(similarities)
|
|
69
69
|
topicEmbedding --> similarities
|
|
70
70
|
similarities --> sortedChunks(sortedChunks)
|
|
71
71
|
sortedChunks --> resourceText(resourceText)
|
|
@@ -74,7 +74,7 @@ flowchart TD
|
|
|
74
74
|
prompt --> query(query)
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
Notice that the conversion of the
|
|
77
|
+
Notice that the conversion of the query text into an embedding vector and text chunks into an array of embedding vectors can be done concurrently because there is no dependency between them. GraphAI will automatically recognize it and execute them concurrently. This kind of *concurrent programing* is very difficult in traditional programming style, and GraphAI's *data flow programming* style is much better alternative.
|
|
78
78
|
|
|
79
79
|
## Quick Install
|
|
80
80
|
|
|
@@ -94,52 +94,83 @@ A Data Flow Graph (DFG) is a JavaScript object, which defines the flow of data.
|
|
|
94
94
|
|
|
95
95
|
A DFG consists of a collection of [nodes](#node), 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 (such as params, inputs, and value) that dictate the node's behavior and its relationship with other nodes. There are two types of nodes, [computed nodes](#computed-node) and [static nodes](#static-node), which are described below.
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
### Data Source
|
|
98
|
+
|
|
99
|
+
Connections between nodes will be established by references from one node to another, using either its "inputs", "update", "if" or "while" property. The values of those properties are *data sources*. A *data souce* is specified by either the ":" + nodeId (e.g., ":node1"), or ":" + nodeId + propertyId (e.g., ":node1.item"), index (e.g., ":node1.$0", ":node2.$last") or combinations (e.g., ":node1.messages.$0.content").
|
|
98
100
|
|
|
99
101
|
### DFG Structure
|
|
100
102
|
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
103
|
+
- *version*: GraphAI version, *required*. The latest version is 0.3.
|
|
104
|
+
- *nodes*: A list of node. Required.
|
|
105
|
+
- *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.
|
|
106
|
+
- *loop*: An optional property, which specifies if the graph needs to be executed multiple times (iterations). See the [Loop section below](#loop) for details.
|
|
104
107
|
|
|
105
108
|
## Agent
|
|
106
109
|
|
|
107
|
-
An *agent* is an abstract object which takes some inputs and generates an output asynchronously. It could be an LLM (such as GPT-4), a media generator, a database, or a REST API over HTTP. A node associated with an agent (specified by '
|
|
110
|
+
An *agent* is an abstract object which takes some inputs and generates an output asynchronously. It could be an LLM call (such as GPT-4), a media generator, a database access, or a REST API over HTTP. A node associated with an agent (specified by the *agent*'* property) is called [computed node](#computed-node), which takes a set of *inputs* from *data sources*, asks the *agent function* to process it, and makes the returned value available to other nodes.
|
|
108
111
|
|
|
109
112
|
### Agent function
|
|
110
113
|
|
|
111
|
-
An agent function is a TypeScript function, which implements a particular *agent*. An *agent function* receives
|
|
114
|
+
An *agent function* is a TypeScript function, which implements a particular *agent*, performing some computations for the associated *computed node*. An *agent function* receives a *context* (type AgentFunctionContext), which has following properties:
|
|
115
|
+
|
|
116
|
+
- *params*: agent specific parameters specified in the DFG (specified by the "params" property of the node)
|
|
117
|
+
- *inputs*: a set of inputs came from other nodes (specified by "inputs" property of the node).
|
|
118
|
+
- *debugInfo*: a set of information for debugging purposes.
|
|
119
|
+
|
|
120
|
+
There are additional optional parameters for developers of nested agents and agent filters.
|
|
121
|
+
|
|
122
|
+
- *graphData*: an optional GraphData (for nested agents)
|
|
123
|
+
- *agents*: AgentFunctionDictonary (for nested agents)
|
|
124
|
+
- *taskManager*: TaskManager (for nested agents)
|
|
125
|
+
- *log*: TransactionLog[] (for nested agents)
|
|
126
|
+
- *filterParams*: agent filter parameters (for agent filters)
|
|
127
|
+
|
|
128
|
+
### Inline Agent Function
|
|
112
129
|
|
|
113
|
-
|
|
114
|
-
|
|
130
|
+
An *inline agent function* is a simplified version of *agent function*, which is embedded in the graph (available only when the graph was described in TypeScript). An *inline agent function* receives only the *inputs* paramter as a variable length arguments.
|
|
131
|
+
|
|
132
|
+
Here is an examnple (from [weather chat](https://github.com/receptron/graphai/blob/main/samples/sample_weather.ts)):
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
messagesWithUserInput: {
|
|
136
|
+
// Appends the user's input to the messages.
|
|
137
|
+
agent: (messages: Array<any>, content: string) => [...messages, { role: "user", content }],
|
|
138
|
+
inputs: [":messages", ":userInput"],
|
|
139
|
+
if: "checkInput",
|
|
140
|
+
},
|
|
141
|
+
```
|
|
115
142
|
|
|
116
143
|
## Node
|
|
117
144
|
|
|
118
|
-
There are two types of Node, *computed nodes* and *static nodes*.
|
|
145
|
+
There are two types of Node, *computed nodes* and *static nodes*.
|
|
146
|
+
|
|
147
|
+
A *computed node* is associated with an *agent function*, which receives some inputs, performs some computations asynchronously, and returns the result (output).
|
|
148
|
+
|
|
149
|
+
A *static node* is a placeholder of a value (just like a variable in programming languages), which is initially specified by its *value* property, and can be updated by an external program (before the execution of the graph), or updated using the *update* property at the end of each iteration of a [loop](#loop) operation.
|
|
119
150
|
|
|
120
151
|
### Computed Node
|
|
121
152
|
|
|
122
|
-
A *computed node*
|
|
153
|
+
A *computed node* has following properties.
|
|
123
154
|
|
|
124
|
-
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
-
-
|
|
131
|
-
-
|
|
155
|
+
- *agent*: An **required** property, which specifies the id of the *agent function*, or an *inline agent function* (NOTE: this is not possible in JSON or YAML).
|
|
156
|
+
- *params*: An optional agent-specific property to control the behavior of the associated agent function. The top level property may reference a *data source*.
|
|
157
|
+
- *inputs*: An optional list of *data sources* that the current node receives the data from. This establishes a data 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.
|
|
158
|
+
- *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.
|
|
159
|
+
- *retry*: An optional number, which specifies the maximum number of retries to be made. If the last attempt fails, the error will be recorded.
|
|
160
|
+
- *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. The returned value received after the time out will be discarded.
|
|
161
|
+
- *isResult*: An optional boolean value, which indicates that the return value of this node, should be included as a property of the return value from the run() method of the GraphUI instance.
|
|
162
|
+
- *priority*: An optional number, which specifies the priority of the execution of the associated agent (the task). Default is 0, which means "neutral". Negative numbers are allowed as well.
|
|
132
163
|
|
|
133
164
|
### Static Node
|
|
134
165
|
|
|
135
|
-
A *static* node
|
|
166
|
+
A *static* node has following properties.
|
|
136
167
|
|
|
137
|
-
-
|
|
138
|
-
-
|
|
168
|
+
- *value*: An **required** property, which specifies the initial value of this static node (equivalent to calling the injectValue method from outside).
|
|
169
|
+
- *update*: An optional property, which specifies the *data source* for a [loop](#loop) operation. After each iteration, the value of this node will be updated with the data from the specified *data source*.
|
|
139
170
|
|
|
140
171
|
## Flow Control
|
|
141
172
|
|
|
142
|
-
Since the data-flow graph must be asyclic by design, we added a few
|
|
173
|
+
Since the data-flow graph must be asyclic by design, we added a few mechanisms to control data flows, [nesting](#nesting), [loop](#loop), [mapping](#mapping) and [conditional flow](#conditional-flow).
|
|
143
174
|
|
|
144
175
|
### Nested Graph
|
|
145
176
|
|
|
@@ -152,24 +183,24 @@ nodes:
|
|
|
152
183
|
question:
|
|
153
184
|
value: "Find out which materials we need to purchase this week for Joe Smith's residential house project."
|
|
154
185
|
projectId: // identifies the projectId from the question
|
|
155
|
-
|
|
156
|
-
inputs: ["source"] // == "sourceNode.query"
|
|
186
|
+
agent: "identifierAgent"
|
|
187
|
+
inputs: [":source"] // == "sourceNode.query"
|
|
157
188
|
database:
|
|
158
|
-
|
|
159
|
-
inputs: ["question", "projectId"]
|
|
189
|
+
agent: "nestedAgent"
|
|
190
|
+
inputs: [":question", ":projectId"]
|
|
160
191
|
graph:
|
|
161
192
|
nodes:
|
|
162
193
|
schema: // retrieves the database schema for the apecified projectId
|
|
163
|
-
|
|
164
|
-
inputs: ["
|
|
194
|
+
agent: "schemaAgent"
|
|
195
|
+
inputs: [":$1"]
|
|
165
196
|
... // issue query to the database and build an appropriate prompt with it.
|
|
166
197
|
query: // send the generated prompt to the LLM
|
|
167
|
-
|
|
168
|
-
inputs: ["prompt"]
|
|
198
|
+
agent: "llama3Agent"
|
|
199
|
+
inputs: [":prompt"]
|
|
169
200
|
isResult: true
|
|
170
201
|
response: // Deliver the answer
|
|
171
|
-
|
|
172
|
-
inputs: [database.query.$last.content]
|
|
202
|
+
agent: "deliveryAgent"
|
|
203
|
+
inputs: [:database.query.$last.content]
|
|
173
204
|
```
|
|
174
205
|
|
|
175
206
|
The databaseQuery node (which is associated "nestedAgent") takes the data from "question" node abd "projectId" node, and make them available to inner nodes (nodes of the child graph) via phantom node, "$0" and "$1". After the completion of the child graph, the data from "query" node (which has "isResult" property) becomes available as a property of the output of "database" node.
|
|
@@ -181,7 +212,7 @@ flowchart LR
|
|
|
181
212
|
question --> projectId(projectId)
|
|
182
213
|
question --> database
|
|
183
214
|
projectId --> database
|
|
184
|
-
database[[database]] -- query --> response(
|
|
215
|
+
database[[database]] -- query --> response(response)
|
|
185
216
|
```
|
|
186
217
|
|
|
187
218
|
Here is the diagram of the child graph. Notice that two phantom nodes are automatically created to allow inner nodes to access input data from the parent graph.
|
|
@@ -198,35 +229,38 @@ This mechanism does not only allows devleoper to reuse code, but also makes it p
|
|
|
198
229
|
|
|
199
230
|
### Loop
|
|
200
231
|
|
|
201
|
-
The loop is an
|
|
232
|
+
The loop is an optional property of a graph, which has two optional properties.
|
|
202
233
|
|
|
203
|
-
|
|
234
|
+
- *count*: Specifies the number of times the graph needs to be executed.
|
|
235
|
+
- *while*: Specifies the *data source* to check after the each iteration. It continues if the data from that *data source* is *true*. Unlike JavaScript, an empty array will be treated as *false*.
|
|
236
|
+
|
|
237
|
+
Here is an example, which performs an LLM query for each person in the list and create the list of answers. The "people" node (static), is initialized with an array of names, and the "retriever" node (computed) retrieves one name at a time, and sends it to the "query" node (computed) to perform an LLM query. The "reducer" append it the array retrieved form the "result" node (static node, which is initialized as an empty array).
|
|
204
238
|
|
|
205
239
|
The "update" property of two static nodes ("people" and "result"), updates those properties based on the results from the previous itelation. This loop continues until the value of "people" node become an empty array.
|
|
206
240
|
|
|
207
241
|
```
|
|
208
242
|
loop:
|
|
209
|
-
while: people
|
|
243
|
+
while: :people
|
|
210
244
|
nodes:
|
|
211
245
|
people:
|
|
212
246
|
value: [Steve Jobs, Elon Musk, Nikola Tesla]
|
|
213
|
-
update: retriever.array
|
|
247
|
+
update: :retriever.array
|
|
214
248
|
result:
|
|
215
249
|
value: []
|
|
216
|
-
update: reducer
|
|
250
|
+
update: :reducer
|
|
217
251
|
isResult: true
|
|
218
252
|
retriever:
|
|
219
|
-
|
|
253
|
+
agent: shift
|
|
220
254
|
inputs: [people]
|
|
221
255
|
query:
|
|
222
|
-
|
|
256
|
+
agent: slashgpt
|
|
223
257
|
params:
|
|
224
258
|
manifest:
|
|
225
259
|
prompt: Describe about the person in less than 100 words
|
|
226
|
-
inputs: [retriever.item]
|
|
260
|
+
inputs: [:retriever.item]
|
|
227
261
|
reducer:
|
|
228
|
-
|
|
229
|
-
inputs: [result, query.content]
|
|
262
|
+
agent: push
|
|
263
|
+
inputs: [:result, :query.content]
|
|
230
264
|
```
|
|
231
265
|
|
|
232
266
|
```mermaid
|
|
@@ -258,16 +292,16 @@ nodes:
|
|
|
258
292
|
people:
|
|
259
293
|
value: [Steve Jobs, Elon Musk, Nikola Tesla]
|
|
260
294
|
retriever:
|
|
261
|
-
|
|
262
|
-
inputs: ["people"]
|
|
295
|
+
agent: "mapAgent"
|
|
296
|
+
inputs: [":people"]
|
|
263
297
|
graph:
|
|
264
298
|
nodes:
|
|
265
299
|
query:
|
|
266
|
-
|
|
300
|
+
agent: slashgpt
|
|
267
301
|
params:
|
|
268
302
|
manifest:
|
|
269
303
|
prompt: Describe about the person in less than 100 words
|
|
270
|
-
inputs: ["
|
|
304
|
+
inputs: [":$0"]
|
|
271
305
|
```
|
|
272
306
|
|
|
273
307
|
Here is the conceptual representation of this operation.
|
|
@@ -283,7 +317,34 @@ flowchart LR
|
|
|
283
317
|
```
|
|
284
318
|
### Conditional Flow
|
|
285
319
|
|
|
286
|
-
|
|
320
|
+
When a node has *if* property (which specifies the data source), the data flows to this node only if the value from the data source has some value.
|
|
321
|
+
|
|
322
|
+
A sample code, [weather chat](https://github.com/receptron/graphai/blob/main/samples/sample_weather.ts) uses the following *if* property to execute a block of graph, if the LLM asks to use a tool (i.e., function call).
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
tool_calls: {
|
|
326
|
+
// This node is activated if the LLM requests a tool call.
|
|
327
|
+
agent: "nestedAgent",
|
|
328
|
+
inputs: [":groq.choices.$0.message.tool_calls", ":messagesWithFirstRes"],
|
|
329
|
+
if: ":groq.choices.$0.message.tool_calls",
|
|
330
|
+
graph: {
|
|
331
|
+
// This graph is nested only for the readability.
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Even though it is not required, we strongly recommand to use it with a nested graph for the readability.
|
|
335
|
+
|
|
336
|
+
The *anyInput* property (boolean) allows the developer to "merge" multiple data flow paths into one. When the value of this property is true, the agent function associated with this node will be executed when the data from one of data sources became available.
|
|
337
|
+
|
|
338
|
+
The [weather chat](https://github.com/receptron/graphai/blob/main/samples/sample_weather.ts) sample application uses this property to continue the chat iteration either a tool was requested by LLM or not.
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
reducer: {
|
|
342
|
+
// Receives messages from either case.
|
|
343
|
+
agent: "copyAgent",
|
|
344
|
+
anyInput: true,
|
|
345
|
+
inputs: [":no_tool_calls", ":tool_calls.messagesWithSecondRes"],
|
|
346
|
+
},
|
|
347
|
+
```
|
|
287
348
|
|
|
288
349
|
## Concurrency
|
|
289
350
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { totalAgent } from "../../experimental_agents/data_agents/total_agent";
|
|
2
|
-
export { dataObjectMergeTemplateAgent } from "../../experimental_agents/data_agents/data_object_merge_template_agent";
|
|
3
2
|
export { dataSumTemplateAgent } from "../../experimental_agents/data_agents/data_sum_template_agent";
|
|
4
3
|
export { propertyFilterAgent } from "../../experimental_agents/data_agents/property_filter_agent";
|
|
5
4
|
export { copyAgent } from "../../experimental_agents/data_agents/copy_agent";
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.copyAgent = exports.propertyFilterAgent = exports.dataSumTemplateAgent = exports.
|
|
3
|
+
exports.copyAgent = exports.propertyFilterAgent = exports.dataSumTemplateAgent = exports.totalAgent = void 0;
|
|
4
4
|
var total_agent_1 = require("../../experimental_agents/data_agents/total_agent");
|
|
5
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
6
|
var data_sum_template_agent_1 = require("../../experimental_agents/data_agents/data_sum_template_agent");
|
|
9
7
|
Object.defineProperty(exports, "dataSumTemplateAgent", { enumerable: true, get: function () { return data_sum_template_agent_1.dataSumTemplateAgent; } });
|
|
10
8
|
var property_filter_agent_1 = require("../../experimental_agents/data_agents/property_filter_agent");
|
|
@@ -37,7 +37,7 @@ const mapAgent = async ({ params, inputs, agents, log, taskManager, graphData })
|
|
|
37
37
|
});
|
|
38
38
|
const results = await Promise.all(runs);
|
|
39
39
|
const nodeIds = Object.keys(results[0]);
|
|
40
|
-
|
|
40
|
+
// assert(nodeIds.length > 0, "mapAgent: no return values (missing isResult)");
|
|
41
41
|
const compositeResult = nodeIds.reduce((tmp, nodeId) => {
|
|
42
42
|
tmp[nodeId] = results.map((result) => {
|
|
43
43
|
return result[nodeId];
|
|
@@ -38,22 +38,13 @@ const nestedAgent = async ({ params, inputs, agents, log, taskManager, graphData
|
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
const graphAI = new graphai_1.GraphAI(nestedGraphData, agents || {}, { taskManager });
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return results;
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
log?.push(...graphAI.transactionLogs());
|
|
52
|
-
if (error instanceof Error) {
|
|
53
|
-
console.log("Error:", error.message);
|
|
54
|
-
}
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
41
|
+
// Inject inputs to specified source nodes
|
|
42
|
+
injectionTo.forEach((injectToNodeId, index) => {
|
|
43
|
+
graphAI.injectValue(injectToNodeId, inputs[index]);
|
|
44
|
+
});
|
|
45
|
+
const results = await graphAI.run(false);
|
|
46
|
+
log?.push(...graphAI.transactionLogs());
|
|
47
|
+
return results;
|
|
57
48
|
};
|
|
58
49
|
exports.nestedAgent = nestedAgent;
|
|
59
50
|
const nestedAgentInfo = {
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./vanilla";
|
|
2
|
+
export { dataObjectMergeTemplateAgent } from "../experimental_agents/data_agents/data_object_merge_template_agent";
|
|
2
3
|
export * from "./sleeper_agents";
|
|
3
|
-
export * from "./data_agents";
|
|
4
|
-
export * from "./array_agents";
|
|
5
|
-
export * from "./matrix_agents";
|
|
6
|
-
export * from "./test_agents";
|
|
7
|
-
export * from "./graph_agents";
|
|
8
4
|
export * from "./llm_agents";
|
|
9
5
|
export * from "./service_agents";
|
|
10
|
-
export * from "./embedding_agent";
|
|
11
6
|
export * from "./token_agent";
|
|
12
|
-
export * from "./function_agent";
|
|
@@ -14,15 +14,12 @@ 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
|
-
|
|
17
|
+
exports.dataObjectMergeTemplateAgent = void 0;
|
|
18
|
+
__exportStar(require("./vanilla"), exports);
|
|
19
|
+
// Agents that use npm modules will be added here.
|
|
20
|
+
var data_object_merge_template_agent_1 = require("../experimental_agents/data_agents/data_object_merge_template_agent");
|
|
21
|
+
Object.defineProperty(exports, "dataObjectMergeTemplateAgent", { enumerable: true, get: function () { return data_object_merge_template_agent_1.dataObjectMergeTemplateAgent; } });
|
|
18
22
|
__exportStar(require("./sleeper_agents"), exports);
|
|
19
|
-
__exportStar(require("./data_agents"), exports);
|
|
20
|
-
__exportStar(require("./array_agents"), exports);
|
|
21
|
-
__exportStar(require("./matrix_agents"), exports);
|
|
22
|
-
__exportStar(require("./test_agents"), exports);
|
|
23
|
-
__exportStar(require("./graph_agents"), exports);
|
|
24
23
|
__exportStar(require("./llm_agents"), exports);
|
|
25
24
|
__exportStar(require("./service_agents"), exports);
|
|
26
|
-
__exportStar(require("./embedding_agent"), exports);
|
|
27
25
|
__exportStar(require("./token_agent"), exports);
|
|
28
|
-
__exportStar(require("./function_agent"), exports);
|
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
import { AgentFunction } from "../../graphai";
|
|
2
|
-
|
|
2
|
+
import { Groq } from "groq-sdk";
|
|
3
|
+
export declare const groqAgent: AgentFunction<{
|
|
3
4
|
model: string;
|
|
4
5
|
query?: string;
|
|
5
6
|
system?: string;
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
tools?: Record<string, Groq.Chat.CompletionCreateParams.Tool>;
|
|
9
|
+
temperature?: number;
|
|
10
|
+
max_tokens?: number;
|
|
11
|
+
tool_choice?: string | Record<string, Groq.Chat.CompletionCreateParams.ToolChoice>;
|
|
12
|
+
}, Groq.Chat.ChatCompletion, string | Array<Groq.Chat.CompletionCreateParams.Message>>;
|
|
13
|
+
declare const groqAgentInfo: {
|
|
8
14
|
name: string;
|
|
9
15
|
agent: AgentFunction<{
|
|
10
16
|
model: string;
|
|
11
17
|
query?: string | undefined;
|
|
12
18
|
system?: string | undefined;
|
|
13
|
-
|
|
19
|
+
verbose?: boolean | undefined;
|
|
20
|
+
tools?: Record<string, Groq.Chat.Completions.CompletionCreateParams.Tool> | undefined;
|
|
21
|
+
temperature?: number | undefined;
|
|
22
|
+
max_tokens?: number | undefined;
|
|
23
|
+
tool_choice?: string | Record<string, Groq.Chat.Completions.CompletionCreateParams.ToolChoice> | undefined;
|
|
24
|
+
}, Groq.Chat.Completions.ChatCompletion, string | Groq.Chat.Completions.CompletionCreateParams.Message[]>;
|
|
14
25
|
mock: AgentFunction<{
|
|
15
26
|
model: string;
|
|
16
27
|
query?: string | undefined;
|
|
17
28
|
system?: string | undefined;
|
|
18
|
-
|
|
29
|
+
verbose?: boolean | undefined;
|
|
30
|
+
tools?: Record<string, Groq.Chat.Completions.CompletionCreateParams.Tool> | undefined;
|
|
31
|
+
temperature?: number | undefined;
|
|
32
|
+
max_tokens?: number | undefined;
|
|
33
|
+
tool_choice?: string | Record<string, Groq.Chat.Completions.CompletionCreateParams.ToolChoice> | undefined;
|
|
34
|
+
}, Groq.Chat.Completions.ChatCompletion, string | Groq.Chat.Completions.CompletionCreateParams.Message[]>;
|
|
19
35
|
samples: never[];
|
|
20
36
|
description: string;
|
|
21
37
|
category: string[];
|
|
@@ -23,4 +39,4 @@ declare const gloqAgentInfo: {
|
|
|
23
39
|
repository: string;
|
|
24
40
|
license: string;
|
|
25
41
|
};
|
|
26
|
-
export default
|
|
42
|
+
export default groqAgentInfo;
|
|
@@ -1,29 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.groqAgent = void 0;
|
|
4
4
|
const groq_sdk_1 = require("groq-sdk");
|
|
5
5
|
const utils_1 = require("../../utils/utils");
|
|
6
6
|
const groq = process.env.GROQ_API_KEY ? new groq_sdk_1.Groq({ apiKey: process.env.GROQ_API_KEY }) : undefined;
|
|
7
|
-
|
|
7
|
+
//
|
|
8
|
+
// This agent takes two optional inputs, and following parameters.
|
|
9
|
+
// inputs:
|
|
10
|
+
// - [0]: query string (typically from the user), optional
|
|
11
|
+
// - [1]: array of messages from previous conversation, optional
|
|
12
|
+
//
|
|
13
|
+
// params:
|
|
14
|
+
// - model: LLM model (Llama3-8b-8192, Llama3-70b-8192, Mixtral-8x7b-32768), required.
|
|
15
|
+
// - query: Additional query string from the app to prepend the query from the user, optional.
|
|
16
|
+
// - system: System prompt (ignored if inputs[1] is specified), optional
|
|
17
|
+
// - tools: Function definitions, optional
|
|
18
|
+
// - tool_choice: Tool choice parameter, optional (default = "auto")
|
|
19
|
+
// - temperature: Controls randomness of responses, optional (default = 0.7)
|
|
20
|
+
// - max_tokens: The maximum number of tokens that the model can process in a single response, optional.
|
|
21
|
+
// - verbose: dumps the message array to the debug console, before sending it the LLM.
|
|
22
|
+
//
|
|
23
|
+
// https://console.groq.com/docs/quickstart
|
|
24
|
+
//
|
|
25
|
+
const groqAgent = async ({ params, inputs }) => {
|
|
8
26
|
(0, utils_1.assert)(groq !== undefined, "The GROQ_API_KEY environment variable is missing.");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
messages.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
27
|
+
const { verbose, query, system, tools, tool_choice, max_tokens, temperature } = params;
|
|
28
|
+
const [input_query, previous_messages] = inputs;
|
|
29
|
+
// Notice that we ignore params.system if previous_message exists.
|
|
30
|
+
const messages = previous_messages && Array.isArray(previous_messages) ? previous_messages : system ? [{ role: "system", content: system }] : [];
|
|
31
|
+
const content = (query ? [query] : []).concat(input_query && typeof input_query === "string" ? [input_query] : []).join("\n");
|
|
32
|
+
if (content) {
|
|
33
|
+
messages.push({
|
|
34
|
+
role: "user",
|
|
35
|
+
content,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (verbose) {
|
|
39
|
+
console.log(messages);
|
|
40
|
+
}
|
|
41
|
+
const options = {
|
|
17
42
|
messages,
|
|
18
43
|
model: params.model,
|
|
19
|
-
|
|
44
|
+
temperature: temperature ?? 0.7,
|
|
45
|
+
};
|
|
46
|
+
if (max_tokens) {
|
|
47
|
+
options.max_tokens = max_tokens;
|
|
48
|
+
}
|
|
49
|
+
if (tools) {
|
|
50
|
+
options.tools = tools;
|
|
51
|
+
options.tool_choice = tool_choice ?? "auto";
|
|
52
|
+
}
|
|
53
|
+
const result = await groq.chat.completions.create(options);
|
|
20
54
|
return result;
|
|
21
55
|
};
|
|
22
|
-
exports.
|
|
23
|
-
const
|
|
24
|
-
name: "
|
|
25
|
-
agent: exports.
|
|
26
|
-
mock: exports.
|
|
56
|
+
exports.groqAgent = groqAgent;
|
|
57
|
+
const groqAgentInfo = {
|
|
58
|
+
name: "groqAgent",
|
|
59
|
+
agent: exports.groqAgent,
|
|
60
|
+
mock: exports.groqAgent,
|
|
27
61
|
samples: [],
|
|
28
62
|
description: "Groq Agent",
|
|
29
63
|
category: ["llm"],
|
|
@@ -31,4 +65,4 @@ const gloqAgentInfo = {
|
|
|
31
65
|
repository: "https://github.com/receptron/graphai",
|
|
32
66
|
license: "MIT",
|
|
33
67
|
};
|
|
34
|
-
exports.default =
|
|
68
|
+
exports.default = groqAgentInfo;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import groqAgent from "../../experimental_agents/llm_agents/groq_agent";
|
|
2
2
|
import slashGPTAgent from "../../experimental_agents/llm_agents/slashgpt_agent";
|
|
3
|
-
export {
|
|
3
|
+
export { groqAgent, slashGPTAgent };
|
|
@@ -3,8 +3,8 @@ 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.slashGPTAgent = exports.
|
|
6
|
+
exports.slashGPTAgent = exports.groqAgent = void 0;
|
|
7
7
|
const groq_agent_1 = __importDefault(require("../../experimental_agents/llm_agents/groq_agent"));
|
|
8
|
-
exports.
|
|
8
|
+
exports.groqAgent = groq_agent_1.default;
|
|
9
9
|
const slashgpt_agent_1 = __importDefault(require("../../experimental_agents/llm_agents/slashgpt_agent"));
|
|
10
10
|
exports.slashGPTAgent = slashgpt_agent_1.default;
|
|
@@ -6,6 +6,7 @@ export * from "./matrix_agents/packages";
|
|
|
6
6
|
export * from "./test_agents/packages";
|
|
7
7
|
export * from "./graph_agents/packages";
|
|
8
8
|
export * from "./llm_agents/packages";
|
|
9
|
+
export * from "./service_agents/packages";
|
|
9
10
|
import stringEmbeddingsAgent from "./embedding_agent";
|
|
10
11
|
import tokenBoundStringsAgent from "./token_agent";
|
|
11
12
|
import functionAgentInfo from "./function_agent";
|
|
@@ -26,6 +26,7 @@ __exportStar(require("./matrix_agents/packages"), exports);
|
|
|
26
26
|
__exportStar(require("./test_agents/packages"), exports);
|
|
27
27
|
__exportStar(require("./graph_agents/packages"), exports);
|
|
28
28
|
__exportStar(require("./llm_agents/packages"), exports);
|
|
29
|
+
__exportStar(require("./service_agents/packages"), exports);
|
|
29
30
|
const embedding_agent_1 = __importDefault(require("./embedding_agent"));
|
|
30
31
|
exports.stringEmbeddingsAgent = embedding_agent_1.default;
|
|
31
32
|
const token_agent_1 = __importDefault(require("./token_agent"));
|