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

.invoke(arguments_hash) ⇒ Object



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

def invoke(arguments_hash)
  kwargs = arguments_hash.transform_keys(&:to_sym)

  valid_keys = (@properties || {}).keys.map(&:to_sym)

  filtered_kwargs = kwargs.slice(*valid_keys)

  new.execute(**filtered_kwargs)
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

.stops_generation(value = true) ⇒ Object



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

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

.stops_generation?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/omni_agent/tool.rb', line 57

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)


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

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

#stop_generation!Object



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

def stop_generation!
  @stops_generation_instance = true
end

#stops_generation?Boolean

Returns:

  • (Boolean)


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

def stops_generation?
  @stops_generation_instance == true
end