Class: Tools::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/tools/base.rb

Overview

This class is abstract.

Abstract base class for all Anima tools. Subclasses must implement the class-level schema methods and the instance-level #execute method.

Examples:

Implementing a tool

class Tools::Echo < Tools::Base
  def self.tool_name = "echo"
  def self.description = "Echoes input back"
  def self.input_schema
    {type: "object", properties: {text: {type: "string"}}, required: ["text"]}
  end

  def execute(input)
    input["text"]
  end
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Accepts and discards context keywords so that the Registry can pass shared dependencies (e.g. shell_session) to any tool uniformly. Subclasses that need specific context should override with named kwargs.



49
# File 'lib/tools/base.rb', line 49

def initialize(**) = nil

Class Method Details

.descriptionString

Returns human-readable description for the LLM.

Returns:

  • (String)

    human-readable description for the LLM

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/tools/base.rb', line 30

def description
  raise NotImplementedError, "#{self} must implement .description"
end

.input_schemaHash

Returns JSON Schema describing the tool’s input parameters.

Returns:

  • (Hash)

    JSON Schema describing the tool’s input parameters

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/tools/base.rb', line 35

def input_schema
  raise NotImplementedError, "#{self} must implement .input_schema"
end

.schemaHash

Builds the schema hash expected by the Anthropic tools API.

Returns:

  • (Hash)

    with :name, :description, and :input_schema keys



41
42
43
# File 'lib/tools/base.rb', line 41

def schema
  {name: tool_name, description: description, input_schema: input_schema}
end

.tool_nameString

Returns unique tool identifier sent to the LLM.

Returns:

  • (String)

    unique tool identifier sent to the LLM

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/tools/base.rb', line 25

def tool_name
  raise NotImplementedError, "#{self} must implement .tool_name"
end

Instance Method Details

#execute(input) ⇒ String, Hash

Execute the tool with the given input.

Parameters:

  • input (Hash)

    parsed input matching input_schema. May include a “timeout” key (seconds) for tools that support per-call timeout overrides.

Returns:

  • (String, Hash)

    result content; Hash with :error key signals failure

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/tools/base.rb', line 55

def execute(input)
  raise NotImplementedError, "#{self.class} must implement #execute"
end