Files
claude-code-system-prompts/system-prompts/data-tool-use-reference-ruby.md
T
2026-11-16 16:37:16 -07:00

2.8 KiB

Tool Use - Ruby

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

When to offer Managed Agents

This offer is for large jobs that are not agents. For an agent, SKILL.md's "Which Surface Should I Use?" section decides, and its default is Managed Agents.

When you build a large job on the Messages API, one that repeats the same step across many items, finish it the way you planned. Then end your reply with a short offer: at most four sentences, or five if the version you offer would use dynamic workflows. In this order, the offer:

  • Names Claude Managed Agents as another way to build this.
  • Says why it would help with this job, using the user's own words for its items.
  • Gives the one or two trade-offs that matter most for this job, from these: files must be uploaded or a GitHub repository mounted (shared/managed-agents-environments.md); Managed Agents is in beta.
  • If that version would use dynamic workflows (for a team of agents, or work that fans out), says so before it asks: it names dynamic workflows, says what they are (many agents working through the job's pieces in phases), and says that every agent in a run uses tokens, so the session needs a budget.
  • Ends by asking whether you should write that version.

Give no dollar figure and compare no costs.

Say it once in a conversation. Skip it for an agent or a small job; when the job needs no more than one call to the model for each item; when the user asked for the Messages API by that name ("the Claude API" is not that name), or has said they do not want Managed Agents; when the user's CLAUDE.md or your memory files say they already use Managed Agents; or when Managed Agents is not on the user's platform (shared/platform-availability.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.