Class: LLM::A2A::Transport::HTTP

Inherits:
Object
  • Object
show all
Includes:
Transport::Utils
Defined in:
lib/llm/a2a/transport/http.rb

Overview

The HTTP class provides the HTTP+JSON/REST protocol binding for the A2A protocol. It sends JSON payloads to A2A agent endpoints and handles both synchronous responses and Server-Sent Events for streaming operations.

This transport implements the HTTP+JSON/REST binding as defined in the A2A specification (Section 11).

Instance Method Summary collapse

Methods included from Transport::Utils

#resolve_transport

Constructor Details

#initialize(url:, headers: {}, timeout: nil, persistent: false, transport: nil, protocol_version: "1.0") ⇒ HTTP

Returns a new instance of HTTP.

Parameters:

  • url (String)

    The base URL of the A2A agent

  • headers (Hash<String, String>) (defaults to: {})

    Extra HTTP headers

  • timeout (Integer, nil) (defaults to: nil)

    The timeout in seconds

  • persistent (Boolean) (defaults to: false)

    Whether to use persistent HTTP connections

  • transport (LLM::Transport, Class, Symbol, nil) (defaults to: nil)

    Override transport

  • protocol_version (String) (defaults to: "1.0")

    The A2A protocol version header



23
24
25
26
27
28
# File 'lib/llm/a2a/transport/http.rb', line 23

def initialize(url:, headers: {}, timeout: nil, persistent: false, transport: nil, protocol_version: "1.0")
  @uri = URI.parse(url)
  @headers = headers
  @protocol_version = protocol_version
  @transport = resolve_transport(host: @uri.host, port: uri.port, ssl: @uri.scheme == "https", timeout:, persistent:, transport:)
end

Instance Method Details

#delete(path, accept: "application/json") ⇒ Hash

Sends a DELETE request.

Parameters:

  • path (String)

    The URL path

Returns:

  • (Hash)


56
57
58
59
60
# File 'lib/llm/a2a/transport/http.rb', line 56

def delete(path, accept: "application/json")
  req = LLM::Transport::Request.delete(request_path(path), headers(accept:))
  res = transport.request(req, owner: self)
  parse_response(res)
end

#get(path, accept: "application/json") ⇒ Hash

Sends a GET request.

Parameters:

  • path (String)

    The URL path

Returns:

  • (Hash)


34
35
36
37
38
# File 'lib/llm/a2a/transport/http.rb', line 34

def get(path, accept: "application/json")
  req = LLM::Transport::Request.get(request_path(path), headers(accept:))
  res = transport.request(req, owner: self)
  parse_response(res)
end

#get_stream(path) {|event| ... } ⇒ void

This method returns an undefined value.

Sends a GET request with a streaming (SSE) response.

The block is called for each event parsed from the event stream.

Parameters:

  • path (String)

    The URL path

Yield Parameters:



69
70
71
72
# File 'lib/llm/a2a/transport/http.rb', line 69

def get_stream(path, &on_event)
  req = LLM::Transport::Request.get(request_path(path), headers(accept: "text/event-stream"))
  stream(req, &on_event)
end

#post(path, body, content_type: "application/json", accept: "application/json") ⇒ Hash

Sends a POST request.

Parameters:

  • path (String)

    The URL path

  • body (Hash)

    The JSON body

Returns:

  • (Hash)


45
46
47
48
49
50
# File 'lib/llm/a2a/transport/http.rb', line 45

def post(path, body, content_type: "application/json", accept: "application/json")
  req = LLM::Transport::Request.post(request_path(path), headers(content_type:, accept:))
  req.body = LLM.json.dump(body)
  res = transport.request(req, owner: self)
  parse_response(res)
end

#post_stream(path, body, content_type: "application/json") {|event| ... } ⇒ void

This method returns an undefined value.

Sends a POST request with a streaming (SSE) response.

The block is called for each event parsed from the event stream.

Parameters:

  • path (String)

    The URL path

  • body (Hash)

    The JSON body

Yield Parameters:



82
83
84
85
86
# File 'lib/llm/a2a/transport/http.rb', line 82

def post_stream(path, body, content_type: "application/json", &on_event)
  req = LLM::Transport::Request.post(request_path(path), headers(content_type:, accept: "text/event-stream"))
  req.body = LLM.json.dump(body)
  stream(req, &on_event)
end