@graphai/agent_generator 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # graphai agent generator
2
+
3
+ This tool is a graphai application in which the user writes a simple specification, and based on that specification, AI fully automates the creation of a graphai agent.
4
+
5
+ ## update spec
6
+
7
+ edit template/spec.md
8
+
9
+ # set openai key
10
+
11
+ edit .env and set OPENAI_API_KEY=sk-....
12
+
13
+ ## run
14
+
15
+ ```
16
+ yarn run run
17
+ ```
18
+
19
+ ## then
20
+
21
+ generate agent in tmp directory
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import templateAgent from "./template_agent";
2
+ export { templateAgent };
package/lib/index.js ADDED
@@ -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.templateAgent = void 0;
7
+ const template_agent_1 = __importDefault(require("./template_agent"));
8
+ exports.templateAgent = template_agent_1.default;
package/lib/run.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/run.js ADDED
@@ -0,0 +1,376 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ //仕様と必要な情報(npmやデータ)をテキストで用意する
40
+ // generatorを呼び出してスケルトンを作る
41
+ // agentの中身を実装する
42
+ // unit testを動かす -> 失敗したら結果やエラーを元に3を再実装
43
+ // できたら、documentもつくる
44
+ const path = __importStar(require("node:path"));
45
+ const graphai_1 = require("graphai");
46
+ const openai_agent_1 = require("@graphai/openai_agent");
47
+ const vanilla_1 = require("@graphai/vanilla");
48
+ const vanilla_node_agents_1 = require("@graphai/vanilla_node_agents");
49
+ const shell_utilty_agent_1 = require("@graphai/shell_utilty_agent");
50
+ const dotenv_1 = __importDefault(require("dotenv"));
51
+ dotenv_1.default.config({ quiet: true });
52
+ const tools = [
53
+ {
54
+ type: "function",
55
+ function: {
56
+ name: "generate_package",
57
+ description: "generate agent skelton",
58
+ parameters: {
59
+ type: "object",
60
+ properties: {
61
+ agentName: {
62
+ type: "string",
63
+ description: "The agent name. Separate words with spaces.",
64
+ },
65
+ description: {
66
+ type: "string",
67
+ description: "Explain what the agent does",
68
+ },
69
+ category: {
70
+ type: "string",
71
+ description: "category of the agent.",
72
+ },
73
+ npmPackages: {
74
+ type: "string",
75
+ description: "list of npm package if you need. Separate packages with spaces. ",
76
+ },
77
+ },
78
+ required: ["agentName", "description", "category"],
79
+ },
80
+ },
81
+ },
82
+ ];
83
+ /*
84
+ const tools_npminstall = [
85
+ {
86
+ type: "function",
87
+ function: {
88
+ name: "installNpm",
89
+ description: "install npm package",
90
+ parameters: {
91
+ type: "object",
92
+ properties: {
93
+ npmPackages: {
94
+ type: "string",
95
+ description: "list of npm package if you need. Separate packages with spaces. ",
96
+ },
97
+ },
98
+ required: ["npmPackages"],
99
+ },
100
+ },
101
+ },
102
+ ];
103
+ */
104
+ const main = async () => {
105
+ const graphData = {
106
+ version: 0.5,
107
+ nodes: {
108
+ packageBaseDir: {
109
+ value: "",
110
+ },
111
+ templateBaseDir: {
112
+ value: "",
113
+ },
114
+ specPrompt: {
115
+ value: "",
116
+ },
117
+ implementPrompt: {
118
+ value: "",
119
+ },
120
+ errorPrompt: {
121
+ value: "",
122
+ },
123
+ specFileReader: {
124
+ agent: "fileReadAgent",
125
+ inputs: {
126
+ array: ["template/spec.md", "template/spec_base.md"],
127
+ },
128
+ params: {
129
+ baseDir: ":templateBaseDir",
130
+ outputType: "text",
131
+ },
132
+ console: { after: true },
133
+ isResult: true,
134
+ },
135
+ specFile: {
136
+ agent: "copyAgent",
137
+ inputs: { data: "${:specFileReader.array.$0}\n\n${:specFileReader.array.$1}" },
138
+ isResult: true,
139
+ },
140
+ specLLM: {
141
+ agent: "openAIAgent",
142
+ inputs: {
143
+ prompt: "${:specPrompt}\n\n ${:specFile.data}",
144
+ tools,
145
+ },
146
+ console: { after: true },
147
+ },
148
+ packageInfo: {
149
+ agent: "stringCaseVariantsAgent",
150
+ params: {
151
+ suffix: "agent",
152
+ },
153
+ inputs: {
154
+ text: ":specLLM.tool.arguments.agentName",
155
+ },
156
+ isResult: true,
157
+ },
158
+ createSkeleton: {
159
+ agent: "runShellAgent",
160
+ inputs: {
161
+ commands: [
162
+ "npm",
163
+ "create",
164
+ "graphai-agent@latest",
165
+ "--",
166
+ "-c",
167
+ "--agentName",
168
+ ":packageInfo.kebabCase",
169
+ "--description",
170
+ ":specLLM.tool.arguments.description",
171
+ "--author",
172
+ "me",
173
+ "--license",
174
+ "MIT",
175
+ "--category",
176
+ ":specLLM.tool.arguments.category",
177
+ "--outdir",
178
+ ":packageBaseDir",
179
+ ],
180
+ baseDir: ":packageBaseDir",
181
+ },
182
+ },
183
+ yarnInstall: {
184
+ agent: "runShellAgent",
185
+ params: {},
186
+ inputs: {
187
+ commands: ["yarn", "install"],
188
+ dirs: [":packageBaseDir", ":packageInfo.kebabCase"],
189
+ waiting: ":createSkeleton",
190
+ },
191
+ },
192
+ packageDir: {
193
+ agent: "copyAgent",
194
+ inputs: {
195
+ text: "${:packageBaseDir}/${:packageInfo.kebabCase}",
196
+ },
197
+ },
198
+ yarnAdd: {
199
+ agent: "runShellAgent",
200
+ if: ":specLLM.tool.arguments.npmPackages",
201
+ defaultValue: {},
202
+ inputs: {
203
+ commands: ["yarn", "add", "${:specLLM.tool.arguments.npmPackages}"],
204
+ baseDir: ":packageDir.text",
205
+ wait: ":yarnInstall",
206
+ },
207
+ },
208
+ srcFile: {
209
+ agent: "pathUtilsAgent",
210
+ params: { method: "join" },
211
+ inputs: { dirs: [":packageInfo.kebabCase", "src", "${:packageInfo.snakeCase}.ts"] },
212
+ },
213
+ programmer: {
214
+ agent: "nestedAgent",
215
+ isResult: true,
216
+ inputs: {
217
+ waiting: ":yarnAdd",
218
+ packageInfo: ":packageInfo",
219
+ srcFile: ":srcFile",
220
+ specFile: ":specFile",
221
+ packageBaseDir: ":packageBaseDir",
222
+ implementPrompt: ":implementPrompt",
223
+ errorPrompt: ":errorPrompt",
224
+ npmPackages: [":specLLM.tool.arguments.npmPackages"],
225
+ },
226
+ graph: {
227
+ loop: {
228
+ while: ":yarnTest.error",
229
+ },
230
+ nodes: {
231
+ npmPackages: {
232
+ update: ":npmPackagesStack.array",
233
+ },
234
+ error: {
235
+ value: "",
236
+ update: ":yarnTest.stdout",
237
+ },
238
+ sourceFile: {
239
+ agent: "fileReadAgent",
240
+ inputs: {
241
+ file: ":srcFile.path",
242
+ },
243
+ params: {
244
+ baseDir: ":packageBaseDir",
245
+ outputType: "text",
246
+ },
247
+ },
248
+ llm: {
249
+ agent: "openAIAgent",
250
+ inputs: {
251
+ system: ":specFile.data",
252
+ prompt: "${:implementPrompt}\n\n###ソース###\n\n${:sourceFile.data}\n\n\n###npmは以下が追加さています###\n${:npmPackages.join(,)}\n\n###${:errorPrompt}###\n\n${:error}",
253
+ // model: "o1-mini",
254
+ // tools: tools_npminstall,
255
+ },
256
+ console: { before: true, after: true },
257
+ },
258
+ yarnAdd: {
259
+ agent: "runShellAgent",
260
+ if: ":llm.tool.arguments.npmPackages",
261
+ inputs: {
262
+ command: ["yarn", "add", "${:llm.tool.arguments.npmPackages}"],
263
+ dirs: [":packageBaseDir", ":packageInfo.kebabCase"],
264
+ },
265
+ defaultValue: {},
266
+ },
267
+ res: {
268
+ agent: "copyAgent",
269
+ inputs: {
270
+ text: ":llm.text.codeBlock()",
271
+ },
272
+ isResult: true,
273
+ },
274
+ writeFile: {
275
+ if: ":res.text",
276
+ defaultValue: {},
277
+ agent: "fileWriteAgent",
278
+ inputs: {
279
+ file: ":srcFile.path",
280
+ text: ":llm.text.codeBlock()",
281
+ },
282
+ params: {
283
+ baseDir: ":packageBaseDir",
284
+ },
285
+ console: {
286
+ before: true,
287
+ },
288
+ },
289
+ yarnTest: {
290
+ agent: "runShellAgent",
291
+ params: {},
292
+ inputs: {
293
+ commands: ["yarn", "run", "test"],
294
+ waiting: ":writeFile",
295
+ dirs: [":packageBaseDir", ":packageInfo.kebabCase"],
296
+ },
297
+ console: {
298
+ after: true,
299
+ },
300
+ },
301
+ npmPackagesStack: {
302
+ agent: "pushAgent",
303
+ inputs: {
304
+ array: ":npmPackages",
305
+ items: [":llm.tool.arguments.npmPackages"],
306
+ },
307
+ console: {
308
+ after: true,
309
+ },
310
+ },
311
+ /*
312
+ isLoop: {
313
+ agent: "copyAgent",
314
+ inputs: { array: [":yarnTest.error", ":yarnAdd"]}
315
+ },
316
+ */
317
+ },
318
+ },
319
+ },
320
+ final: {
321
+ agent: "runShellAgent",
322
+ params: {},
323
+ inputs: {
324
+ commands: ["yarn", "run", "build"], // , "&&", "yarn", "run", "doc"
325
+ dirs: [":packageBaseDir", ":packageInfo.kebabCase"],
326
+ waiting: ":programmer",
327
+ },
328
+ },
329
+ final2: {
330
+ agent: "runShellAgent",
331
+ params: {},
332
+ inputs: {
333
+ commands: ["yarn", "run", "doc"],
334
+ dirs: [":packageBaseDir", ":packageInfo.kebabCase"],
335
+ waiting: ":programmer",
336
+ },
337
+ },
338
+ /*
339
+ writeSpec: {
340
+ agent: "fileWriteAgent",
341
+ inputs: {
342
+ file: "spec.txt",
343
+ waiting: ":programmer",
344
+ text: ":specFileReader.array.$0",
345
+ },
346
+ params: {
347
+ baseDir: "${:packageBaseDir}/${:packageInfo.kebabCase}",
348
+ outputType: "text",
349
+ },
350
+ },
351
+ */
352
+ },
353
+ };
354
+ const graph = new graphai_1.GraphAI(graphData, {
355
+ openAIAgent: openai_agent_1.openAIAgent,
356
+ copyAgent: vanilla_1.copyAgent,
357
+ pushAgent: vanilla_1.pushAgent,
358
+ fileReadAgent: vanilla_node_agents_1.fileReadAgent,
359
+ fileWriteAgent: vanilla_node_agents_1.fileWriteAgent,
360
+ nestedAgent: vanilla_1.nestedAgent,
361
+ runShellAgent: shell_utilty_agent_1.runShellAgent,
362
+ stringCaseVariantsAgent: vanilla_1.stringCaseVariantsAgent,
363
+ pathUtilsAgent: vanilla_node_agents_1.pathUtilsAgent,
364
+ });
365
+ graph.injectValue("templateBaseDir", path.resolve(__dirname, ".."));
366
+ // graph.injectValue("packageBaseDir", "/Users/isamu/ss/llm/ai-generated-graphai-agents");
367
+ graph.injectValue("packageBaseDir", path.resolve(__dirname, "..", "tmp"));
368
+ graph.injectValue("specPrompt", "以下の仕様を元に必要な情報を教えて下さい。結果はgenerate_packageで返してください。npmパッケージが必要な場合はそれも一覧で返してください。");
369
+ graph.injectValue("packageBaseDir", path.resolve(__dirname, "..", "tmp"));
370
+ graph.injectValue("specPrompt", "以下の仕様を元に必要な情報を教えて下さい。結果はgenerate_packageで返してください。npmパッケージが必要な場合はそれも一覧で返してください。");
371
+ graph.injectValue("implementPrompt", "以下のソースを仕様に従って変更して");
372
+ graph.injectValue("errorPrompt", "エラー情報");
373
+ const result = (await graph.run());
374
+ console.log(result);
375
+ };
376
+ main();
package/lib/run2.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/run2.js ADDED
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ // import * as path from "node:path";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const graphai_1 = require("graphai");
8
+ const openai_agent_1 = require("@graphai/openai_agent");
9
+ const vanilla_1 = require("@graphai/vanilla");
10
+ const vanilla_node_agents_1 = require("@graphai/vanilla_node_agents");
11
+ const shell_utilty_agent_1 = require("@graphai/shell_utilty_agent");
12
+ const dotenv_1 = __importDefault(require("dotenv"));
13
+ dotenv_1.default.config({ quiet: true });
14
+ const tools = [
15
+ {
16
+ type: "function",
17
+ function: {
18
+ name: "searchNpm",
19
+ description: "searchNpm",
20
+ parameters: {
21
+ type: "object",
22
+ properties: {
23
+ keywords: {
24
+ type: "string",
25
+ description: "Consists of letters and numbers, with a space if more than one",
26
+ },
27
+ },
28
+ required: ["keywords"],
29
+ },
30
+ },
31
+ },
32
+ ];
33
+ const tools2 = [
34
+ {
35
+ type: "function",
36
+ function: {
37
+ name: "choiseNpmPackageName",
38
+ description: "choice npm package",
39
+ parameters: {
40
+ type: "object",
41
+ properties: {
42
+ packageName: {
43
+ type: "string",
44
+ description: "npm package name",
45
+ },
46
+ },
47
+ required: ["keywords"],
48
+ },
49
+ },
50
+ },
51
+ ];
52
+ const main = async () => {
53
+ const graphData = {
54
+ version: 0.5,
55
+ nodes: {
56
+ prompt: {
57
+ // value: "s3のクライアントを作りたいです。",
58
+ value: "税務計算のソフトを作りたいです。",
59
+ },
60
+ npmKeywords: {
61
+ agent: "openAIAgent",
62
+ inputs: {
63
+ prompt: "${:prompt} 必要なnpmを探すので検索を",
64
+ tools,
65
+ },
66
+ console: { after: true },
67
+ },
68
+ search: {
69
+ agent: "runShellAgent",
70
+ params: {},
71
+ inputs: {
72
+ command: "npm search ${:npmKeywords.tool.arguments.keywords}",
73
+ },
74
+ console: { after: true },
75
+ },
76
+ choiceNpm: {
77
+ agent: "openAIAgent",
78
+ inputs: {
79
+ system: "${:prompt}推奨するnpmのパッケージをえらんでください。選んだらchoiseNpmPackageNameの関数をtoolsで返して",
80
+ prompt: "${:search.text}",
81
+ tools: tools2,
82
+ },
83
+ console: { after: true },
84
+ },
85
+ },
86
+ };
87
+ const graph = new graphai_1.GraphAI(graphData, {
88
+ openAIAgent: openai_agent_1.openAIAgent,
89
+ copyAgent: vanilla_1.copyAgent,
90
+ fileReadAgent: vanilla_node_agents_1.fileReadAgent,
91
+ fileWriteAgent: vanilla_node_agents_1.fileWriteAgent,
92
+ nestedAgent: vanilla_1.nestedAgent,
93
+ runShellAgent: shell_utilty_agent_1.runShellAgent,
94
+ stringCaseVariantsAgent: vanilla_1.stringCaseVariantsAgent,
95
+ pathUtilsAgent: vanilla_node_agents_1.pathUtilsAgent,
96
+ });
97
+ const result = (await graph.run());
98
+ console.log(result);
99
+ };
100
+ main();
@@ -0,0 +1,4 @@
1
+ import { AgentFunction, AgentFunctionInfo } from "graphai";
2
+ export declare const templateAgent: AgentFunction;
3
+ declare const templateAgentInfo: AgentFunctionInfo;
4
+ export default templateAgentInfo;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.templateAgent = void 0;
4
+ const templateAgent = async ({ params, namedInputs }) => {
5
+ return { params, namedInputs };
6
+ };
7
+ exports.templateAgent = templateAgent;
8
+ const templateAgentInfo = {
9
+ name: "templateAgent",
10
+ agent: exports.templateAgent,
11
+ mock: exports.templateAgent,
12
+ samples: [],
13
+ description: "Template Agent",
14
+ category: ["template"],
15
+ author: "Receptron team",
16
+ repository: "https://github.com/receptron/graphai",
17
+ license: "MIT",
18
+ };
19
+ exports.default = templateAgentInfo;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@graphai/agent_generator",
3
+ "version": "0.0.2",
4
+ "description": "",
5
+ "main": "lib/index.js",
6
+ "files": [
7
+ "./lib"
8
+ ],
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "eslint": "eslint src --fix",
12
+ "format": "prettier --write '{src,tests}/**/*.ts'",
13
+ "doc": "echo hello",
14
+ "run": "npx ts-node src/run.ts",
15
+ "run2": "npx ts-node src/run2.ts",
16
+ "test_run": "node --test --require ts-node/register ./tests/run_*.ts",
17
+ "test": "echo hello",
18
+ "ci": "yarn run format && yarn run eslint && yarn run test && yarn run build"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/receptron/graphai-agents.git"
23
+ },
24
+ "author": "",
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/receptron/graphai-agents/issues"
28
+ },
29
+ "homepage": "https://github.com/receptron/graphai-agents#readme",
30
+ "devDependencies": {},
31
+ "dependencies": {
32
+ "@graphai/openai_agent": "^2.0.9",
33
+ "@graphai/shell_utilty_agent": "^0.1.0",
34
+ "@graphai/vanilla": "^2.0.12",
35
+ "@graphai/vanilla_node_agents": "^2.0.4",
36
+ "graphai": "^2.0.16"
37
+ }
38
+ }