UNPKG

@langchain/anthropic

Version:
1 lines 4.08 kB
{"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"}