NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

ExploraCoder: Advancing Code Generation for Multiple Unseen APIs via Planning and Chained Exploration

Yunkun Wang, Yue Zhang, Zhen Qin, Chen Zhi, Binhua Li, Fei Huang, Yongbin Li, Shuiguang Deng

Abstract

Large Language Models (LLMs) often struggle with code generation for unfamiliar or newly released APIs, a challenge known as library-oriented code generation. While Retrieval-Augmented Generation (RAG) provides documentation, it frequently fails on complex tasks requiring multiple API calls due to documentation ambiguity and cascading hallucinations. We present ExploraCoder, a training-free framework that mimics human exploratory programming. By decomposing complex requirements into subtasks and executing experimental code in a sandbox, ExploraCoder leverages execution feedback to guide final solution generation. Our results demonstrate significant performance improvements over standard RAG and agentic baselines on complex multi-API benchmarks.

Introduction

Modern LLMs excel at generating code for libraries present in their pretraining data. However, their performance degrades significantly when encountering "unseen" APIs—those that are private, updated, or released after the model's knowledge cutoff. The standard solution, Retrieval-Augmented Generation (RAG), involves fetching relevant documentation to augment the prompt. While effective for simple tasks, RAG struggles with complex requirements that necessitate chaining multiple unfamiliar APIs. Documentation is often insufficient to resolve ambiguities regarding return types or data formats, leading to early hallucinations that propagate through the autoregressive generation process.

Existing methods like iterative self-repair or agentic loops attempt to fix errors after a full script is generated. However, debugging a complex, multi-API script with multiple interacting errors is often intractable for LLMs.

The ExploraCoder Framework

ExploraCoder addresses these challenges by adopting an "Exploratory Programming" paradigm. Instead of attempting to generate a complete solution in one step, the framework follows a structured, step-wise workflow designed to gather practical knowledge through execution.

The ExploraCoder workflow: from complex requirements to final code solution via task planning and chained API exploration.

The workflow consists of four primary stages:

  1. Task Planning: The LLM analyzes a high-level library summary to decompose the user's requirement into a sequence of simpler API invocation subtasks ($t_1, t_2, \dots, t_n$).
  2. API Recommendation: For each subtask, a retriever identifies and fetches the most relevant API documentation.
  3. Chain of API Exploration (CoAE): This core component involves generating and executing small "experimental" code snippets for each subtask. The LLM observes the execution output (e.g., object types, data shapes) or error messages. This "experience" is carried forward to inform subsequent subtasks.
  4. Final Solution Generation: The LLM synthesizes the final, complete code solution using the trace of successful, verified API interactions.

An enhanced version, ExploraCoder*, incorporates intermediate self-debugging. If an experimental snippet fails, the model attempts to fix it immediately, preventing error accumulation before proceeding to the next subtask.

Experimental Evaluation

To evaluate ExploraCoder, the researchers utilized the Torchdata library, which was largely unseen by models like GPT-3.5 and GPT-4-0613. They tested on three benchmarks:

  • Torchdata-Github: 50 tasks from real-world projects (3-8 APIs per task).
  • Torchdata-Manual: A new, highly complex benchmark of 100 tasks requiring 8-14 distinct APIs, representing the longest API sequences in current execution-based evaluations.
  • MonkBeatEval: A benchmark using pseudo-libraries to test generalizability to completely fabricated APIs.

Results and Discussion

ExploraCoder demonstrates substantial improvements over existing state-of-the-art methods. On the Torchdata-Manual benchmark, which specifically targets long-chain API generation, ExploraCoder and its self-debugging variant (ExploraCoder*) significantly outperformed both standard RAG and reactive agentic frameworks.

Performance comparison on the Torchdata-Manual benchmark against various baselines.

As shown in the results, ExploraCoder achieved a 24.26% pass@10* rate on Torchdata-Manual, while standard RAG (DocPrompting) achieved only 4.68%. Agentic frameworks like ReAct and KnowAgent, which rely on reactive planning, scored 7.43% and 13.51% respectively. This highlights the effectiveness of structured, proactive exploration over reactive debugging.

Key insights from the evaluation include:

  • Execution Feedback is Crucial: Observing actual return types and data formats resolves documentation ambiguities that text alone cannot.
  • Prevention is Better Than Cure: Debugging small, 3-line snippets during exploration is far more effective than trying to untangle a large, hallucinated script.
  • Efficiency: Despite its multi-step nature, ExploraCoder is more token-efficient than many agentic baselines because it avoids chaotic debugging loops.

Conclusion

ExploraCoder provides a robust framework for library-oriented code generation by mimicking the human developer's process of tinkering and exploration. By grounding the generation process in execution feedback at each step, it successfully bridges the gap between static documentation and practical API usage. Future work will focus on developing intelligent early-termination mechanisms for unsolvable tasks and reducing reliance on high-quality initial documentation.

Summary updated

BibTeX
@inproceedings{wang2025exploracoder,
  author = {Yunkun Wang and Yue Zhang and Zhen Qin and Chen Zhi and Binhua Li and Fei Huang and Yongbin Li and Shuiguang Deng},
  title = {{ExploraCoder: Advancing Code Generation for Multiple Unseen APIs via Planning and Chained Exploration}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure