Class: A2A::Types::Task
Overview
Represents a task in the A2A protocol
A task represents a unit of work that can be executed by an agent. It includes status information, artifacts, message history, and metadata.
Instance Attribute Summary collapse
-
#artifacts ⇒ Object
readonly
Returns the value of attribute artifacts.
-
#context_id ⇒ Object
readonly
Returns the value of attribute context_id.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#add_artifact(artifact) ⇒ Object
Add an artifact to the task.
-
#add_message(message) ⇒ Object
Add a message to the history.
-
#cancelable? ⇒ Boolean
Check if the task can be canceled.
-
#initialize(id:, context_id:, status:, kind: KIND_TASK, artifacts: nil, history: nil, metadata: nil) ⇒ Task
constructor
Initialize a new task.
-
#terminal? ⇒ Boolean
Check if the task is in a terminal state.
-
#update_status(new_status) ⇒ Object
Update the task status.
- #validate! ⇒ Object private
Methods inherited from BaseModel
#==, #camelize, from_h, from_json, #hash, #to_h, #to_json, underscore, #valid?, #validate_array_type, #validate_inclusion, #validate_required, #validate_type
Constructor Details
#initialize(id:, context_id:, status:, kind: KIND_TASK, artifacts: nil, history: nil, metadata: nil) ⇒ Task
Initialize a new task
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/a2a/types/task.rb', line 24 def initialize(id:, context_id:, status:, kind: KIND_TASK, artifacts: nil, history: nil, metadata: nil) @id = id @context_id = context_id @kind = kind @status = status.is_a?(TaskStatus) ? status : TaskStatus.from_h(status) @artifacts = artifacts&.map { |a| a.is_a?(Artifact) ? a : Artifact.from_h(a) } @history = history&.map { |m| m.is_a?(Message) ? m : Message.from_h(m) } = validate! end |
Instance Attribute Details
#artifacts ⇒ Object (readonly)
Returns the value of attribute artifacts.
12 13 14 |
# File 'lib/a2a/types/task.rb', line 12 def artifacts @artifacts end |
#context_id ⇒ Object (readonly)
Returns the value of attribute context_id.
12 13 14 |
# File 'lib/a2a/types/task.rb', line 12 def context_id @context_id end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
12 13 14 |
# File 'lib/a2a/types/task.rb', line 12 def history @history end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/a2a/types/task.rb', line 12 def id @id end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
12 13 14 |
# File 'lib/a2a/types/task.rb', line 12 def kind @kind end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/a2a/types/task.rb', line 12 def end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/a2a/types/task.rb', line 12 def status @status end |
Instance Method Details
#add_artifact(artifact) ⇒ Object
Add an artifact to the task
40 41 42 43 |
# File 'lib/a2a/types/task.rb', line 40 def add_artifact(artifact) @artifacts ||= [] @artifacts << artifact end |
#add_message(message) ⇒ Object
Add a message to the history
49 50 51 52 |
# File 'lib/a2a/types/task.rb', line 49 def () @history ||= [] @history << end |
#cancelable? ⇒ Boolean
Check if the task can be canceled
74 75 76 |
# File 'lib/a2a/types/task.rb', line 74 def cancelable? %w[submitted working input-required].include?(@status.state) end |
#terminal? ⇒ Boolean
Check if the task is in a terminal state
66 67 68 |
# File 'lib/a2a/types/task.rb', line 66 def terminal? %w[completed canceled failed rejected].include?(@status.state) end |
#update_status(new_status) ⇒ Object
Update the task status
58 59 60 |
# File 'lib/a2a/types/task.rb', line 58 def update_status(new_status) @status = new_status.is_a?(TaskStatus) ? new_status : TaskStatus.from_h(new_status) end |
#validate! ⇒ Object (private)
80 81 82 83 84 85 86 |
# File 'lib/a2a/types/task.rb', line 80 def validate! validate_required(:id, :context_id, :status, :kind) validate_inclusion(:kind, [KIND_TASK]) validate_type(:status, TaskStatus) validate_array_type(:artifacts, Artifact) if @artifacts validate_array_type(:history, Message) if @history end |