Class: OllamaAgent::ToolRuntime::Registry
- Inherits:
-
Object
- Object
- OllamaAgent::ToolRuntime::Registry
- Defined in:
- lib/ollama_agent/tool_runtime/registry.rb
Overview
Per-run tool lookup and prompt text for available tools.
Instance Method Summary collapse
- #descriptions_for_prompt ⇒ Object
-
#initialize(tools = []) ⇒ Registry
constructor
A new instance of Registry.
- #register(tool) ⇒ Object
-
#resolve(plan) ⇒ Hash?
‘{ tool: Tool instance, args: Hash }` or nil if unknown.
Constructor Details
#initialize(tools = []) ⇒ Registry
Returns a new instance of Registry.
9 10 11 12 |
# File 'lib/ollama_agent/tool_runtime/registry.rb', line 9 def initialize(tools = []) @tools = {} Array(tools).each { |tool| register(tool) } end |
Instance Method Details
#descriptions_for_prompt ⇒ Object
37 38 39 40 41 |
# File 'lib/ollama_agent/tool_runtime/registry.rb', line 37 def descriptions_for_prompt @tools.values.map do |t| "#{t.name}: #{t.description} schema=#{JSON.generate(t.schema)}" end.join("\n") end |
#register(tool) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/ollama_agent/tool_runtime/registry.rb', line 14 def register(tool) raise ArgumentError, "tool must respond to #name" unless tool.respond_to?(:name) key = tool.name.to_s raise ArgumentError, "duplicate tool name: #{key}" if @tools.key?(key) @tools[key] = tool end |
#resolve(plan) ⇒ Hash?
Returns ‘{ tool: Tool instance, args: Hash }` or nil if unknown.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ollama_agent/tool_runtime/registry.rb', line 25 def resolve(plan) return nil unless plan.is_a?(Hash) tool_name = tool_name_from(plan) return nil if tool_name.nil? || tool_name.to_s.strip.empty? tool = @tools[tool_name.to_s] return nil unless tool { tool: tool, args: normalize_args(plan) } end |