def _summarize_oldest_chat_history(
        self, chat_history_to_be_summarized: List[ChatMessage]
    ) -> ChatMessage:
        """
        Use the llm to summarize the messages that do not fit into the
        buffer.
        """
        assert self.llm is not None

        # Only summarize if there is new information to be summarized
        if (
            len(chat_history_to_be_summarized) == 1
            and chat_history_to_be_summarized[0].role == MessageRole.SYSTEM
        ):
            return chat_history_to_be_summarized[0]

        summarize_prompt = [
            ChatMessage(
                role=MessageRole.SYSTEM,
                content=self.summarize_prompt,
            )
        ]
        summarize_prompt.append(
            ChatMessage(
                role=MessageRole.USER,
                content=self._get_prompt_to_summarize(chat_history_to_be_summarized),
            )
        )
        # TODO: Maybe it is better to pass a list of history to llm
        r = self.llm.chat(summarize_prompt)
        return ChatMessage(
            role=MessageRole.SYSTEM,
            content=r.message.content,
        )

        Use the llm to summarize the messages that do not fit into the
        buffer.
        
llama-index-core/llama_index/core/memory/chat_summary_memory_buffer.py