Class OpenAiResponsesStore
POST /v1/responses). The Responses API is stateful in a way the Chat
Completions and Anthropic Messages APIs are not: a client may send only the new
turn's input plus a previous_response_id, and the server reconstructs the
full conversation from the stored prior turn. This registry models that so agents
that chain turns via previous_response_id can run against the mock.
Three behaviours, all opt-in-by-data and back-compatible (a request with no
previous_response_id and the default store:true behaves exactly as
before, only additionally recording the issued response for later chaining/retrieval):
- Chaining —
OpenAiResponsesCodec.decodeprepends the stored prior conversation when the inbound request carries aprevious_response_id, so conversation matchers and usage inference see the full dialogue. - Store flag — honours the
storefield (defaulttrue); astore:falseresponse is neither retrievable nor chainable. - Retrieval —
GET /v1/responses/{id}returns the stored response body verbatim.
Bounded (LRU) so a long-running proxy cannot grow it without limit, thread-safe,
and cleared on HttpState.reset() for test isolation.
Mirrors the singleton shape of LlmQuotaRegistry.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAn issued, stored Responses-API response: its id, the full conversation as of this turn, and the raw response body. -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenAiResponsesStorepriorMessagesFor(String requestBody) IfrequestBodycarries aprevious_response_idwhose response is stored, return the prior conversation's messages so the codec can prepend them to the current turn's messages; otherwise an empty list.voidvoidrecordIfStored(String requestBody, ParsedConversation chainedConversation, Completion completion, String encodedBody) Record the response just issued for aPOST /v1/responsesturn so it can be chained (viaprevious_response_id) or retrieved (viaGET /v1/responses/{id}).voidreset()Clear all stored responses.retrievalResponseOrNull(HttpRequest request) Ifrequestis aGET /v1/responses/{id}whose id is stored, return the stored response body as a200 application/jsonresponse; otherwisenullso the caller falls through to normal handling.
-
Method Details
-
getInstance
-
put
-
get
-
reset
public void reset()Clear all stored responses. Called on server reset and for test isolation. -
priorMessagesFor
IfrequestBodycarries aprevious_response_idwhose response is stored, return the prior conversation's messages so the codec can prepend them to the current turn's messages; otherwise an empty list. Fail-soft: an unparseable body or unknown id yields an empty list (no chaining), never an error. -
recordIfStored
public void recordIfStored(String requestBody, ParsedConversation chainedConversation, Completion completion, String encodedBody) Record the response just issued for aPOST /v1/responsesturn so it can be chained (viaprevious_response_id) or retrieved (viaGET /v1/responses/{id}). No-op unless the request opts in to storage (storedefaults totrue;store:falseskips it).The stored conversation is the fully-chained decode of this request (which, when the request carried a
previous_response_id, already includes the prior turns) plus this turn's assistant output — so a subsequent turn referencing this id reconstructs the entire dialogue. Fail-soft: any parsing error simply skips registration and never affects the served response.- Parameters:
chainedConversation- the codec's decode of this request (already chained)completion- the assistant completion that was encodedencodedBody- the response body that was returned to the client
-
retrievalResponseOrNull
Ifrequestis aGET /v1/responses/{id}whose id is stored, return the stored response body as a200 application/jsonresponse; otherwisenullso the caller falls through to normal handling. Returningnullfor an unknown id keeps the mock non-intrusive — a user-configured expectation or the standard 404 path still applies.
-