Skip to content
Kward Search API index

Class: Kward::Tools::Base

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

Overview

Base class for model-callable tools and their JSON schemas.

Concrete built-in tools initialize this class with their model-facing name, description, and strict argument schema, then implement call to perform the operation. Tool execution is coordinated by Kward::ToolRegistry.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description, properties: {}, required: []) ⇒ Base

Creates a tool schema definition shared by all concrete tool wrappers.

Parameters:

  • name (String) —

    function name exposed to the model

  • description (String) —

    model-facing description of the operation

  • properties (Hash) (defaults to: {}) —

    JSON Schema properties keyed by argument name

  • required (Array<String, Symbol>) (defaults to: []) —

    required argument names



24
25
26
27
28
29
# File 'lib/kward/tools/base.rb', line 24

def initialize(name, description, properties: {}, required: [])
  @name = name
  @description = description
  @properties = properties
  @required = required
end

Instance Attribute Details

#name ⇒ String (readonly)

Returns function name exposed to the model.

Returns:

  • (String) —

    function name exposed to the model



16
17
18
# File 'lib/kward/tools/base.rb', line 16

def name
  @name
end

Instance Method Details

#schema ⇒ Hash

Returns the strict JSON schema advertised to model providers.

Returns:

  • (Hash) —

    function schema with additional properties disabled



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kward/tools/base.rb', line 35

def schema
  {
    type: "function",
    function: {
      name: @name,
      description: @description,
      parameters: {
        type: "object",
        properties: sorted_properties,
        required: @required.sort,
        additionalProperties: false
      }
    }
  }
end