Class: A2A::AgentCard::Builder

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

Overview

Fluent builder for constructing an AgentCard without deep nested constructors.

Usage:

card = A2A::AgentCard::Builder.new
  .name("My Agent")
  .description("Does things")
  .version("1.0")
  .interface(url: "https://agent.example.com/rpc", protocol_binding: A2A::AgentInterface::JSONRPC)
  .capabilities(streaming: true)
  .input_modes("text/plain")
  .output_modes("text/plain")
  .skill(id: "summarise", name: "Summarise", description: "Summarises text", tags: ["text"])
  .build

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



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

def initialize
  @name = nil
  @description = nil
  @version = nil
  @interfaces = []
  @capabilities_opts = {}
  @input_modes = []
  @output_modes = []
  @skills = []
  @provider = nil
  @documentation_url = nil
  @icon_url = nil
  @security_schemes = {}
  @security_requirements = nil
end

Instance Method Details

#buildObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/a2a/agent_card/builder.rb', line 110

def build
  AgentCard.new(
    name: @name,
    description: @description,
    version: @version,
    supported_interfaces: @interfaces,
    capabilities: resolve_capabilities,
    default_input_modes: @input_modes,
    default_output_modes: @output_modes,
    skills: @skills,
    provider: @provider,
    documentation_url: @documentation_url,
    icon_url: @icon_url,
    security_schemes: @security_schemes.empty? ? nil : @security_schemes,
    security_requirements: @security_requirements
  )
end

#capabilities(caps = nil, **kwargs) ⇒ Object

Sets capabilities via kwargs (streaming:, push_notifications:, etc.) or accepts an AgentCapabilities object directly.



59
60
61
62
# File 'lib/a2a/agent_card/builder.rb', line 59

def capabilities(caps = nil, **kwargs)
  @capabilities_opts = caps.is_a?(AgentCapabilities) ? caps : kwargs
  self
end

#description(value) ⇒ Object



40
41
42
43
# File 'lib/a2a/agent_card/builder.rb', line 40

def description(value)
  @description = value
  self
end

#documentation_url(value) ⇒ Object



88
89
90
91
# File 'lib/a2a/agent_card/builder.rb', line 88

def documentation_url(value)
  @documentation_url = value
  self
end

#icon_url(value) ⇒ Object



93
94
95
96
# File 'lib/a2a/agent_card/builder.rb', line 93

def icon_url(value)
  @icon_url = value
  self
end

#input_modes(*modes) ⇒ Object

Appends one or more accepted input MIME types.



65
66
67
68
# File 'lib/a2a/agent_card/builder.rb', line 65

def input_modes(*modes)
  @input_modes.concat(modes.flatten)
  self
end

#interface(iface = nil, **kwargs) ⇒ Object

Appends a supported interface. Accepts either an AgentInterface object or kwargs forwarded to AgentInterface.new.



52
53
54
55
# File 'lib/a2a/agent_card/builder.rb', line 52

def interface(iface = nil, **kwargs)
  @interfaces << (iface.is_a?(AgentInterface) ? iface : AgentInterface.new(**kwargs))
  self
end

#name(value) ⇒ Object



35
36
37
38
# File 'lib/a2a/agent_card/builder.rb', line 35

def name(value)
  @name = value
  self
end

#output_modes(*modes) ⇒ Object

Appends one or more accepted output MIME types.



71
72
73
74
# File 'lib/a2a/agent_card/builder.rb', line 71

def output_modes(*modes)
  @output_modes.concat(modes.flatten)
  self
end

#provider(org, url: nil) ⇒ Object



83
84
85
86
# File 'lib/a2a/agent_card/builder.rb', line 83

def provider(org, url: nil)
  @provider = AgentProvider.new(organization: org, url: url)
  self
end

#security(requirements) ⇒ Object



105
106
107
108
# File 'lib/a2a/agent_card/builder.rb', line 105

def security(requirements)
  @security_requirements = requirements
  self
end

#security_scheme(name, scheme) ⇒ Object

Registers a security scheme under ‘name`. Accepts a SecurityScheme subclass or a raw hash forwarded to SecurityScheme.from_h.



100
101
102
103
# File 'lib/a2a/agent_card/builder.rb', line 100

def security_scheme(name, scheme)
  @security_schemes[name] = scheme.is_a?(Hash) ? SecurityScheme.from_h(scheme) : scheme
  self
end

#skill(obj = nil, **kwargs) ⇒ Object

Appends a skill. Accepts either an AgentSkill object or kwargs forwarded to AgentSkill.new.



78
79
80
81
# File 'lib/a2a/agent_card/builder.rb', line 78

def skill(obj = nil, **kwargs)
  @skills << (obj.is_a?(AgentSkill) ? obj : AgentSkill.new(**kwargs))
  self
end

#version(value) ⇒ Object



45
46
47
48
# File 'lib/a2a/agent_card/builder.rb', line 45

def version(value)
  @version = value
  self
end