Skip to content

Commit cd1571f

Browse files
add docs
1 parent f354802 commit cd1571f

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

libs/providers/langchain-anthropic/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,64 @@ const response2 = await llm.invoke(
506506

507507
For more information, see [Anthropic's Code Execution Tool documentation](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/code-execution-tool).
508508

509+
### Bash Tool
510+
511+
The bash tool (`bash_20250124`) enables shell command execution in a persistent bash session. Unlike the sandboxed code execution tool, this tool requires you to provide your own execution environment.
512+
513+
> **⚠️ Security Warning:** The bash tool provides direct system access. Implement safety measures such as running in isolated environments (Docker/VM), command filtering, and resource limits.
514+
515+
The bash tool provides:
516+
517+
- **Persistent bash session** - Maintains state between commands
518+
- **Shell command execution** - Run any shell command
519+
- **Environment access** - Access to environment variables and working directory
520+
- **Command chaining** - Support for pipes, redirects, and scripting
521+
522+
Available commands:
523+
524+
- Execute a command: `{ command: "ls -la" }`
525+
- Restart the session: `{ restart: true }`
526+
527+
```typescript
528+
import { ChatAnthropic, bash_20250124 } from "@langchain/anthropic";
529+
import type { Bash20250124Command } from "@langchain/anthropic";
530+
import { execSync } from "child_process";
531+
532+
const llm = new ChatAnthropic({
533+
model: "claude-sonnet-4-5-20250929",
534+
});
535+
536+
const bash = bash_20250124({
537+
execute: async (args: Bash20250124Command) => {
538+
if (args.restart) {
539+
// Reset session state
540+
return "Bash session restarted";
541+
}
542+
try {
543+
const output = execSync(args.command!, {
544+
encoding: "utf-8",
545+
timeout: 30000,
546+
});
547+
return output;
548+
} catch (error) {
549+
return `Error: ${(error as Error).message}`;
550+
}
551+
},
552+
});
553+
554+
const llmWithBash = llm.bindTools([bash]);
555+
556+
const response = await llmWithBash.invoke(
557+
"List all Python files in the current directory"
558+
);
559+
560+
// Process tool calls and execute commands
561+
console.log(response.tool_calls?.[0].name); // "bash"
562+
console.log(response.tool_calls?.[0].args.command); // "ls -la *.py"
563+
```
564+
565+
For more information, see [Anthropic's Bash Tool documentation](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/bash-tool).
566+
509567
## Development
510568

511569
To develop the Anthropic package, you'll need to follow these instructions:

0 commit comments

Comments
 (0)