Skip to content

ConversationExchangeServiceModel

Scoped exchange service for a specific conversation. Auto-fills conversationId from the conversation.

Methods

createFeedback()

createFeedback(exchangeId: string, options: CreateFeedbackOptions): Promise<FeedbackCreateResponse>

Creates feedback for an exchange

Parameters

Parameter Type Description
exchangeId string The exchange to provide feedback for
options CreateFeedbackOptions Feedback data including rating and optional comment

Returns

Promise<FeedbackCreateResponse>

Promise resolving to the feedback creation response

Example

await conversation.exchanges.createFeedback(exchangeId, {
  rating: FeedbackRating.Positive,
  comment: 'Very helpful!'
});

getAll()

getAll<T>(options?: T): Promise<T extends HasPaginationOptions<T> ? PaginatedResponse<ExchangeGetResponse> : NonPaginatedResponse<ExchangeGetResponse>>

Gets all exchanges for this conversation with optional filtering and pagination

Type Parameters

Type Parameter Default type
T extends ExchangeGetAllOptions ExchangeGetAllOptions

Parameters

Parameter Type Description
options? T Options for querying exchanges including optional pagination parameters

Returns

Promise<T extends HasPaginationOptions<T> ? PaginatedResponse<ExchangeGetResponse> : NonPaginatedResponse<ExchangeGetResponse>>

Promise resolving to either an array of exchanges or a paginated response

Example

const conversation = await conversationalAgent.conversations.getById(conversationId);

// Get all exchanges
const allExchanges = await conversation.exchanges.getAll();

// With pagination
const firstPage = await conversation.exchanges.getAll({ pageSize: 10 });
if (firstPage.hasNextPage) {
  const nextPage = await conversation.exchanges.getAll({ cursor: firstPage.nextCursor });
}

getById()

getById(exchangeId: string, options?: ExchangeGetByIdOptions): Promise<ExchangeGetResponse>

Gets an exchange by ID with its messages

Parameters

Parameter Type Description
exchangeId string The exchange ID to retrieve
options? ExchangeGetByIdOptions Optional parameters for message sorting

Returns

Promise<ExchangeGetResponse>

Promise resolving to the exchange with messages

Example

const exchange = await conversation.exchanges.getById(exchangeId);
for (const message of exchange.messages) {
  console.log(message.role, message.contentParts);
}