graphai 0.4.1 → 0.4.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.
Files changed (56) hide show
  1. package/README.md +1 -1
  2. package/lib/experimental_agents/array_agents/pop_agent.d.ts +1 -1
  3. package/lib/experimental_agents/array_agents/push_agent.d.ts +17 -3
  4. package/lib/experimental_agents/array_agents/push_agent.js +15 -1
  5. package/lib/experimental_agents/array_agents/shift_agent.d.ts +1 -1
  6. package/lib/experimental_agents/data_agents/copy_agent.d.ts +1 -1
  7. package/lib/experimental_agents/data_agents/data_object_merge_template_agent.d.ts +1 -1
  8. package/lib/experimental_agents/data_agents/data_sum_template_agent.d.ts +1 -1
  9. package/lib/experimental_agents/data_agents/property_filter_agent.d.ts +1 -1
  10. package/lib/experimental_agents/data_agents/total_agent.d.ts +1 -1
  11. package/lib/experimental_agents/embedding_agent.d.ts +1 -1
  12. package/lib/experimental_agents/function_agent.d.ts +1 -1
  13. package/lib/experimental_agents/graph_agents/map_agent.d.ts +1 -1
  14. package/lib/experimental_agents/graph_agents/map_agent.js +2 -2
  15. package/lib/experimental_agents/graph_agents/nested_agent.d.ts +1 -1
  16. package/lib/experimental_agents/graph_agents/nested_agent.js +2 -2
  17. package/lib/experimental_agents/index.d.ts +1 -0
  18. package/lib/experimental_agents/index.js +1 -0
  19. package/lib/experimental_agents/input_agents/index.d.ts +2 -0
  20. package/lib/experimental_agents/input_agents/index.js +8 -0
  21. package/lib/experimental_agents/input_agents/packages.d.ts +2 -0
  22. package/lib/experimental_agents/input_agents/packages.js +8 -0
  23. package/lib/experimental_agents/input_agents/text_input_agent.d.ts +26 -0
  24. package/lib/experimental_agents/input_agents/text_input_agent.js +23 -0
  25. package/lib/experimental_agents/llm_agents/groq_agent.d.ts +13 -10
  26. package/lib/experimental_agents/llm_agents/groq_agent.js +32 -5
  27. package/lib/experimental_agents/llm_agents/groq_stream_agent.d.ts +1 -1
  28. package/lib/experimental_agents/llm_agents/openai_agent.d.ts +5 -1
  29. package/lib/experimental_agents/llm_agents/openai_agent.js +2 -0
  30. package/lib/experimental_agents/llm_agents/slashgpt_agent.d.ts +1 -1
  31. package/lib/experimental_agents/matrix_agents/dot_product_agent.d.ts +1 -1
  32. package/lib/experimental_agents/matrix_agents/sort_by_values_agent.d.ts +1 -1
  33. package/lib/experimental_agents/service_agents/fetch_agent.d.ts +1 -1
  34. package/lib/experimental_agents/service_agents/wikipedia.d.ts +1 -1
  35. package/lib/experimental_agents/sleeper_agents/sleeper_agent.d.ts +1 -1
  36. package/lib/experimental_agents/sleeper_agents/sleeper_agent_debug.d.ts +1 -1
  37. package/lib/experimental_agents/string_agents/string_splitter_agent.d.ts +2 -33
  38. package/lib/experimental_agents/string_agents/string_template_agent.d.ts +51 -9
  39. package/lib/experimental_agents/string_agents/string_template_agent.js +36 -9
  40. package/lib/experimental_agents/test_agents/bypass_agent.d.ts +1 -1
  41. package/lib/experimental_agents/test_agents/copy2array_agent.d.ts +1 -1
  42. package/lib/experimental_agents/test_agents/copy_message_agent.d.ts +1 -2
  43. package/lib/experimental_agents/test_agents/counting_agent.d.ts +1 -2
  44. package/lib/experimental_agents/test_agents/echo_agent.d.ts +1 -2
  45. package/lib/experimental_agents/test_agents/merge_node_id_agent.d.ts +1 -2
  46. package/lib/experimental_agents/test_agents/stream_mock_agent.d.ts +1 -2
  47. package/lib/experimental_agents/token_agent.d.ts +1 -1
  48. package/lib/graphai.d.ts +1 -1
  49. package/lib/index.d.ts +2 -3
  50. package/lib/index.js +1 -1
  51. package/lib/node.d.ts +2 -1
  52. package/lib/node.js +7 -0
  53. package/lib/type.d.ts +1 -0
  54. package/lib/utils/test_agents.d.ts +1 -1
  55. package/lib/validators/common.js +14 -1
  56. package/package.json +5 -1
