graphai 0.4.2 → 0.4.3

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.
Files changed (92) hide show
  1. package/README.md +7 -77
  2. package/lib/experimental_agents/array_agents/push_agent.d.ts +1 -1
  3. package/lib/experimental_agents/array_agents/push_agent.js +1 -1
  4. package/lib/experimental_agents/array_agents/shift_agent.d.ts +1 -1
  5. package/lib/experimental_agents/array_agents/shift_agent.js +1 -1
  6. package/lib/experimental_agents/data_agents/property_filter_agent.d.ts +45 -0
  7. package/lib/experimental_agents/data_agents/property_filter_agent.js +28 -4
  8. package/lib/experimental_agents/embedding_agent.d.ts +1 -1
  9. package/lib/experimental_agents/embedding_agent.js +1 -1
  10. package/lib/experimental_agents/graph_agents/map_agent.d.ts +1 -1
  11. package/lib/experimental_agents/graph_agents/map_agent.js +1 -1
  12. package/lib/experimental_agents/graph_agents/nested_agent.d.ts +1 -1
  13. package/lib/experimental_agents/graph_agents/nested_agent.js +1 -1
  14. package/lib/experimental_agents/graph_agents/packages.d.ts +2 -1
  15. package/lib/experimental_agents/graph_agents/packages.js +3 -1
  16. package/lib/experimental_agents/graph_agents/vanilla.d.ts +2 -1
  17. package/lib/experimental_agents/graph_agents/vanilla.js +3 -1
  18. package/lib/experimental_agents/graph_agents/worker_agent.d.ts +39 -0
  19. package/lib/experimental_agents/graph_agents/worker_agent.js +111 -0
  20. package/lib/experimental_agents/index.d.ts +1 -2
  21. package/lib/experimental_agents/index.js +1 -3
  22. package/lib/experimental_agents/input_agents/text_input_agent.d.ts +8 -1
  23. package/lib/experimental_agents/input_agents/text_input_agent.js +9 -2
  24. package/lib/experimental_agents/llm_agents/anthropic_agent.d.ts +34 -0
  25. package/lib/experimental_agents/llm_agents/anthropic_agent.js +47 -0
  26. package/lib/experimental_agents/llm_agents/groq_agent.d.ts +5 -3
  27. package/lib/experimental_agents/llm_agents/groq_agent.js +6 -4
  28. package/lib/experimental_agents/llm_agents/index.d.ts +2 -2
  29. package/lib/experimental_agents/llm_agents/index.js +3 -3
  30. package/lib/experimental_agents/llm_agents/openai_agent.d.ts +8 -0
  31. package/lib/experimental_agents/llm_agents/openai_agent.js +13 -2
  32. package/lib/experimental_agents/llm_agents/packages.d.ts +2 -2
  33. package/lib/experimental_agents/llm_agents/packages.js +3 -3
  34. package/lib/experimental_agents/llm_agents/slashgpt_agent.d.ts +2 -0
  35. package/lib/experimental_agents/llm_agents/slashgpt_agent.js +2 -0
  36. package/lib/experimental_agents/matrix_agents/dot_product_agent.d.ts +1 -1
  37. package/lib/experimental_agents/matrix_agents/dot_product_agent.js +1 -1
  38. package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +1 -1
  39. package/lib/experimental_agents/matrix_agents/sort_by_values_agent.js +1 -1
  40. package/lib/experimental_agents/service_agents/fetch_agent.js +1 -1
  41. package/lib/experimental_agents/service_agents/wikipedia.js +1 -1
  42. package/lib/experimental_agents/sleeper_agents/sleeper_agent.d.ts +1 -1
  43. package/lib/experimental_agents/sleeper_agents/sleeper_agent.js +1 -1
  44. package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.d.ts +1 -1
  45. package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.js +1 -1
  46. package/lib/experimental_agents/string_agents/json_parser_agent.d.ts +38 -0
  47. package/lib/experimental_agents/string_agents/json_parser_agent.js +39 -0
  48. package/lib/experimental_agents/string_agents/packages.d.ts +2 -1
  49. package/lib/experimental_agents/string_agents/packages.js +3 -1
  50. package/lib/experimental_agents/string_agents/string_splitter_agent.js +1 -1
  51. package/lib/experimental_agents/string_agents/string_template_agent.d.ts +9 -7
  52. package/lib/experimental_agents/string_agents/string_template_agent.js +4 -1
  53. package/lib/experimental_agents/string_agents/vanilla.d.ts +2 -1
  54. package/lib/experimental_agents/string_agents/vanilla.js +3 -1
  55. package/lib/experimental_agents/test_agents/bypass_agent.js +1 -1
  56. package/lib/experimental_agents/test_agents/copy2array_agent.js +1 -1
  57. package/lib/experimental_agents/test_agents/copy_message_agent.js +1 -1
  58. package/lib/experimental_agents/test_agents/counting_agent.js +1 -1
  59. package/lib/experimental_agents/test_agents/echo_agent.js +13 -2
  60. package/lib/experimental_agents/test_agents/merge_node_id_agent.js +1 -1
  61. package/lib/experimental_agents/test_agents/stream_mock_agent.js +9 -2
  62. package/lib/experimental_agents/vanilla.d.ts +1 -2
  63. package/lib/experimental_agents/vanilla.js +1 -3
  64. package/lib/graphai.d.ts +5 -5
  65. package/lib/graphai.js +9 -9
  66. package/lib/index.d.ts +2 -1
  67. package/lib/index.js +3 -1
  68. package/lib/node.d.ts +2 -1
  69. package/lib/node.js +37 -11
  70. package/lib/transaction_log.d.ts +1 -0
  71. package/lib/transaction_log.js +2 -0
  72. package/lib/type.d.ts +11 -6
  73. package/lib/utils/runner.d.ts +2 -0
  74. package/lib/utils/runner.js +20 -0
  75. package/lib/utils/test_agents.d.ts +2 -2
  76. package/lib/utils/test_utils.d.ts +1 -17
  77. package/lib/utils/test_utils.js +3 -21
  78. package/lib/utils/utils.d.ts +2 -0
  79. package/lib/utils/utils.js +45 -1
  80. package/lib/validators/agent_validator.js +2 -1
  81. package/lib/validators/common.d.ts +3 -0
  82. package/lib/validators/common.js +10 -1
  83. package/lib/validators/computed_node_validator.js +1 -1
  84. package/lib/validators/graph_data_validator.js +9 -9
  85. package/lib/validators/nodeValidator.js +3 -2
  86. package/lib/validators/relation_validator.js +6 -5
  87. package/lib/validators/static_node_validator.js +1 -1
  88. package/package.json +3 -4
  89. package/lib/experimental_agents/function_agent.d.ts +0 -42
  90. package/lib/experimental_agents/function_agent.js +0 -40
  91. package/lib/experimental_agents/llm_agents/groq_stream_agent.d.ts +0 -42
  92. package/lib/experimental_agents/llm_agents/groq_stream_agent.js +0 -84
