Class: OllamaAgent::Tools::Base
- Inherits:
-
Object
- Object
- OllamaAgent::Tools::Base
- Defined in:
- lib/ollama_agent/tools/base.rb
Overview
Base class for all typed, permissioned, auditable tools.
Subclasses must implement #call(args, context:) and define:
- name String
- description String
- input_schema Hash (JSON schema for arguments)
Direct Known Subclasses
FilesystemExplorer, GitBase, HttpGet, HttpPost, MemoryDelete, MemoryList, MemoryRecall, MemoryStore, RunShell, SafeCalculator
Constant Summary collapse
- RISK_LEVELS =
%i[low medium high critical].freeze
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#input_schema ⇒ Object
readonly
Returns the value of attribute input_schema.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output_schema ⇒ Object
readonly
Returns the value of attribute output_schema.
-
#requires_approval ⇒ Object
readonly
Returns the value of attribute requires_approval.
-
#risk_level ⇒ Object
readonly
Returns the value of attribute risk_level.
Class Method Summary collapse
- .tool_description(desc = nil) ⇒ Object
- .tool_name(name = nil) ⇒ Object
- .tool_output_schema(schema = nil) ⇒ Object
- .tool_requires_approval(flag = nil) ⇒ Object
- .tool_risk(level = nil) ⇒ Object
- .tool_schema(schema = nil) ⇒ Object
Instance Method Summary collapse
-
#call(args, context: {}) ⇒ String, Hash
Execute the tool.
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#to_anthropic_schema ⇒ Object
Anthropic-format tool definition.
-
#to_ollama_schema ⇒ Object
JSON schema formatted for Ollama / OpenAI tool_call.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
63 64 65 66 67 68 69 70 |
# File 'lib/ollama_agent/tools/base.rb', line 63 def initialize @name = self.class.tool_name @description = self.class.tool_description @input_schema = self.class.tool_schema @output_schema = self.class.tool_output_schema @risk_level = self.class.tool_risk @requires_approval = self.class.tool_requires_approval end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
61 62 63 |
# File 'lib/ollama_agent/tools/base.rb', line 61 def description @description end |
#input_schema ⇒ Object (readonly)
Returns the value of attribute input_schema.
61 62 63 |
# File 'lib/ollama_agent/tools/base.rb', line 61 def input_schema @input_schema end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
61 62 63 |
# File 'lib/ollama_agent/tools/base.rb', line 61 def name @name end |
#output_schema ⇒ Object (readonly)
Returns the value of attribute output_schema.
61 62 63 |
# File 'lib/ollama_agent/tools/base.rb', line 61 def output_schema @output_schema end |
#requires_approval ⇒ Object (readonly)
Returns the value of attribute requires_approval.
61 62 63 |
# File 'lib/ollama_agent/tools/base.rb', line 61 def requires_approval @requires_approval end |
#risk_level ⇒ Object (readonly)
Returns the value of attribute risk_level.
61 62 63 |
# File 'lib/ollama_agent/tools/base.rb', line 61 def risk_level @risk_level end |
Class Method Details
.tool_description(desc = nil) ⇒ Object
32 33 34 35 |
# File 'lib/ollama_agent/tools/base.rb', line 32 def tool_description(desc = nil) @tool_description = desc if desc @tool_description || "" end |
.tool_name(name = nil) ⇒ Object
27 28 29 30 |
# File 'lib/ollama_agent/tools/base.rb', line 27 def tool_name(name = nil) @tool_name = name.to_s if name @tool_name || raise(NotImplementedError, "#{self}.tool_name not set") end |
.tool_output_schema(schema = nil) ⇒ Object
55 56 57 58 |
# File 'lib/ollama_agent/tools/base.rb', line 55 def tool_output_schema(schema = nil) @tool_output_schema = schema if schema @tool_output_schema end |
.tool_requires_approval(flag = nil) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/ollama_agent/tools/base.rb', line 42 def tool_requires_approval(flag = nil) @tool_requires_approval = flag unless flag.nil? return @tool_requires_approval unless @tool_requires_approval.nil? risk = @tool_risk || :low %i[high critical].include?(risk) end |
.tool_risk(level = nil) ⇒ Object
37 38 39 40 |
# File 'lib/ollama_agent/tools/base.rb', line 37 def tool_risk(level = nil) @tool_risk = level.to_sym if level @tool_risk || :low end |
.tool_schema(schema = nil) ⇒ Object
50 51 52 53 |
# File 'lib/ollama_agent/tools/base.rb', line 50 def tool_schema(schema = nil) @tool_schema = schema if schema @tool_schema || { type: "object", properties: {}, required: [] } end |
Instance Method Details
#call(args, context: {}) ⇒ String, Hash
Execute the tool.
76 77 78 |
# File 'lib/ollama_agent/tools/base.rb', line 76 def call(args, context: {}) raise NotImplementedError, "#{self.class}#call not implemented" end |
#to_anthropic_schema ⇒ Object
Anthropic-format tool definition
93 94 95 96 97 98 99 |
# File 'lib/ollama_agent/tools/base.rb', line 93 def to_anthropic_schema { name: @name, description: @description, input_schema: @input_schema } end |
#to_ollama_schema ⇒ Object
JSON schema formatted for Ollama / OpenAI tool_call
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ollama_agent/tools/base.rb', line 81 def to_ollama_schema { type: "function", function: { name: @name, description: @description, parameters: @input_schema } } end |
#to_s ⇒ Object
101 102 103 |
# File 'lib/ollama_agent/tools/base.rb', line 101 def to_s "#<Tool:#{@name} risk=#{@risk_level} approval=#{@requires_approval}>" end |