Mark a tool as callable from Claude's code execution environment.
Arguments
- tool
A tool object from
claude_tool().
Details
Programmatic tool calling enables Claude to orchestrate tools through code rather than individual API round-trips. Claude writes Python code that calls multiple tools, processes outputs, and controls what enters context.
Requirements:
Beta header:
beta_headers$BETA_ADVANCED_TOOLSCode execution tool must be enabled
Benefits:
37%+ reduction in token consumption
Batch processing of tool calls
Filtered/aggregated results
API Reference: https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling
Examples
if (FALSE) { # \dontrun{
# Create programmatic search tool
search_tool <- claude_tool_programmatic(claude_tool(
fn = function(query) paste("Results for:", query),
name = "search",
desc = "Search the database",
query = ellmer::type_string("Search query")
))
chat <- claude_new(
tools = list(search_tool, claude_code_exec(type = "python")),
beta = c(beta_headers$BETA_ADVANCED_TOOLS, beta_headers$BETA_CODE_EXEC_PYTHON)
)
chat$chat("Search for 'impressionism', 'baroque', and 'renaissance' and combine results")
# Claude writes Python to call search 3 times and aggregate
} # }
