Instruct, Not Assist: LLM-based Multi-Turn Planning and Hierarchical Questioning for Socratic Code Debugging

Priyanka Kargupta, Ishika Agarwal, Dilek Hakkani-Tur, Jiawei Han · OpenReview

Abstract

Socratic questioning is an effective teaching strategy, encouraging critical thinking and problem-solving. The conversational capabilities of large language models (LLMs) show great potential for providing scalable, real-time student guidance. However, current LLMs often give away solutions directly, making them ineffective instructors. We tackle this issue in the code debugging domain with TreeInstruct, an Instructor agent guided by a novel state space-based planning algorithm. TreeInstruct asks probing questions to help students independently identify and resolve errors. It estimates a student's conceptual and syntactical knowledge to dynamically construct a question tree based on their responses and current knowledge state, effectively addressing both independent and dependent mistakes concurrently in a multi-turn interaction setting. In addition to using an existing single-bug debugging benchmark, we construct a more challenging multi-bug dataset of 150 coding problems, incorrect solutions, and bug fixes -- all carefully constructed and annotated by experts. Extensive evaluation shows TreeInstruct's state-of-the-art performance on both datasets, proving it to be a more effective instructor than baselines. Furthermore, a real-world case study with five students of varying skill levels further demonstrates TreeInstruct's ability to guide students to debug their code efficiently with minimal turns and highly Socratic questioning. We provide our code and datasets at http://github.com/agarwalishika/TreeInstruct .

Introduction

In educational settings, the primary objective of debugging assistance is not merely to correct a code error but to foster a student's understanding of the underlying concepts. While Large Language Models (LLMs) excel at code generation, they are typically optimized for "helpfulness," which often translates to providing immediate, direct solutions. This "assistant-like" behavior can be detrimental to the learning process, as it bypasses the critical thinking required for a student to develop independent problem-solving skills.

Comparison between a direct-answer "Assistant" and a Socratic "Instructor" approach to code debugging.

Real-world debugging is further complicated by the presence of multiple, often interdependent bugs. A student might harbor a conceptual misunderstanding that manifests as a specific syntactical error. Current LLM-based tutoring systems often fail to track these evolving knowledge states across multiple turns, leading to repetitive questioning or a failure to address the root cause of the student's confusion.

Methodology: The TreeInstruct Framework

To address these challenges, we introduce TreeInstruct, a framework designed to re-orient LLMs into effective Socratic instructors. TreeInstruct utilizes a novel state-space-based planning algorithm to manage complex, multi-turn interactions. The framework bifurcates the tutoring role into two specialized agents:

1. The Verifier (State Space Estimation)

The Verifier is responsible for monitoring the student's progress. It decomposes the debugging objective into a series of "state variables"—milestones representing specific conceptual or syntactical knowledge. By analyzing student responses, the Verifier tracks which variables have been resolved and which require further guidance.

2. The Instructor (Hierarchical Questioning)

The Instructor agent generates the dialogue based on a Socratic Question Tree. Rather than following a static script, it dynamically generates questions:

  • Sibling Questions: If a student provides an incorrect answer, the Instructor offers a question of similar difficulty but from a different perspective to clarify the concept.
  • Child Questions: If a student answers correctly but requires deeper exploration, the Instructor asks more specific follow-up questions to ensure full mastery.

This system is augmented by Adaptive Conversation Restructuring, which allows the agent to skip mastered concepts or pivot when new misunderstandings are identified, ensuring a fluid and efficient dialogue.

Datasets and Evaluation

TreeInstruct was evaluated using two primary benchmarks:

  1. Socratic Debugging Benchmark: A standard dataset consisting of 149 single-bug problems.
  2. MULTI-DEBUG: A new, more rigorous dataset developed for this study. It contains 150 expert-annotated samples with 1, 2, or 3 injected bugs per problem. These bugs range in difficulty and are designed to test the agent's ability to handle interdependent conceptual and syntactical errors.

Results and Discussion

TreeInstruct demonstrated state-of-the-art performance across both benchmarks. In the complex multi-bug scenarios of the MULTI-DEBUG dataset, TreeInstruct achieved a 16.6% improvement in success rates for syntactical bugs and an 11.59% improvement for conceptual bugs compared to baseline models.

Beyond quantitative metrics, qualitative expert evaluations revealed a strong preference for TreeInstruct, with experts choosing it 78.43% of the time over other models. The framework was specifically lauded for its "indirectness"—its capacity to guide students toward the answer without revealing it prematurely. A real-world case study involving five students confirmed these findings, with participants noting that the tool encouraged critical thinking rather than reliance on trial-and-error.

Conclusion

TreeInstruct represents a significant step toward creating LLM-based tutors that prioritize pedagogical goals over simple task completion. By explicitly modeling the student's knowledge state and employing hierarchical questioning, it provides a scalable solution for Socratic code debugging. Future work will explore the integration of Vision-Language Models to provide real-time feedback on student IDEs and investigate structured fine-tuning to further embed Socratic planning capabilities directly into the model's architecture.

Summary updated

BibTeX
@inproceedings{kargupta2024instruct,
  author = {Priyanka Kargupta and Ishika Agarwal and Dilek Hakkani-Tur and Jiawei Han},
  title = {{Instruct, Not Assist: LLM-based Multi-Turn Planning and Hierarchical Questioning for Socratic Code Debugging}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.553},
}
Figure