Class: OpenRouter::SubagentTool

Inherits:
Tool
  • Object
show all
Defined in:
lib/open_router/subagent_tool.rb

Overview

Represents the openrouter:subagent server tool, which lets an orchestrator model delegate self-contained subtasks to a cheaper worker model mid-generation.

Unlike a function Tool, it serializes to the server-tool shape:

{ type: "openrouter:subagent", parameters: { model:, instructions:, ... } }

Examples:

sub = OpenRouter::SubagentTool.new(model: "z-ai/glm-5.2", instructions: "Be concise.")
client.complete(messages, model: "anthropic/claude-3.5-sonnet", tools: [sub])

Constant Summary collapse

SERVER_TOOL_TYPE =
"openrouter:subagent"

Instance Attribute Summary

Attributes inherited from Tool

#function, #type

Instance Method Summary collapse

Methods inherited from Tool

define, #to_json

Constructor Details

#initialize(model:, instructions: nil, max_completion_tokens: nil, temperature: nil, reasoning: nil) ⇒ SubagentTool

We deliberately do not call super: Tool#initialize expects a function definition with a name/description and validates it, neither of which a server tool has. The server-tool shape is built directly here instead.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/open_router/subagent_tool.rb', line 21

def initialize(model:, instructions: nil, max_completion_tokens: nil, # rubocop:disable Lint/MissingSuper
               temperature: nil, reasoning: nil)
  raise ArgumentError, "model is required for SubagentTool" if model.nil? || model.to_s.strip.empty?

  @type = SERVER_TOOL_TYPE
  @parameters_config = {
    model: model,
    instructions: instructions,
    max_completion_tokens: max_completion_tokens,
    temperature: temperature,
    reasoning: reasoning
  }.compact
end

Instance Method Details

#descriptionObject



43
44
45
# File 'lib/open_router/subagent_tool.rb', line 43

def description
  "OpenRouter subagent server tool (worker: #{@parameters_config[:model]})"
end

#nameObject



39
40
41
# File 'lib/open_router/subagent_tool.rb', line 39

def name
  @type
end

#parametersObject



47
48
49
# File 'lib/open_router/subagent_tool.rb', line 47

def parameters
  nil
end

#to_hObject



35
36
37
# File 'lib/open_router/subagent_tool.rb', line 35

def to_h
  { type: @type, parameters: @parameters_config }
end