Class: Remitmd::AgentCard

Inherits:
Object
  • Object
show all
Defined in:
lib/remitmd/a2a.rb

Overview

A2A agent card parsed from /.well-known/agent-card.json.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ AgentCard

Returns a new instance of AgentCard.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/remitmd/a2a.rb', line 19

def initialize(data)
  @protocol_version = data["protocolVersion"] || "0.6"
  @name             = data["name"].to_s
  @description      = data["description"].to_s
  @url              = data["url"].to_s
  @version          = data["version"].to_s
  @documentation_url = data["documentationUrl"].to_s
  @capabilities     = data["capabilities"] || {}
  @skills           = (data["skills"] || []).map do |s|
    AgentSkill.new(
      id:          s["id"].to_s,
      name:        s["name"].to_s,
      description: s["description"].to_s,
      tags:        s["tags"] || []
    )
  end
  @x402 = data["x402"] || {}
end

Instance Attribute Details

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



16
17
18
# File 'lib/remitmd/a2a.rb', line 16

def capabilities
  @capabilities
end

#descriptionObject (readonly)

Returns the value of attribute description.



16
17
18
# File 'lib/remitmd/a2a.rb', line 16

def description
  @description
end

#documentation_urlObject (readonly)

Returns the value of attribute documentation_url.



16
17
18
# File 'lib/remitmd/a2a.rb', line 16

def documentation_url
  @documentation_url
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/remitmd/a2a.rb', line 16

def name
  @name
end

#protocol_versionObject (readonly)

Returns the value of attribute protocol_version.



16
17
18
# File 'lib/remitmd/a2a.rb', line 16

def protocol_version
  @protocol_version
end

#skillsObject (readonly)

Returns the value of attribute skills.



16
17
18
# File 'lib/remitmd/a2a.rb', line 16

def skills
  @skills
end

#urlObject (readonly)

Returns the value of attribute url.



16
17
18
# File 'lib/remitmd/a2a.rb', line 16

def url
  @url
end

#versionObject (readonly)

Returns the value of attribute version.



16
17
18
# File 'lib/remitmd/a2a.rb', line 16

def version
  @version
end

#x402Object (readonly)

Returns the value of attribute x402.



16
17
18
# File 'lib/remitmd/a2a.rb', line 16

def x402
  @x402
end

Class Method Details

.discover(base_url) ⇒ AgentCard

Fetch and parse the A2A agent card from base_url/.well-known/agent-card.json.

card = Remitmd::AgentCard.discover("https://remit.md")
puts card.name   # => "remit.md"
puts card.url    # => "https://remit.md/a2a"

Parameters:

  • base_url (String)

    root URL of the agent

Returns:



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/remitmd/a2a.rb', line 46

def self.discover(base_url)
  url = URI("#{base_url.chomp("/")}/.well-known/agent-card.json")
  response = Net::HTTP.start(url.host, url.port, use_ssl: url.scheme == "https") do |http|
    req = Net::HTTP::Get.new(url)
    req["Accept"] = "application/json"
    http.request(req)
  end
  raise "Agent card discovery failed: HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess)

  new(JSON.parse(response.body))
end