Class: A2A::Server::AgentExecution::AgentExecutor
- Inherits:
-
Object
- Object
- A2A::Server::AgentExecution::AgentExecutor
- 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
Instance Method Summary collapse
-
#cancel(context, event_queue) ⇒ Object
abstract
Request the agent to cancel an ongoing task.
-
#execute(context, event_queue) ⇒ Object
abstract
Execute the agent's logic for a given request context.
-
#publish_message(event_queue, message) ⇒ Object
protected
Helper method to publish a message object.
-
#publish_task(event_queue, task) ⇒ Object
protected
Helper method to publish a task object.
-
#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.
-
#publish_task_status_update(event_queue, task_id, context_id, status, metadata = nil) ⇒ Object
protected
Helper method to publish a task status update event.
Instance Method Details
#cancel(context, event_queue) ⇒ Object
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.
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
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).
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
117 118 119 120 121 122 123 124 |
# File 'lib/a2a/server/agent_execution/agent_executor.rb', line 117 def (event_queue, ) event = A2A::Server::Events::Event.new( type: "message", data: ) event_queue.publish(event) end |
#publish_task(event_queue, task) ⇒ Object (protected)
Helper method to publish a task object
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
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
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 |