@@ -4,20 +4,20 @@ exports.graphDataValidator = exports.graphNodesValidator = void 0;
4
4
  const common_1 = require("../validators/common");
5
5
  const graphNodesValidator = (data) => {
6
6
  if (data.nodes === undefined) {
7
- throw new Error("Invalid Graph Data: no nodes");
7
+ throw new common_1.ValidationError("Invalid Graph Data: no nodes");
8
8
  }
9
9
  if (typeof data.nodes !== "object") {
10
- throw new Error("Invalid Graph Data: invalid nodes");
10
+ throw new common_1.ValidationError("Invalid Graph Data: invalid nodes");
11
11
  }
12
12
  if (Array.isArray(data.nodes)) {
13
- throw new Error("Invalid Graph Data: nodes must be object");
13
+ throw new common_1.ValidationError("Invalid Graph Data: nodes must be object");
14
14
  }
15
15
  if (Object.keys(data.nodes).length === 0) {
16
- throw new Error("Invalid Graph Data: nodes is empty");
16
+ throw new common_1.ValidationError("Invalid Graph Data: nodes is empty");
17
17
  }
18
18
  Object.keys(data).forEach((key) => {
19
19
  if (!common_1.graphDataAttributeKeys.includes(key)) {
20
- throw new Error("Graph Data does not allow " + key);
20
+ throw new common_1.ValidationError("Graph Data does not allow " + key);
21
21
  }
22
22
  });
23
23
  };
