activeagent-datacircle 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 58475383e96566ee06ec3263822783aaaec305f3ba123c143666504e52f60657
4
+ data.tar.gz: b2822ff8c1197bc3c3c0e544dae7332a9c20e28677ec0ff534ec4fd37d5b5fb1
5
+ SHA512:
6
+ metadata.gz: a31c2fce17cd6b1b87c7e4185bbc4f5a352a61577487ad53ae01396023cc22d6f64873e9f4e344a146e2403796ab7c65f766eda7a7f89d9d2c314a6a3afdd2c1
7
+ data.tar.gz: dd90cc8908e835392a9064344e90c2e83a7dc19e653bb304b4f101ea966fe1a8c51b497233cc23b6af523da9269347d2b73da46ca6cc4b255c274c1505a30c50
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Datacircle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Datacircle tools for Active Agent
2
+
3
+ Find the best GTM APIs. We benchmark all the GTM APIs and we put the results on our website: https://datacircle.dev
4
+
5
+ This gem gives your [Active Agent](https://github.com/activeagents/activeagent) agents four tools that call Datacircle's open API, https://api.datacircle.dev/v1. You need no key and no account.
6
+
7
+ | Tool | What the tool gives | Call |
8
+ | --- | --- | --- |
9
+ | `datacircle_list_apis` | Every GTM API on Datacircle, with the API's slug, number of plans, number of providers and best plan | `GET /apis` |
10
+ | `datacircle_best_plans` | One API's plans, sorted by score out of 100, best first. Each plan comes with a rank and a price per 1,000 calls | `GET /apis/{slug}/best` |
11
+ | `datacircle_search_plans` | Plans that match a provider or plan name. Search all APIs or one API. Sort by score, provider or price | `GET /plans` |
12
+ | `datacircle_provider` | The APIs a provider sells, and the provider's rank on each API | `GET /providers/{slug}` |
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ bundle add activeagent-datacircle
18
+ ```
19
+
20
+ The gem needs Active Agent 1.9 or later and Ruby 3.1 or later.
21
+
22
+ ## Use the tools
23
+
24
+ Include the module in an agent. Pass `datacircle_tools` to `prompt`. The agent answers each tool call with the method of the same name.
25
+
26
+ ```ruby
27
+ class PlanAgent < ApplicationAgent
28
+ include ActiveAgent::Datacircle
29
+
30
+ def ask
31
+ prompt(message: params[:question], tools: datacircle_tools)
32
+ end
33
+ end
34
+
35
+ PlanAgent.with(question: "Which email finder API is best for under $5 per 1,000?").ask.generate_now
36
+ ```
37
+
38
+ To give an action fewer tools, pass their names to `datacircle_tools`:
39
+
40
+ ```ruby
41
+ prompt(message: params[:question], tools: datacircle_tools(:best_plans, :search_plans))
42
+ ```
43
+
44
+ `ActiveAgent::Datacircle::TOOLS` holds the four tool definitions in Active Agent's common format.
45
+
46
+ You can call a tool yourself:
47
+
48
+ ```ruby
49
+ PlanAgent.new.datacircle_best_plans(slug: "email-finder", limit: 3)
50
+ # => {"api" => "Employee email", "slug" => "email-finder", ..., "plans" => [{"api" => "Employee email", "rank" => 1, "provider" => "Emelia", ...}, ...]}
51
+ ```
52
+
53
+ Each plan comes with a rank, provider, plan, score, price per 1,000 (`perThousand`, in dollars) and a page on datacircle.dev. That page lists every field. The tool gives `{"error" => ...}` with the API's words when the API has no data, for example for an unknown slug. The agent reads the error and can call the tool again. Module calls like `ActiveAgent::Datacircle.best_plans(slug: "email-finder")` raise `ActiveAgent::Datacircle::Error` when the API has no data.
54
+
55
+ ## Network
56
+
57
+ Each tool call makes one HTTPS GET request to https://api.datacircle.dev/v1. A plan search makes a second request when the agent names a provider instead of an API. A request holds only the tool's own arguments: no key, no config, nothing from your prompts. The API takes up to 60 calls a minute from one IP address. The tool waits once, for a minute at most, when the API asks the tool to wait. The gem depends only on Active Agent and stores nothing.
58
+
59
+ ## Links
60
+
61
+ - Datacircle: https://datacircle.dev
62
+ - The API: https://datacircle.dev/api
63
+ - The API's spec: https://api.datacircle.dev/v1/openapi.json
64
+ - What each key means: https://datacircle.dev/fields
65
+
66
+ MIT license.
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveAgent
4
+ module Datacircle
5
+ # A plan holds about 90 keys (its terms of use, its aggregators...): a tool gives the ones that choose a plan,
6
+ # the rest is on its page.
7
+ PLAN_KEYS = %w[api rank provider plan score perThousand notFoundPerThousand billing pay currency units unit
8
+ strengths latencyMs page pricingPage docs].freeze
9
+
10
+ # The four calls, one HTTPS GET each: what a tool gives, or Datacircle::Error.
11
+ class << self
12
+ # GET /apis
13
+ def list_apis(query: nil, limit: nil)
14
+ words = query.to_s.downcase.tr('-', ' ').split
15
+ held = client.get('/apis').each_with_index.filter_map do |api, index|
16
+ name = "#{api['api']} #{api['slug'].to_s.tr('-', ' ')}".downcase
17
+ matched = words.count { |word| name.include?(word) }
18
+ [-matched, index, api] if matched.positive? || words.empty?
19
+ end
20
+ found = held.sort_by { |matched, index, _| [matched, index] }
21
+ .map { |_, _, api| brief(api, %w[api slug plans providers best bestPage sheetPage]) }
22
+ { 'total' => found.size, 'apis' => found.first(number(limit, 1, 200) || 20) }
23
+ end
24
+
25
+ # GET /apis/{slug}/best
26
+ def best_plans(slug:, limit: nil)
27
+ api = slugify(slug)
28
+ raise Error, "Give an API's slug, like 'email-finder': datacircle_list_apis gives every slug" if api.empty?
29
+
30
+ answer = client.get("/apis/#{api}/best", limit: number(limit, 1, 50))
31
+ answer.merge('plans' => Array(answer['plans']).map { |plan| brief(plan) })
32
+ end
33
+
34
+ # GET /plans
35
+ def search_plans(api: nil, query: nil, sort: nil, limit: nil, offset: nil)
36
+ answer = search(api, query, sort, limit, offset)
37
+ answer.merge('plans' => Array(answer['plans']).map { |plan| brief(plan) })
38
+ rescue Error => e
39
+ raise unless e.status == 400 && e.message.include?('api must be') && query.to_s.strip.empty?
40
+
41
+ # A provider's name sent as the API: the plans whose provider or plan name holds it.
42
+ answer = search(nil, api, sort, limit, offset)
43
+ { 'note' => "No API is named #{api.to_s.inspect}: these are the plans whose provider or plan name holds it." }
44
+ .merge(answer, 'plans' => Array(answer['plans']).map { |plan| brief(plan) })
45
+ end
46
+
47
+ # GET /providers/{slug}
48
+ def provider(slug:)
49
+ provider = slugify(slug)
50
+ raise Error, "Give a provider's slug or name, like 'bright-data' or 'Bright Data'" if provider.empty?
51
+
52
+ answer = client.get("/providers/#{provider}")
53
+ apis = Array(answer['apis']).map do |entry|
54
+ plans = Array(entry['plans'])
55
+ brief(entry, %w[api slug rank bestPage]).merge('plans' => plans.size, 'best' => best(plans))
56
+ end
57
+ answer.merge('apis' => apis)
58
+ end
59
+
60
+ # A tool's answer: the call's, or the API's error as { 'error' => ... } for the agent to read.
61
+ def answer
62
+ yield
63
+ rescue Error => e
64
+ { 'error' => e.message }
65
+ end
66
+
67
+ private
68
+
69
+ def client
70
+ @client ||= Client.new
71
+ end
72
+
73
+ def search(api, query, sort, limit, offset)
74
+ client.get('/plans', api: api, query: query, sort: (sort.to_s if %w[score provider price].include?(sort.to_s)),
75
+ limit: number(limit, 1, 50), offset: number(offset, 0, 1_000_000))
76
+ end
77
+
78
+ def brief(item, keys = PLAN_KEYS)
79
+ keys.each_with_object({}) { |key, kept| kept[key] = item[key] unless item[key].nil? }
80
+ end
81
+
82
+ # A number the agent sent, within the API's range, or nil when it sent none.
83
+ def number(value, low, high)
84
+ return nil if value.nil? || value.to_s.strip.empty?
85
+
86
+ Integer(value.to_s.strip, 10).clamp(low, high)
87
+ rescue ArgumentError
88
+ nil
89
+ end
90
+
91
+ # The API's rule for a slug: the name in lowercase letters and digits, the rest a hyphen.
92
+ def slugify(value)
93
+ value.to_s.strip.downcase.unicode_normalize(:nfkd).gsub(/\p{Mn}/, '').gsub(/[^a-z0-9]+/, '-').gsub(/\A-|-\z/, '')
94
+ end
95
+
96
+ # A provider's best plan on an API: its lowest rank, a plan with no score having none.
97
+ def best(plans)
98
+ top = plans.min_by { |plan| plan['rank'].is_a?(Numeric) ? plan['rank'] : Float::INFINITY }
99
+ top && brief(top, %w[plan score perThousand page])
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'uri'
6
+
7
+ module ActiveAgent
8
+ module Datacircle
9
+ # What Datacircle's API answered when it gave no data (its HTTP status in #status), or why it could not be reached.
10
+ class Error < StandardError
11
+ attr_reader :status
12
+
13
+ def initialize(message = nil, status: nil)
14
+ super(message)
15
+ @status = status
16
+ end
17
+ end
18
+
19
+ # One HTTPS GET to Datacircle's open API, with no key: its answer as a Hash or an Array.
20
+ class Client
21
+ BASE = 'https://api.datacircle.dev/v1'
22
+
23
+ def get(path, params = {})
24
+ uri = URI("#{BASE}#{path}")
25
+ query = params.reject { |_, value| value.nil? || value == '' }
26
+ uri.query = URI.encode_www_form(query) unless query.empty?
27
+ 2.times do |attempt|
28
+ response = request(uri)
29
+ return JSON.parse(response.body) if response.is_a?(Net::HTTPSuccess)
30
+
31
+ if response.code == '429' && attempt.zero?
32
+ sleep(wait(response))
33
+ next
34
+ end
35
+ raise Error.new("Datacircle's API answered #{response.code}: #{words(response.body)}", status: response.code.to_i)
36
+ end
37
+ raise Error, "Datacircle's API answered 429 twice: wait a minute and call again"
38
+ end
39
+
40
+ private
41
+
42
+ def request(uri)
43
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 15, read_timeout: 30) do |http|
44
+ http.get(uri.request_uri, 'Accept' => 'application/json', 'User-Agent' => "activeagent-datacircle/#{VERSION}")
45
+ end
46
+ rescue SocketError, SystemCallError, Timeout::Error, OpenSSL::SSL::SSLError, Net::HTTPBadResponse => e
47
+ raise Error, "Datacircle's API could not be reached: #{e.message}"
48
+ end
49
+
50
+ # The API asks to wait in Retry-After: its seconds, a minute at most.
51
+ def wait(response)
52
+ Integer(response['Retry-After'] || 30).clamp(1, 60)
53
+ rescue ArgumentError
54
+ 30
55
+ end
56
+
57
+ # The API's error, with the slugs it knows when it gives them.
58
+ def words(body)
59
+ parsed = JSON.parse(body)
60
+ return body[0, 3000] unless parsed.is_a?(Hash) && parsed['error']
61
+ return parsed['error'] unless parsed['slugs']
62
+
63
+ "#{parsed['error']}; the slugs: #{Array(parsed['slugs']).join(', ')}"[0, 3000]
64
+ rescue JSON::ParserError
65
+ body.to_s[0, 3000]
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveAgent
4
+ module Datacircle
5
+ # The four tools in Active Agent's common format, for prompt(tools: ...): each one's name is the agent's method
6
+ # that answers it.
7
+ TOOLS = [
8
+ {
9
+ name: 'datacircle_list_apis',
10
+ description: "Lists the GTM APIs on Datacircle's sheet (https://datacircle.dev), with each API's slug, " \
11
+ "how many plans and providers it has and its best plan. Call it first to find an API's slug.",
12
+ parameters: {
13
+ type: 'object',
14
+ properties: {
15
+ query: { type: 'string',
16
+ description: "Words of the API's name or slug, like 'email' or 'linkedin profile': the APIs " \
17
+ "that hold the most of them come first. The sheet's order when left out." },
18
+ limit: { type: 'integer', minimum: 1, maximum: 200,
19
+ description: 'How many APIs to give, 1 to 200. 20 when left out: the sheet has about 150.' }
20
+ },
21
+ required: []
22
+ }
23
+ },
24
+ {
25
+ name: 'datacircle_best_plans',
26
+ description: "Gives an API's plans best first by their score out of 100 on Datacircle's benchmark " \
27
+ '(https://datacircle.dev), each with its rank, provider, plan, $ per 1,000 calls and its page. ' \
28
+ "perThousand is a plan's price of 1,000 items in dollars, pay the plan's whole price in its currency.",
29
+ parameters: {
30
+ type: 'object',
31
+ properties: {
32
+ slug: { type: 'string',
33
+ description: "The API's slug, like 'email-finder' or 'linkedin-profile', as datacircle_list_apis gives it." },
34
+ limit: { type: 'integer', minimum: 1, maximum: 50, description: 'How many plans to give, 1 to 50. 10 when left out.' }
35
+ },
36
+ required: ['slug']
37
+ }
38
+ },
39
+ {
40
+ name: 'datacircle_search_plans',
41
+ description: "Searches every plan on Datacircle's sheet (https://datacircle.dev), or one API's, by provider or plan " \
42
+ 'name, sorted by score, provider or price. Gives how many were found and up to limit of them. ' \
43
+ "perThousand is a plan's price of 1,000 items in dollars, pay the plan's whole price in its currency.",
44
+ parameters: {
45
+ type: 'object',
46
+ properties: {
47
+ api: { type: 'string',
48
+ description: "Only this API's plans: its name or slug, like 'email-finder'. A provider's name goes in " \
49
+ 'query, never here. Every API when left out.' },
50
+ query: { type: 'string', description: "Words that must all appear in the provider's or plan's name, like 'bright data'." },
51
+ sort: { type: 'string', enum: %w[score provider price],
52
+ description: 'score (best first, the default), provider (A to Z) or price ($ per 1,000, lowest first).' },
53
+ limit: { type: 'integer', minimum: 1, maximum: 50, description: 'How many plans to give, 1 to 50. 10 when left out.' },
54
+ offset: { type: 'integer', minimum: 0, description: 'How many found plans to skip first. 0 when left out.' }
55
+ },
56
+ required: []
57
+ }
58
+ },
59
+ {
60
+ name: 'datacircle_provider',
61
+ description: "Gives each API one provider sells and its rank on each on Datacircle's benchmark " \
62
+ '(https://datacircle.dev), with its best plan there.',
63
+ parameters: {
64
+ type: 'object',
65
+ properties: {
66
+ slug: { type: 'string',
67
+ description: "The provider's slug, like 'bright-data', or its name, like 'Bright Data': the name is made a slug." }
68
+ },
69
+ required: ['slug']
70
+ }
71
+ }
72
+ ].freeze
73
+ end
74
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveAgent
4
+ module Datacircle
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_agent'
4
+ require_relative 'datacircle/version'
5
+ require_relative 'datacircle/client'
6
+ require_relative 'datacircle/tools'
7
+ require_relative 'datacircle/calls'
8
+
9
+ module ActiveAgent
10
+ # Four Active Agent tools on Datacircle's open API (https://api.datacircle.dev/v1), with no key. An agent that
11
+ # includes this module answers them with its methods of the same names:
12
+ #
13
+ # class PlanAgent < ApplicationAgent
14
+ # include ActiveAgent::Datacircle
15
+ #
16
+ # def ask(question:)
17
+ # prompt(message: question, tools: datacircle_tools)
18
+ # end
19
+ # end
20
+ module Datacircle
21
+ # The tools' definitions, all four or those named (:best_plans or 'datacircle_best_plans'), for prompt(tools: ...).
22
+ def self.tools(*names)
23
+ wanted = names.flatten.map { |name| name.to_s.delete_prefix('datacircle_') }
24
+ unknown = wanted - TOOLS.map { |tool| tool[:name].delete_prefix('datacircle_') }
25
+ raise ArgumentError, "No Datacircle tool is named #{unknown.join(', ')}" if unknown.any?
26
+
27
+ TOOLS.select { |tool| wanted.empty? || wanted.include?(tool[:name].delete_prefix('datacircle_')) }.deep_dup
28
+ end
29
+
30
+ # GET /apis: every API on the sheet, those whose name holds query's words first.
31
+ def datacircle_list_apis(query: nil, limit: nil, **)
32
+ Datacircle.answer { Datacircle.list_apis(query: query, limit: limit) }
33
+ end
34
+
35
+ # GET /apis/{slug}/best: one API's plans, best first.
36
+ def datacircle_best_plans(slug: nil, limit: nil, **)
37
+ Datacircle.answer { Datacircle.best_plans(slug: slug, limit: limit) }
38
+ end
39
+
40
+ # GET /plans: the plans whose provider or plan name holds query, on every API or on one.
41
+ def datacircle_search_plans(api: nil, query: nil, sort: nil, limit: nil, offset: nil, **)
42
+ Datacircle.answer { Datacircle.search_plans(api: api, query: query, sort: sort, limit: limit, offset: offset) }
43
+ end
44
+
45
+ # GET /providers/{slug}: one provider's rank on each API it sells.
46
+ def datacircle_provider(slug: nil, **)
47
+ Datacircle.answer { Datacircle.provider(slug: slug) }
48
+ end
49
+
50
+ private
51
+
52
+ def datacircle_tools(*names)
53
+ Datacircle.tools(*names)
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeagent-datacircle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wayne Hamadi
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activeagent
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.9'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '1.9'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '2'
32
+ description: 'Four Active Agent tools on Datacircle''s open API, with no key: list
33
+ the GTM APIs, the best plans of one API, a search of every plan and one provider''s
34
+ ranks. We benchmark all the GTM APIs and we put the results on our website: https://datacircle.dev'
35
+ email:
36
+ - wayne@datacircle.dev
37
+ executables: []
38
+ extensions: []
39
+ extra_rdoc_files: []
40
+ files:
41
+ - LICENSE.txt
42
+ - README.md
43
+ - lib/activeagent/datacircle.rb
44
+ - lib/activeagent/datacircle/calls.rb
45
+ - lib/activeagent/datacircle/client.rb
46
+ - lib/activeagent/datacircle/tools.rb
47
+ - lib/activeagent/datacircle/version.rb
48
+ homepage: https://datacircle.dev
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://datacircle.dev
53
+ source_code_uri: https://github.com/waynehamadi/activeagent-datacircle
54
+ documentation_uri: https://github.com/waynehamadi/activeagent-datacircle#readme
55
+ bug_tracker_uri: https://github.com/waynehamadi/activeagent-datacircle/issues
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '3.1'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.6.9
71
+ specification_version: 4
72
+ summary: Find the best GTM APIs, in Active Agent.
73
+ test_files: []