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.
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.