Files
claude-code-system-prompts/system-prompts/data-tool-use-reference-ruby.md
T
2026-08-25 19:39:27 -06:00

1.2 KiB

Tool Use - Ruby

For conceptual overview (tool definitions, tool choice, tips), see shared/tool-use-concepts.md.

Tool Use

The Ruby SDK supports tool use via raw JSON schema definitions and also provides a beta tool runner for automatic tool execution.

Tool Runner (Beta)

class GetWeatherInput < Anthropic::BaseModel
  required :location, String, doc: "City and state, e.g. San Francisco, CA"
end

class GetWeather < Anthropic::BaseTool
  doc "Get the current weather for a location"

  input_schema GetWeatherInput

  def call(input)
    "The weather in #{input.location} is sunny and 72°F."
  end
end

client.beta.messages.tool_runner(
  model: :"{{OPUS_ID}}",
  max_tokens: 16000,
  tools: [GetWeather.new],
  messages: [{ role: "user", content: "What's the weather in San Francisco?" }]
).each_message do |message|
  puts message.content
end

Manual Loop

See the shared tool use concepts for the tool definition format and agentic loop pattern.