Class: A2A::Server
- Inherits:
-
Object
- Object
- A2A::Server
- Defined in:
- lib/a2a/server.rb,
lib/a2a/server/env.rb,
lib/a2a/server/triage.rb,
lib/a2a/server/sse/stream.rb,
lib/a2a/server/well_known.rb,
lib/a2a/server/bindings/grpc.rb,
lib/a2a/server/bindings/rest.rb,
lib/a2a/server/sse/rest_stream.rb,
lib/a2a/server/sse/event_parser.rb,
lib/a2a/server/bindings/json_rpc.rb,
lib/a2a/server/sse/json_rpc_stream.rb,
lib/a2a/server/middleware/fetch_task.rb,
lib/a2a/server/middleware/sse_stream.rb,
lib/a2a/server/middleware/extract_message.rb,
lib/a2a/server/middleware/limit_history_length.rb,
lib/a2a/server/middleware/limit_pagination_size.rb
Overview
Rack application that exposes an A2A-compliant agent server.
Composes a single linear middleware stack. Each middleware checks the request path and either handles the request or passes it downstream:
Env → injects shared context into the env
WellKnown → serves /.well-known/agent-card.json
Bindings::Grpc → /grpc (reserved) → 501 Not Implemented
Bindings::Rest → /rest (HTTP+JSON/REST)
Bindings::JsonRpc → everything else (JSON-RPC 2.0)
SSEStream → offers env["a2a.stream"] to the agent
Triage → resolves the target operation
ExtractMessage → sets env["a2a.message"] when a message is present
LimitHistoryLength → sets env["a2a.history_length"]
LimitPaginationSize → sets env["a2a.page_size"]
Agent → the terminal app (your block)
The block is the terminal rack app — it is executed at the end of the stack, wrapped in the A2A::Agent error boundary. Usage (A2A.agent is a shorthand for this):
app = A2A::Server.new(agent_card: { "name" => "My Agent", ... }) do |env|
case env["a2a.operation"]
in "SendMessage"
A2A::Protocol::JsonSchema["Send Message Response"].new({})
end
end
run app
Defined Under Namespace
Modules: Bindings, Middleware, SSE Classes: Env, Triage, WellKnown
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(agent_card: {}, history_length: 100, page_size: 100, &block) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(agent_card: {}, history_length: 100, page_size: 100, &block) ⇒ Server
Returns a new instance of Server.
42 43 44 45 46 47 48 49 50 |
# File 'lib/a2a/server.rb', line 42 def initialize(agent_card: {}, history_length: 100, page_size: 100, &block) raise ArgumentError, "Server requires a block" unless block @agent_card = agent_card @agent = Agent.new(&block) @history_length = history_length @page_size = page_size @app = build_app end |
Instance Method Details
#call(env) ⇒ Object
52 53 54 |
# File 'lib/a2a/server.rb', line 52 def call(env) @app.call(env) end |