Module: OllamaAgent::Tools::Registry
- Defined in:
- lib/ollama_agent/tools/registry.rb
Overview
Stores and executes custom tool definitions registered by users.
Class Method Summary collapse
- .custom_schemas ⇒ Object
- .custom_tool?(name) ⇒ Boolean
- .execute_custom(name, args, root:, read_only:) ⇒ Object
- .register(name, schema:, &handler) ⇒ Object
- .reset! ⇒ Object
Class Method Details
.custom_schemas ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/ollama_agent/tools/registry.rb', line 40 def custom_schemas @custom_tools.map do |name, entry| { type: "function", function: entry[:schema].merge(name: name) } end end |
.custom_tool?(name) ⇒ Boolean
29 30 31 |
# File 'lib/ollama_agent/tools/registry.rb', line 29 def custom_tool?(name) @custom_tools.key?(name.to_s) end |
.execute_custom(name, args, root:, read_only:) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/ollama_agent/tools/registry.rb', line 33 def execute_custom(name, args, root:, read_only:) entry = @custom_tools[name.to_s] return "Unknown custom tool: #{name}" unless entry entry[:handler].call(args, root: root, read_only: read_only) end |
.register(name, schema:, &handler) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/ollama_agent/tools/registry.rb', line 22 def register(name, schema:, &handler) raise ArgumentError, "handler block required" unless block_given? raise ArgumentError, "schema must be a Hash" unless schema.is_a?(Hash) @custom_tools[name.to_s] = { schema: schema, handler: handler } end |
.reset! ⇒ Object
49 50 51 |
# File 'lib/ollama_agent/tools/registry.rb', line 49 def reset! @custom_tools = {} end |