Abstract
While generative artificial intelligence offers transformative potential for programming education, its impact on students' internal cognitive and behavioral patterns remains underexplored. This study aims to address this "black box" issue by investigating how AI-driven interventions influence metacognitive regulation and self-regulated learning. A randomized controlled trial was conducted with 122 Computer Science undergraduates (mean age = 19.6 years; 28.2% female) from a university in China. Participants were assigned to an AI-assisted intervention group (n = 62) or a control group (n = 60) within a Python programming course. Using a customized Jupyter environment, an integrated autonomous AI agent monitored real-time behavioral logs and triggered non-directive, process-oriented prompts based on specific algorithmic thresholds. Data collection integrated fine-grained log analysis with standardized assessments to quantify implicit planning, monitoring, and regulation processes. The AI intervention significantly optimized learning behaviors, facilitating a shift from impulsive "trial-and-error" approaches to deliberate planning and superior debugging precision. These behavioral improvements were accompanied by significant gains in both academic performance and subjective metacognitive awareness compared to the control group. The findings confirm that when designed as a process-oriented scaffold, AI functions as a catalyst for self-regulated learning rather than a passive crutch. This study highlights the role of AI as a psychological scaffold that supports metacognitive regulation, providing an evidence-based blueprint for the design of effective learning environments in educational psychology.