agent2agentSourceA2AAgent

class Agent

DSL wrapper that collects operation handlers for an A2A agent.

An Agent produces handler objects that conform to the Dispatcher's duck-type contract (#operations, #call). Register an agent on a Server the same way you would register a plain handler.

agent = A2A::Agent.new do on "SendMessage" do |request| respond A2A::Schema["Send Message Response"].new() end

on "GetTask" do |request|
  task = store.get(request.id)
  respond A2A::Schema["Task"].new(task.to_h)
end

end

server.register(agent)

Nested

Definitions

def on(*operations, &block)

Register a handler block for one or more A2A operations.

Operations are identified by their proto name (e.g. "SendMessage", "GetTask", "CancelTask"). See A2A::Proto.operations for the full list.

Implementation

def on(*operations, &block)
  raise ArgumentError, "on requires at least one operation" if operations.empty?
  raise ArgumentError, "on requires a block" unless block

  handler = Handler.new(
    agent:      self,
    operations: operations.flatten,
    block:      block
  )

  @handlers << handler
  handler
end