OpenAIResponsesCompactionSession
Session decorator that triggers responses.compact when the stored history grows.
This session is intended to be passed to run() so the runner can automatically supply the latest responseId and invoke compaction after each completed turn is persisted.
To debug compaction decisions, enable the debug logger for openai-agents:openai:compaction (for example, DEBUG=openai-agents:openai:compaction).
Implements
Section titled “Implements”OpenAIResponsesCompactionAwareSessionOpenAISessionApiTagged<"responses">
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new OpenAIResponsesCompactionSession(options): OpenAIResponsesCompactionSession;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
Returns
Section titled “Returns”OpenAIResponsesCompactionSession
Properties
Section titled “Properties”[OPENAI_SESSION_API]
Section titled “[OPENAI_SESSION_API]”readonly [OPENAI_SESSION_API]: "responses";Implementation of
Section titled “Implementation of”OpenAISessionApiTagged.[OPENAI_SESSION_API]Methods
Section titled “Methods”addItems()
Section titled “addItems()”addItems(items): Promise<void>;Append new items to the conversation history.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
| Items to add to the session history. |
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”OpenAIResponsesCompactionAwareSession.addItems
clearSession()
Section titled “clearSession()”clearSession(): Promise<void>;Remove all items that belong to the session and reset its state.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”OpenAIResponsesCompactionAwareSession.clearSession
getItems()
Section titled “getItems()”getItems(limit?): Promise<AgentInputItem[]>;Retrieve items from the conversation history.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
| The maximum number of items to return. When provided the most recent limit items should be returned in chronological order. |
Returns
Section titled “Returns”Promise<AgentInputItem[]>
Implementation of
Section titled “Implementation of”OpenAIResponsesCompactionAwareSession.getItems
getSessionId()
Section titled “getSessionId()”getSessionId(): Promise<string>;Ensure and return the identifier for this session.
Returns
Section titled “Returns”Promise<string>
Implementation of
Section titled “Implementation of”OpenAIResponsesCompactionAwareSession.getSessionId
popItem()
Section titled “popItem()”popItem(): Promise< | AgentInputItem| undefined>;Remove and return the most recent item from the conversation history if it exists.
Returns
Section titled “Returns”Promise< | AgentInputItem | undefined>
Implementation of
Section titled “Implementation of”OpenAIResponsesCompactionAwareSession.popItem
runCompaction()
Section titled “runCompaction()”runCompaction(args?): Promise< | OpenAIResponsesCompactionResult| null>;Invoked by the runner after it persists a completed turn into the session.
Implementations may decide to call responses.compact (or an equivalent API) and replace the stored history.
This hook is best-effort. Implementations should consider handling transient failures and deciding whether to retry or skip compaction for the current turn.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
Returns
Section titled “Returns”Promise< | OpenAIResponsesCompactionResult | null>