async def test_final_answer_event_format():
    """Test that the final answer event has the expected format and content."""
    # Create mock config
    config = MagicMock()
    config.stream = True

    # Create mock providers
    llm_provider = MockLLMProvider(
        response_content="This is a test final answer",
        citations=[]
    )
    db_provider = MockDatabaseProvider()

    # Create mock search results collector
    search_results_collector = MockSearchResultsCollector({})

    # Create agent
    agent = MockR2RStreamingAgent(
        database_provider=db_provider,
        llm_provider=llm_provider,
        config=config,
        rag_generation_config=GenerationConfig(model="test/model")
    )

    # Set the search results collector
    agent.search_results_collector = search_results_collector

    # Test a simple query
    messages = [Message(role="user", content="Test query")]

    # Run the agent
    stream = agent.arun(messages=messages)
    output = await collect_stream_output(stream)

    # Extract and verify final answer event
    final_answer_events = [line for line in output if 'event: agent.final_answer' in line]
    assert len(final_answer_events) > 0, "Final answer event should be emitted"

    data_part = final_answer_events[0].split('data: ')[1] if 'data: ' in final_answer_events[0] else ""
    try:
        data = json.loads(data_part)
        assert data["id"] == "msg_final", "Final answer ID should be msg_final"
        assert data["object"] == "agent.final_answer", "Final answer object should be agent.final_answer"
        assert "generated_answer" in data, "Final answer should include generated_answer"
        assert "citations" in data, "Final answer should include citations field"
    except json.JSONDecodeError:
        assert False, "Final answer event data should be valid JSON"
Test that the final answer event has the expected format and content.
py/tests/unit/agent/test_agent_old.py