LlmTrimHistory Function  
 
LONG WINAPI LlmTrimHistory(
  HCLIENT hClient,  
  LONG nMessageCount,  
  LONG nMaxTokens  
);

The LlmTrimHistory function removes older messages from the conversation history for the current client session.

Parameters

hClient
A handle to the client session.
nMessageCount
The number of messages to remove from the beginning of the conversation history. If this value is zero, messages are only removed if required by the nMaxTokens parameter. If this value is equal to or greater than the number of messages in the history, the entire history is cleared.
nMaxTokens
The maximum number of input tokens that should remain in the conversation history. If this value is zero, token usage is not checked. If the current history exceeds this value, additional older messages may be deleted until the total input token count is below the specified limit.

Return Value

If the function succeeds, the return value is the number of messages deleted from the conversation history. If the function fails, the return value is LLM_ERROR. To get extended error information, call LlmGetLastError.

If no messages are available to delete, the return value is zero.

Remarks

The LlmTrimHistory function removes messages from the beginning of the conversation history. This can be used to reduce memory usage, discard older context, or limit how much previous conversation text is included with future requests.

The nMessageCount parameter specifies the minimum number of older messages to remove. If nMaxTokens is greater than zero, the function also checks the total number of input tokens currently stored in the message history. If the token count exceeds the specified limit, additional older messages will be removed until the total input token count is below the specified threshold.

When both parameters are specified, the function may remove more messages than requested by nMessageCount to reduce the token count below the limit specified by nMaxTokens. The return value always indicates the actual number of messages removed.

If the number of messages to remove is equal to or greater than the number of messages currently stored, the entire conversation history is cleared. This is equivalent to calling LlmClearHistory.

This function only removes the local message and response history maintained by the client session. It does not change the current provider, model, system prompt, connection settings or cached provider metadata.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csllmv12.lib

See Also

LlmClearHistory, LlmGetHistorySize, LlmSetHistorySize, LlmGetFirstMessage, LlmGetNextMessage, LlmGetTokenUsage