Module: ForceDream::Agents
- Defined in:
- lib/force_dream/agents.rb
Overview
Ported precisely from @forcedream/mcp-server's search_agents.ts (via the same logic already proven in every other SDK tonight). Real, load-bearing fact confirmed directly from that source in earlier work tonight, not assumed here: the server has no working server-side capability/query filter on /v1/agents/list -- filtering must happen client-side, after fetching the full list. Also merges in real reliability data from the separate /v1/agents/reliability endpoint, exactly as every other SDK does.
Class Method Summary collapse
Class Method Details
.search_agents_filtered(api_base:, capability: nil, query: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/force_dream/agents.rb', line 13 def search_agents_filtered(api_base:, capability: nil, query: nil) data = Http.get("#{api_base}/v1/agents/list") agents = data['agents'].is_a?(Array) ? data['agents'] : [] rel_data = begin Http.get("#{api_base}/v1/agents/reliability") rescue StandardError nil end reliability_by_slug = {} if rel_data && rel_data['agents'].is_a?(Array) rel_data['agents'].each do |ra| reliability_by_slug[ra['agent_slug']] = ra['reliability'] if ra['agent_slug'] && ra['reliability'] end end if capability cap_lower = capability.downcase agents = agents.select do |a| (a['capabilities'] || []).any? { |c| c.to_s.downcase == cap_lower } end end if query q_lower = query.downcase agents = agents.select do |a| slug = (a['slug'] || '').downcase name = (a['name'] || '').downcase next true if slug.include?(q_lower) || name.include?(q_lower) (a['capabilities'] || []).any? { |c| c.to_s.downcase.include?(q_lower) } end end enriched = agents.map do |a| a.merge('health' => reliability_by_slug[a['slug']]) end { 'count' => enriched.length, 'agents' => enriched, 'note' => enriched.empty? ? \ 'No agents matched. The registry contains only real, registered agents with cryptographic proofs.' : \ 'Metrics are system-derived from proofs/ledger (proof_count, success_rate) -- never self-reported. Health (success_rate, avg_latency_ms, sample_size) is honestly null where no real reliability data exists yet.' } end |