@@ -25,18 +25,18 @@ exports.graphNodesValidator = graphNodesValidator;
25
25
  const graphDataValidator = (data) => {
26
26
  if (data.loop) {
27
27
  if (data.loop.count === undefined && data.loop.while === undefined) {
28
- throw new Error("Loop: Either count or while is required in loop");
28
+ throw new common_1.ValidationError("Loop: Either count or while is required in loop");
29
29
  }
30
30
  if (data.loop.count !== undefined && data.loop.while !== undefined) {
31
- throw new Error("Loop: Both count and while cannot be set");
31
+ throw new common_1.ValidationError("Loop: Both count and while cannot be set");
32
32
  }
33
33
  }
34
34
  if (data.concurrency !== undefined) {
35
35
  if (!Number.isInteger(data.concurrency)) {
36
- throw new Error("Concurrency must be an integer");
36
+ throw new common_1.ValidationError("Concurrency must be an integer");
37
37
  }
38
38
  if (data.concurrency < 1) {
39
- throw new Error("Concurrency must be a positive integer");
39
+ throw new common_1.ValidationError("Concurrency must be a positive integer");
40
40
  }
41
41
  }
42
42
  };
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nodeValidator = void 0;
4
+ const common_1 = require("../validators/common");
4
5
  const nodeValidator = (nodeData) => {
5
6
  if (nodeData.agent && nodeData.value) {
6
- throw new Error("Cannot set both agent and value");
7
+ throw new common_1.ValidationError("Cannot set both agent and value");
7
8
  }
8
9
  if (!("agent" in nodeData) && !("value" in nodeData)) {
9
- throw new Error("Either agent or value is required");
10
+ throw new common_1.ValidationError("Either agent or value is required");
10
11
  }
11
12
  return true;
12
13
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.relationValidator = void 0;
4
4
  const utils_1 = require("../utils/utils");
5
+ const common_1 = require("../validators/common");
5
6
  const relationValidator = (data, staticNodeIds, computedNodeIds) => {
6
7
  const nodeIds = new Set(Object.keys(data.nodes));
7
8
  const pendings = {};
@@ -15,7 +16,7 @@ const relationValidator = (data, staticNodeIds, computedNodeIds) => {
15
16
  const sourceNodeId = (0, utils_1.parseNodeName)(inputNodeId, data.version ?? 0.02).nodeId;
16
17
  if (sourceNodeId) {
17
18
  if (!nodeIds.has(sourceNodeId)) {
18
- throw new Error(`Inputs not match: NodeId ${computedNodeId}, Inputs: ${sourceNodeId}`);
19
+ throw new common_1.ValidationError(`Inputs not match: NodeId ${computedNodeId}, Inputs: ${sourceNodeId}`);
19
20
  }
20
21
  waitlist[sourceNodeId] === undefined && (waitlist[sourceNodeId] = new Set());
21
22
  pendings[computedNodeId].add(sourceNodeId);
@@ -31,10 +32,10 @@ const relationValidator = (data, staticNodeIds, computedNodeIds) => {
31
32
  const update = nodeData.update;
32
33
  const updateNodeId = (0, utils_1.parseNodeName)(update, data.version ?? 0.02).nodeId;
33
34
  if (!updateNodeId) {
34
- throw new Error("Update it a literal");
35
+ throw new common_1.ValidationError("Update it a literal");
35
36
  }
36
37
  if (!nodeIds.has(updateNodeId)) {
37
- throw new Error(`Update not match: NodeId ${staticNodeId}, update: ${update}`);
38
+ throw new common_1.ValidationError(`Update not match: NodeId ${staticNodeId}, update: ${update}`);
38
39
  }
39
40
  }
40
41
  });
@@ -55,13 +56,13 @@ const relationValidator = (data, staticNodeIds, computedNodeIds) => {
55
56
  };
56
57
  let runningQueue = cycle(staticNodeIds);
57
58
  if (runningQueue.length === 0) {
58
- throw new Error("No Initial Runnning Node");
59
+ throw new common_1.ValidationError("No Initial Runnning Node");
59
60
  }
60
61
  do {
61
62
  runningQueue = cycle(runningQueue);
62
63
  } while (runningQueue.length > 0);
63
64
  if (Object.keys(pendings).length > 0) {
64
- throw new Error("Some nodes are not executed: " + Object.keys(pendings).join(", "));
65
+ throw new common_1.ValidationError("Some nodes are not executed: " + Object.keys(pendings).join(", "));
65
66
  }
66
67
  };
67
68
  exports.relationValidator = relationValidator;
@@ -5,7 +5,7 @@ const common_1 = require("../validators/common");
5
5
  const staticNodeValidator = (nodeData) => {
6
6
  Object.keys(nodeData).forEach((key) => {
7
7
  if (!common_1.staticNodeAttributeKeys.includes(key)) {
8
- throw new Error("Static node does not allow " + key);
8
+ throw new common_1.ValidationError("Static node does not allow " + key);
9
9
  }
10
10
  });
11
11
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphai",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Asynchronous data flow execution engine for agentic AI apps.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -28,6 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/receptron/graphai#readme",
30
30
  "devDependencies": {
31
+ "@anthropic-ai/sdk": "^0.21.0",
31
32
  "@inquirer/prompts": "^5.0.0",
32
33
  "@types/cors": "^2.8.17",
33
34
  "@types/express": "^4.17.21",
@@ -48,6 +49,7 @@
48
49
  "ts-node": "^10.9.2",
49
50
  "tsc-alias": "^1.8.8",
50
51
  "tsconfig-paths": "^4.2.0",
52
+ "typedoc": "^0.25.13",
51
53
  "typescript": "^5.4.5",
52
54
  "typescript-eslint": "^7.8.0",
53
55
  "wikipedia": "^2.1.2",
@@ -58,8 +60,5 @@
58
60
  "directories": {
59
61
  "lib": "lib",
60
62
  "test": "tests"
61
- },
62
- "dependencies": {
63
- "typedoc": "^0.25.13"
64
63
  }
65
64
  }
@@ -1,42 +0,0 @@
1
- import { AgentFunction } from "../index";
2
- export declare const functionAgent: AgentFunction<{
3
- function: (...args: any[]) => any;
4
- }>;
5
- declare const functionAgentInfo: {
6
- name: string;
7
- agent: AgentFunction<{
8
- function: (...args: any[]) => any;
9
- }>;
10
- mock: AgentFunction<{
11
- function: (...args: any[]) => any;
12
- }>;
13
- samples: ({
14
- inputs: {
15
- model: string;
16
- maker: string;
17
- range: number;
18
- price: number;
19
- }[];
20
- params: {
21
- function: (info: Record<string, any>) => string;
22
- };
23
- result: string;
24
- } | {
25
- inputs: string[];
26
- params: {
27
- function: (str: string) => any;
28
- };
29
- result: {
30
- model: string;
31
- maker: string;
32
- range: number;
33
- price: number;
34
- };
35
- })[];
36
- description: string;
37
- category: string[];
38
- author: string;
39
- repository: string;
40
- license: string;
41
- };
42
- export default functionAgentInfo;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.functionAgent = void 0;
4
- const functionAgent = async ({ inputs, params }) => {
5
- return params.function(...inputs);
6
- };
7
- exports.functionAgent = functionAgent;
8
- const carInfo = { model: "Model 3", maker: "Tesla", range: 300, price: 35000 };
9
- const functionAgentInfo = {
10
- name: "functionAgent",
11
- agent: exports.functionAgent,
12
- mock: exports.functionAgent,
13
- samples: [
14
- {
15
- inputs: [carInfo],
16
- params: {
17
- function: (info) => {
18
- const { model, maker, range, price } = info;
19
- return `A ${maker} ${model} has the range of ${range} miles. It costs $${price}.`;
20
- },
21
- },
22
- result: "A Tesla Model 3 has the range of 300 miles. It costs $35000.",
23
- },
24
- {
25
- inputs: [JSON.stringify(carInfo)],
26
- params: {
27
- function: (str) => {
28
- return JSON.parse(str);
29
- },
30
- },
31
- result: carInfo,
32
- },
33
- ],
34
- description: "It allows developers to implement the agent function within the graph itself.",
35
- category: ["data"],
36
- author: "Receptron team",
37
- repository: "https://github.com/receptron/graphai",
38
- license: "MIT",
39
- };
40
- exports.default = functionAgentInfo;
@@ -1,42 +0,0 @@
1
- import { AgentFunction } from "../../index";
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;
@@ -1,84 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.groqStreamAgent = void 0;
4
- const groq_sdk_1 = require("groq-sdk");
5
- const utils_1 = require("../../utils/utils");
6
- const groq = process.env.GROQ_API_KEY ? new groq_sdk_1.Groq({ apiKey: process.env.GROQ_API_KEY }) : undefined;
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 groqStreamAgent = async ({ params, inputs, filterParams }) => {
26
- (0, utils_1.assert)(groq !== undefined, "The GROQ_API_KEY environment variable is missing.");
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 = {
42
- messages,
43
- model: params.model,
44
- temperature: temperature ?? 0.7,
45
- stream: true,
46
- };
47
- if (max_tokens) {
48
- options.max_tokens = max_tokens;
49
- }
50
- if (tools) {
51
- options.tools = tools;
52
- options.tool_choice = tool_choice ?? "auto";
53
- }
54
- const stream = await groq.chat.completions.create(options);
55
- let lastMessage = null;
56
- const contents = [];
57
- for await (const message of stream) {
58
- const token = message.choices[0].delta.content;
59
- if (token) {
60
- if (filterParams && filterParams.streamTokenCallback) {
61
- filterParams.streamTokenCallback(token);
62
- }
63
- contents.push(token);
64
- }
65
- lastMessage = message;
66
- }
67
- if (lastMessage) {
68
- lastMessage.choices[0]["message"] = [{ role: "assistant", content: contents.join("") }];
69
- }
70
- return lastMessage;
71
- };
72
- exports.groqStreamAgent = groqStreamAgent;
73
- const groqStreamAgentInfo = {
74
- name: "groqStreamAgent",
75
- agent: exports.groqStreamAgent,
76
- mock: exports.groqStreamAgent,
77
- samples: [],
78
- description: "Groq Stream Agent",
79
- category: ["llm"],
80
- author: "Receptron team",
81
- repository: "https://github.com/receptron/graphai",
82
- license: "MIT",
83
- };
84
- exports.default = groqStreamAgentInfo;