Routing and clustering for wireless sensor networks (WSN) play a significant role for reliable and energy efficient data dissemination. Although these research areas attract a lot of interest lately, there is still no holistic approach that is able to meet the requirements and challenges of many different applications and network scenarios, like various network sizes and topologies, multiple mobile data sinks, or node failures. The main goal of this work is to demonstrate that machine learning is a practical approach to a range of complex distributed problems in WSNs. Showing this will open up new paths for development at all levels of the communication stack. To achieve this goal we present a robust, energy-efficient, and flexible data dissemination framework consisting of the routing protocol FROMS and the clustering protocol Clique. Both are based on reinforcement learning, and exhibit vital properties such as robustness against mobility, node and link failures, fast recovery after failures, very low control overhead and a wide variety of supported network scenarios and applications. Both protocols are fully distributed and have minimal communication overhead.