async def test_rag_prompt_with_conversation_history(self, mock_providers, mock_search_results):
        """Test RAG prompt construction with conversation history."""
        class RAGPromptBuilder:
            def __init__(self, providers):
                self.providers = providers

            async def build_prompt(self, query, search_results, system_prompt_template_id=None, conversation_history=None):
                # Simple implementation that handles search results
                chunks = search_results.get("chunk_search_results", [])

                context = ""
                for i, chunk in enumerate(chunks):
                    # Format the chunk text
                    chunk_text = f"[{i+1}] {chunk.get('text', '')}"

                    context += chunk_text + "\n\n"

                messages = [
                    {"role": "system", "content": f"System prompt with context:\n\n{context}"}
                ]

                # Add conversation history if provided
                if conversation_history:
                    messages.extend(conversation_history)
                else:
                    # Only add the query as a separate message if no conversation history
                    messages.append({"role": "user", "content": query})

                return messages

        # Create a RAG prompt builder
        builder = RAGPromptBuilder(providers=mock_providers)

        # Setup conversation history
        conversation_history = [
            {"role": "user", "content": "Tell me about Aristotle"},
            {"role": "assistant", "content": "Aristotle was a Greek philosopher."},
            {"role": "user", "content": "What about his ethics?"}
        ]

        # The last message in conversation history is the query
        query = conversation_history[-1]["content"]
        messages = await builder.build_prompt(
            query=query,
            search_results=mock_search_results,
            system_prompt_template_id="default_rag_prompt",
            conversation_history=conversation_history
        )

        # Check that all conversation messages are included
        history_messages = [m for m in messages if m["role"] in ["user", "assistant"]]
        assert len(history_messages) == len(conversation_history), \
            "All conversation history messages should be included"

        # Check that the conversation history is preserved in the correct order
        for i, msg in enumerate(history_messages):
            assert msg["role"] == conversation_history[i]["role"]
            assert msg["content"] == conversation_history[i]["content"]
Test RAG prompt construction with conversation history.
py/tests/unit/retrieval/test_rag_processing.py