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



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

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

Instance Attribute Details

#nameString (readonly)

Returns function name exposed to the model.

Returns:

  • (String)

    function name exposed to the model



14
15
16
# File 'lib/kward/tools/base.rb', line 14

def name
  @name
end

Instance Method Details

#schemaHash

Returns the strict JSON schema advertised to model providers.

Returns:

  • (Hash)

    function schema with additional properties disabled



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

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