An Integer value which specifies the number of messages that were
removed from the history. A value of -1 indicates an error has occurred
and the LastError property will contain the error code. If there
are no messages in the conversation history, or the history has been
disabled, the method will return zero.
The TrimHistory method 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 MessageCount parameter specifies the minimum number of older
messages to remove. If MaxTokens is greater than zero, the
method 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 method may remove more
messages than requested by MessageCount to reduce the token count
below the limit specified by MaxTokens. 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 the ClearHistory method.
If you remove any messages from the history method while enumerating
the messages using the GetFirstMessage and GetNextMessage
methods, you must call GetFirstMessage again to begin a new
enumeration.
This method 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.