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 23 24 25 |
# 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. A JSON answer can still be given in a tool-free turn. return Predict.call(request, task: "#{request.task}\n\nWork done:\n#{notes}") unless request.schema.code_only? # An object cannot come back as JSON, so there is nowhere to fall back to. raise ContractError, "#{request.generation.name}: the model never called finish(#{request.schema.describe})" end |
.capabilities(request) ⇒ Object
46 47 48 |
# File 'lib/omakase/strategies/code_act.rb', line 46 def capabilities(request) Capabilities.of(request.agent.class, except: request.generation.name).map { |entry| "- #{entry}" } end |
.instructions(request) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/omakase/strategies/code_act.rb', line 27 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 |