agent2agentSourceA2AAgentContext

class Context

Execution context for handler blocks. Provides helper methods so blocks can call store, respond, stream, etc. directly without holding a reference to the env hash.

Definitions

def stream

Create an SSE stream for streaming responses.

Automatically selects the right stream type based on the binding:

  • JSON-RPC binding -> JsonRpcStream (wraps events in envelopes)
  • REST binding -> RestStream (bare JSON events)

The stream is registered on env["a2a.stream"] so the binding middleware returns it as the Rack body. Falcon streams it natively via Protocol::HTTP::Body::Writable — no threads, no polling.

Usage in a handler block:

on "SendStreamingMessage" do |request| s = stream Async do s.event("task" => { ... }) s.event("statusUpdate" => { ... }) s.finish end end

Implementation

def stream
  require "a2a/sse"

  s = if @env["a2a.json_rpc_id"]
    A2A::SSE::JsonRpcStream.new(json_rpc_id: @env["a2a.json_rpc_id"])
  else
    A2A::SSE::RestStream.new
  end

  @env["a2a.stream"] = s
  s
end