Class: A2A::Server::AgentExecution::AgentExecutor

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

Overview

Abstract base class for agent executors

Agent executors contain the core logic of the agent, executing tasks based on requests and publishing updates to an event queue. This mirrors the Python AgentExecutor interface.

Direct Known Subclasses

SimpleAgentExecutor

Instance Method Summary collapse

Instance Method Details

#cancel(context, event_queue) ⇒ Object

This method is abstract.

Subclasses must implement this method

Request the agent to cancel an ongoing task

The agent should attempt to stop the task identified by the task_id in the context and publish a TaskStatusUpdateEvent with state 'canceled' to the event_queue.

Parameters:

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/a2a/server/agent_execution/agent_executor.rb', line 42

def cancel(context, event_queue)
  raise NotImplementedError, "Subclasses must implement cancel"
end

#execute(context, event_queue) ⇒ Object

This method is abstract.

Subclasses must implement this method

Execute the agent's logic for a given request context

The agent should read necessary information from the context and publish Task or Message events, or TaskStatusUpdateEvent/TaskArtifactUpdateEvent to the event_queue. This method should return once the agent's execution for this request is complete or yields control (e.g., enters an input-required state).

Parameters:

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/a2a/server/agent_execution/agent_executor.rb', line 28

def execute(context, event_queue)
  raise NotImplementedError, "Subclasses must implement execute"
end

#publish_message(event_queue, message) ⇒ Object (protected)

Helper method to publish a message object

Parameters:



117
118
119
120
121
122
123
124
# File 'lib/a2a/server/agent_execution/agent_executor.rb', line 117

def publish_message(event_queue, message)
  event = A2A::Server::Events::Event.new(
    type: "message",
    data: message
  )

  event_queue.publish(event)
end

#publish_task(event_queue, task) ⇒ Object (protected)

Helper method to publish a task object

Parameters:



103
104
105
106
107
108
109
110
# File 'lib/a2a/server/agent_execution/agent_executor.rb', line 103

def publish_task(event_queue, task)
  event = A2A::Server::Events::Event.new(
    type: "task",
    data: task
  )

  event_queue.publish(event)
end

#publish_task_artifact_update(event_queue, task_id, context_id, artifact, append = false, metadata = nil) ⇒ Object (protected)

Helper method to publish a task artifact update event

Parameters:

  • event_queue (A2A::Server::Events::EventQueue)

    The event queue

  • task_id (String)

    The task ID

  • context_id (String)

    The context ID

  • artifact (A2A::Types::Artifact)

    The artifact

  • append (Boolean) (defaults to: false)

    Whether this is an append operation

  • metadata (Hash, nil) (defaults to: nil)

    Optional metadata



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/a2a/server/agent_execution/agent_executor.rb', line 81

def publish_task_artifact_update(event_queue, task_id, context_id, artifact, append = false,  = nil)
  event_data = A2A::Types::TaskArtifactUpdateEvent.new(
    task_id: task_id,
    context_id: context_id,
    artifact: artifact,
    append: append,
    metadata: 
  )

  event = A2A::Server::Events::Event.new(
    type: "task_artifact_update",
    data: event_data
  )

  event_queue.publish(event)
end

#publish_task_status_update(event_queue, task_id, context_id, status, metadata = nil) ⇒ Object (protected)

Helper method to publish a task status update event

Parameters:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/a2a/server/agent_execution/agent_executor.rb', line 56

def publish_task_status_update(event_queue, task_id, context_id, status,  = nil)
  event_data = A2A::Types::TaskStatusUpdateEvent.new(
    task_id: task_id,
    context_id: context_id,
    status: status,
    metadata: 
  )

  event = A2A::Server::Events::Event.new(
    type: "task_status_update",
    data: event_data
  )

  event_queue.publish(event)
end