Class: A2A::Agent
- Inherits:
-
Object
- Object
- A2A::Agent
- 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
- #call(env) ⇒ Object
-
#initialize(&block) ⇒ Agent
constructor
A new instance of Agent.
Constructor Details
#initialize(&block) ⇒ Agent
Returns a new instance of Agent.
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.}", e) A2A::Error.new("Internal error", code: -32603, http_status: 500) end |