Class: OllamaAgent::Tools::HttpGet

Inherits:
Base
  • Object
show all
Defined in:
lib/ollama_agent/tools/http_tools.rb

Overview

HTTP GET tool — for fetching documentation, APIs, public resources. rubocop:disable Metrics/ClassLength, Metrics/MethodLength, Metrics/AbcSize – schema + URL policy + Net::HTTP

Constant Summary collapse

DEFAULT_MAX_BYTES =
32_768
ALLOWED_SCHEMES =
%w[http https].freeze
ALLOWED_CONTENT_TYPES =
%w[
  text/plain text/html text/markdown application/json application/xml
  text/xml text/csv application/yaml text/yaml
].freeze

Constants inherited from Base

Base::RISK_LEVELS

Instance Attribute Summary

Attributes inherited from Base

#description, #input_schema, #name, #output_schema, #requires_approval, #risk_level

Instance Method Summary collapse

Methods inherited from Base

#to_anthropic_schema, #to_ollama_schema, #to_s, tool_description, tool_name, tool_output_schema, tool_requires_approval, tool_risk, tool_schema

Constructor Details

#initialize(allowed_hosts: nil, denied_hosts: nil, timeout: 15, **_opts) ⇒ HttpGet

Returns a new instance of HttpGet.



55
56
57
58
59
60
# File 'lib/ollama_agent/tools/http_tools.rb', line 55

def initialize(allowed_hosts: nil, denied_hosts: nil, timeout: 15, **_opts)
  super()
  @allowed_hosts = allowed_hosts
  @denied_hosts  = Array(denied_hosts)
  @timeout       = timeout
end

Instance Method Details

#call(args, _context: {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/ollama_agent/tools/http_tools.rb', line 62

def call(args, _context: {})
  url       = args["url"].to_s.strip
  max_bytes = [args["max_bytes"]&.to_i || DEFAULT_MAX_BYTES, 131_072].min

  uri = parse_and_validate_url!(url)
  check_host!(uri.host)

  headers = build_headers(args["headers"])
  fetch(uri, headers: headers, max_bytes: max_bytes)
end