Class: HermesAgent::Client::Entities::ResponseOutputItem
- Inherits:
-
HermesAgent::Client::Entity
- Object
- HermesAgent::Client::Entity
- HermesAgent::Client::Entities::ResponseOutputItem
- Defined in:
- lib/hermes_agent/client/entities/response.rb
Overview
One item in a Response's output array. The output is heterogeneous:
an item's type selects which readers are meaningful. Observed types
are "message" (an assistant reply, with #role and #content),
"function_call" (a tool invocation, with #name, #arguments, and
#call_id), and "function_call_output" (a tool result, with
#call_id, #output, and #output_text). Readers for fields that do
not apply to the item's type return nil. #id and #status are
populated only on items carried by streaming response.output_item.*
events, not on items read off a final Response.
Instance Method Summary collapse
-
#arguments ⇒ String?
The arguments of a
function_callitem, as the raw JSON string the server emitted (not parsed). -
#call_id ⇒ String?
The tool-call id linking a
function_callto itsfunction_call_output. -
#content ⇒ Array<ResponseContent>?
The content parts of a
messageitem, each wrapped in a ResponseContent. -
#id ⇒ String?
The item id (
"msg_…","fc_…", or"fco_…"). -
#name ⇒ String?
The tool name of a
function_callitem. -
#output ⇒ String, ...
The raw result of a
function_call_outputitem, as the server emitted it. -
#output_text ⇒ String?
The result text of a
function_call_outputitem, normalized across both #output shapes: the string itself when non-streaming, or the concatenatedtextof the content parts when streaming. -
#role ⇒ String?
The author role of a
messageitem, e.g. -
#status ⇒ String?
The item lifecycle status, e.g.
-
#text ⇒ String?
The assembled text of a
messageitem: the concatenation of itsoutput_textcontent parts. -
#type ⇒ String?
The item type:
"message","function_call", or"function_call_output".
Methods inherited from HermesAgent::Client::Entity
Instance Method Details
#arguments ⇒ String?
The arguments of a function_call item, as the raw JSON string the
server emitted (not parsed).
138 139 140 |
# File 'lib/hermes_agent/client/entities/response.rb', line 138 def arguments self["arguments"] end |
#call_id ⇒ String?
The tool-call id linking a function_call to its
function_call_output.
147 148 149 |
# File 'lib/hermes_agent/client/entities/response.rb', line 147 def call_id self["call_id"] end |
#content ⇒ Array<ResponseContent>?
The content parts of a message item, each wrapped in a
HermesAgent::Client::Entities::ResponseContent. Returns nil when the field is absent.
118 119 120 121 122 123 |
# File 'lib/hermes_agent/client/entities/response.rb', line 118 def content raw = self["content"] return nil unless raw.is_a?(::Array) raw.map { |part| ResponseContent.new(part) } end |
#id ⇒ String?
The item id ("msg_…", "fc_…", or "fco_…"). Present on items
carried by streaming response.output_item.* events; nil for items
read off a final HermesAgent::Client::Entities::Response's output (the server omits it there).
90 91 92 |
# File 'lib/hermes_agent/client/entities/response.rb', line 90 def id self["id"] end |
#name ⇒ String?
The tool name of a function_call item.
129 130 131 |
# File 'lib/hermes_agent/client/entities/response.rb', line 129 def name self["name"] end |
#output ⇒ String, ...
The raw result of a function_call_output item, as the server
emitted it. The shape differs by representation: a raw JSON string
in non-streaming (POST/GET) bodies, but an array of content parts
([{ "type" => "input_text", "text" => … }]) in the streaming
representation. Use #output_text for the result text regardless of
shape.
160 161 162 |
# File 'lib/hermes_agent/client/entities/response.rb', line 160 def output self["output"] end |
#output_text ⇒ String?
The result text of a function_call_output item, normalized across
both #output shapes: the string itself when non-streaming, or the
concatenated text of the content parts when streaming. Returns nil
when there is no output (e.g. a non-output item).
171 172 173 174 175 176 177 |
# File 'lib/hermes_agent/client/entities/response.rb', line 171 def output_text raw = self["output"] return raw if raw.is_a?(::String) return nil unless raw.is_a?(::Array) raw.filter_map { |part| part["text"] if part.is_a?(::Hash) }.join end |
#role ⇒ String?
The author role of a message item, e.g. "assistant".
109 110 111 |
# File 'lib/hermes_agent/client/entities/response.rb', line 109 def role self["role"] end |
#status ⇒ String?
The item lifecycle status, e.g. "in_progress" or "completed".
Present on items carried by streaming response.output_item.* events;
nil for items read off a final HermesAgent::Client::Entities::Response's output. Like all such
statuses it is a lifecycle marker, not a success signal.
101 102 103 |
# File 'lib/hermes_agent/client/entities/response.rb', line 101 def status self["status"] end |
#text ⇒ String?
The assembled text of a message item: the concatenation of its
output_text content parts. Returns nil for an item with no
content (e.g. a tool item).
185 186 187 188 189 190 |
# File 'lib/hermes_agent/client/entities/response.rb', line 185 def text parts = content return nil unless parts parts.filter_map { |part| part.text if part.type == "output_text" }.join end |
#type ⇒ String?
The item type: "message", "function_call", or
"function_call_output".
80 81 82 |
# File 'lib/hermes_agent/client/entities/response.rb', line 80 def type self["type"] end |