Skip to contents

Mark a tool for deferred loading in tool search scenarios.

Usage

claude_tool_defer(tool)

Arguments

tool

A tool object from claude_tool().

Value

The tool with defer_loading = TRUE attribute.

Details

When using tool search (beta), you can mark tools for deferred loading. Claude will search for and load only the tools it needs, rather than loading all tool definitions into context upfront.

This enables working with hundreds of tools without context exhaustion.

Requires: beta = beta_headers$BETA_TOOL_SEARCH

API Reference: https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-search-tool

Examples

if (FALSE) { # \dontrun{
# Create 100 tools with deferred loading
tools <- lapply(1:100, function(i) {
  claude_tool_defer(claude_tool(
    fn = function() paste("Result from tool", i),
    name = paste0("tool_", i),
    desc = paste("Tool number", i)
  ))
})

chat <- claude_new(
  tools = tools,
  beta = beta_headers$BETA_TOOL_SEARCH
)
chat$chat("Use tool_42")
# Only tool_42 is loaded into context
} # }