def test_new_conversation_gets_named_after_first_agent_interaction(client: R2RClient):
    """Test that a new conversation is automatically named after the first agent interaction."""
    # Create a new conversation
    conv_resp = client.conversations.create()
    conversation_id = conv_resp.results.id

    try:
        # Verify it has no name initially
        conv_overview = client.conversations.list(
            offset=0,
            limit=10,
            # conversation_ids=[conversation_id]
        )

        target_conv = next((c for c in conv_overview.results if str(c.id) == str(conversation_id)), None)
        assert target_conv is not None, "Test conversation not found"
        assert target_conv.name is None, "New conversation already had a name"

        # Add a message via the agent method which should trigger naming
        response = client.retrieval.agent(
            message={"role": "user", "content": "Hello, this is a test message"},
            conversation_id=conversation_id,
        )
        time.sleep(5) # sleep while name is fetched
        # Verify the conversation now has a name
        conv_overview = client.conversations.list(
            offset=0,
            limit=10,
            # conversation_ids=[conversation_id]
        )
        target_conv = next((c for c in conv_overview.results if str(c.id) == str(conversation_id)), None)
        assert target_conv is not None, "Test conversation not found"
        assert target_conv.name is not None and target_conv.name != "", "Conversation was not automatically named"

    finally:
        # Cleanup
        client.conversations.delete(id=conversation_id)
Test that a new conversation is automatically named after the first agent interaction.
py/tests/integration/test_conversations.py