Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tools

LangChainRust ships with 12+ built-in tools and a #[tool] macro for custom tools.

Built-in Tools

ToolStructNameKey Input
CalculatorCalculatorcalculatorexpression: String
DateTimeDateTimeTooldatetimeoperation, datetime, unit
MathSimpleMathToolmathoperation, value, value2
Python REPLPythonREPLToolpython_replcode: String
DuckDuckGo SearchDuckDuckGoSearchToolweb_searchquery: String
URL FetchURLFetchToolurl_fetchurl, operation
WikipediaWikipediaToolwikipediaquery, lang
FileFileToolfile_operationop, path, content
HTTPHTTPToolhttp_requesturl, method, body
SQLSQLToolsql_querySQL string
Computer UseComputerUseToolcomputer_useaction, coordinate
SandboxSandboxTool<S>code_interpretercode: String

Using Tools with Agents

#![allow(unused)]
fn main() {
use langchainrust::tools::{Calculator, DateTimeTool, SimpleMathTool};
use langchainrust::{FunctionCallingAgent, AgentExecutor, BaseAgent};
use std::sync::Arc;

let tools: Vec<Arc<dyn BaseTool>> = vec![
    Arc::new(Calculator::new()),
    Arc::new(DateTimeTool::new()),
    Arc::new(SimpleMathTool::new()),
];

let agent = FunctionCallingAgent::new(llm, tools.clone(), None);
let executor = AgentExecutor::new(Arc::new(agent) as Arc<dyn BaseAgent>, tools)
    .with_max_iterations(5);

let result = executor.invoke("Calculate 15 * 4 and tell me the time".to_string()).await?;
}

Security Features

HTTPTool: SSRF protection by default – blocks private IPs (127.0.0.1, 10.x, 192.168.x, cloud metadata).

FileTool: Path traversal prevention, extension whitelist, size limits.

SQLTool: SELECT-only, blocks SQL comments and dangerous patterns (sleep, benchmark, exec).

PythonREPLTool: Disabled by default; blocks dangerous imports (os, subprocess, socket); configurable timeout.

Sandbox

#![allow(unused)]
fn main() {
use langchainrust::tools::sandbox::{LocalSandbox, CodeSandbox, Language, SandboxTool};

let sandbox = LocalSandbox::new();
let result = sandbox.run("print(2 + 2)", Language::Python, 10_000).await?;
// result.stdout, result.stderr, result.exit_code

let tool = SandboxTool::new(LocalSandbox::new(), Language::Python).with_timeout(10_000);
}

Computer Use

#![allow(unused)]
fn main() {
use langchainrust::tools::ComputerUseTool;

let tool = ComputerUseTool::new_anthropic("sk-...", 1920, 1080);
// Actions: screenshot, click, type, scroll, key_press, wait
}

See also