Module: A2A::Server::Agent::ClassMethods
- Defined in:
- lib/a2a/server/agent.rb
Instance Method Summary collapse
-
#a2a_capability(name) { ... } ⇒ Object
Define a capability using the DSL.
-
#a2a_capability_registry ⇒ A2A::Protocol::CapabilityRegistry
Get the capability registry.
-
#a2a_config(**options) ⇒ Object
Configure the agent.
-
#a2a_method(name, **options) {|params, context| ... } ⇒ Object
Define an A2A method that can be called via JSON-RPC.
-
#a2a_method_definition(name) ⇒ Hash?
Get method definition.
-
#a2a_method_registered?(name) ⇒ Boolean
Check if a method is registered.
-
#a2a_method_registry ⇒ Hash
Get all registered A2A methods.
-
#a2a_middleware(middleware_class, **options) ⇒ Object
Add middleware to the agent.
Instance Method Details
#a2a_capability(name) { ... } ⇒ Object
Define a capability using the DSL
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/a2a/server/agent.rb', line 121 def a2a_capability(name, &block) if name.nil? || (respond_to?(:empty?) && empty?) || (is_a?(String) && strip.empty?) raise ArgumentError, "Capability name is required" end raise ArgumentError, "Capability block is required" unless block_given? builder = CapabilityBuilder.new(name.to_s) builder.instance_eval(&block) capability = builder.build _a2a_capabilities.register(capability) capability end |
#a2a_capability_registry ⇒ A2A::Protocol::CapabilityRegistry
Get the capability registry
181 182 183 |
# File 'lib/a2a/server/agent.rb', line 181 def a2a_capability_registry _a2a_capabilities end |
#a2a_config(**options) ⇒ Object
Configure the agent
152 153 154 |
# File 'lib/a2a/server/agent.rb', line 152 def a2a_config(**) _a2a_config.merge!() end |
#a2a_method(name, **options) {|params, context| ... } ⇒ Object
Define an A2A method that can be called via JSON-RPC
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/a2a/server/agent.rb', line 86 def a2a_method(name, **, &block) if name.nil? || (respond_to?(:empty?) && empty?) || (is_a?(String) && strip.empty?) raise ArgumentError, "Method name is required" end raise ArgumentError, "Method block is required" unless block_given? method_name = name.to_s _a2a_methods[method_name] = { handler: block, options: .dup, streaming: [:streaming] || false, async: [:async] || false, security: [:security] || [], metadata: [:metadata] || {} } end |
#a2a_method_definition(name) ⇒ Hash?
Get method definition
199 200 201 |
# File 'lib/a2a/server/agent.rb', line 199 def a2a_method_definition(name) _a2a_methods[name.to_s] end |
#a2a_method_registered?(name) ⇒ Boolean
Check if a method is registered
190 191 192 |
# File 'lib/a2a/server/agent.rb', line 190 def a2a_method_registered?(name) _a2a_methods.key?(name.to_s) end |
#a2a_method_registry ⇒ Hash
Get all registered A2A methods
173 174 175 |
# File 'lib/a2a/server/agent.rb', line 173 def a2a_method_registry _a2a_methods.dup end |
#a2a_middleware(middleware_class, **options) ⇒ Object
Add middleware to the agent
165 166 167 |
# File 'lib/a2a/server/agent.rb', line 165 def a2a_middleware(middleware_class, **) _a2a_middleware << { class: middleware_class, options: } end |