Class: OmniAgent::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/omni_agent/tool.rb,
lib/omni_agent/tool/schema_builder.rb

Defined Under Namespace

Classes: SchemaBuilder

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configured_tagsObject



20
21
22
# File 'lib/omni_agent/tool.rb', line 20

def configured_tags
  tags
end

.description(text = nil) ⇒ Object



4
5
6
7
# File 'lib/omni_agent/tool.rb', line 4

def description(text = nil)
  @description = text if text
  @description || "No description provided."
end

.input(&block) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/omni_agent/tool.rb', line 24

def input(&block)
  if block_given?
    builder = SchemaBuilder.new
    builder.instance_eval(&block)

    @properties = builder.properties
    @required = builder.required_fields
  end
end

.json_schemaObject



34
35
36
37
38
39
40
41
# File 'lib/omni_agent/tool.rb', line 34

def json_schema
  {
    type: "object",
    properties: @properties || {},
    required: @required || [],
    additionalProperties: false
  }
end

.metadata(options = nil) ⇒ Object



9
10
11
12
# File 'lib/omni_agent/tool.rb', line 9

def (options = nil)
  @metadata = options if options
  @metadata || {}
end

.parse_arguments(arguments_hash) ⇒ Object



43
44
45
46
47
# File 'lib/omni_agent/tool.rb', line 43

def parse_arguments(arguments_hash)
  kwargs = arguments_hash.transform_keys(&:to_sym)
  valid_keys = (@properties || {}).keys.map(&:to_sym)
  kwargs.slice(*valid_keys)
end

.stops_generation(value = true) ⇒ Object



49
50
51
# File 'lib/omni_agent/tool.rb', line 49

def stops_generation(value = true)
  @stops_generation = !!value
end

.stops_generation?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/omni_agent/tool.rb', line 53

def stops_generation?
  @stops_generation == true
end

.tags(*tag_names) ⇒ Object



14
15
16
17
18
# File 'lib/omni_agent/tool.rb', line 14

def tags(*tag_names)
  return @tags || [] if tag_names.empty?

  @tags = (tags + normalize_tags(tag_names)).uniq
end

Instance Method Details

#execute(**args) ⇒ Object

Raises:

  • (NotImplementedError)


85
86
87
# File 'lib/omni_agent/tool.rb', line 85

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

#invoke(arguments_hash) ⇒ Object



72
73
74
75
# File 'lib/omni_agent/tool.rb', line 72

def invoke(arguments_hash)
  filtered_kwargs = self.class.parse_arguments(arguments_hash)
  execute(**filtered_kwargs)
end

#stop_generation!Object



77
78
79
# File 'lib/omni_agent/tool.rb', line 77

def stop_generation!
  @stops_generation_instance = true
end

#stops_generation?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/omni_agent/tool.rb', line 81

def stops_generation?
  @stops_generation_instance == true
end