Class: A2A::Agent

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

Overview

Wraps the agent block with the server's error boundary:

NoMatchingPatternError -> A2A::UnsupportedOperationError, so an
unhandled operation falls out of `case ... in` with no else branch
A2A::Error             -> returned for the binding layer to format
anything else          -> logged, returned as a JSON-RPC internal error

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Agent

Returns a new instance of Agent.

Raises:

  • (ArgumentError)


46
47
48
49
50
# File 'lib/a2a/agent.rb', line 46

def initialize(&block)
  raise ArgumentError, "agent requires a block" unless block

  @block = block
end

Instance Method Details

#call(env) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/a2a/agent.rb', line 52

def call(env)
  @block.call(env)
rescue NoMatchingPatternError
  A2A::UnsupportedOperationError.new(
    message: "Operation not supported: #{env["a2a.operation"]}"
  )
rescue A2A::Error => e
  e
rescue => e
  Console.error(self, "Agent raised #{e.class}: #{e.message}", e)
  A2A::Error.new("Internal error", code: -32603, http_status: 500)
end