Class: OllamaAgent::ToolRuntime::ToolRegistry
- Inherits:
-
Object
- Object
- OllamaAgent::ToolRuntime::ToolRegistry
- Defined in:
- lib/ollama_agent/tool_runtime/tool_registry.rb
Overview
Phase-scoped tool visibility (planning vs mutation vs verification vs integration).
Constant Summary collapse
- PHASES =
%i[planning mutation verification integration].freeze
Instance Method Summary collapse
- #available_in(phase:) ⇒ Object
-
#initialize ⇒ ToolRegistry
constructor
A new instance of ToolRegistry.
- #invoke(name:, phase:, **args) ⇒ Object
- #register(name:, callable:, phases:) ⇒ Object
Constructor Details
#initialize ⇒ ToolRegistry
Returns a new instance of ToolRegistry.
9 10 11 |
# File 'lib/ollama_agent/tool_runtime/tool_registry.rb', line 9 def initialize @entries = {} end |
Instance Method Details
#available_in(phase:) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/ollama_agent/tool_runtime/tool_registry.rb', line 24 def available_in(phase:) ph = phase.to_sym validate_phase!(ph) @entries.filter_map do |name, | next unless [:phases].include?(ph) { name: name, callable: [:callable] } end end |
#invoke(name:, phase:, **args) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/ollama_agent/tool_runtime/tool_registry.rb', line 34 def invoke(name:, phase:, **args) ph = phase.to_sym validate_phase!(ph) entry = @entries[name.to_s] return :tool_not_available_in_phase unless entry && entry[:phases].include?(ph) entry[:callable].call(**args) end |
#register(name:, callable:, phases:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ollama_agent/tool_runtime/tool_registry.rb', line 13 def register(name:, callable:, phases:) raise ArgumentError, "callable must respond to #call" unless callable.respond_to?(:call) key = name.to_s raise ArgumentError, "duplicate tool name: #{key}" if @entries.key?(key) list = Array(phases).map(&:to_sym) list.each { |ph| validate_phase!(ph) } @entries[key] = { callable: callable, phases: list } end |