graphai 0.0.6 → 0.0.7

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 CHANGED
@@ -36,26 +36,26 @@ const sampleAgentFunction = async (context: AgentFunctionContext) => {
36
36
 
37
37
  ...
38
38
  const file = fs.readFileSync(pathToYamlFile, "utf8");
39
- const graphdata = YAML.parse(file);
40
- const graph = new GraphAI(graph_data, sampleAgentFunction);
39
+ const graphData = YAML.parse(file);
40
+ const graph = new GraphAI(graphData, sampleAgentFunction);
41
41
  const results = await graph.run();
42
42
  return results["taskC"];
43
43
  ```
44
44
 
45
45
  ## Data Flow Graph
46
46
 
47
- A Data Flow Graph (DFG) is a JSON object, which defines the flow of data. It is typically described in YAML file and loaded at runtime.
47
+ 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.
48
48
 
49
49
  A DFG consists of a collection of 'nodes', which contains a series of nested keys representing individual nodes in the data flow. Each node is identified by a unique key (e.g., node1, node2) and can contain several predefined keys (params, inputs, retry, timeout, source, dispatch, agentId) that dictate the node's behavior and its relationship with other nodes.
50
50
 
51
51
  ### DFG Structure
52
52
 
53
- - 'nodes': A list of node.
54
- - 'concurrency': An optional number, which specifies the maximum number of concurrent operations (agent functions to be executed at the same time). The default is 8.
53
+ - 'nodes': A list of node. Required.
54
+ - '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.
55
55
 
56
56
  ## Agent
57
57
 
58
- An agent is an abstract object, which takes some inputs and generates an output asynchronously. It could be an LLM (such as GPT-4), an image/video/music generation, a database, or a REST API over HTTP. Each node (except 'source node') is associated with an agent function, which takes data flow into the node as inputs, and generates an output.
58
+ An agent is an abstract object, which takes some inputs and generates an output asynchronously. It could be an LLM (such as GPT-4), an image/video/music generator, a database, or a REST API over HTTP. Each node (except 'source node') is associated with an agent function, which takes data flow into the node as inputs, and generates an output.
59
59
 
60
60
  ## Agent function
61
61
 
@@ -73,4 +73,38 @@ A regular agent function returns the data (type: ```Record<string, any>```), but
73
73
  - '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.
74
74
  - '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.
75
75
  - 'params': An optional parameters to the associated agent function, which are agent specific.
76
- - 'payloadMapping': An optional property (type: ```Record<string, string>```), which maps input nodeIds to agent specific inputIDs.
76
+ - 'payloadMapping': An optional property (type: ```Record<string, string>```), which maps input nodeIds to agent specific inputIDs.
77
+
78
+ ## GraphAI class
79
+
80
+ ### ```constructor(data: GraphData, callbackDictonary: AgentFunctionDictonary | AgentFunction<any, any, any>)```
81
+ Initializes a new instance of the GraphAI class with the specified graph data and a dictionary of callback functions.
82
+
83
+ - ```data: GraphData```: The graph data including nodes and optional concurrency limit.
84
+ - ```callbackDictonary: AgentFunctionDictonary | AgentFunction<any, any, any>```: A dictionary mapping agent IDs to their respective callback functions, or a single default callback function to be used for all nodes.
85
+
86
+ ### ```async run(): Promise<ResultDataDictonary<ResultData>>```
87
+ Executes the graph asynchronously, starting with nodes that have no dependencies or whose dependencies have been met. The method continues to execute nodes as their dependencies are satisfied until all nodes have been executed or an error occurs.
88
+
89
+ Returns: A promise that resolves with the results of all executed nodes or rejects with the first encountered error.
90
+
91
+ ### ```results(): ResultDataDictonary<ResultData>```
92
+ Compiles and returns the results of all executed nodes in the graph.
93
+
94
+ Returns: A dictionary mapping node IDs to their results. Only includes nodes that have completed execution and produced a result.
95
+
96
+ ### ```errors(): Record<string, Error>```
97
+ Compiles and returns the errors from all nodes that encountered an error during execution.
98
+
99
+ Returns: A dictionary mapping node IDs to the errors they encountered. Only includes nodes that have executed and encountered an error. It does not include any errors which have been retried.
100
+
101
+ ### ```transactionLogs(): Array<TransactionLog>```
102
+ Retrieves all transaction logs recorded during the execution of the graph.
103
+
104
+ Returns: An array of transaction logs detailing the execution states and outcomes of the nodes within the graph.
105
+
106
+ ### ```injectResult(nodeId: string, result: ResultData): void```
107
+ Injects a result into a specified node. This is used to manually set the result of a source node, allowing dependent nodes to proceed with execution.
108
+
109
+ - ```nodeId: string```: The ID of the source node into which the result is to be injected.
110
+ - ```result: ResultData```: The result to be injected into the specified node.
package/lib/graphai.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  export declare enum NodeState {
2
- Waiting = 0,
3
- Executing = 1,
4
- Failed = 2,
5
- TimedOut = 3,
6
- Completed = 4,
7
- Injected = 5,
8
- Dispatched = 6
2
+ Waiting = "waiting",
3
+ Executing = "executing",
4
+ Failed = "failed",
5
+ TimedOut = "timed-out",
6
+ Completed = "completed",
7
+ Injected = "injected",
8
+ Dispatched = "dispatched"
9
9
  }
10
10
  type ResultData<ResultType = Record<string, any>> = ResultType | undefined;
11
11
  type ResultDataDictonary<ResultType = Record<string, any>> = Record<string, ResultData<ResultType>>;
package/lib/graphai.js CHANGED
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GraphAI = exports.NodeState = void 0;
4
4
  var NodeState;
5
5
  (function (NodeState) {
6
- NodeState[NodeState["Waiting"] = 0] = "Waiting";
7
- NodeState[NodeState["Executing"] = 1] = "Executing";
8
- NodeState[NodeState["Failed"] = 2] = "Failed";
9
- NodeState[NodeState["TimedOut"] = 3] = "TimedOut";
10
- NodeState[NodeState["Completed"] = 4] = "Completed";
11
- NodeState[NodeState["Injected"] = 5] = "Injected";
12
- NodeState[NodeState["Dispatched"] = 6] = "Dispatched";
6
+ NodeState["Waiting"] = "waiting";
7
+ NodeState["Executing"] = "executing";
8
+ NodeState["Failed"] = "failed";
9
+ NodeState["TimedOut"] = "timed-out";
10
+ NodeState["Completed"] = "completed";
11
+ NodeState["Injected"] = "injected";
12
+ NodeState["Dispatched"] = "dispatched";
13
13
  })(NodeState || (exports.NodeState = NodeState = {}));
14
14
  class Node {
15
15
  constructor(nodeId, data, graph) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphai",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Asynchronous data flow execution engine to make it simple to build LLM apps.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
package/src/graphai.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  export enum NodeState {
2
- Waiting,
3
- Executing,
4
- Failed,
5
- TimedOut,
6
- Completed,
7
- Injected,
8
- Dispatched,
2
+ Waiting = "waiting",
3
+ Executing = "executing",
4
+ Failed = "failed",
5
+ TimedOut = "timed-out",
6
+ Completed = "completed",
7
+ Injected = "injected",
8
+ Dispatched = "dispatched",
9
9
  }
10
10
  type ResultData<ResultType = Record<string, any>> = ResultType | undefined;
11
11
  type ResultDataDictonary<ResultType = Record<string, any>> = Record<string, ResultData<ResultType>>;