跳转到内容

OpenAIResponsesCompactionSessionOptions

此内容尚不支持你的语言。

type OpenAIResponsesCompactionSessionOptions = object;
optional client: OpenAI;

OpenAI client used to call responses.compact.

When omitted, the session will use getDefaultOpenAIClient() if configured. Otherwise it creates a new OpenAI() instance via new OpenAI().


optional compactionMode: OpenAIResponsesCompactionMode;

Controls how the compaction request is built.

  • auto (default): Uses input when the last response was not stored or no response id is available.
  • previous_response_id: Uses the server-managed response chain.
  • input: Sends the locally stored session items as input and does not require a response id.

optional model: OpenAI.ResponsesModel;

The OpenAI model to use for responses.compact.

Defaults to DEFAULT_OPENAI_MODEL. The value must resemble an OpenAI model name (for example gpt-*, o*, or a fine-tuned ft:gpt-* identifier), otherwise the constructor throws.


optional shouldTriggerCompaction: (context) => boolean | Promise<boolean>;

Custom decision hook that determines whether to call responses.compact.

The default implementation compares the length of OpenAIResponsesCompactionDecisionContext.compactionCandidateItems to an internal threshold (10). Override this to support token-based triggers or other heuristics using OpenAIResponsesCompactionDecisionContext.compactionCandidateItems or OpenAIResponsesCompactionDecisionContext.sessionItems.

Parameter Type

context

OpenAIResponsesCompactionDecisionContext

boolean | Promise<boolean>


optional underlyingSession: Session & object;

Session store that receives items and holds the compacted history.

The underlying session is the source of truth for persisted items. Compaction clears the underlying session and writes the output items returned by responses.compact.

This must not be an OpenAIConversationsSession, because compaction relies on locally stored items and replaces the underlying session history after responses.compact.

Defaults to an in-memory session for demos.

Name Type

[OPENAI_SESSION_API]?

"responses"