Introduction
In computer science education, the primary goal of a tutor is to guide students toward self-discovery and critical thinking. However, modern Large Language Models (LLMs) are predominantly optimized to be "helpful assistants." When presented with a buggy code snippet, these models typically provide the corrected code or direct hints immediately. While efficient for productivity, this behavior is counterproductive for learning, as it bypasses the student's cognitive struggle.
To bridge this gap, we introduce TreeInstruct, a novel framework that transforms LLMs into Socratic tutors. By utilizing state-space planning and a dynamic hierarchical question tree, TreeInstruct guides students to identify and resolve their own programming errors through multi-turn dialogue without ever revealing the solution directly.
The Challenge of Socratic Debugging
Existing LLMs struggle with multi-turn Socratic interactions for several reasons:
- Context Loss: They often lose track of the student's progress over multiple turns.
- Irrelevance: They may ask questions that don't address the core misunderstanding.
- Answer Leakage: When a student is stuck, models often "leak" the answer to be helpful, defeating the Socratic purpose.
- Complex Interdependencies: Real-world debugging often involves multiple, interdependent bugs (e.g., a conceptual error leading to a syntax error), which standard benchmarks fail to capture.
The TreeInstruct Framework
TreeInstruct operates on three core principles to ensure a robust pedagogical experience:
1. State Space Estimation
Instead of treating the conversation as a simple chat, the system defines a "state space" consisting of necessary tasks or concepts the student must master. A Verifier agent tracks these state variables, marking them as "True" (resolved) or "False" based on student responses. This grounding prevents the model from repeating questions or losing focus.
2. Tree-Based Socratic Questioning
The system dynamically constructs a question tree to navigate the student's understanding:
- Sibling Questions: If a student answers incorrectly, the Instructor agent generates a "sibling" question at the same difficulty level to clarify the specific misunderstanding.
- Child Questions: If a student answers correctly but hasn't reached the final goal, the agent generates a "child" question to delve deeper into the next concept.
3. Adaptive Conversation Restructuring
The Instructor plans the conversation flow based on the "distance" between the student's current state and the goal. If a student is consistently stuck, the system can pivot to a "teaching" mode to provide foundational knowledge before returning to the questioning phase.
Evaluation and Results
The researchers evaluated TreeInstruct on the Socratic Debugging Benchmark and a new, more challenging dataset called MULTI-DEBUG. MULTI-DEBUG contains 150 samples based on 50 LeetCode problems, each featuring 1 to 3 interdependent conceptual and syntactical bugs.
Key Performance Metrics
- Expert Preference: In blind evaluations, TreeInstruct was preferred 78.43% of the time over baselines like BRIDGE, scoring significantly higher in Indirectness and Logical Flow.
- Multi-Bug Success: On the 3-bug MULTI-DEBUG dataset, TreeInstruct (powered by GPT-4) achieved a 73% success rate for syntactical bugs and 92% for conceptual bugs, vastly outperforming the BRIDGE baseline (19% and 43%, respectively).
- Human Validation: A study with students of varying skill levels confirmed that TreeInstruct successfully adapted to individual needs, forcing them to think critically rather than relying on trial and error.
Discussion and Future Work
While TreeInstruct represents a significant step forward, it faces a "reasoning bottleneck"—its efficacy is highly dependent on the base model's capabilities. Performance remains high with GPT-4 but drops with smaller models like Llama-3-8B. Additionally, LLMs occasionally exhibit "syntactical blindness," overlooking minor errors like missing colons because they are trained to generate correct code.
Future research will explore incorporating Vision-Language Models for multi-modal feedback and structured fine-tuning to embed Socratic planning directly into the model's weights.
Summary updated