MessageHistoryLimiter

MessageHistoryLimiter(max_messages: int | None = None, keep_first_message: bool = False)

Limits the number of messages considered by an agent for response generation.
This transform keeps only the most recent messages up to the specified maximum number of messages (max_messages).
It trims the conversation history by removing older messages, retaining only the most recent messages.

Parameters:
NameDescription
max_messagesType: int | None

Default: None
keep_first_messageType: bool

Default: False

Instance Methods

apply_transform

apply_transform(self, messages: list[dict[str, Any]]) -> list[dict[str, Any]]

Truncates the conversation history to the specified maximum number of messages.
This method returns a new list containing the most recent messages up to the specified maximum number of messages (max_messages). If max_messages is None, it returns the original list of messages unmodified.

Parameters:
NameDescription
messagesThe list of messages representing the conversation history.

Type: list[dict[str, typing.Any]]
Returns:
TypeDescription
list[dict[str, typing.Any]]List[Dict]: A new list containing the most recent messages up to the specified maximum.

get_logs

get_logs(
    self,
    pre_transform_messages: list[dict[str, Any]],
    post_transform_messages: list[dict[str, Any]]
) -> tuple[str, bool]
Parameters:
NameDescription
pre_transform_messagesType: list[dict[str, typing.Any]]
post_transform_messagesType: list[dict[str, typing.Any]]