@langchain/anthropic 1.2.3 → 1.3.0-dev-1765432861398

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 (112) hide show
  1. package/README.md +620 -3
  2. package/dist/chat_models.cjs +8 -5
  3. package/dist/chat_models.cjs.map +1 -1
  4. package/dist/chat_models.d.cts +13 -16
  5. package/dist/chat_models.d.cts.map +1 -0
  6. package/dist/chat_models.d.ts +13 -16
  7. package/dist/chat_models.d.ts.map +1 -0
  8. package/dist/chat_models.js +7 -4
  9. package/dist/chat_models.js.map +1 -1
  10. package/dist/index.cjs +3 -1
  11. package/dist/index.d.cts +12 -2
  12. package/dist/index.d.ts +12 -2
  13. package/dist/index.js +2 -1
  14. package/dist/tools/bash.cjs +95 -0
  15. package/dist/tools/bash.cjs.map +1 -0
  16. package/dist/tools/bash.d.cts +99 -0
  17. package/dist/tools/bash.d.cts.map +1 -0
  18. package/dist/tools/bash.d.ts +99 -0
  19. package/dist/tools/bash.d.ts.map +1 -0
  20. package/dist/tools/bash.js +94 -0
  21. package/dist/tools/bash.js.map +1 -0
  22. package/dist/tools/codeExecution.cjs +70 -0
  23. package/dist/tools/codeExecution.cjs.map +1 -0
  24. package/dist/tools/codeExecution.d.cts +75 -0
  25. package/dist/tools/codeExecution.d.cts.map +1 -0
  26. package/dist/tools/codeExecution.d.ts +75 -0
  27. package/dist/tools/codeExecution.d.ts.map +1 -0
  28. package/dist/tools/codeExecution.js +69 -0
  29. package/dist/tools/codeExecution.js.map +1 -0
  30. package/dist/tools/computer.cjs +161 -0
  31. package/dist/tools/computer.cjs.map +1 -0
  32. package/dist/tools/computer.d.cts +289 -0
  33. package/dist/tools/computer.d.cts.map +1 -0
  34. package/dist/tools/computer.d.ts +289 -0
  35. package/dist/tools/computer.d.ts.map +1 -0
  36. package/dist/tools/computer.js +159 -0
  37. package/dist/tools/computer.js.map +1 -0
  38. package/dist/tools/index.cjs +28 -0
  39. package/dist/tools/index.cjs.map +1 -0
  40. package/dist/tools/index.d.cts +28 -0
  41. package/dist/tools/index.d.cts.map +1 -0
  42. package/dist/tools/index.d.ts +28 -0
  43. package/dist/tools/index.d.ts.map +1 -0
  44. package/dist/tools/index.js +28 -0
  45. package/dist/tools/index.js.map +1 -0
  46. package/dist/tools/mcpToolset.cjs +111 -0
  47. package/dist/tools/mcpToolset.cjs.map +1 -0
  48. package/dist/tools/mcpToolset.d.cts +141 -0
  49. package/dist/tools/mcpToolset.d.cts.map +1 -0
  50. package/dist/tools/mcpToolset.d.ts +141 -0
  51. package/dist/tools/mcpToolset.d.ts.map +1 -0
  52. package/dist/tools/mcpToolset.js +110 -0
  53. package/dist/tools/mcpToolset.js.map +1 -0
  54. package/dist/tools/memory.cjs +56 -0
  55. package/dist/tools/memory.cjs.map +1 -0
  56. package/dist/tools/memory.d.cts +92 -0
  57. package/dist/tools/memory.d.cts.map +1 -0
  58. package/dist/tools/memory.d.ts +92 -0
  59. package/dist/tools/memory.d.ts.map +1 -0
  60. package/dist/tools/memory.js +55 -0
  61. package/dist/tools/memory.js.map +1 -0
  62. package/dist/tools/textEditor.cjs +79 -0
  63. package/dist/tools/textEditor.cjs.map +1 -0
  64. package/dist/tools/textEditor.d.cts +114 -0
  65. package/dist/tools/textEditor.d.cts.map +1 -0
  66. package/dist/tools/textEditor.d.ts +114 -0
  67. package/dist/tools/textEditor.d.ts.map +1 -0
  68. package/dist/tools/textEditor.js +78 -0
  69. package/dist/tools/textEditor.js.map +1 -0
  70. package/dist/tools/toolSearch.cjs +110 -0
  71. package/dist/tools/toolSearch.cjs.map +1 -0
  72. package/dist/tools/toolSearch.d.cts +108 -0
  73. package/dist/tools/toolSearch.d.cts.map +1 -0
  74. package/dist/tools/toolSearch.d.ts +108 -0
  75. package/dist/tools/toolSearch.d.ts.map +1 -0
  76. package/dist/tools/toolSearch.js +108 -0
  77. package/dist/tools/toolSearch.js.map +1 -0
  78. package/dist/tools/types.cjs +204 -0
  79. package/dist/tools/types.cjs.map +1 -0
  80. package/dist/tools/types.d.cts +366 -0
  81. package/dist/tools/types.d.cts.map +1 -0
  82. package/dist/tools/types.d.ts +366 -0
  83. package/dist/tools/types.d.ts.map +1 -0
  84. package/dist/tools/types.js +199 -0
  85. package/dist/tools/types.js.map +1 -0
  86. package/dist/tools/webFetch.cjs +70 -0
  87. package/dist/tools/webFetch.cjs.map +1 -0
  88. package/dist/tools/webFetch.d.cts +96 -0
  89. package/dist/tools/webFetch.d.cts.map +1 -0
  90. package/dist/tools/webFetch.d.ts +96 -0
  91. package/dist/tools/webFetch.d.ts.map +1 -0
  92. package/dist/tools/webFetch.js +69 -0
  93. package/dist/tools/webFetch.js.map +1 -0
  94. package/dist/tools/webSearch.cjs +57 -0
  95. package/dist/tools/webSearch.cjs.map +1 -0
  96. package/dist/tools/webSearch.d.cts +84 -0
  97. package/dist/tools/webSearch.d.cts.map +1 -0
  98. package/dist/tools/webSearch.d.ts +84 -0
  99. package/dist/tools/webSearch.d.ts.map +1 -0
  100. package/dist/tools/webSearch.js +56 -0
  101. package/dist/tools/webSearch.js.map +1 -0
  102. package/dist/types.d.cts +2 -3
  103. package/dist/types.d.cts.map +1 -0
  104. package/dist/types.d.ts +2 -3
  105. package/dist/types.d.ts.map +1 -0
  106. package/dist/utils/prompts.d.cts.map +1 -0
  107. package/dist/utils/prompts.d.ts.map +1 -0
  108. package/dist/utils/tools.cjs +9 -2
  109. package/dist/utils/tools.cjs.map +1 -1
  110. package/dist/utils/tools.js +13 -6
  111. package/dist/utils/tools.js.map +1 -1
  112. package/package.json +8 -7
