跳转到内容

RunContextAwareSession

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

Optional session capability for receiving the active run context.

Sessions opt in explicitly so existing implementations keep their legacy method call shapes. The runner passes the same RunContext instance to every history operation in a run.

Type Parameter Default type

TContext

unknown

readonly acceptsRunContext: true;
addItems(items, runContext?): Promise<void>;

Append new items to the conversation history.

Parameter Type Description

items

AgentInputItem[]

Items to add to the session history.

runContext?

RunContext<TContext>

Promise<void>

Session.addItems


clearSession(runContext?): Promise<void>;

Remove all items that belong to the session and reset its state.

Parameter Type

runContext?

RunContext<TContext>

Promise<void>

Session.clearSession


getItems(limit?, runContext?): Promise<AgentInputItem[]>;

Retrieve items from the conversation history.

Parameter Type Description

limit?

number

The maximum number of items to return. When provided the most recent limit items should be returned in chronological order.

runContext?

RunContext<TContext>

Promise<AgentInputItem[]>

Session.getItems


getSessionId(): Promise<string>;

Ensure and return the identifier for this session.

Promise<string>

Session.getSessionId


popItem(runContext?): Promise<
| AgentInputItem
| undefined>;

Remove and return the most recent item from the conversation history if it exists.

Parameter Type

runContext?

RunContext<TContext>

Promise< | AgentInputItem | undefined>

Session.popItem


optional prepareHistoryItemForModelInput(item): AgentInputItem;

Optionally rewrite a stored history item before it is sent back to the model.

Session implementations can use this to strip provider-managed replay metadata while preserving their public getItems() shape for UI and deletion workflows.

Parameter Type

item

AgentInputItem

AgentInputItem

Session.prepareHistoryItemForModelInput


prepareHistoryItemsForPersistenceComparison()?

Section titled “prepareHistoryItemsForPersistenceComparison()?”
optional prepareHistoryItemsForPersistenceComparison(items): AgentInputItem[];

Optionally normalize stored and expected history before persistence reconciliation compares them.

Session implementations can use this to remove backend-assigned metadata while preserving their public getItems() shape.

Parameter Type

items

AgentInputItem[]

AgentInputItem[]

Session.prepareHistoryItemsForPersistenceComparison


optional preserveReasoningItemIdsForPersistence(): boolean;

Optionally preserve reasoning item IDs when persisting generated output.

Some remote session stores require provider-assigned reasoning identities to accept stored reasoning items, even when model replay should omit those IDs.

boolean

Session.preserveReasoningItemIdsForPersistence


optional replaceHistoryWithCompaction(items, runContext?): Promise<void>;

Optionally replace the logical session history with a compaction marker and its retained suffix without resetting the session identity.

Implementations may append the replacement when their backend treats the leading compaction item as the authoritative replay boundary. If this method is absent, the runner falls back to clearing and rebuilding the session with rollback protection.

Parameter Type

items

AgentInputItem[]

runContext?

RunContext<TContext>

Promise<void>

Session.replaceHistoryWithCompaction