Class: A2A::Server::RequestHandler

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

Overview

Abstract base class for A2A request handlers

This interface defines the methods that an A2A server implementation must provide to handle incoming JSON-RPC requests. It mirrors the Python RequestHandler interface for consistency.

Direct Known Subclasses

DefaultRequestHandler

Instance Method Summary collapse

Instance Method Details

#on_cancel_task(params, context = nil) ⇒ A2A::Types::Task?

This method is abstract.

Subclasses must implement this method

Handle the 'tasks/cancel' method

Requests the agent to cancel an ongoing task.

Parameters:

  • Parameters specifying the task ID

  • (defaults to: nil)

    Context provided by the server

Returns:

  • The Task object with its status updated to canceled, or nil if not found

Raises:



38
39
40
# File 'lib/a2a/server/request_handler.rb', line 38

def on_cancel_task(params, context = nil)
  raise NotImplementedError, "Subclasses must implement on_cancel_task"
end

#on_delete_task_push_notification_config(params, context = nil) ⇒ void

This method is abstract.

Subclasses must implement this method

This method returns an undefined value.

Handle the 'tasks/pushNotificationConfig/delete' method

Deletes a push notification configuration associated with a task.

Parameters:

  • Parameters including the task ID and config ID

  • (defaults to: nil)

    Context provided by the server

Raises:



131
132
133
# File 'lib/a2a/server/request_handler.rb', line 131

def on_delete_task_push_notification_config(params, context = nil)
  raise NotImplementedError, "Subclasses must implement on_delete_task_push_notification_config"
end

#on_get_task(params, context = nil) ⇒ A2A::Types::Task?

This method is abstract.

Subclasses must implement this method

Handle the 'tasks/get' method

Retrieves the state and history of a specific task.

Parameters:

  • Parameters specifying the task ID and optionally history length

  • (defaults to: nil)

    Context provided by the server

Returns:

  • The Task object if found, otherwise nil

Raises:



25
26
27
# File 'lib/a2a/server/request_handler.rb', line 25

def on_get_task(params, context = nil)
  raise NotImplementedError, "Subclasses must implement on_get_task"
end

#on_get_task_push_notification_config(params, context = nil) ⇒ A2A::Types::TaskPushNotificationConfig

This method is abstract.

Subclasses must implement this method

Handle the 'tasks/pushNotificationConfig/get' method

Retrieves the current push notification configuration for a task.

Parameters:

  • Parameters including the task ID

  • (defaults to: nil)

    Context provided by the server

Returns:

  • The TaskPushNotificationConfig for the task

Raises:



92
93
94
# File 'lib/a2a/server/request_handler.rb', line 92

def on_get_task_push_notification_config(params, context = nil)
  raise NotImplementedError, "Subclasses must implement on_get_task_push_notification_config"
end

#on_list_task_push_notification_config(params, context = nil) ⇒ Array<A2A::Types::TaskPushNotificationConfig>

This method is abstract.

Subclasses must implement this method

Handle the 'tasks/pushNotificationConfig/list' method

Retrieves the current push notification configurations for a task.

Parameters:

  • Parameters including the task ID

  • (defaults to: nil)

    Context provided by the server

Returns:

  • The list of TaskPushNotificationConfig for the task

Raises:



118
119
120
# File 'lib/a2a/server/request_handler.rb', line 118

def on_list_task_push_notification_config(params, context = nil)
  raise NotImplementedError, "Subclasses must implement on_list_task_push_notification_config"
end

#on_message_send(params, context = nil) ⇒ A2A::Types::Task, A2A::Types::Message

This method is abstract.

Subclasses must implement this method

Handle the 'message/send' method (non-streaming)

Sends a message to the agent to create, continue, or restart a task, and waits for the final result (Task or Message).

Parameters:

  • Parameters including the message and configuration

  • (defaults to: nil)

    Context provided by the server

Returns:

  • The final Task object or a final Message object

Raises:



52
53
54
# File 'lib/a2a/server/request_handler.rb', line 52

def on_message_send(params, context = nil)
  raise NotImplementedError, "Subclasses must implement on_message_send"
end

#on_message_send_stream(_params, _context = nil) ⇒ Enumerator

This method is abstract.

Subclasses must implement this method

Handle the 'message/stream' method (streaming)

Sends a message to the agent and yields stream events as they are produced (Task updates, Message chunks, Artifact updates).

Parameters:

  • Parameters including the message and configuration

  • Context provided by the server

Returns:

  • Enumerator yielding Event objects from the agent's execution

Raises:



66
67
68
# File 'lib/a2a/server/request_handler.rb', line 66

def on_message_send_stream(_params, _context = nil)
  raise A2A::Errors::UnsupportedOperation, "Streaming not supported by this handler"
end

#on_resubscribe_to_task(_params, _context = nil) ⇒ Enumerator

This method is abstract.

Subclasses must implement this method

Handle the 'tasks/resubscribe' method

Allows a client to re-subscribe to a running streaming task's event stream.

Parameters:

  • Parameters including the task ID

  • Context provided by the server

Returns:

  • Enumerator yielding Event objects from the agent's ongoing execution

Raises:



105
106
107
# File 'lib/a2a/server/request_handler.rb', line 105

def on_resubscribe_to_task(_params, _context = nil)
  raise A2A::Errors::UnsupportedOperation, "Task resubscription not supported by this handler"
end

#on_set_task_push_notification_config(params, context = nil) ⇒ A2A::Types::TaskPushNotificationConfig

This method is abstract.

Subclasses must implement this method

Handle the 'tasks/pushNotificationConfig/set' method

Sets or updates the push notification configuration for a task.

Parameters:

  • Parameters including the task ID and push notification configuration

  • (defaults to: nil)

    Context provided by the server

Returns:

  • The provided TaskPushNotificationConfig upon success

Raises:



79
80
81
# File 'lib/a2a/server/request_handler.rb', line 79

def on_set_task_push_notification_config(params, context = nil)
  raise NotImplementedError, "Subclasses must implement on_set_task_push_notification_config"
end