Class: HermesAgent::Client::Resources::Responses
- Inherits:
-
Object
- Object
- HermesAgent::Client::Resources::Responses
- Defined in:
- lib/hermes_agent/client/resources/responses.rb
Overview
The responses resource: the Responses API (/v1/responses). Unlike
chat completions, the server persists conversation state, so turns can
be chained (via previous_response_id or a named conversation) and a
response can be retrieved or deleted by id afterward. On a server
configured with an API key, these calls require a bearer token (see
HermesAgent::Client / Configuration).
Server-side storage is capped (LRU eviction), so callers should not assume an older response remains retrievable.
Instance Method Summary collapse
-
#conversation(name: nil, previous_response_id: nil) ⇒ Conversation
Begin a multi-turn conversation that automatically chains its turns.
-
#create(input:, previous_response_id: nil, conversation: nil, idempotency_key: nil, **extra) ⇒ Entities::Response
Create a response.
-
#delete(id) ⇒ Entities::ResponseDeletion
Delete a response by id.
-
#get(id) ⇒ Entities::Response
Retrieve a previously created response by id.
-
#stream_create(input:, previous_response_id: nil, conversation: nil, **extra) {|event| ... } ⇒ Entities::Response, Stream
Create a response, streaming the turn's events.
Instance Method Details
#conversation(name: nil, previous_response_id: nil) ⇒ Conversation
Begin a multi-turn conversation that automatically chains its turns.
Returns a Conversation — a stateful helper wrapping this resource —
whose create / stream_create take only the per-turn input: (plus
extra) and handle chaining for you. With no arguments it tracks the
previous_response_id of each turn client-side and threads it into the
next; pass name: instead to chain via a server-side named
conversation; pass previous_response_id: to resume a client-side
thread from a known id. name: and previous_response_id: are
mutually exclusive (they select different chaining mechanisms).
157 158 159 |
# File 'lib/hermes_agent/client/resources/responses.rb', line 157 def conversation(name: nil, previous_response_id: nil) Conversation.new(self, name: name, previous_response_id: previous_response_id) end |
#create(input:, previous_response_id: nil, conversation: nil, idempotency_key: nil, **extra) ⇒ Entities::Response
Create a response.
No model is sent: the model is configured server-side and the
server ignores a client-supplied one. (A caller who really wants to
send fields we have not modeled — including model — can pass them
through extra.)
66 67 68 69 70 71 |
# File 'lib/hermes_agent/client/resources/responses.rb', line 66 def create(input:, previous_response_id: nil, conversation: nil, idempotency_key: nil, **extra) body = build_body(input, previous_response_id, conversation, extra) headers = idempotency_key ? {"Idempotency-Key" => idempotency_key} : nil result = @transport.post("/v1/responses", body, headers: headers) Entities::Response.new(result.body, **Util.session_headers(result.headers)) end |
#delete(id) ⇒ Entities::ResponseDeletion
Delete a response by id.
180 181 182 |
# File 'lib/hermes_agent/client/resources/responses.rb', line 180 def delete(id) Entities::ResponseDeletion.new(@transport.delete("/v1/responses/#{id}")) end |
#get(id) ⇒ Entities::Response
Retrieve a previously created response by id.
169 170 171 |
# File 'lib/hermes_agent/client/resources/responses.rb', line 169 def get(id) Entities::Response.new(@transport.get("/v1/responses/#{id}")) end |
#stream_create(input:, previous_response_id: nil, conversation: nil, **extra) {|event| ... } ⇒ Entities::Response, Stream
Create a response, streaming the turn's events.
With a block, each Entities::ResponseStreamEvent is yielded as it
arrives and the assembled Entities::Response is returned once the
stream closes. Without a block, a Stream is returned for the caller
to iterate; its Stream#result is the assembled response. The final
response is taken from the terminal response.completed event (see
Entities::Response.from_events).
95 96 97 98 |
# File 'lib/hermes_agent/client/resources/responses.rb', line 95 def stream_create(input:, previous_response_id: nil, conversation: nil, **extra, &) stream_response(on_result: nil, input: input, previous_response_id: previous_response_id, conversation: conversation, **extra, &) end |