Class: HermesAgent::Client::Entities::ResponseOutputItem

Inherits:
HermesAgent::Client::Entity show all
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

Methods inherited from HermesAgent::Client::Entity

#==, #[], #eql?, #hash, #to_h

Instance Method Details

#argumentsString?

The arguments of a function_call item, as the raw JSON string the server emitted (not parsed).

Returns:

  • (String, nil)


138
139
140
# File 'lib/hermes_agent/client/entities/response.rb', line 138

def arguments
  self["arguments"]
end

#call_idString?

The tool-call id linking a function_call to its function_call_output.

Returns:

  • (String, nil)


147
148
149
# File 'lib/hermes_agent/client/entities/response.rb', line 147

def call_id
  self["call_id"]
end

#contentArray<ResponseContent>?

The content parts of a message item, each wrapped in a HermesAgent::Client::Entities::ResponseContent. Returns nil when the field is absent.

Returns:



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

#idString?

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).

Returns:

  • (String, nil)


90
91
92
# File 'lib/hermes_agent/client/entities/response.rb', line 90

def id
  self["id"]
end

#nameString?

The tool name of a function_call item.

Returns:

  • (String, nil)


129
130
131
# File 'lib/hermes_agent/client/entities/response.rb', line 129

def name
  self["name"]
end

#outputString, ...

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.

Returns:

  • (String, Array<Hash>, nil)


160
161
162
# File 'lib/hermes_agent/client/entities/response.rb', line 160

def output
  self["output"]
end

#output_textString?

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).

Returns:

  • (String, nil)


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

#roleString?

The author role of a message item, e.g. "assistant".

Returns:

  • (String, nil)


109
110
111
# File 'lib/hermes_agent/client/entities/response.rb', line 109

def role
  self["role"]
end

#statusString?

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.

Returns:

  • (String, nil)


101
102
103
# File 'lib/hermes_agent/client/entities/response.rb', line 101

def status
  self["status"]
end

#textString?

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).

Returns:

  • (String, nil)


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

#typeString?

The item type: "message", "function_call", or "function_call_output".

Returns:

  • (String, nil)


80
81
82
# File 'lib/hermes_agent/client/entities/response.rb', line 80

def type
  self["type"]
end