Module: Omakase::Strategies::CodeAct

Defined in:
lib/omakase/strategies/code_act.rb

Overview

The model acts by writing Ruby against the agent object and answers with finish(value) — the answer is computed, not retyped.

Class Method Summary collapse

Class Method Details

.call(request) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/omakase/strategies/code_act.rb', line 10

def call(request)
  tool = Tools::Ruby.new(request.agent, request.schema)
  notes = request.chat
    .with_instructions(instructions(request))
    .with_tool(tool)
    .ask(request.task)
    .content

  return tool.answer.value if tool.answer

  # It never called finish: fall back to a tool-free turn under the schema.
  Predict.call(request, task: "#{request.task}\n\nWork done:\n#{notes}")
end

.capabilities(request) ⇒ Object



43
44
45
# File 'lib/omakase/strategies/code_act.rb', line 43

def capabilities(request)
  Capabilities.of(request.agent.class, except: request.generation.name).map { |entry| "- #{entry}" }
end

.instructions(request) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/omakase/strategies/code_act.rb', line 24

def instructions(request)
  <<~TEXT
    #{request.instructions}

    You act by writing Ruby: call the `ruby` tool with code that is evaluated on the
    agent object, so its methods and state are available on self.

    #{capabilities(request).join("\n")}

    `doc(object)` prints what an object of an unfamiliar type offers.

    Return the answer from inside the code, never as a message — the last thing you run is:

        finish(#{request.schema.describe})

    Work in as few tool calls as you can.
  TEXT
end