The quality and safety of agricultural products involve a variety of risk factors, a large amount of risk information data, and multiple circulation and disposal processes, making it difficult to accurately trace the source of risks. To achieve precise traceability of agricultural product quality and safety, the monitoring and supervision level of agricultural product traceability systems needs to be improved. In this paper, the agricultural product quality- and safety-related detection data are taken as the research object, the agricultural product supply chain and business process are sorted out, the agricultural product risk factors under the influence of heavy metals are analyzed, and the agricultural product quality and safety risk evaluation model is established. The agricultural product risk traceability system was designed based on the six-layer architecture of the equipment layer, data layer, service layer, application layer, display layer, and user layer. Combined with the agricultural product quality and safety risk evaluation model, the system data were stored and modified by using the MySQL relational database, and the agricultural product risk traceability system was developed, which realized the accurate traceability of the risk link of the quality and safety of agricultural products. The research results of this paper provide an effective information means for the quality and safety supervision of agricultural products, and provide a technical reference for the development of a traceability system of risk factors related to agricultural products, which has good practical significance.