@librechat/agents 1.5.6 → 1.5.8
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/dist/cjs/tools/CodeExecutor.cjs +10 -2
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +10 -2
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/types/scripts/code_exec_simple.d.ts +1 -0
- package/package.json +2 -1
- package/src/scripts/code_exec.ts +1 -1
- package/src/scripts/code_exec_simple.ts +113 -0
- package/src/tools/CodeExecutor.ts +10 -2
|
@@ -55,8 +55,12 @@ function createCodeExecutionTool(params = {}) {
|
|
|
55
55
|
}
|
|
56
56
|
const result = await response.json();
|
|
57
57
|
let formattedOutput = '';
|
|
58
|
-
if (result.stdout)
|
|
58
|
+
if (result.stdout) {
|
|
59
59
|
formattedOutput += `stdout:\n${result.stdout}\n`;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
formattedOutput += 'stdout: Empty. To output values, write explicitly to stdout.\n';
|
|
63
|
+
}
|
|
60
64
|
if (result.stderr)
|
|
61
65
|
formattedOutput += `stderr:\n${result.stderr}\n`;
|
|
62
66
|
if (result.files && result.files.length > 0) {
|
|
@@ -77,7 +81,11 @@ function createCodeExecutionTool(params = {}) {
|
|
|
77
81
|
}
|
|
78
82
|
}, {
|
|
79
83
|
name: 'execute_code',
|
|
80
|
-
description:
|
|
84
|
+
description: `Executes code in various programming languages, returning stdout/stderr output.
|
|
85
|
+
|
|
86
|
+
# Usage
|
|
87
|
+
- Input code is automatically displayed to the user, so don't repeat it in your response unless asked.
|
|
88
|
+
- All desired output must be explicitly written to stdout.`,
|
|
81
89
|
schema: CodeExecutionToolSchema,
|
|
82
90
|
responseFormat: 'content_and_artifact',
|
|
83
91
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeExecutor.cjs","sources":["../../../src/tools/CodeExecutor.ts"],"sourcesContent":["import { z } from 'zod';\nimport { config } from 'dotenv';\nimport { tool, DynamicStructuredTool } from '@langchain/core/tools';\nimport { getEnvironmentVariable } from '@langchain/core/utils/env';\n\nconfig();\n\nconst EXEC_ENDPOINT = 'https://api.librechat.ai/exec';\n\nexport type CodeExecutionToolParams = undefined | {\n session_id?: string;\n user_id?: string;\n apiKey?: string;\n LIBRECHAT_CODE_API_KEY?: string;\n}\n\nexport type FileRef = {\n id: string;\n name: string;\n path?: string;\n};\n\nexport type FileRefs = FileRef[];\n\nexport type ExecuteResult = {\n session_id: string;\n stdout: string;\n stderr: string;\n files?: FileRefs;\n};\n\nconst CodeExecutionToolSchema = z.object({\n lang: z.enum([\n 'py',\n 'js',\n 'ts',\n 'c',\n 'cpp',\n 'java',\n 'php',\n 'rs',\n 'go',\n 'bash',\n 'd',\n 'f90',\n ])\n .describe('The programming language or runtime to execute the code in.'),\n code: z.string()\n .describe('The complete, self-contained code to execute, without any truncation or minimization.'),\n args: z.array(z.string()).optional()\n .describe('Additional arguments to execute the code with.'),\n});\n\nfunction createCodeExecutionTool(params: CodeExecutionToolParams = {}): DynamicStructuredTool<typeof CodeExecutionToolSchema> {\n const apiKey = params.LIBRECHAT_CODE_API_KEY ?? params.apiKey ?? getEnvironmentVariable('LIBRECHAT_CODE_API_KEY') ?? '';\n if (!apiKey) {\n throw new Error('No API key provided for code execution tool.');\n }\n return tool<typeof CodeExecutionToolSchema>(\n async ({ lang, code, ...rest }) => {\n const postData = {\n lang,\n code,\n ...rest,\n ...params,\n };\n\n try {\n const response = await fetch(EXEC_ENDPOINT, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'User-Agent': 'LibreChat/1.0',\n 'X-API-Key': apiKey,\n },\n body: JSON.stringify(postData),\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const result: ExecuteResult = await response.json();\n let formattedOutput = '';\n if (result.stdout) formattedOutput += `stdout:\\n${result.stdout}\\n`;\n if (result.stderr) formattedOutput += `stderr:\\n${result.stderr}\\n`;\n if (result.files && result.files.length > 0) {\n formattedOutput += 'Generated files:\\n';\n result.files.forEach((file: FileRef) => {\n formattedOutput += `${file.name}`;\n });\n return [formattedOutput.trim(), result.files];\n }\n\n return [formattedOutput.trim(), undefined];\n } catch (error) {\n return `Calling tool with arguments:\\n\\n${JSON.stringify({\n lang,\n code,\n ...rest,\n })}\\n\\nraised the following error:\\n\\n${(error as Error | undefined)?.message}`;\n }\n },\n {\n name: 'execute_code',\n description:
|
|
1
|
+
{"version":3,"file":"CodeExecutor.cjs","sources":["../../../src/tools/CodeExecutor.ts"],"sourcesContent":["import { z } from 'zod';\nimport { config } from 'dotenv';\nimport { tool, DynamicStructuredTool } from '@langchain/core/tools';\nimport { getEnvironmentVariable } from '@langchain/core/utils/env';\n\nconfig();\n\nconst EXEC_ENDPOINT = 'https://api.librechat.ai/exec';\n\nexport type CodeExecutionToolParams = undefined | {\n session_id?: string;\n user_id?: string;\n apiKey?: string;\n LIBRECHAT_CODE_API_KEY?: string;\n}\n\nexport type FileRef = {\n id: string;\n name: string;\n path?: string;\n};\n\nexport type FileRefs = FileRef[];\n\nexport type ExecuteResult = {\n session_id: string;\n stdout: string;\n stderr: string;\n files?: FileRefs;\n};\n\nconst CodeExecutionToolSchema = z.object({\n lang: z.enum([\n 'py',\n 'js',\n 'ts',\n 'c',\n 'cpp',\n 'java',\n 'php',\n 'rs',\n 'go',\n 'bash',\n 'd',\n 'f90',\n ])\n .describe('The programming language or runtime to execute the code in.'),\n code: z.string()\n .describe('The complete, self-contained code to execute, without any truncation or minimization.'),\n args: z.array(z.string()).optional()\n .describe('Additional arguments to execute the code with.'),\n});\n\nfunction createCodeExecutionTool(params: CodeExecutionToolParams = {}): DynamicStructuredTool<typeof CodeExecutionToolSchema> {\n const apiKey = params.LIBRECHAT_CODE_API_KEY ?? params.apiKey ?? getEnvironmentVariable('LIBRECHAT_CODE_API_KEY') ?? '';\n if (!apiKey) {\n throw new Error('No API key provided for code execution tool.');\n }\n return tool<typeof CodeExecutionToolSchema>(\n async ({ lang, code, ...rest }) => {\n const postData = {\n lang,\n code,\n ...rest,\n ...params,\n };\n\n try {\n const response = await fetch(EXEC_ENDPOINT, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'User-Agent': 'LibreChat/1.0',\n 'X-API-Key': apiKey,\n },\n body: JSON.stringify(postData),\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const result: ExecuteResult = await response.json();\n let formattedOutput = '';\n if (result.stdout) {\n formattedOutput += `stdout:\\n${result.stdout}\\n`;\n } else {\n formattedOutput += 'stdout: Empty. To output values, write explicitly to stdout.\\n';\n }\n if (result.stderr) formattedOutput += `stderr:\\n${result.stderr}\\n`;\n if (result.files && result.files.length > 0) {\n formattedOutput += 'Generated files:\\n';\n result.files.forEach((file: FileRef) => {\n formattedOutput += `${file.name}`;\n });\n return [formattedOutput.trim(), result.files];\n }\n\n return [formattedOutput.trim(), undefined];\n } catch (error) {\n return `Calling tool with arguments:\\n\\n${JSON.stringify({\n lang,\n code,\n ...rest,\n })}\\n\\nraised the following error:\\n\\n${(error as Error | undefined)?.message}`;\n }\n },\n {\n name: 'execute_code',\n description: `Executes code in various programming languages, returning stdout/stderr output.\n\n# Usage\n- Input code is automatically displayed to the user, so don't repeat it in your response unless asked.\n- All desired output must be explicitly written to stdout.`,\n schema: CodeExecutionToolSchema,\n responseFormat: 'content_and_artifact',\n }\n );\n}\n\nexport { createCodeExecutionTool };"],"names":["config","z","getEnvironmentVariable","tool"],"mappings":";;;;;;;AAKAA,aAAM,EAAE,CAAC;AAET,MAAM,aAAa,GAAG,+BAA+B,CAAC;AAwBtD,MAAM,uBAAuB,GAAGC,KAAC,CAAC,MAAM,CAAC;AACvC,IAAA,IAAI,EAAEA,KAAC,CAAC,IAAI,CAAC;QACX,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,KAAK;QACL,MAA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C/B,QAAA,cAAc,EAAE,sBAAsB;AACvC,KAAA,CACF,CAAC;AACJ;;;;"}
|
|
@@ -53,8 +53,12 @@ function createCodeExecutionTool(params = {}) {
|
|
|
53
53
|
}
|
|
54
54
|
const result = await response.json();
|
|
55
55
|
let formattedOutput = '';
|
|
56
|
-
if (result.stdout)
|
|
56
|
+
if (result.stdout) {
|
|
57
57
|
formattedOutput += `stdout:\n${result.stdout}\n`;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
formattedOutput += 'stdout: Empty. To output values, write explicitly to stdout.\n';
|
|
61
|
+
}
|
|
58
62
|
if (result.stderr)
|
|
59
63
|
formattedOutput += `stderr:\n${result.stderr}\n`;
|
|
60
64
|
if (result.files && result.files.length > 0) {
|
|
@@ -75,7 +79,11 @@ function createCodeExecutionTool(params = {}) {
|
|
|
75
79
|
}
|
|
76
80
|
}, {
|
|
77
81
|
name: 'execute_code',
|
|
78
|
-
description:
|
|
82
|
+
description: `Executes code in various programming languages, returning stdout/stderr output.
|
|
83
|
+
|
|
84
|
+
# Usage
|
|
85
|
+
- Input code is automatically displayed to the user, so don't repeat it in your response unless asked.
|
|
86
|
+
- All desired output must be explicitly written to stdout.`,
|
|
79
87
|
schema: CodeExecutionToolSchema,
|
|
80
88
|
responseFormat: 'content_and_artifact',
|
|
81
89
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeExecutor.mjs","sources":["../../../src/tools/CodeExecutor.ts"],"sourcesContent":["import { z } from 'zod';\nimport { config } from 'dotenv';\nimport { tool, DynamicStructuredTool } from '@langchain/core/tools';\nimport { getEnvironmentVariable } from '@langchain/core/utils/env';\n\nconfig();\n\nconst EXEC_ENDPOINT = 'https://api.librechat.ai/exec';\n\nexport type CodeExecutionToolParams = undefined | {\n session_id?: string;\n user_id?: string;\n apiKey?: string;\n LIBRECHAT_CODE_API_KEY?: string;\n}\n\nexport type FileRef = {\n id: string;\n name: string;\n path?: string;\n};\n\nexport type FileRefs = FileRef[];\n\nexport type ExecuteResult = {\n session_id: string;\n stdout: string;\n stderr: string;\n files?: FileRefs;\n};\n\nconst CodeExecutionToolSchema = z.object({\n lang: z.enum([\n 'py',\n 'js',\n 'ts',\n 'c',\n 'cpp',\n 'java',\n 'php',\n 'rs',\n 'go',\n 'bash',\n 'd',\n 'f90',\n ])\n .describe('The programming language or runtime to execute the code in.'),\n code: z.string()\n .describe('The complete, self-contained code to execute, without any truncation or minimization.'),\n args: z.array(z.string()).optional()\n .describe('Additional arguments to execute the code with.'),\n});\n\nfunction createCodeExecutionTool(params: CodeExecutionToolParams = {}): DynamicStructuredTool<typeof CodeExecutionToolSchema> {\n const apiKey = params.LIBRECHAT_CODE_API_KEY ?? params.apiKey ?? getEnvironmentVariable('LIBRECHAT_CODE_API_KEY') ?? '';\n if (!apiKey) {\n throw new Error('No API key provided for code execution tool.');\n }\n return tool<typeof CodeExecutionToolSchema>(\n async ({ lang, code, ...rest }) => {\n const postData = {\n lang,\n code,\n ...rest,\n ...params,\n };\n\n try {\n const response = await fetch(EXEC_ENDPOINT, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'User-Agent': 'LibreChat/1.0',\n 'X-API-Key': apiKey,\n },\n body: JSON.stringify(postData),\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const result: ExecuteResult = await response.json();\n let formattedOutput = '';\n if (result.stdout) formattedOutput += `stdout:\\n${result.stdout}\\n`;\n if (result.stderr) formattedOutput += `stderr:\\n${result.stderr}\\n`;\n if (result.files && result.files.length > 0) {\n formattedOutput += 'Generated files:\\n';\n result.files.forEach((file: FileRef) => {\n formattedOutput += `${file.name}`;\n });\n return [formattedOutput.trim(), result.files];\n }\n\n return [formattedOutput.trim(), undefined];\n } catch (error) {\n return `Calling tool with arguments:\\n\\n${JSON.stringify({\n lang,\n code,\n ...rest,\n })}\\n\\nraised the following error:\\n\\n${(error as Error | undefined)?.message}`;\n }\n },\n {\n name: 'execute_code',\n description:
|
|
1
|
+
{"version":3,"file":"CodeExecutor.mjs","sources":["../../../src/tools/CodeExecutor.ts"],"sourcesContent":["import { z } from 'zod';\nimport { config } from 'dotenv';\nimport { tool, DynamicStructuredTool } from '@langchain/core/tools';\nimport { getEnvironmentVariable } from '@langchain/core/utils/env';\n\nconfig();\n\nconst EXEC_ENDPOINT = 'https://api.librechat.ai/exec';\n\nexport type CodeExecutionToolParams = undefined | {\n session_id?: string;\n user_id?: string;\n apiKey?: string;\n LIBRECHAT_CODE_API_KEY?: string;\n}\n\nexport type FileRef = {\n id: string;\n name: string;\n path?: string;\n};\n\nexport type FileRefs = FileRef[];\n\nexport type ExecuteResult = {\n session_id: string;\n stdout: string;\n stderr: string;\n files?: FileRefs;\n};\n\nconst CodeExecutionToolSchema = z.object({\n lang: z.enum([\n 'py',\n 'js',\n 'ts',\n 'c',\n 'cpp',\n 'java',\n 'php',\n 'rs',\n 'go',\n 'bash',\n 'd',\n 'f90',\n ])\n .describe('The programming language or runtime to execute the code in.'),\n code: z.string()\n .describe('The complete, self-contained code to execute, without any truncation or minimization.'),\n args: z.array(z.string()).optional()\n .describe('Additional arguments to execute the code with.'),\n});\n\nfunction createCodeExecutionTool(params: CodeExecutionToolParams = {}): DynamicStructuredTool<typeof CodeExecutionToolSchema> {\n const apiKey = params.LIBRECHAT_CODE_API_KEY ?? params.apiKey ?? getEnvironmentVariable('LIBRECHAT_CODE_API_KEY') ?? '';\n if (!apiKey) {\n throw new Error('No API key provided for code execution tool.');\n }\n return tool<typeof CodeExecutionToolSchema>(\n async ({ lang, code, ...rest }) => {\n const postData = {\n lang,\n code,\n ...rest,\n ...params,\n };\n\n try {\n const response = await fetch(EXEC_ENDPOINT, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'User-Agent': 'LibreChat/1.0',\n 'X-API-Key': apiKey,\n },\n body: JSON.stringify(postData),\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const result: ExecuteResult = await response.json();\n let formattedOutput = '';\n if (result.stdout) {\n formattedOutput += `stdout:\\n${result.stdout}\\n`;\n } else {\n formattedOutput += 'stdout: Empty. To output values, write explicitly to stdout.\\n';\n }\n if (result.stderr) formattedOutput += `stderr:\\n${result.stderr}\\n`;\n if (result.files && result.files.length > 0) {\n formattedOutput += 'Generated files:\\n';\n result.files.forEach((file: FileRef) => {\n formattedOutput += `${file.name}`;\n });\n return [formattedOutput.trim(), result.files];\n }\n\n return [formattedOutput.trim(), undefined];\n } catch (error) {\n return `Calling tool with arguments:\\n\\n${JSON.stringify({\n lang,\n code,\n ...rest,\n })}\\n\\nraised the following error:\\n\\n${(error as Error | undefined)?.message}`;\n }\n },\n {\n name: 'execute_code',\n description: `Executes code in various programming languages, returning stdout/stderr output.\n\n# Usage\n- Input code is automatically displayed to the user, so don't repeat it in your response unless asked.\n- All desired output must be explicitly written to stdout.`,\n schema: CodeExecutionToolSchema,\n responseFormat: 'content_and_artifact',\n }\n );\n}\n\nexport { createCodeExecutionTool };"],"names":[],"mappings":";;;;;AAKA,MAAM,EAAE,CAAC;AAET,MAAM,aAAa,GAAG,+BAA+B,CAAC;AAwBtD,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;AACvC,IAAA,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;QACX,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,KAAK;QACL,MAAM;QACN,KAAK;QACL,IAAI;QACJ,IAAI;QACJ,MAAM;QACN,GAAG;QACH,KAAK;KACN,CAAC;SACC,QAAQ,CAAC,6DAA6D,CAAC;AAC1E,IAAA,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;SACb,QAAQ,CAAC,uFAAuF,CAAC;AACpG,IAAA,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;SACjC,QAAQ,CAAC,gDAAgD,CAAC;AAC9D,CAAA,CAAC,CAAC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AI,MAAM,CAAC,MAAM;AAAE,gBAAA,eAAe,IAAI,CAAY,SAAA,EAAA,MAAM,CAAC,MAAM,IAAI,CAAC;AACpE,YAAA,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC3C,eAAe,IAAI,oBAAoB,CAAC;gBACxC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAa,KAAI;AACrC,oBAAA,eAAe,IAAI,CAAG,EAAA,IAAI,CAAC,IAAI,EAAE,CAAC;AACpC,iBAAC,CAAC,CAAC;gBACH,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;aAC/C;YAED,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,CAAC;SAC5C;QAAC,OAAO,KAAK,EAAE;AACd,YAAA,OAAO,CAAmC,gCAAA,EAAA,IAAI,CAAC,SAAS,CAAC;gBACvD,IAAI;gBACJ,IAAI;AACJ,gBAAA,GAAG,IAAI;AACR,aAAA,CAAC,CAAuC,mCAAA,EAAA,KAA2B,EAAE,OAAO,EAAE,CAAC;SACjF;AACH,KAAC,EACD;AACE,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,WAAW,EAAE,CAAA;;;;AAIwC,0DAAA,CAAA;AACrD,QAAA,MAAM,EAAE,uBAAuB;AAC/B,QAAA,cAAc,EAAE,sBAAsB;AACvC,KAAA,CACF,CAAC;AACJ;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@librechat/agents",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8",
|
|
4
4
|
"main": "./dist/cjs/main.cjs",
|
|
5
5
|
"module": "./dist/esm/main.mjs",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"content": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/content.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
|
44
44
|
"stream": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/stream.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
|
45
45
|
"code_exec": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/code_exec.ts --provider 'openAI' --name 'Jo' --location 'New York, NY'",
|
|
46
|
+
"code_exec_simple": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/code_exec_simple.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
|
46
47
|
"simple": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/simple.ts --provider 'bedrock' --name 'Jo' --location 'New York, NY'",
|
|
47
48
|
"tool-test": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/tools.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
|
48
49
|
"abort": "node -r dotenv/config --loader ./tsconfig-paths-bootstrap.mjs --experimental-specifier-resolution=node ./src/scripts/abort.ts --provider 'anthropic' --name 'Jo' --location 'New York, NY'",
|
package/src/scripts/code_exec.ts
CHANGED
|
@@ -63,7 +63,7 @@ async function testCodeExecution(): Promise<void> {
|
|
|
63
63
|
graphConfig: {
|
|
64
64
|
type: 'standard',
|
|
65
65
|
llmConfig,
|
|
66
|
-
tools: [new TavilySearchResults(), createCodeExecutionTool()],
|
|
66
|
+
tools: [new TavilySearchResults(), createCodeExecutionTool({ apiKey: 'test' })],
|
|
67
67
|
instructions: 'You are a friendly AI assistant with coding capabilities. Always address the user by their name.',
|
|
68
68
|
additional_instructions: `The user's name is ${userName} and they are located in ${location}.`,
|
|
69
69
|
},
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// src/scripts/cli.ts
|
|
2
|
+
import { config } from 'dotenv';
|
|
3
|
+
config();
|
|
4
|
+
import { HumanMessage, AIMessage, BaseMessage } from '@langchain/core/messages';
|
|
5
|
+
import { TavilySearchResults } from '@langchain/community/tools/tavily_search';
|
|
6
|
+
import type * as t from '@/types';
|
|
7
|
+
import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
|
|
8
|
+
import { ToolEndHandler, ModelEndHandler, createMetadataAggregator } from '@/events';
|
|
9
|
+
import { createCodeExecutionTool } from '@/tools/CodeExecutor';
|
|
10
|
+
import { getLLMConfig } from '@/utils/llmConfig';
|
|
11
|
+
import { getArgs } from '@/scripts/args';
|
|
12
|
+
import { GraphEvents } from '@/common';
|
|
13
|
+
import { Run } from '@/run';
|
|
14
|
+
|
|
15
|
+
const conversationHistory: BaseMessage[] = [];
|
|
16
|
+
|
|
17
|
+
async function testCodeExecution(): Promise<void> {
|
|
18
|
+
const { userName, location, provider, currentDate } = await getArgs();
|
|
19
|
+
const { contentParts, aggregateContent } = createContentAggregator();
|
|
20
|
+
const customHandlers = {
|
|
21
|
+
[GraphEvents.TOOL_END]: new ToolEndHandler(),
|
|
22
|
+
[GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
|
|
23
|
+
[GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
|
|
24
|
+
[GraphEvents.ON_RUN_STEP_COMPLETED]: {
|
|
25
|
+
handle: (event: GraphEvents.ON_RUN_STEP_COMPLETED, data: t.StreamEventData): void => {
|
|
26
|
+
console.log('====== ON_RUN_STEP_COMPLETED ======');
|
|
27
|
+
console.dir(data, { depth: null });
|
|
28
|
+
aggregateContent({ event, data: data as unknown as { result: t.ToolEndEvent } });
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
[GraphEvents.ON_RUN_STEP]: {
|
|
32
|
+
handle: (event: GraphEvents.ON_RUN_STEP, data: t.StreamEventData): void => {
|
|
33
|
+
console.log('====== ON_RUN_STEP ======');
|
|
34
|
+
console.dir(data, { depth: null });
|
|
35
|
+
aggregateContent({ event, data: data as t.RunStep });
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
[GraphEvents.ON_RUN_STEP_DELTA]: {
|
|
39
|
+
handle: (event: GraphEvents.ON_RUN_STEP_DELTA, data: t.StreamEventData): void => {
|
|
40
|
+
console.log('====== ON_RUN_STEP_DELTA ======');
|
|
41
|
+
console.dir(data, { depth: null });
|
|
42
|
+
aggregateContent({ event, data: data as t.RunStepDeltaEvent });
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
[GraphEvents.ON_MESSAGE_DELTA]: {
|
|
46
|
+
handle: (event: GraphEvents.ON_MESSAGE_DELTA, data: t.StreamEventData): void => {
|
|
47
|
+
console.log('====== ON_MESSAGE_DELTA ======');
|
|
48
|
+
console.dir(data, { depth: null });
|
|
49
|
+
aggregateContent({ event, data: data as t.MessageDeltaEvent });
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
[GraphEvents.TOOL_START]: {
|
|
53
|
+
handle: (_event: string, data: t.StreamEventData, metadata?: Record<string, unknown>): void => {
|
|
54
|
+
console.log('====== TOOL_START ======');
|
|
55
|
+
console.dir(data, { depth: null });
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const llmConfig = getLLMConfig(provider);
|
|
61
|
+
|
|
62
|
+
const run = await Run.create<t.IState>({
|
|
63
|
+
graphConfig: {
|
|
64
|
+
type: 'standard',
|
|
65
|
+
llmConfig,
|
|
66
|
+
tools: [new TavilySearchResults(), createCodeExecutionTool({ apiKey: 'test' })],
|
|
67
|
+
instructions: 'You are a friendly AI assistant with coding capabilities. Always address the user by their name.',
|
|
68
|
+
additional_instructions: `The user's name is ${userName} and they are located in ${location}.`,
|
|
69
|
+
},
|
|
70
|
+
returnContent: true,
|
|
71
|
+
customHandlers,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const config = {
|
|
75
|
+
configurable: {
|
|
76
|
+
provider,
|
|
77
|
+
thread_id: 'conversation-num-1',
|
|
78
|
+
},
|
|
79
|
+
streamMode: 'values',
|
|
80
|
+
version: 'v2' as const,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
console.log('Test 1: Simple Code Execution');
|
|
84
|
+
|
|
85
|
+
const userMessage1 = `how much memory is this (its in bytes) in MB? 31192000`;
|
|
86
|
+
|
|
87
|
+
conversationHistory.push(new HumanMessage(userMessage1));
|
|
88
|
+
|
|
89
|
+
let inputs = {
|
|
90
|
+
messages: conversationHistory,
|
|
91
|
+
};
|
|
92
|
+
const finalContentParts1 = await run.processStream(inputs, config);
|
|
93
|
+
const finalMessages1 = run.getRunMessages();
|
|
94
|
+
if (finalMessages1) {
|
|
95
|
+
conversationHistory.push(...finalMessages1);
|
|
96
|
+
}
|
|
97
|
+
console.log('\n\n====================\n\n');
|
|
98
|
+
console.dir(contentParts, { depth: null });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
102
|
+
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
|
103
|
+
console.log('Conversation history:');
|
|
104
|
+
console.dir(conversationHistory, { depth: null });
|
|
105
|
+
process.exit(1);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
testCodeExecution().catch((err) => {
|
|
109
|
+
console.error(err);
|
|
110
|
+
console.log('Conversation history:');
|
|
111
|
+
console.dir(conversationHistory, { depth: null });
|
|
112
|
+
process.exit(1);
|
|
113
|
+
});
|
|
@@ -82,7 +82,11 @@ function createCodeExecutionTool(params: CodeExecutionToolParams = {}): DynamicS
|
|
|
82
82
|
|
|
83
83
|
const result: ExecuteResult = await response.json();
|
|
84
84
|
let formattedOutput = '';
|
|
85
|
-
if (result.stdout)
|
|
85
|
+
if (result.stdout) {
|
|
86
|
+
formattedOutput += `stdout:\n${result.stdout}\n`;
|
|
87
|
+
} else {
|
|
88
|
+
formattedOutput += 'stdout: Empty. To output values, write explicitly to stdout.\n';
|
|
89
|
+
}
|
|
86
90
|
if (result.stderr) formattedOutput += `stderr:\n${result.stderr}\n`;
|
|
87
91
|
if (result.files && result.files.length > 0) {
|
|
88
92
|
formattedOutput += 'Generated files:\n';
|
|
@@ -103,7 +107,11 @@ function createCodeExecutionTool(params: CodeExecutionToolParams = {}): DynamicS
|
|
|
103
107
|
},
|
|
104
108
|
{
|
|
105
109
|
name: 'execute_code',
|
|
106
|
-
description:
|
|
110
|
+
description: `Executes code in various programming languages, returning stdout/stderr output.
|
|
111
|
+
|
|
112
|
+
# Usage
|
|
113
|
+
- Input code is automatically displayed to the user, so don't repeat it in your response unless asked.
|
|
114
|
+
- All desired output must be explicitly written to stdout.`,
|
|
107
115
|
schema: CodeExecutionToolSchema,
|
|
108
116
|
responseFormat: 'content_and_artifact',
|
|
109
117
|
}
|