ChatHistoryTruncationReducer Class
A ChatHistory that supports truncation logic.
Because this class inherits from ChatHistoryReducer (which in turn inherits from ChatHistory), it can also be used anywhere a ChatHistory is expected, while adding truncation capability.
Args: target_count: The target message count. threshold_count: The threshold count to avoid orphaning messages. auto_reduce: Whether to automatically reduce the chat history, default is False.
Note: This class is marked as 'experimental' and may change in the future.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Constructor
ChatHistoryTruncationReducer(*, messages: list[ChatMessageContent] = None, system_message: str | None = None, target_count: Annotated[int, Gt(gt=0)], threshold_count: Annotated[int, Ge(ge=0)] = 0, auto_reduce: bool = False)
Keyword-Only Parameters
| Name | Description |
|---|---|
|
messages
Required
|
|
|
system_message
Required
|
|
|
target_count
Required
|
|
|
threshold_count
Required
|
|
|
auto_reduce
Required
|
|
Methods
| reduce |
reduce
async reduce() -> Self | None
Attributes
auto_reduce
auto_reduce: bool
is_experimental
is_experimental = True
messages
messages: list[ChatMessageContent]
stage_status
stage_status = 'experimental'
system_message
system_message: str | None
target_count
target_count: int
threshold_count
threshold_count: int