Class: Omakase::Tools::Ruby

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/omakase/tools/ruby.rb

Overview

The model's one tool. Every capability of the agent reaches the model through it, so the model composes calls in code instead of one per turn.

Constant Summary collapse

BUDGET =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent, schema, budget: BUDGET, timeout: Executor::TIMEOUT, executor: Omakase.executor) ⇒ Ruby

Returns a new instance of Ruby.



20
21
22
23
24
25
26
27
28
# File 'lib/omakase/tools/ruby.rb', line 20

def initialize(agent, schema, budget: BUDGET, timeout: Executor::TIMEOUT, executor: Omakase.executor)
  super()
  @agent = agent
  @schema = schema
  @budget = budget
  @timeout = timeout
  @executor = executor
  @calls = 0
end

Instance Attribute Details

#answerObject (readonly)

Returns the value of attribute answer.



18
19
20
# File 'lib/omakase/tools/ruby.rb', line 18

def answer
  @answer
end

Instance Method Details

#execute(code:) ⇒ Object



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

def execute(code:)
  # Nothing bounds the provider's tool loop, so the budget does.
  @calls += 1
  return "No tool calls left — answer with what you have." if @calls == @budget + 1
  return halt("Tool budget spent.") if @calls > @budget + 1

  outcome = @executor.call(@agent, code, timeout: @timeout)
  return outcome unless outcome.is_a?(Executor::Answer)

  @answer = Executor::Answer.new(value: @schema.take(outcome.value))
  halt("Answer accepted.")
rescue Error => e
  # Off-contract answers are corrected inside the same loop, not by another request.
  "finish rejected: #{e.message}"
end

#nameObject



30
# File 'lib/omakase/tools/ruby.rb', line 30

def name = "ruby"