@@ -0,0 +1,99 @@
1
+ import { Bash20250124Command } from "./types.cjs";
2
+ import * as zod195 from "zod";
3
+ import * as zod_v4_core40 from "zod/v4/core";
4
+ import { DynamicStructuredTool } from "@langchain/core/tools";
5
+
6
+ //#region src/tools/bash.d.ts
7
+ /**
8
+ * Options for the bash tool.
9
+ */
10
+ interface Bash20250124Options {
11
+ /**
12
+ * Optional execute function that handles bash command execution.
13
+ * This function receives the command input and should return the result
14
+ * (stdout and stderr combined, or an error message).
15
+ */
16
+ execute?: (args: Bash20250124Command) => string | Promise<string>;
17
+ }
18
+ /**
19
+ * Creates an Anthropic bash tool for Claude 4 models and Claude 3.7 that enables
20
+ * shell command execution in a persistent bash session.
21
+ *
22
+ * The bash tool provides Claude with:
23
+ * - **Persistent bash session**: Maintains state between commands
24
+ * - **Shell command execution**: Run any shell command
25
+ * - **Environment access**: Access to environment variables and working directory
26
+ * - **Command chaining**: Support for pipes, redirects, and scripting
27
+ *
28
+ * Available commands:
29
+ * - Execute a command: `{ command: "ls -la" }`
30
+ * - Restart the session: `{ restart: true }`
31
+ *
32
+ * @warning The bash tool provides direct system access. Implement safety measures
33
+ * such as running in isolated environments (Docker/VM), command filtering,
34
+ * and resource limits.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * import { ChatAnthropic, tools } from "@langchain/anthropic";
39
+ * import { execSync } from "child_process";
40
+ *
41
+ * const llm = new ChatAnthropic({
42
+ * model: "claude-sonnet-4-5-20250929",
43
+ * });
44
+ *
45
+ * const bash = tools.bash_20250124({
46
+ * execute: async (args) => {
47
+ * if (args.restart) {
48
+ * // Reset session state
49
+ * return "Bash session restarted";
50
+ * }
51
+ * try {
52
+ * const output = execSync(args.command!, {
53
+ * encoding: "utf-8",
54
+ * timeout: 30000,
55
+ * });
56
+ * return output;
57
+ * } catch (error) {
58
+ * return `Error: ${error.message}`;
59
+ * }
60
+ * },
61
+ * });
62
+ *
63
+ * const llmWithBash = llm.bindTools([bash]);
64
+ * const response = await llmWithBash.invoke(
65
+ * "List all Python files in the current directory"
66
+ * );
67
+ *
68
+ * // Outputs: "bash"
69
+ * console.log(response.tool_calls[0].name);
70
+ * // Outputs: "ls -la *.py 2>/dev/null || echo \"No Python files found in the current directory\"
71
+ * console.log(response.tool_calls[0].args.command);
72
+ * ```
73
+ *
74
+ * @example Multi-step automation
75
+ * ```typescript
76
+ * // Claude can chain commands in a persistent session:
77
+ * // 1. cd /tmp
78
+ * // 2. echo "Hello" > test.txt
79
+ * // 3. cat test.txt // Works because we're still in /tmp
80
+ * ```
81
+ *
82
+ * @param options - Configuration options for the bash tool
83
+ * @param options.execute - Function that handles bash command execution
84
+ * @returns The bash tool object that can be passed to `bindTools`
85
+ *
86
+ * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/bash-tool
87
+ */
88
+ declare function bash_20250124(options?: Bash20250124Options): DynamicStructuredTool<zod195.ZodUnion<readonly [zod195.ZodObject<{
89
+ command: zod195.ZodString;
90
+ }, zod_v4_core40.$strip>, zod195.ZodObject<{
91
+ restart: zod195.ZodLiteral<true>;
92
+ }, zod_v4_core40.$strip>]>, {
93
+ command: string;
94
+ } | {
95
+ restart: true;
96
+ }, unknown, string>;
97
+ //#endregion
98
+ export { Bash20250124Options, bash_20250124 };
99
+ //# sourceMappingURL=bash.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash.d.cts","names":["zod_v4_core40","DynamicStructuredTool","Bash20250124Command","Bash20250124Options","Promise","bash_20250124","zod195","ZodString","$strip","ZodObject","ZodLiteral","ZodUnion"],"sources":["../../src/tools/bash.d.ts"],"sourcesContent":["import type { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type Bash20250124Command } from \"./types.js\";\n/**\n * Options for the bash tool.\n */\nexport interface Bash20250124Options {\n /**\n * Optional execute function that handles bash command execution.\n * This function receives the command input and should return the result\n * (stdout and stderr combined, or an error message).\n */\n execute?: (args: Bash20250124Command) => string | Promise<string>;\n}\n/**\n * Creates an Anthropic bash tool for Claude 4 models and Claude 3.7 that enables\n * shell command execution in a persistent bash session.\n *\n * The bash tool provides Claude with:\n * - **Persistent bash session**: Maintains state between commands\n * - **Shell command execution**: Run any shell command\n * - **Environment access**: Access to environment variables and working directory\n * - **Command chaining**: Support for pipes, redirects, and scripting\n *\n * Available commands:\n * - Execute a command: `{ command: \"ls -la\" }`\n * - Restart the session: `{ restart: true }`\n *\n * @warning The bash tool provides direct system access. Implement safety measures\n * such as running in isolated environments (Docker/VM), command filtering,\n * and resource limits.\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n * import { execSync } from \"child_process\";\n *\n * const llm = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\",\n * });\n *\n * const bash = tools.bash_20250124({\n * execute: async (args) => {\n * if (args.restart) {\n * // Reset session state\n * return \"Bash session restarted\";\n * }\n * try {\n * const output = execSync(args.command!, {\n * encoding: \"utf-8\",\n * timeout: 30000,\n * });\n * return output;\n * } catch (error) {\n * return `Error: ${error.message}`;\n * }\n * },\n * });\n *\n * const llmWithBash = llm.bindTools([bash]);\n * const response = await llmWithBash.invoke(\n * \"List all Python files in the current directory\"\n * );\n *\n * // Outputs: \"bash\"\n * console.log(response.tool_calls[0].name);\n * // Outputs: \"ls -la *.py 2>/dev/null || echo \\\"No Python files found in the current directory\\\"\n * console.log(response.tool_calls[0].args.command);\n * ```\n *\n * @example Multi-step automation\n * ```typescript\n * // Claude can chain commands in a persistent session:\n * // 1. cd /tmp\n * // 2. echo \"Hello\" > test.txt\n * // 3. cat test.txt // Works because we're still in /tmp\n * ```\n *\n * @param options - Configuration options for the bash tool\n * @param options.execute - Function that handles bash command execution\n * @returns The bash tool object that can be passed to `bindTools`\n *\n * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/bash-tool\n */\nexport declare function bash_20250124(options?: Bash20250124Options): DynamicStructuredTool<import(\"zod\").ZodUnion<readonly [import(\"zod\").ZodObject<{\n command: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n restart: import(\"zod\").ZodLiteral<true>;\n}, import(\"zod/v4/core\").$strip>]>, {\n command: string;\n} | {\n restart: true;\n}, unknown, string>;\n//# sourceMappingURL=bash.d.ts.map"],"mappings":";;;;;;;;;UAKiBG,mBAAAA;EAAAA;AA8EjB;;;;EAE+BG,OAF4GG,CAAAA,EAAAA,CAAAA,IAAAA,EAxEtHP,mBAwEsHO,EAAAA,GAAAA,MAAAA,GAxErFL,OAwEqFK,CAAAA,MAAAA,CAAAA;;;;;;AAAhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAnEJ,aAAAA,WAAwBF,sBAAsBF,sBAEbK,MAAAA,CAFiDK,mBAE3EL,MAAAA,CAF4GG;WAAxEH,MAAAA,CACxCC;GAASP,aAAAA,CACXQ,MAAAA,GAEMF,MAAAA,CAFiBG;WAFoGH,MAAAA,CAGzHI;GAAUV,aAAAA,CACZQ,MAAAA"}
@@ -0,0 +1,99 @@
1
+ import { Bash20250124Command } from "./types.js";
2
+ import { DynamicStructuredTool } from "@langchain/core/tools";
3
+ import * as zod195 from "zod";
4
+ import * as zod_v4_core40 from "zod/v4/core";
5
+
6
+ //#region src/tools/bash.d.ts
7
+ /**
8
+ * Options for the bash tool.
9
+ */
10
+ interface Bash20250124Options {
11
+ /**
12
+ * Optional execute function that handles bash command execution.
13
+ * This function receives the command input and should return the result
14
+ * (stdout and stderr combined, or an error message).
15
+ */
16
+ execute?: (args: Bash20250124Command) => string | Promise<string>;
17
+ }
18
+ /**
19
+ * Creates an Anthropic bash tool for Claude 4 models and Claude 3.7 that enables
20
+ * shell command execution in a persistent bash session.
21
+ *
22
+ * The bash tool provides Claude with:
23
+ * - **Persistent bash session**: Maintains state between commands
24
+ * - **Shell command execution**: Run any shell command
25
+ * - **Environment access**: Access to environment variables and working directory
26
+ * - **Command chaining**: Support for pipes, redirects, and scripting
27
+ *
28
+ * Available commands:
29
+ * - Execute a command: `{ command: "ls -la" }`
30
+ * - Restart the session: `{ restart: true }`
31
+ *
32
+ * @warning The bash tool provides direct system access. Implement safety measures
33
+ * such as running in isolated environments (Docker/VM), command filtering,
34
+ * and resource limits.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * import { ChatAnthropic, tools } from "@langchain/anthropic";
39
+ * import { execSync } from "child_process";
40
+ *
41
+ * const llm = new ChatAnthropic({
42
+ * model: "claude-sonnet-4-5-20250929",
43
+ * });
44
+ *
45
+ * const bash = tools.bash_20250124({
46
+ * execute: async (args) => {
47
+ * if (args.restart) {
48
+ * // Reset session state
49
+ * return "Bash session restarted";
50
+ * }
51
+ * try {
52
+ * const output = execSync(args.command!, {
53
+ * encoding: "utf-8",
54
+ * timeout: 30000,
55
+ * });
56
+ * return output;
57
+ * } catch (error) {
58
+ * return `Error: ${error.message}`;
59
+ * }
60
+ * },
61
+ * });
62
+ *
63
+ * const llmWithBash = llm.bindTools([bash]);
64
+ * const response = await llmWithBash.invoke(
65
+ * "List all Python files in the current directory"
66
+ * );
67
+ *
68
+ * // Outputs: "bash"
69
+ * console.log(response.tool_calls[0].name);
70
+ * // Outputs: "ls -la *.py 2>/dev/null || echo \"No Python files found in the current directory\"
71
+ * console.log(response.tool_calls[0].args.command);
72
+ * ```
73
+ *
74
+ * @example Multi-step automation
75
+ * ```typescript
76
+ * // Claude can chain commands in a persistent session:
77
+ * // 1. cd /tmp
78
+ * // 2. echo "Hello" > test.txt
79
+ * // 3. cat test.txt // Works because we're still in /tmp
80
+ * ```
81
+ *
82
+ * @param options - Configuration options for the bash tool
83
+ * @param options.execute - Function that handles bash command execution
84
+ * @returns The bash tool object that can be passed to `bindTools`
85
+ *
86
+ * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/bash-tool
87
+ */
88
+ declare function bash_20250124(options?: Bash20250124Options): DynamicStructuredTool<zod195.ZodUnion<readonly [zod195.ZodObject<{
89
+ command: zod195.ZodString;
90
+ }, zod_v4_core40.$strip>, zod195.ZodObject<{
91
+ restart: zod195.ZodLiteral<true>;
92
+ }, zod_v4_core40.$strip>]>, {
93
+ command: string;
94
+ } | {
95
+ restart: true;
96
+ }, unknown, string>;
97
+ //#endregion
98
+ export { Bash20250124Options, bash_20250124 };
99
+ //# sourceMappingURL=bash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash.d.ts","names":["zod_v4_core40","DynamicStructuredTool","Bash20250124Command","Bash20250124Options","Promise","bash_20250124","zod195","ZodString","$strip","ZodObject","ZodLiteral","ZodUnion"],"sources":["../../src/tools/bash.d.ts"],"sourcesContent":["import type { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { type Bash20250124Command } from \"./types.js\";\n/**\n * Options for the bash tool.\n */\nexport interface Bash20250124Options {\n /**\n * Optional execute function that handles bash command execution.\n * This function receives the command input and should return the result\n * (stdout and stderr combined, or an error message).\n */\n execute?: (args: Bash20250124Command) => string | Promise<string>;\n}\n/**\n * Creates an Anthropic bash tool for Claude 4 models and Claude 3.7 that enables\n * shell command execution in a persistent bash session.\n *\n * The bash tool provides Claude with:\n * - **Persistent bash session**: Maintains state between commands\n * - **Shell command execution**: Run any shell command\n * - **Environment access**: Access to environment variables and working directory\n * - **Command chaining**: Support for pipes, redirects, and scripting\n *\n * Available commands:\n * - Execute a command: `{ command: \"ls -la\" }`\n * - Restart the session: `{ restart: true }`\n *\n * @warning The bash tool provides direct system access. Implement safety measures\n * such as running in isolated environments (Docker/VM), command filtering,\n * and resource limits.\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n * import { execSync } from \"child_process\";\n *\n * const llm = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\",\n * });\n *\n * const bash = tools.bash_20250124({\n * execute: async (args) => {\n * if (args.restart) {\n * // Reset session state\n * return \"Bash session restarted\";\n * }\n * try {\n * const output = execSync(args.command!, {\n * encoding: \"utf-8\",\n * timeout: 30000,\n * });\n * return output;\n * } catch (error) {\n * return `Error: ${error.message}`;\n * }\n * },\n * });\n *\n * const llmWithBash = llm.bindTools([bash]);\n * const response = await llmWithBash.invoke(\n * \"List all Python files in the current directory\"\n * );\n *\n * // Outputs: \"bash\"\n * console.log(response.tool_calls[0].name);\n * // Outputs: \"ls -la *.py 2>/dev/null || echo \\\"No Python files found in the current directory\\\"\n * console.log(response.tool_calls[0].args.command);\n * ```\n *\n * @example Multi-step automation\n * ```typescript\n * // Claude can chain commands in a persistent session:\n * // 1. cd /tmp\n * // 2. echo \"Hello\" > test.txt\n * // 3. cat test.txt // Works because we're still in /tmp\n * ```\n *\n * @param options - Configuration options for the bash tool\n * @param options.execute - Function that handles bash command execution\n * @returns The bash tool object that can be passed to `bindTools`\n *\n * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/bash-tool\n */\nexport declare function bash_20250124(options?: Bash20250124Options): DynamicStructuredTool<import(\"zod\").ZodUnion<readonly [import(\"zod\").ZodObject<{\n command: import(\"zod\").ZodString;\n}, import(\"zod/v4/core\").$strip>, import(\"zod\").ZodObject<{\n restart: import(\"zod\").ZodLiteral<true>;\n}, import(\"zod/v4/core\").$strip>]>, {\n command: string;\n} | {\n restart: true;\n}, unknown, string>;\n//# sourceMappingURL=bash.d.ts.map"],"mappings":";;;;;;;;;UAKiBG,mBAAAA;EAAAA;AA8EjB;;;;EAE+BG,OAF4GG,CAAAA,EAAAA,CAAAA,IAAAA,EAxEtHP,mBAwEsHO,EAAAA,GAAAA,MAAAA,GAxErFL,OAwEqFK,CAAAA,MAAAA,CAAAA;;;;;;AAAhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAnEJ,aAAAA,WAAwBF,sBAAsBF,sBAEbK,MAAAA,CAFiDK,mBAE3EL,MAAAA,CAF4GG;WAAxEH,MAAAA,CACxCC;GAASP,aAAAA,CACXQ,MAAAA,GAEMF,MAAAA,CAFiBG;WAFoGH,MAAAA,CAGzHI;GAAUV,aAAAA,CACZQ,MAAAA"}
@@ -0,0 +1,94 @@
1
+ import { Bash20250124CommandSchema } from "./types.js";
2
+ import { tool } from "@langchain/core/tools";
3
+
4
+ //#region src/tools/bash.ts
5
+ /**
6
+ * Creates an Anthropic bash tool for Claude 4 models and Claude 3.7 that enables
7
+ * shell command execution in a persistent bash session.
8
+ *
9
+ * The bash tool provides Claude with:
10
+ * - **Persistent bash session**: Maintains state between commands
11
+ * - **Shell command execution**: Run any shell command
12
+ * - **Environment access**: Access to environment variables and working directory
13
+ * - **Command chaining**: Support for pipes, redirects, and scripting
14
+ *
15
+ * Available commands:
16
+ * - Execute a command: `{ command: "ls -la" }`
17
+ * - Restart the session: `{ restart: true }`
18
+ *
19
+ * @warning The bash tool provides direct system access. Implement safety measures
20
+ * such as running in isolated environments (Docker/VM), command filtering,
21
+ * and resource limits.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * import { ChatAnthropic, tools } from "@langchain/anthropic";
26
+ * import { execSync } from "child_process";
27
+ *
28
+ * const llm = new ChatAnthropic({
29
+ * model: "claude-sonnet-4-5-20250929",
30
+ * });
31
+ *
32
+ * const bash = tools.bash_20250124({
33
+ * execute: async (args) => {
34
+ * if (args.restart) {
35
+ * // Reset session state
36
+ * return "Bash session restarted";
37
+ * }
38
+ * try {
39
+ * const output = execSync(args.command!, {
40
+ * encoding: "utf-8",
41
+ * timeout: 30000,
42
+ * });
43
+ * return output;
44
+ * } catch (error) {
45
+ * return `Error: ${error.message}`;
46
+ * }
47
+ * },
48
+ * });
49
+ *
50
+ * const llmWithBash = llm.bindTools([bash]);
51
+ * const response = await llmWithBash.invoke(
52
+ * "List all Python files in the current directory"
53
+ * );
54
+ *
55
+ * // Outputs: "bash"
56
+ * console.log(response.tool_calls[0].name);
57
+ * // Outputs: "ls -la *.py 2>/dev/null || echo \"No Python files found in the current directory\"
58
+ * console.log(response.tool_calls[0].args.command);
59
+ * ```
60
+ *
61
+ * @example Multi-step automation
62
+ * ```typescript
63
+ * // Claude can chain commands in a persistent session:
64
+ * // 1. cd /tmp
65
+ * // 2. echo "Hello" > test.txt
66
+ * // 3. cat test.txt // Works because we're still in /tmp
67
+ * ```
68
+ *
69
+ * @param options - Configuration options for the bash tool
70
+ * @param options.execute - Function that handles bash command execution
71
+ * @returns The bash tool object that can be passed to `bindTools`
72
+ *
73
+ * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/bash-tool
74
+ */
75
+ function bash_20250124(options) {
76
+ const name = "bash";
77
+ const bashTool = tool(options?.execute, {
78
+ name,
79
+ description: "A tool for executing bash commands",
80
+ schema: Bash20250124CommandSchema
81
+ });
82
+ bashTool.extras = {
83
+ ...bashTool.extras ?? {},
84
+ providerToolDefinition: {
85
+ type: "bash_20250124",
86
+ name
87
+ }
88
+ };
89
+ return bashTool;
90
+ }
91
+
92
+ //#endregion
93
+ export { bash_20250124 };
94
+ //# sourceMappingURL=bash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash.js","names":["options?: Bash20250124Options"],"sources":["../../src/tools/bash.ts"],"sourcesContent":["import Anthropic from \"@anthropic-ai/sdk\";\nimport { tool } from \"@langchain/core/tools\";\nimport type { DynamicStructuredTool, ToolRuntime } from \"@langchain/core/tools\";\n\nimport {\n Bash20250124CommandSchema,\n type Bash20250124Command,\n} from \"./types.js\";\n\n/**\n * Options for the bash tool.\n */\nexport interface Bash20250124Options {\n /**\n * Optional execute function that handles bash command execution.\n * This function receives the command input and should return the result\n * (stdout and stderr combined, or an error message).\n */\n execute?: (args: Bash20250124Command) => string | Promise<string>;\n}\n\n/**\n * Creates an Anthropic bash tool for Claude 4 models and Claude 3.7 that enables\n * shell command execution in a persistent bash session.\n *\n * The bash tool provides Claude with:\n * - **Persistent bash session**: Maintains state between commands\n * - **Shell command execution**: Run any shell command\n * - **Environment access**: Access to environment variables and working directory\n * - **Command chaining**: Support for pipes, redirects, and scripting\n *\n * Available commands:\n * - Execute a command: `{ command: \"ls -la\" }`\n * - Restart the session: `{ restart: true }`\n *\n * @warning The bash tool provides direct system access. Implement safety measures\n * such as running in isolated environments (Docker/VM), command filtering,\n * and resource limits.\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n * import { execSync } from \"child_process\";\n *\n * const llm = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\",\n * });\n *\n * const bash = tools.bash_20250124({\n * execute: async (args) => {\n * if (args.restart) {\n * // Reset session state\n * return \"Bash session restarted\";\n * }\n * try {\n * const output = execSync(args.command!, {\n * encoding: \"utf-8\",\n * timeout: 30000,\n * });\n * return output;\n * } catch (error) {\n * return `Error: ${error.message}`;\n * }\n * },\n * });\n *\n * const llmWithBash = llm.bindTools([bash]);\n * const response = await llmWithBash.invoke(\n * \"List all Python files in the current directory\"\n * );\n *\n * // Outputs: \"bash\"\n * console.log(response.tool_calls[0].name);\n * // Outputs: \"ls -la *.py 2>/dev/null || echo \\\"No Python files found in the current directory\\\"\n * console.log(response.tool_calls[0].args.command);\n * ```\n *\n * @example Multi-step automation\n * ```typescript\n * // Claude can chain commands in a persistent session:\n * // 1. cd /tmp\n * // 2. echo \"Hello\" > test.txt\n * // 3. cat test.txt // Works because we're still in /tmp\n * ```\n *\n * @param options - Configuration options for the bash tool\n * @param options.execute - Function that handles bash command execution\n * @returns The bash tool object that can be passed to `bindTools`\n *\n * @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/bash-tool\n */\nexport function bash_20250124(options?: Bash20250124Options) {\n const name = \"bash\";\n const bashTool = tool(\n options?.execute as (\n input: unknown,\n runtime: ToolRuntime<unknown, unknown>\n ) => string | Promise<string>,\n {\n name,\n description: \"A tool for executing bash commands\",\n schema: Bash20250124CommandSchema,\n }\n );\n\n bashTool.extras = {\n ...(bashTool.extras ?? {}),\n providerToolDefinition: {\n type: \"bash_20250124\",\n name,\n } satisfies Anthropic.Beta.BetaToolBash20250124,\n };\n\n return bashTool as DynamicStructuredTool<\n typeof Bash20250124CommandSchema,\n Bash20250124Command,\n unknown,\n string\n >;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2FA,SAAgB,cAAcA,SAA+B;CAC3D,MAAM,OAAO;CACb,MAAM,WAAW,KACf,SAAS,SAIT;EACE;EACA,aAAa;EACb,QAAQ;CACT,EACF;CAED,SAAS,SAAS;EAChB,GAAI,SAAS,UAAU,CAAE;EACzB,wBAAwB;GACtB,MAAM;GACN;EACD;CACF;AAED,QAAO;AAMR"}
@@ -0,0 +1,70 @@
1
+
2
+ //#region src/tools/codeExecution.ts
3
+ /**
4
+ * Creates a code execution tool that allows Claude to run Bash commands and manipulate files
5
+ * in a secure, sandboxed environment. Claude can analyze data, create visualizations,
6
+ * perform calculations, and process files.
7
+ *
8
+ * When this tool is provided, Claude automatically gains access to:
9
+ * - **Bash commands**: Execute shell commands for system operations
10
+ * - **File operations**: Create, view, and edit files directly
11
+ *
12
+ * @note This tool requires the beta header `code-execution-2025-08-25` in API requests.
13
+ *
14
+ * @see {@link https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/code-execution-tool | Anthropic Code Execution Documentation}
15
+ * @param options - Configuration options for the code execution tool
16
+ * @returns A code execution tool definition to be passed to the Anthropic API
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { ChatAnthropic, tools } from "@langchain/anthropic";
21
+ *
22
+ * const model = new ChatAnthropic({
23
+ * model: "claude-sonnet-4-5-20250929",
24
+ * });
25
+ *
26
+ * // Basic usage - calculations and data analysis
27
+ * const response = await model.invoke(
28
+ * "Calculate the mean and standard deviation of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]",
29
+ * { tools: [tools.codeExecution_20250825()] }
30
+ * );
31
+ *
32
+ * // File operations and visualization
33
+ * const response2 = await model.invoke(
34
+ * "Create a matplotlib visualization of sales data and save it as chart.png",
35
+ * { tools: [tools.codeExecution_20250825()] }
36
+ * );
37
+ * ```
38
+ *
39
+ * @example Container reuse
40
+ * ```typescript
41
+ * // First request - creates a container
42
+ * const response1 = await model.invoke(
43
+ * "Write a random number to /tmp/number.txt",
44
+ * { tools: [tools.codeExecution_20250825()] }
45
+ * );
46
+ *
47
+ * // Extract container ID from response for reuse
48
+ * const containerId = response1.response_metadata?.container?.id;
49
+ *
50
+ * // Second request - reuse container to access the file
51
+ * const response2 = await model.invoke(
52
+ * "Read /tmp/number.txt and calculate its square",
53
+ * {
54
+ * tools: [tools.codeExecution_20250825()],
55
+ * // Pass container ID to reuse the same environment
56
+ * }
57
+ * );
58
+ * ```
59
+ */
60
+ function codeExecution_20250825(options) {
61
+ return {
62
+ type: "code_execution_20250825",
63
+ name: "code_execution",
64
+ cache_control: options?.cacheControl
65
+ };
66
+ }
67
+
68
+ //#endregion
69
+ exports.codeExecution_20250825 = codeExecution_20250825;
70
+ //# sourceMappingURL=codeExecution.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codeExecution.cjs","names":["options?: CodeExecution20250825Options"],"sources":["../../src/tools/codeExecution.ts"],"sourcesContent":["import Anthropic from \"@anthropic-ai/sdk\";\nimport { type ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Options for the code execution tool.\n */\nexport interface CodeExecution20250825Options {\n /**\n * Create a cache control breakpoint at this content block.\n */\n cacheControl?: Anthropic.Beta.BetaCacheControlEphemeral;\n}\n\n/**\n * Creates a code execution tool that allows Claude to run Bash commands and manipulate files\n * in a secure, sandboxed environment. Claude can analyze data, create visualizations,\n * perform calculations, and process files.\n *\n * When this tool is provided, Claude automatically gains access to:\n * - **Bash commands**: Execute shell commands for system operations\n * - **File operations**: Create, view, and edit files directly\n *\n * @note This tool requires the beta header `code-execution-2025-08-25` in API requests.\n *\n * @see {@link https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/code-execution-tool | Anthropic Code Execution Documentation}\n * @param options - Configuration options for the code execution tool\n * @returns A code execution tool definition to be passed to the Anthropic API\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n *\n * const model = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\",\n * });\n *\n * // Basic usage - calculations and data analysis\n * const response = await model.invoke(\n * \"Calculate the mean and standard deviation of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\",\n * { tools: [tools.codeExecution_20250825()] }\n * );\n *\n * // File operations and visualization\n * const response2 = await model.invoke(\n * \"Create a matplotlib visualization of sales data and save it as chart.png\",\n * { tools: [tools.codeExecution_20250825()] }\n * );\n * ```\n *\n * @example Container reuse\n * ```typescript\n * // First request - creates a container\n * const response1 = await model.invoke(\n * \"Write a random number to /tmp/number.txt\",\n * { tools: [tools.codeExecution_20250825()] }\n * );\n *\n * // Extract container ID from response for reuse\n * const containerId = response1.response_metadata?.container?.id;\n *\n * // Second request - reuse container to access the file\n * const response2 = await model.invoke(\n * \"Read /tmp/number.txt and calculate its square\",\n * {\n * tools: [tools.codeExecution_20250825()],\n * // Pass container ID to reuse the same environment\n * }\n * );\n * ```\n */\nexport function codeExecution_20250825(\n options?: CodeExecution20250825Options\n): ServerTool {\n return {\n type: \"code_execution_20250825\",\n name: \"code_execution\",\n cache_control: options?.cacheControl,\n } satisfies Anthropic.Beta.BetaCodeExecutionTool20250825;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,SAAgB,uBACdA,SACY;AACZ,QAAO;EACL,MAAM;EACN,MAAM;EACN,eAAe,SAAS;CACzB;AACF"}
@@ -0,0 +1,75 @@
1
+ import Anthropic from "@anthropic-ai/sdk";
2
+ import { ServerTool } from "@langchain/core/tools";
3
+
4
+ //#region src/tools/codeExecution.d.ts
5
+
6
+ /**
7
+ * Options for the code execution tool.
8
+ */
9
+ interface CodeExecution20250825Options {
10
+ /**
11
+ * Create a cache control breakpoint at this content block.
12
+ */
13
+ cacheControl?: Anthropic.Beta.BetaCacheControlEphemeral;
14
+ }
15
+ /**
16
+ * Creates a code execution tool that allows Claude to run Bash commands and manipulate files
17
+ * in a secure, sandboxed environment. Claude can analyze data, create visualizations,
18
+ * perform calculations, and process files.
19
+ *
20
+ * When this tool is provided, Claude automatically gains access to:
21
+ * - **Bash commands**: Execute shell commands for system operations
22
+ * - **File operations**: Create, view, and edit files directly
23
+ *
24
+ * @note This tool requires the beta header `code-execution-2025-08-25` in API requests.
25
+ *
26
+ * @see {@link https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/code-execution-tool | Anthropic Code Execution Documentation}
27
+ * @param options - Configuration options for the code execution tool
28
+ * @returns A code execution tool definition to be passed to the Anthropic API
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * import { ChatAnthropic, tools } from "@langchain/anthropic";
33
+ *
34
+ * const model = new ChatAnthropic({
35
+ * model: "claude-sonnet-4-5-20250929",
36
+ * });
37
+ *
38
+ * // Basic usage - calculations and data analysis
39
+ * const response = await model.invoke(
40
+ * "Calculate the mean and standard deviation of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]",
41
+ * { tools: [tools.codeExecution_20250825()] }
42
+ * );
43
+ *
44
+ * // File operations and visualization
45
+ * const response2 = await model.invoke(
46
+ * "Create a matplotlib visualization of sales data and save it as chart.png",
47
+ * { tools: [tools.codeExecution_20250825()] }
48
+ * );
49
+ * ```
50
+ *
51
+ * @example Container reuse
52
+ * ```typescript
53
+ * // First request - creates a container
54
+ * const response1 = await model.invoke(
55
+ * "Write a random number to /tmp/number.txt",
56
+ * { tools: [tools.codeExecution_20250825()] }
57
+ * );
58
+ *
59
+ * // Extract container ID from response for reuse
60
+ * const containerId = response1.response_metadata?.container?.id;
61
+ *
62
+ * // Second request - reuse container to access the file
63
+ * const response2 = await model.invoke(
64
+ * "Read /tmp/number.txt and calculate its square",
65
+ * {
66
+ * tools: [tools.codeExecution_20250825()],
67
+ * // Pass container ID to reuse the same environment
68
+ * }
69
+ * );
70
+ * ```
71
+ */
72
+ declare function codeExecution_20250825(options?: CodeExecution20250825Options): ServerTool;
73
+ //#endregion
74
+ export { CodeExecution20250825Options, codeExecution_20250825 };
75
+ //# sourceMappingURL=codeExecution.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codeExecution.d.cts","names":["Anthropic","ServerTool","CodeExecution20250825Options","Beta","BetaCacheControlEphemeral","codeExecution_20250825"],"sources":["../../src/tools/codeExecution.d.ts"],"sourcesContent":["import Anthropic from \"@anthropic-ai/sdk\";\nimport { type ServerTool } from \"@langchain/core/tools\";\n/**\n * Options for the code execution tool.\n */\nexport interface CodeExecution20250825Options {\n /**\n * Create a cache control breakpoint at this content block.\n */\n cacheControl?: Anthropic.Beta.BetaCacheControlEphemeral;\n}\n/**\n * Creates a code execution tool that allows Claude to run Bash commands and manipulate files\n * in a secure, sandboxed environment. Claude can analyze data, create visualizations,\n * perform calculations, and process files.\n *\n * When this tool is provided, Claude automatically gains access to:\n * - **Bash commands**: Execute shell commands for system operations\n * - **File operations**: Create, view, and edit files directly\n *\n * @note This tool requires the beta header `code-execution-2025-08-25` in API requests.\n *\n * @see {@link https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/code-execution-tool | Anthropic Code Execution Documentation}\n * @param options - Configuration options for the code execution tool\n * @returns A code execution tool definition to be passed to the Anthropic API\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n *\n * const model = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\",\n * });\n *\n * // Basic usage - calculations and data analysis\n * const response = await model.invoke(\n * \"Calculate the mean and standard deviation of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\",\n * { tools: [tools.codeExecution_20250825()] }\n * );\n *\n * // File operations and visualization\n * const response2 = await model.invoke(\n * \"Create a matplotlib visualization of sales data and save it as chart.png\",\n * { tools: [tools.codeExecution_20250825()] }\n * );\n * ```\n *\n * @example Container reuse\n * ```typescript\n * // First request - creates a container\n * const response1 = await model.invoke(\n * \"Write a random number to /tmp/number.txt\",\n * { tools: [tools.codeExecution_20250825()] }\n * );\n *\n * // Extract container ID from response for reuse\n * const containerId = response1.response_metadata?.container?.id;\n *\n * // Second request - reuse container to access the file\n * const response2 = await model.invoke(\n * \"Read /tmp/number.txt and calculate its square\",\n * {\n * tools: [tools.codeExecution_20250825()],\n * // Pass container ID to reuse the same environment\n * }\n * );\n * ```\n */\nexport declare function codeExecution_20250825(options?: CodeExecution20250825Options): ServerTool;\n//# sourceMappingURL=codeExecution.d.ts.map"],"mappings":";;;;;;;AAKA;AA+DwBK,UA/DPH,4BAAAA,CA+DwCA;;;;iBA3DtCF,SAAAA,CAAUG,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2DVC,sBAAAA,WAAiCH,+BAA+BD"}
@@ -0,0 +1,75 @@
1
+ import Anthropic from "@anthropic-ai/sdk";
2
+ import { ServerTool } from "@langchain/core/tools";
3
+
4
+ //#region src/tools/codeExecution.d.ts
5
+
6
+ /**
7
+ * Options for the code execution tool.
8
+ */
9
+ interface CodeExecution20250825Options {
10
+ /**
11
+ * Create a cache control breakpoint at this content block.
12
+ */
13
+ cacheControl?: Anthropic.Beta.BetaCacheControlEphemeral;
14
+ }
15
+ /**
16
+ * Creates a code execution tool that allows Claude to run Bash commands and manipulate files
17
+ * in a secure, sandboxed environment. Claude can analyze data, create visualizations,
18
+ * perform calculations, and process files.
19
+ *
20
+ * When this tool is provided, Claude automatically gains access to:
21
+ * - **Bash commands**: Execute shell commands for system operations
22
+ * - **File operations**: Create, view, and edit files directly
23
+ *
24
+ * @note This tool requires the beta header `code-execution-2025-08-25` in API requests.
25
+ *
26
+ * @see {@link https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/code-execution-tool | Anthropic Code Execution Documentation}
27
+ * @param options - Configuration options for the code execution tool
28
+ * @returns A code execution tool definition to be passed to the Anthropic API
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * import { ChatAnthropic, tools } from "@langchain/anthropic";
33
+ *
34
+ * const model = new ChatAnthropic({
35
+ * model: "claude-sonnet-4-5-20250929",
36
+ * });
37
+ *
38
+ * // Basic usage - calculations and data analysis
39
+ * const response = await model.invoke(
40
+ * "Calculate the mean and standard deviation of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]",
41
+ * { tools: [tools.codeExecution_20250825()] }
42
+ * );
43
+ *
44
+ * // File operations and visualization
45
+ * const response2 = await model.invoke(
46
+ * "Create a matplotlib visualization of sales data and save it as chart.png",
47
+ * { tools: [tools.codeExecution_20250825()] }
48
+ * );
49
+ * ```
50
+ *
51
+ * @example Container reuse
52
+ * ```typescript
53
+ * // First request - creates a container
54
+ * const response1 = await model.invoke(
55
+ * "Write a random number to /tmp/number.txt",
56
+ * { tools: [tools.codeExecution_20250825()] }
57
+ * );
58
+ *
59
+ * // Extract container ID from response for reuse
60
+ * const containerId = response1.response_metadata?.container?.id;
61
+ *
62
+ * // Second request - reuse container to access the file
63
+ * const response2 = await model.invoke(
64
+ * "Read /tmp/number.txt and calculate its square",
65
+ * {
66
+ * tools: [tools.codeExecution_20250825()],
67
+ * // Pass container ID to reuse the same environment
68
+ * }
69
+ * );
70
+ * ```
71
+ */
72
+ declare function codeExecution_20250825(options?: CodeExecution20250825Options): ServerTool;
73
+ //#endregion
74
+ export { CodeExecution20250825Options, codeExecution_20250825 };
75
+ //# sourceMappingURL=codeExecution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codeExecution.d.ts","names":["Anthropic","ServerTool","CodeExecution20250825Options","Beta","BetaCacheControlEphemeral","codeExecution_20250825"],"sources":["../../src/tools/codeExecution.d.ts"],"sourcesContent":["import Anthropic from \"@anthropic-ai/sdk\";\nimport { type ServerTool } from \"@langchain/core/tools\";\n/**\n * Options for the code execution tool.\n */\nexport interface CodeExecution20250825Options {\n /**\n * Create a cache control breakpoint at this content block.\n */\n cacheControl?: Anthropic.Beta.BetaCacheControlEphemeral;\n}\n/**\n * Creates a code execution tool that allows Claude to run Bash commands and manipulate files\n * in a secure, sandboxed environment. Claude can analyze data, create visualizations,\n * perform calculations, and process files.\n *\n * When this tool is provided, Claude automatically gains access to:\n * - **Bash commands**: Execute shell commands for system operations\n * - **File operations**: Create, view, and edit files directly\n *\n * @note This tool requires the beta header `code-execution-2025-08-25` in API requests.\n *\n * @see {@link https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/code-execution-tool | Anthropic Code Execution Documentation}\n * @param options - Configuration options for the code execution tool\n * @returns A code execution tool definition to be passed to the Anthropic API\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n *\n * const model = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\",\n * });\n *\n * // Basic usage - calculations and data analysis\n * const response = await model.invoke(\n * \"Calculate the mean and standard deviation of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\",\n * { tools: [tools.codeExecution_20250825()] }\n * );\n *\n * // File operations and visualization\n * const response2 = await model.invoke(\n * \"Create a matplotlib visualization of sales data and save it as chart.png\",\n * { tools: [tools.codeExecution_20250825()] }\n * );\n * ```\n *\n * @example Container reuse\n * ```typescript\n * // First request - creates a container\n * const response1 = await model.invoke(\n * \"Write a random number to /tmp/number.txt\",\n * { tools: [tools.codeExecution_20250825()] }\n * );\n *\n * // Extract container ID from response for reuse\n * const containerId = response1.response_metadata?.container?.id;\n *\n * // Second request - reuse container to access the file\n * const response2 = await model.invoke(\n * \"Read /tmp/number.txt and calculate its square\",\n * {\n * tools: [tools.codeExecution_20250825()],\n * // Pass container ID to reuse the same environment\n * }\n * );\n * ```\n */\nexport declare function codeExecution_20250825(options?: CodeExecution20250825Options): ServerTool;\n//# sourceMappingURL=codeExecution.d.ts.map"],"mappings":";;;;;;;AAKA;AA+DwBK,UA/DPH,4BAAAA,CA+DwCA;;;;iBA3DtCF,SAAAA,CAAUG,IAAAA,CAAKC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2DVC,sBAAAA,WAAiCH,+BAA+BD"}
@@ -0,0 +1,69 @@
1
+ //#region src/tools/codeExecution.ts
2
+ /**
3
+ * Creates a code execution tool that allows Claude to run Bash commands and manipulate files
4
+ * in a secure, sandboxed environment. Claude can analyze data, create visualizations,
5
+ * perform calculations, and process files.
6
+ *
7
+ * When this tool is provided, Claude automatically gains access to:
8
+ * - **Bash commands**: Execute shell commands for system operations
9
+ * - **File operations**: Create, view, and edit files directly
10
+ *
11
+ * @note This tool requires the beta header `code-execution-2025-08-25` in API requests.
12
+ *
13
+ * @see {@link https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/code-execution-tool | Anthropic Code Execution Documentation}
14
+ * @param options - Configuration options for the code execution tool
15
+ * @returns A code execution tool definition to be passed to the Anthropic API
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { ChatAnthropic, tools } from "@langchain/anthropic";
20
+ *
21
+ * const model = new ChatAnthropic({
22
+ * model: "claude-sonnet-4-5-20250929",
23
+ * });
24
+ *
25
+ * // Basic usage - calculations and data analysis
26
+ * const response = await model.invoke(
27
+ * "Calculate the mean and standard deviation of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]",
28
+ * { tools: [tools.codeExecution_20250825()] }
29
+ * );
30
+ *
31
+ * // File operations and visualization
32
+ * const response2 = await model.invoke(
33
+ * "Create a matplotlib visualization of sales data and save it as chart.png",
34
+ * { tools: [tools.codeExecution_20250825()] }
35
+ * );
36
+ * ```
37
+ *
38
+ * @example Container reuse
39
+ * ```typescript
40
+ * // First request - creates a container
41
+ * const response1 = await model.invoke(
42
+ * "Write a random number to /tmp/number.txt",
43
+ * { tools: [tools.codeExecution_20250825()] }
44
+ * );
45
+ *
46
+ * // Extract container ID from response for reuse
47
+ * const containerId = response1.response_metadata?.container?.id;
48
+ *
49
+ * // Second request - reuse container to access the file
50
+ * const response2 = await model.invoke(
51
+ * "Read /tmp/number.txt and calculate its square",
52
+ * {
53
+ * tools: [tools.codeExecution_20250825()],
54
+ * // Pass container ID to reuse the same environment
55
+ * }
56
+ * );
57
+ * ```
58
+ */
59
+ function codeExecution_20250825(options) {
60
+ return {
61
+ type: "code_execution_20250825",
62
+ name: "code_execution",
63
+ cache_control: options?.cacheControl
64
+ };
65
+ }
66
+
67
+ //#endregion
68
+ export { codeExecution_20250825 };
69
+ //# sourceMappingURL=codeExecution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codeExecution.js","names":["options?: CodeExecution20250825Options"],"sources":["../../src/tools/codeExecution.ts"],"sourcesContent":["import Anthropic from \"@anthropic-ai/sdk\";\nimport { type ServerTool } from \"@langchain/core/tools\";\n\n/**\n * Options for the code execution tool.\n */\nexport interface CodeExecution20250825Options {\n /**\n * Create a cache control breakpoint at this content block.\n */\n cacheControl?: Anthropic.Beta.BetaCacheControlEphemeral;\n}\n\n/**\n * Creates a code execution tool that allows Claude to run Bash commands and manipulate files\n * in a secure, sandboxed environment. Claude can analyze data, create visualizations,\n * perform calculations, and process files.\n *\n * When this tool is provided, Claude automatically gains access to:\n * - **Bash commands**: Execute shell commands for system operations\n * - **File operations**: Create, view, and edit files directly\n *\n * @note This tool requires the beta header `code-execution-2025-08-25` in API requests.\n *\n * @see {@link https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/code-execution-tool | Anthropic Code Execution Documentation}\n * @param options - Configuration options for the code execution tool\n * @returns A code execution tool definition to be passed to the Anthropic API\n *\n * @example\n * ```typescript\n * import { ChatAnthropic, tools } from \"@langchain/anthropic\";\n *\n * const model = new ChatAnthropic({\n * model: \"claude-sonnet-4-5-20250929\",\n * });\n *\n * // Basic usage - calculations and data analysis\n * const response = await model.invoke(\n * \"Calculate the mean and standard deviation of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\",\n * { tools: [tools.codeExecution_20250825()] }\n * );\n *\n * // File operations and visualization\n * const response2 = await model.invoke(\n * \"Create a matplotlib visualization of sales data and save it as chart.png\",\n * { tools: [tools.codeExecution_20250825()] }\n * );\n * ```\n *\n * @example Container reuse\n * ```typescript\n * // First request - creates a container\n * const response1 = await model.invoke(\n * \"Write a random number to /tmp/number.txt\",\n * { tools: [tools.codeExecution_20250825()] }\n * );\n *\n * // Extract container ID from response for reuse\n * const containerId = response1.response_metadata?.container?.id;\n *\n * // Second request - reuse container to access the file\n * const response2 = await model.invoke(\n * \"Read /tmp/number.txt and calculate its square\",\n * {\n * tools: [tools.codeExecution_20250825()],\n * // Pass container ID to reuse the same environment\n * }\n * );\n * ```\n */\nexport function codeExecution_20250825(\n options?: CodeExecution20250825Options\n): ServerTool {\n return {\n type: \"code_execution_20250825\",\n name: \"code_execution\",\n cache_control: options?.cacheControl,\n } satisfies Anthropic.Beta.BetaCodeExecutionTool20250825;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,SAAgB,uBACdA,SACY;AACZ,QAAO;EACL,MAAM;EACN,MAAM;EACN,eAAe,SAAS;CACzB;AACF"}