ReqAnthropic.Tools (ReqAnthropic v0.2.1)

Copy Markdown View Source

Builders for Anthropic tool definitions, so callers don't need to memorize tool type strings or beta header names.

Each builder returns a plain map suitable for passing in tools: [...] on a Messages request. Tools that depend on a beta header expose the beta string via beta_header/1 and via the :beta key on the map, so the calling resource module can wire it up automatically.

tools = [
  ReqAnthropic.Tools.web_search(),
  ReqAnthropic.Tools.bash(),
  ReqAnthropic.Tools.custom(name: "get_weather", description: "...", input_schema: %{...})
]

ReqAnthropic.Messages.create(model: "...", max_tokens: 1024, tools: tools, messages: [...])

Summary

Functions

Advisor tool. Adds the advisor-tool-2026-03-01 beta header.

Built-in bash tool.

Computer use tool. Required: :display_width_px, :display_height_px. Optional: :display_number. Adds the computer-use-2025-01-24 beta.

Define a custom tool with a JSON Schema input.

Build a %{name => function} lookup from a list of tool maps. Only tools that carry a __function__ are included.

Memory tool.

Collect any beta header strings required by a list of tool maps. The resource modules use this to merge required betas into the request before sending.

Strip internal markers (__beta__, __function__) from a list of tool maps so they can be safely sent over the wire.

Built-in text editor tool. The default name str_replace_based_edit_tool is what the Claude 4 family expects; override with :name if you need a different binding.

Web fetch tool.

Web search tool. Pass :max_uses to cap searches per request.

Functions

advisor(opts \\ [])

@spec advisor(keyword()) :: map()

Advisor tool. Adds the advisor-tool-2026-03-01 beta header.

bash(opts \\ [])

@spec bash(keyword()) :: map()

Built-in bash tool.

computer(opts)

@spec computer(keyword()) :: map()

Computer use tool. Required: :display_width_px, :display_height_px. Optional: :display_number. Adds the computer-use-2025-01-24 beta.

custom(opts)

@spec custom(keyword()) :: map()

Define a custom tool with a JSON Schema input.

An optional :function (1-arity) can be provided. When present, Messages.run/1 will call it automatically with the tool input map whenever the model invokes this tool, and feed the result back.

Tools.custom(
  name: "get_weather",
  description: "Look up the weather for a city.",
  input_schema: %{type: "object", properties: %{city: %{type: "string"}}, required: ["city"]},
  function: fn %{"city" => city} -> "72°F and sunny in #{city}" end
)

function_map(tools)

@spec function_map([map()]) :: %{required(String.t()) => (map() -> term())}

Build a %{name => function} lookup from a list of tool maps. Only tools that carry a __function__ are included.

memory(opts \\ [])

@spec memory(keyword()) :: map()

Memory tool.

required_betas(tools)

@spec required_betas([map()]) :: [String.t()]

Collect any beta header strings required by a list of tool maps. The resource modules use this to merge required betas into the request before sending.

strip(tools)

@spec strip([map()]) :: [map()]

Strip internal markers (__beta__, __function__) from a list of tool maps so they can be safely sent over the wire.

text_editor(opts \\ [])

@spec text_editor(keyword()) :: map()

Built-in text editor tool. The default name str_replace_based_edit_tool is what the Claude 4 family expects; override with :name if you need a different binding.

web_fetch(opts \\ [])

@spec web_fetch(keyword()) :: map()

Web fetch tool.

web_search(opts \\ [])

@spec web_search(keyword()) :: map()

Web search tool. Pass :max_uses to cap searches per request.