package/README.md CHANGED
@@ -418,7 +418,7 @@ Step 1. Install git, node and yarn
418
418
  Step 2. Clone the project and install necessary node modules
419
419
 
420
420
  ```
421
- git clone git@github.com:snakajima/graphai.git
421
+ git clone git@github.com:receptron/graphai.git
422
422
  cd graphai
423
423
  yarn install
424
424
  ```
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const popAgent: AgentFunction<Record<string, any>, Record<string, any>, Array<any>>;
3
3
  declare const popAgentInfo: {
4
4
  name: string;
@@ -1,14 +1,28 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const pushAgent: AgentFunction<Record<string, any>, Record<string, any>, Array<any>>;
3
3
  declare const pushAgentInfo: {
4
4
  name: string;
5
5
  agent: AgentFunction<Record<string, any>, Record<string, any>, any[]>;
6
6
  mock: AgentFunction<Record<string, any>, Record<string, any>, any[]>;
7
- samples: {
7
+ samples: ({
8
8
  inputs: (number | number[])[];
9
9
  params: {};
10
10
  result: number[];
11
- }[];
11
+ } | {
12
+ inputs: ({
13
+ apple: number;
14
+ }[] | {
15
+ lemon: number;
16
+ })[];
17
+ params: {};
18
+ result: ({
19
+ apple: number;
20
+ lemon?: undefined;
21
+ } | {
22
+ lemon: number;
23
+ apple?: undefined;
24
+ })[];
25
+ })[];
12
26
  description: string;
13
27
  category: never[];
14
28
  author: string;
@@ -3,7 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pushAgent = void 0;
4
4
  const pushAgent = async ({ inputs }) => {
5
5
  const array = inputs[0].map((item) => item); // shallow copy
6
- array.push(inputs[1]);
6
+ inputs.forEach((input, index) => {
7
+ if (index > 0) {
8
+ array.push(input);
9
+ }
10
+ });
7
11
  return array;
8
12
  };
9
13
  exports.pushAgent = pushAgent;
@@ -17,6 +21,16 @@ const pushAgentInfo = {
17
21
  params: {},
18
22
  result: [1, 2, 3],
19
23
  },
24
+ {
25
+ inputs: [[1, 2], 3, 4, 5],
26
+ params: {},
27
+ result: [1, 2, 3, 4, 5],
28
+ },
29
+ {
30
+ inputs: [[{ apple: 1 }], { lemon: 2 }],
31
+ params: {},
32
+ result: [{ apple: 1 }, { lemon: 2 }],
33
+ },
20
34
  ],
21
35
  description: "push Agent",
22
36
  category: [],
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const shiftAgent: AgentFunction<Record<string, any>, Record<string, any>, Array<any>>;
3
3
  declare const shiftAgentInfo: {
4
4
  name: string;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const copyAgent: AgentFunction;
3
3
  declare const copyAgentInfo: {
4
4
  name: string;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const dataObjectMergeTemplateAgent: AgentFunction;
3
3
  declare const dataObjectMergeTemplateAgentInfo: {
4
4
  name: string;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const dataSumTemplateAgent: AgentFunction<Record<string, any>, number, number>;
3
3
  declare const dataSumTemplateAgentInfo: {
4
4
  name: string;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const propertyFilterAgent: AgentFunction<{
3
3
  include?: Array<string>;
4
4
  exclude?: Array<string>;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const totalAgent: AgentFunction<Record<never, never>, Record<string, number>>;
3
3
  declare const totalAgentInfo: {
4
4
  name: string;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../graphai";
1
+ import { AgentFunction } from "../index";
2
2
  export declare const stringEmbeddingsAgent: AgentFunction<{
3
3
  model?: string;
4
4
  }, any, Array<string> | string>;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../graphai";
1
+ import { AgentFunction } from "../index";
2
2
  export declare const functionAgent: AgentFunction<{
3
3
  function: (...args: any[]) => any;
4
4
  }>;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const mapAgent: AgentFunction<{
3
3
  namedInputs?: Array<string>;
4
4
  limit?: number;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mapAgent = void 0;
4
- const graphai_1 = require("../../graphai");
4
+ const index_1 = require("../../index");
5
5
  const utils_1 = require("../../utils/utils");
6
6
  const nested_agent_1 = require("./nested_agent");
7
7
  const mapAgent = async ({ params, inputs, agents, log, taskManager, graphData, agentFilters }) => {
@@ -25,7 +25,7 @@ const mapAgent = async ({ params, inputs, agents, log, taskManager, graphData, a
25
25
  }
26
26
  });
27
27
  const graphs = input.map((data) => {
28
- const graphAI = new graphai_1.GraphAI(nestedGraphData, agents || {}, { taskManager, agentFilters: agentFilters || [] });
28
+ const graphAI = new index_1.GraphAI(nestedGraphData, agents || {}, { taskManager, agentFilters: agentFilters || [] });
29
29
  // Only the first input will be mapped
30
30
  namedInputs.forEach((injectToNodeId, index) => {
31
31
  graphAI.injectValue(injectToNodeId, index === 0 ? data : inputs[index], "__mapAgent_inputs__");
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  import { GraphData } from "../../type";
3
3
  export declare const getNestedGraphData: (graphData: GraphData | string | undefined, inputs: Array<any>) => GraphData;
4
4
  export declare const nestedAgent: AgentFunction<{
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nestedAgent = exports.getNestedGraphData = void 0;
4
- const graphai_1 = require("../../graphai");
4
+ const index_1 = require("../../index");
5
5
  const utils_1 = require("../../utils/utils");
6
6
  // This function allows us to use one of inputs as the graph data for this nested agent,
7
7
  // which is equivalent to "eval" of JavaScript.
@@ -38,7 +38,7 @@ const nestedAgent = async ({ params, inputs, agents, log, taskManager, graphData
38
38
  nestedGraphData.nodes[nodeId]["value"] = inputs[index];
39
39
  }
40
40
  });
41
- const graphAI = new graphai_1.GraphAI(nestedGraphData, agents || {}, { taskManager, agentFilters });
41
+ const graphAI = new index_1.GraphAI(nestedGraphData, agents || {}, { taskManager, agentFilters });
42
42
  const results = await graphAI.run(false);
43
43
  log?.push(...graphAI.transactionLogs());
44
44
  return results;
@@ -7,6 +7,7 @@ export * from "./data_agents";
7
7
  export * from "./sleeper_agents";
8
8
  export * from "./llm_agents";
9
9
  export * from "./service_agents";
10
+ export * from "./input_agents";
10
11
  import functionAgent from "./function_agent";
11
12
  import stringEmbeddingsAgent from "./embedding_agent";
12
13
  import tokenBoundStringsAgent from "./token_agent";
@@ -28,6 +28,7 @@ __exportStar(require("./data_agents"), exports);
28
28
  __exportStar(require("./sleeper_agents"), exports);
29
29
  __exportStar(require("./llm_agents"), exports);
30
30
  __exportStar(require("./service_agents"), exports);
31
+ __exportStar(require("./input_agents"), exports);
31
32
  // TODO sub folder
32
33
  const function_agent_1 = __importDefault(require("./function_agent"));
33
34
  exports.functionAgent = function_agent_1.default;
@@ -0,0 +1,2 @@
1
+ import textInputAgent from "../../experimental_agents/input_agents/text_input_agent";
2
+ export { textInputAgent };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.textInputAgent = void 0;
7
+ const text_input_agent_1 = __importDefault(require("../../experimental_agents/input_agents/text_input_agent"));
8
+ exports.textInputAgent = text_input_agent_1.default;
@@ -0,0 +1,2 @@
1
+ import textInputAgent from "../../experimental_agents/input_agents/text_input_agent";
2
+ export { textInputAgent };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.textInputAgent = void 0;
7
+ const text_input_agent_1 = __importDefault(require("../../experimental_agents/input_agents/text_input_agent"));
8
+ exports.textInputAgent = text_input_agent_1.default;
@@ -0,0 +1,26 @@
1
+ import { AgentFunction } from "../../index";
2
+ export declare const textInputAgent: AgentFunction<{
3
+ message?: string;
4
+ }, string | {
5
+ [x: string]: string;
6
+ }>;
7
+ declare const textInputAgentInfo: {
8
+ name: string;
9
+ agent: AgentFunction<{
10
+ message?: string | undefined;
11
+ }, string | {
12
+ [x: string]: string;
13
+ }>;
14
+ mock: AgentFunction<{
15
+ message?: string | undefined;
16
+ }, string | {
17
+ [x: string]: string;
18
+ }>;
19
+ samples: never[];
20
+ description: string;
21
+ category: string[];
22
+ author: string;
23
+ repository: string;
24
+ license: string;
25
+ };
26
+ export default textInputAgentInfo;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.textInputAgent = void 0;
7
+ const input_1 = __importDefault(require("@inquirer/input"));
8
+ const textInputAgent = async ({ params }) => {
9
+ return await (0, input_1.default)({ message: params.message ?? "Enter" });
10
+ };
11
+ exports.textInputAgent = textInputAgent;
12
+ const textInputAgentInfo = {
13
+ name: "textInputAgent",
14
+ agent: exports.textInputAgent,
15
+ mock: exports.textInputAgent,
16
+ samples: [],
17
+ description: "Text Input Agent",
18
+ category: ["array"],
19
+ author: "Receptron team",
20
+ repository: "https://github.com/receptron/graphai",
21
+ license: "MIT",
22
+ };
23
+ exports.default = textInputAgentInfo;
@@ -1,15 +1,16 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  import { Groq } from "groq-sdk";
3
3
  export declare const groqAgent: AgentFunction<{
4
4
  model: string;
5
5
  query?: string;
6
6
  system?: string;
7
7
  verbose?: boolean;
8
- tools?: Record<string, Groq.Chat.CompletionCreateParams.Tool>;
8
+ tools?: Groq.Chat.CompletionCreateParams.Tool[];
9
9
  temperature?: number;
10
10
  max_tokens?: number;
11
- tool_choice?: string | Record<string, Groq.Chat.CompletionCreateParams.ToolChoice>;
12
- }, Groq.Chat.ChatCompletion, string | Array<Groq.Chat.CompletionCreateParams.Message>>;
11
+ tool_choice?: Groq.Chat.CompletionCreateParams.ToolChoice;
12
+ isStreaming?: boolean;
13
+ }, any, string | Array<Groq.Chat.CompletionCreateParams.Message>>;
13
14
  declare const groqAgentInfo: {
14
15
  name: string;
15
16
  agent: AgentFunction<{
@@ -17,21 +18,23 @@ declare const groqAgentInfo: {
17
18
  query?: string | undefined;
18
19
  system?: string | undefined;
19
20
  verbose?: boolean | undefined;
20
- tools?: Record<string, Groq.Chat.Completions.CompletionCreateParams.Tool> | undefined;
21
+ tools?: Groq.Chat.Completions.CompletionCreateParams.Tool[] | undefined;
21
22
  temperature?: number | undefined;
22
23
  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[]>;
24
+ tool_choice?: Groq.Chat.Completions.CompletionCreateParams.ToolChoice | undefined;
25
+ isStreaming?: boolean | undefined;
26
+ }, any, string | Groq.Chat.Completions.CompletionCreateParams.Message[]>;
25
27
  mock: AgentFunction<{
26
28
  model: string;
27
29
  query?: string | undefined;
28
30
  system?: string | undefined;
29
31
  verbose?: boolean | undefined;
30
- tools?: Record<string, Groq.Chat.Completions.CompletionCreateParams.Tool> | undefined;
32
+ tools?: Groq.Chat.Completions.CompletionCreateParams.Tool[] | undefined;
31
33
  temperature?: number | undefined;
32
34
  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[]>;
35
+ tool_choice?: Groq.Chat.Completions.CompletionCreateParams.ToolChoice | undefined;
36
+ isStreaming?: boolean | undefined;
37
+ }, any, string | Groq.Chat.Completions.CompletionCreateParams.Message[]>;
35
38
  samples: never[];
36
39
  description: string;
37
40
  category: string[];
@@ -22,9 +22,9 @@ const groq = process.env.GROQ_API_KEY ? new groq_sdk_1.Groq({ apiKey: process.en
22
22
  //
23
23
  // https://console.groq.com/docs/quickstart
24
24
  //
25
- const groqAgent = async ({ params, inputs }) => {
25
+ const groqAgent = async ({ params, inputs, filterParams }) => {
26
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;
27
+ const { verbose, query, system, tools, tool_choice, max_tokens, temperature, isStreaming } = params;
28
28
  const [input_query, previous_messages] = inputs;
29
29
  // Notice that we ignore params.system if previous_message exists.
30
30
  const messages = previous_messages && Array.isArray(previous_messages) ? previous_messages : system ? [{ role: "system", content: system }] : [];
@@ -38,11 +38,18 @@ const groqAgent = async ({ params, inputs }) => {
38
38
  if (verbose) {
39
39
  console.log(messages);
40
40
  }
41
- const options = {
41
+ const streamOption = {
42
42
  messages,
43
43
  model: params.model,
44
44
  temperature: temperature ?? 0.7,
45
+ stream: true,
45
46
  };
47
+ const nonStreamOption = {
48
+ messages,
49
+ model: params.model,
50
+ temperature: temperature ?? 0.7,
51
+ };
52
+ const options = isStreaming ? streamOption : nonStreamOption;
46
53
  if (max_tokens) {
47
54
  options.max_tokens = max_tokens;
48
55
  }
@@ -50,8 +57,28 @@ const groqAgent = async ({ params, inputs }) => {
50
57
  options.tools = tools;
51
58
  options.tool_choice = tool_choice ?? "auto";
52
59
  }
53
- const result = await groq.chat.completions.create(options);
54
- return result;
60
+ if (!options.stream) {
61
+ const result = await groq.chat.completions.create(options);
62
+ return result;
63
+ }
64
+ // streaming
65
+ const stream = await groq.chat.completions.create(options);
66
+ let lastMessage = null;
67
+ const contents = [];
68
+ for await (const message of stream) {
69
+ const token = message.choices[0].delta.content;
70
+ if (token) {
71
+ if (filterParams && filterParams.streamTokenCallback) {
72
+ filterParams.streamTokenCallback(token);
73
+ }
74
+ contents.push(token);
75
+ }
76
+ lastMessage = message;
77
+ }
78
+ if (lastMessage) {
79
+ lastMessage.choices[0]["message"] = [{ role: "assistant", content: contents.join("") }];
80
+ }
81
+ return lastMessage;
55
82
  };
56
83
  exports.groqAgent = groqAgent;
57
84
  const groqAgentInfo = {
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  import { Groq } from "groq-sdk";
3
3
  export declare const groqStreamAgent: AgentFunction<{
4
4
  model: string;
@@ -1,8 +1,10 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const openAIAgent: AgentFunction<{
3
3
  model?: string;
4
4
  query?: string;
5
5
  system?: string;
6
+ tools?: any;
7
+ tool_choice?: any;
6
8
  verbose?: boolean;
7
9
  temperature?: number;
8
10
  }, Record<string, any> | string, string | Array<any>>;
@@ -19,6 +21,8 @@ declare const openaiAgentInfo: {
19
21
  model?: string | undefined;
20
22
  query?: string | undefined;
21
23
  system?: string | undefined;
24
+ tools?: any;
25
+ tool_choice?: any;
22
26
  verbose?: boolean | undefined;
23
27
  temperature?: number | undefined;
24
28
  }, string | Record<string, any>, string | any[]>;
@@ -25,6 +25,8 @@ const openAIAgent = async ({ filterParams, params, inputs }) => {
25
25
  const chatStream = await openai.beta.chat.completions.stream({
26
26
  model: params.model || "gpt-3.5-turbo",
27
27
  messages,
28
+ tools: params.tools,
29
+ tool_choice: params.tool_choice,
28
30
  temperature: temperature ?? 0.7,
29
31
  stream: true,
30
32
  });
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  import { ManifestData, ChatData } from "slashgpt";
3
3
  export declare const slashGPTAgent: AgentFunction<{
4
4
  manifest: ManifestData;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const dotProductAgent: AgentFunction<Record<never, never>, Array<number>, Array<Array<number>> | Array<number>>;
3
3
  declare const dotProductAgentInfo: {
4
4
  name: string;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const sortByValuesAgent: AgentFunction<{
3
3
  assendant?: boolean;
4
4
  }, Array<any>, Array<any>>;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const fetchAgent: AgentFunction<{
3
3
  debug?: boolean;
4
4
  type?: string;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const wikipediaAgent: AgentFunction<{
3
3
  lang?: string;
4
4
  summary?: boolean;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const sleeperAgent: AgentFunction<{
3
3
  duration?: number;
4
4
  value?: Record<string, any>;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const sleeperAgentDebug: AgentFunction<{
3
3
  duration: number;
4
4
  value?: Record<string, any>;
@@ -1,40 +1,9 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction, AgentFunctionInfo } from "../../index";
2
2
  export declare const stringSplitterAgent: AgentFunction<{
3
3
  chunkSize?: number;
4
4
  overlap?: number;
5
5
  }, {
6
6
  contents: Array<string>;
7
7
  }, string>;
8
- declare const stringSplitterAgentInfo: {
9
- name: string;
10
- agent: AgentFunction<{
11
- chunkSize?: number | undefined;
12
- overlap?: number | undefined;
13
- }, {
14
- contents: Array<string>;
15
- }, string>;
16
- mock: AgentFunction<{
17
- chunkSize?: number | undefined;
18
- overlap?: number | undefined;
19
- }, {
20
- contents: Array<string>;
21
- }, string>;
22
- samples: {
23
- inputs: string[];
24
- params: {
25
- chunkSize: number;
26
- };
27
- result: {
28
- contents: string[];
29
- count: number;
30
- chunkSize: number;
31
- overlap: number;
32
- };
33
- }[];
34
- description: string;
35
- category: never[];
36
- author: string;
37
- repository: string;
38
- license: string;
39
- };
8
+ declare const stringSplitterAgentInfo: AgentFunctionInfo;
40
9
  export default stringSplitterAgentInfo;
@@ -1,22 +1,64 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  export declare const stringTemplateAgent: AgentFunction<{
3
- template: string;
4
- }, string, string>;
3
+ template: any;
4
+ }, any, string>;
5
5
  declare const stringTemplateAgentInfo: {
6
6
  name: string;
7
7
  agent: AgentFunction<{
8
- template: string;
9
- }, string, string>;
8
+ template: any;
9
+ }, any, string>;
10
10
  mock: AgentFunction<{
11
- template: string;
12
- }, string, string>;
13
- samples: {
11
+ template: any;
12
+ }, any, string>;
13
+ samples: ({
14
14
  inputs: string[];
15
15
  params: {
16
16
  template: string;
17
17
  };
18
18
  result: string;
19
- }[];
19
+ } | {
20
+ inputs: string[];
21
+ params: {
22
+ template: string[];
23
+ };
24
+ result: string[];
25
+ } | {
26
+ inputs: string[];
27
+ params: {
28
+ template: {
29
+ apple: string;
30
+ lemon: string;
31
+ };
32
+ };
33
+ result: {
34
+ apple: string;
35
+ lemon: string;
36
+ };
37
+ } | {
38
+ inputs: string[];
39
+ params: {
40
+ template: {
41
+ apple: string;
42
+ lemon: string;
43
+ }[];
44
+ };
45
+ result: {
46
+ apple: string;
47
+ lemon: string;
48
+ }[];
49
+ } | {
50
+ inputs: string[];
51
+ params: {
52
+ template: {
53
+ apple: string;
54
+ lemon: string[];
55
+ };
56
+ };
57
+ result: {
58
+ apple: string;
59
+ lemon: string[];
60
+ };
61
+ })[];
20
62
  description: string;
21
63
  category: never[];
22
64
  author: string;
@@ -1,18 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stringTemplateAgent = void 0;
4
- // see example
5
- // tests/agents/test_string_agent.ts
4
+ const processTemplate = (template, match, input) => {
5
+ if (typeof template === "string") {
6
+ return template.replace(match, input);
7
+ }
8
+ else if (Array.isArray(template)) {
9
+ return template.map((item) => processTemplate(item, match, input));
10
+ }
11
+ return Object.keys(template).reduce((tmp, key) => {
12
+ tmp[key] = processTemplate(template[key], match, input);
13
+ return tmp;
14
+ }, {});
15
+ };
6
16
  const stringTemplateAgent = async ({ params, inputs }) => {
7
- const content = inputs.reduce((template, input, index) => {
8
- return template.replace("${" + index + "}", input);
17
+ return inputs.reduce((template, input, index) => {
18
+ return processTemplate(template, "${" + index + "}", input);
9
19
  }, params.template);
10
- return content;
11
20
  };
12
21
  exports.stringTemplateAgent = stringTemplateAgent;
13
22
  const sampleInput = ["hello", "test"];
14
- const sampleParams = { template: "${0}: ${1}" };
15
- const sampleResult = "hello: test";
16
23
  // for test and document
17
24
  const stringTemplateAgentInfo = {
18
25
  name: "stringTemplateAgent",
@@ -21,8 +28,28 @@ const stringTemplateAgentInfo = {
21
28
  samples: [
22
29
  {
23
30
  inputs: sampleInput,
24
- params: sampleParams,
25
- result: sampleResult,
31
+ params: { template: "${0}: ${1}" },
32
+ result: "hello: test",
33
+ },
34
+ {
35
+ inputs: sampleInput,
36
+ params: { template: ["${0}: ${1}", "${1}: ${0}"] },
37
+ result: ["hello: test", "test: hello"],
38
+ },
39
+ {
40
+ inputs: sampleInput,
41
+ params: { template: { apple: "${0}", lemon: "${1}" } },
42
+ result: { apple: "hello", lemon: "test" },
43
+ },
44
+ {
45
+ inputs: sampleInput,
46
+ params: { template: [{ apple: "${0}", lemon: "${1}" }] },
47
+ result: [{ apple: "hello", lemon: "test" }],
48
+ },
49
+ {
50
+ inputs: sampleInput,
51
+ params: { template: { apple: "${0}", lemon: ["${1}"] } },
52
+ result: { apple: "hello", lemon: ["test"] },
26
53
  },
27
54
  ],
28
55
  description: "Template agent",
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  import { AgentFunctionInfo } from "../../type";
3
3
  export declare const bypassAgent: AgentFunction<{
4
4
  flat?: number;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
1
+ import { AgentFunction } from "../../index";
2
2
  import { AgentFunctionInfo } from "../../type";
3
3
  export declare const copy2ArrayAgent: AgentFunction<{
4
4
  count: number;
@@ -1,5 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
2
- import { AgentFunctionInfo } from "../../type";
1
+ import { AgentFunction, AgentFunctionInfo } from "../../index";
3
2
  export declare const copyMessageAgent: AgentFunction<{
4
3
  count: number;
5
4
  message: string;
@@ -1,5 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
2
- import { AgentFunctionInfo } from "../../type";
1
+ import { AgentFunction, AgentFunctionInfo } from "../../index";
3
2
  export declare const countingAgent: AgentFunction<{
4
3
  count: number;
5
4
  }, {
@@ -1,5 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
2
- import { AgentFunctionInfo } from "../../type";
1
+ import { AgentFunction, AgentFunctionInfo } from "../../index";
3
2
  export declare const echoAgent: AgentFunction;
4
3
  declare const echoAgentInfo: AgentFunctionInfo;
5
4
  export default echoAgentInfo;
@@ -1,5 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
2
- import { AgentFunctionInfo } from "../../type";
1
+ import { AgentFunction, AgentFunctionInfo } from "../../index";
3
2
  export declare const mergeNodeIdAgent: AgentFunction;
4
3
  declare const mergeNodeIdAgentInfo: AgentFunctionInfo;
5
4
  export default mergeNodeIdAgentInfo;
@@ -1,5 +1,4 @@
1
- import { AgentFunction } from "../../graphai";
2
- import { AgentFunctionInfo } from "../../type";
1
+ import { AgentFunction, AgentFunctionInfo } from "../../index";
3
2
  export declare const streamMockAgent: AgentFunction;
4
3
  declare const streamMockAgentInfo: AgentFunctionInfo;
5
4
  export default streamMockAgentInfo;
@@ -1,4 +1,4 @@
1
- import { AgentFunction } from "../graphai";
1
+ import { AgentFunction } from "../index";
2
2
  export declare const tokenBoundStringsAgent: AgentFunction<{
3
3
  limit?: number;
4
4
  }, {
package/lib/graphai.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { AgentFunction, GraphData, AgentFunctionInfoDictonary } from "./type";
2
1
  import { AgentFunctionInfoDictonary, AgentFilterInfo, GraphData, DataSource, ResultDataDictonary, ResultData, DefaultResultData } from "./type";
3
2
  import { TransactionLog } from "./transaction_log";
4
3
  import { ComputedNode, StaticNode } from "./node";
@@ -45,3 +44,4 @@ export declare class GraphAI {
45
44
  injectValue(nodeId: string, value: ResultData, injectFrom?: string): void;
46
45
  resultsOf(sources: Array<DataSource>): ResultData[];
47
46
  }
47
+ export {};
package/lib/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { GraphAI } from "./graphai";
2
- export { GraphAI };
3
- export { AgentFunction, AgentFunctionInfoDictonary, GraphData, ResultDataDictonary, ResultData, NodeState } from "./type";
1
+ export { GraphAI } from "./graphai";
2
+ export { AgentFunction, AgentFunctionInfo, AgentFunctionInfoDictonary, GraphData, ResultDataDictonary, ResultData, NodeState, AgentFilterFunction, } from "./type";
4
3
  export type { TransactionLog } from "./transaction_log";
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NodeState = exports.GraphAI = void 0;
4
- const graphai_1 = require("./graphai");
4
+ var graphai_1 = require("./graphai");
5
5
  Object.defineProperty(exports, "GraphAI", { enumerable: true, get: function () { return graphai_1.GraphAI; } });
6
6
  var type_1 = require("./type");
7
7
  Object.defineProperty(exports, "NodeState", { enumerable: true, get: function () { return type_1.NodeState; } });
package/lib/node.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { GraphAI, GraphData } from "./graphai";
1
+ import type { GraphAI, GraphData } from "./index";
2
2
  import { NodeDataParams, ResultData, DataSource, ComputedNodeData, StaticNodeData, NodeState } from "./type";
3
3
  import { TransactionLog } from "./transaction_log";
4
4
  export declare class Node {
@@ -31,6 +31,7 @@ export declare class ComputedNode extends Node {
31
31
  dataSources: Array<DataSource>;
32
32
  pendings: Set<string>;
33
33
  private ifSource?;
34
+ private console;
34
35
  readonly isStaticNode = false;
35
36
  readonly isComputedNode = true;
36
37
  constructor(graphId: string, nodeId: string, data: ComputedNodeData, graph: GraphAI);
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.console = data.console ?? {};
41
42
  this.filterParams = data.filterParams ?? {};
42
43
  this.nestedGraph = data.graph;
43
44
  if (typeof data.agent === "string") {
@@ -229,7 +230,13 @@ class ComputedNode extends Node {
229
230
  context.graphData = this.nestedGraph;
230
231
  context.agents = this.graph.agentFunctionInfoDictionary;
231
232
  }
233
+ if (this.console.before) {
234
+ console.log(this.console.before === true ? JSON.stringify(context.inputs, null, 2) : this.console.before);
235
+ }
232
236
  const result = await this.agentFilterHandler(context, agentFunction);
237
+ if (this.console.after) {
238
+ console.log(this.console.after === true ? (typeof result === "string" ? result : JSON.stringify(result, null, 2)) : this.console.after);
239
+ }
233
240
  if (this.nestedGraph) {
234
241
  this.graph.taskManager.restoreAfterNesting();
235
242
  }
package/lib/type.d.ts CHANGED
@@ -40,6 +40,7 @@ export type ComputedNodeData = {
40
40
  graph?: GraphData;
41
41
  isResult?: boolean;
42
42
  priority?: number;
43
+ console?: Record<string, string | boolean>;
43
44
  };
44
45
  export type NodeData = StaticNodeData | ComputedNodeData;
45
46
  export type LoopData = {
@@ -1,2 +1,2 @@
1
- import { AgentFunctionInfoDictonary } from "../graphai";
1
+ import { AgentFunctionInfoDictonary } from "../index";
2
2
  export declare const defaultTestAgents: AgentFunctionInfoDictonary;
@@ -2,5 +2,18 @@
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", "filterParams"];
5
+ exports.computedNodeAttributeKeys = [
6
+ "inputs",
7
+ "anyInput",
8
+ "params",
9
+ "retry",
10
+ "timeout",
11
+ "agent",
12
+ "graph",
13
+ "isResult",
14
+ "priority",
15
+ "if",
16
+ "filterParams",
17
+ "console",
18
+ ];
6
19
  exports.staticNodeAttributeKeys = ["value", "update", "isResult"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphai",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Asynchronous data flow execution engine for agentic AI apps.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -9,6 +9,7 @@
9
9
  "scripts": {
10
10
  "build": "rm -r lib/* && tsc && tsc-alias",
11
11
  "eslint": "eslint",
12
+ "apiDoc": " npx typedoc src/index.ts --out apiDoc",
12
13
  "format": "prettier --write '{src,tests,samples}/**/*.ts'",
13
14
  "test": "node --test -r tsconfig-paths/register --require ts-node/register ./tests/**/test_*.ts",
14
15
  "http_test": "node --test -r tsconfig-paths/register --require ts-node/register ./tests/**/http_*.ts",
@@ -57,5 +58,8 @@
57
58
  "directories": {
58
59
  "lib": "lib",
59
60
  "test": "tests"
61
+ },
62
+ "dependencies": {
63
+ "typedoc": "^0.25.13"
60
64
  }
61
65
  }