def truncate_conversation(history, max_tokens=1024): """ Truncate the conversation history to fit within the token limit. """ truncated_history = history[-max_tokens:] return truncated_history