Class: HermesAgent::Client::Entities::Response
- Inherits:
-
HermesAgent::Client::Entity
- Object
- HermesAgent::Client::Entity
- HermesAgent::Client::Entities::Response
- Includes:
- SessionHeaders
- Defined in:
- lib/hermes_agent/client/entities/response.rb
Overview
A response from the Responses API (POST /v1/responses,
GET /v1/responses/{id}). The server persists conversation state, so a
response can be retrieved later and chained from. Field readers are
best-effort; HermesAgent::Client::Entity#to_h remains the source of truth.
Instance Attribute Summary
Attributes included from SessionHeaders
Class Method Summary collapse
-
.from_events(events, session_id: nil, session_key: nil) ⇒ Response
Build a Response from a streamed turn's events.
Instance Method Summary collapse
-
#created_at ⇒ Integer?
When the response was created, as a Unix timestamp (seconds).
-
#id ⇒ String?
The response id, e.g.
-
#model ⇒ String?
The model that produced the response, e.g.
-
#object ⇒ String?
The object type,
"response". -
#output ⇒ Array<ResponseOutputItem>?
The output items, each wrapped in a ResponseOutputItem.
-
#output_text ⇒ String?
The assistant's text: the concatenation of the text of every
messageoutput item, ignoring tool items. -
#status ⇒ String?
The response status, e.g.
-
#usage ⇒ ResponseUsage?
The token usage, wrapped in a ResponseUsage.
Methods included from SessionHeaders
Methods inherited from HermesAgent::Client::Entity
Class Method Details
.from_events(events, session_id: nil, session_key: nil) ⇒ Response
Build a HermesAgent::Client::Entities::Response from a streamed turn's events. The terminal
response.completed event carries the full final response object, so
this takes the last response payload seen across the events (which
is that terminal one — response.created carries an interim one).
Returns a HermesAgent::Client::Entities::Response wrapping an empty payload if no event carried a
response object.
218 219 220 221 222 223 224 225 |
# File 'lib/hermes_agent/client/entities/response.rb', line 218 def self.from_events(events, session_id: nil, session_key: nil) payload = {} events.each do |event| raw = event["response"] payload = raw if raw.is_a?(::Hash) end new(payload, session_id: session_id, session_key: session_key) end |
Instance Method Details
#created_at ⇒ Integer?
When the response was created, as a Unix timestamp (seconds).
256 257 258 |
# File 'lib/hermes_agent/client/entities/response.rb', line 256 def created_at self["created_at"] end |
#id ⇒ String?
The response id, e.g. "resp_…". Pass it as previous_response_id to
chain a follow-up turn.
232 233 234 |
# File 'lib/hermes_agent/client/entities/response.rb', line 232 def id self["id"] end |
#model ⇒ String?
The model that produced the response, e.g. "hermes-test".
264 265 266 |
# File 'lib/hermes_agent/client/entities/response.rb', line 264 def model self["model"] end |
#object ⇒ String?
The object type, "response".
240 241 242 |
# File 'lib/hermes_agent/client/entities/response.rb', line 240 def object self["object"] end |
#output ⇒ Array<ResponseOutputItem>?
The output items, each wrapped in a HermesAgent::Client::Entities::ResponseOutputItem. Returns
nil when the field is absent.
273 274 275 276 277 278 |
# File 'lib/hermes_agent/client/entities/response.rb', line 273 def output raw = self["output"] return nil unless raw.is_a?(::Array) raw.map { |item| ResponseOutputItem.new(item) } end |
#output_text ⇒ String?
The assistant's text: the concatenation of the text of every
message output item, ignoring tool items. A convenience over
#output for the common single-message case. Returns nil when
there is no output.
297 298 299 300 301 302 |
# File 'lib/hermes_agent/client/entities/response.rb', line 297 def output_text items = output return nil unless items items.select { |item| item.type == "message" }.filter_map(&:text).join end |
#status ⇒ String?
The response status, e.g. "completed" or "in_progress".
248 249 250 |
# File 'lib/hermes_agent/client/entities/response.rb', line 248 def status self["status"] end |
#usage ⇒ ResponseUsage?
The token usage, wrapped in a HermesAgent::Client::Entities::ResponseUsage. Returns nil when the
field is absent.
285 286 287 288 |
# File 'lib/hermes_agent/client/entities/response.rb', line 285 def usage raw = self["usage"] raw.is_a?(::Hash) ? ResponseUsage.new(raw) : nil end |