def _handle_assistant_and_tool_messages(
        self,
        chat_history_full_text: List[ChatMessage],
        chat_history_to_be_summarized: List[ChatMessage],
    ) -> None:
        """
        To avoid breaking API's, we need to ensure the following.

        - the first message cannot be ASSISTANT
        - ASSISTANT/TOOL should be considered in pairs
        Therefore, we switch messages to summarized list until the first message is
        not an ASSISTANT or TOOL message.
        """
        while chat_history_full_text and chat_history_full_text[0].role in (
            MessageRole.ASSISTANT,
            MessageRole.TOOL,
        ):
            chat_history_to_be_summarized.append(chat_history_full_text.pop(0))

        To avoid breaking API's, we need to ensure the following.

        - the first message cannot be ASSISTANT
        - ASSISTANT/TOOL should be considered in pairs
        Therefore, we switch messages to summarized list until the first message is
        not an ASSISTANT or TOOL message.
        
llama-index-core/llama_index/core/memory/chat_summary_memory_buffer.py