Toward Interactive Understanding of Code APIs

Dhananjay Ashok, Jesse Thomason, Jonathan MayarXiv 2026

TL;DR

While Large Language Models (LLMs) are becoming expert coders, they are surprisingly poor at understanding "black-box" tools where the source code is hidden. This paper introduces PAU (Python API Understanding), a benchmark that requires models to deduce an API's logic through interactive exploration, and proposes a robotics-inspired Asymmetric Actor Critic (AAC) training method that enables smaller models to match the performance of frontier giants.

What Problem Does This Paper Address?

Most current evaluations of AI coding agents provide the model with full "read access" to the source code. However, real-world software engineering often involves interacting with proprietary or external APIs where the internal implementation is a mystery. In these scenarios, a developer must act like a scientist: forming a hypothesis about how the API works, querying it with specific inputs, and refining their understanding based on the outputs.

The authors found that even state-of-the-art models like Claude-4-Opus and GPT-4o struggle in this "black-box" setting. They often fail to explore edge cases, exhibit extreme overconfidence, and prematurely decide they understand a function even when their own observations contradict their conclusions.

Methods

The researchers developed a fixed agentic workflow based on the ReACT paradigm, forcing models to cycle through three phases:

  1. Reason: Conceptualize what kind of input would best test the current hypothesis.
  2. Act: Generate a specific Python tuple to query the black-box API.
  3. Reflect: Observe the output, update the hypothesis, and decide whether to terminate or continue exploring.
The interactive loop used for API discovery.

To improve model performance, they adapted Asymmetric Actor Critic (AAC) from the field of robot learning. In standard Reinforcement Learning (RL), it's hard to reward a model for a "good" exploratory query because there is no immediate "right" answer. AAC solves this by using a Critic that has "privileged information"—specifically, the ground-truth description of the API. During training, the Critic rewards the Actor (the model being trained) for making queries that are informative and for correctly deciding when to stop. Crucially, the Actor never sees the ground truth; it only learns to behave in ways the "all-knowing" Critic deems effective.

Overview of the AAC training paradigm.

Datasets

The authors introduced the PAU (Python API Understanding) benchmark, consisting of 3.9K training and 741 test instances.

  • Sources: The functions are derived from popular coding benchmarks like HumanEval, MBPP, and CruxEval.
  • Processing: To ensure models don't just "guess" based on function names, all functions and arguments are anonymized (e.g., def test_func(arg0, arg1)).
  • Validation: Every function includes a test suite that ensures 99% branch coverage, providing a rigorous way to check if a model's deduced logic actually matches the hidden code.

Key Insights and Ideas

  • The Overconfidence Trap: The primary reason models fail isn't a lack of reasoning power, but a lack of skepticism. Models frequently terminate exploration after just one or two queries, convinced they've solved the puzzle.
  • Sycophancy in Logic: Models often suffer from "inflated self-judgment," where they rate their own incorrect hypotheses as highly accurate, leading to insufficient exploration.
  • Privileged Training is Essential: Traditional supervised fine-tuning failed to improve performance because "optimal" trajectories (where a model knows the answer) look very different from "exploratory" trajectories (where a model is searching for the answer). AAC allows models to learn the process of discovery.
Distribution of failure modes for frontier models, highlighting insufficient exploration and reasoning errors.

Key Results

  • Frontier Failure: Even the best model, Claude-4-Opus, failed to understand over 45% of the PAU test set.
  • Interactive vs. Static: For many models, having interactive access to the API provided almost no benefit over seeing just two static examples, suggesting they don't know how to use the "tool" at their disposal.
  • AAC Success: RL-tuning with the Asymmetric Actor Critic paradigm consistently improved performance across different model scales. An AAC-tuned Qwen3-8B model was able to match the performance of the much larger, closed-source GPT-5-mini.
  • Better Exploration: AAC-tuned models conducted significantly more queries and used more diverse inputs compared to their base versions.

Limitations and Future Work

  • Statelessness: The current benchmark only uses stateless Python methods. Real-world APIs often have internal states or side effects (like database changes) that would make discovery much harder.
  • Language Scope: The benchmark is currently limited to Python.
  • Data Contamination: While the authors anonymized the code, the underlying logic of HumanEval/MBPP is likely in the training data of most frontier LMs. The fact that they still struggle despite this potential "leakage" underscores the difficulty of the interactive task.
  • Future Directions: The authors suggest extending this work to stateful APIs and more complex software environments where "zero-day" vulnerability detection requires this kind of interactive, black-box reasoning.

Summary updated

Abstract

Empowered by advances in Language Model agents, systems have made substantial strides in code generation and understanding. However, these approaches often rely on read access to the relevant code, an assumption which does not hold when dealing with external APIs. In this work, we introduce the PAU (Python API Understanding) benchmark, where we provide models with black-box, API-level access to code snippets. Models must query the API with exploratory inputs and draw insights from the resulting outputs, with the goal of describing the snippet's true functionality. By treating the code snippets as external tools that must be understood via interaction alone, PAU studies the more general problem of unsupervised tool understanding, specifically for tools implemented as Python methods. Despite recent progress in coding agents, even frontier models struggle to achieve high performance on PAU, with the best model (Claude-4-Opus) failing to understand over 45% of the PAU test set. An investigation into the common error modes reveals that models are overconfident; they often overrate the quality of their current hypothesis, leading to insufficient exploration and premature termination. Finally, we take inspiration from the Asymmetric Actor Critic (AAC) paradigm, frequently used in robot learning, to post-train models for interactive code understanding. Models trained with AAC conduct more active exploration of the APIs, with an AAC-tuned Qwen3-8B model matching the performance of GPT-5-mini.
BibTeX
@misc{ashok2026toward,
  author = {Dhananjay Ashok and Jesse Thomason and Jonathan May},
  title = {{Toward Interactive Understanding of Code APIs}},
  year = {2026},
  eprint = {2609.32081},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.32081},
}
Figure