Table of Contents
Fetching ...

Environment-Aware Code Generation: How far are We?

Tongtong Wu, Rongyi Chen, Wenjie Du, Suyu Ma, Guilin Qi, Zhenchang Xing, Shahram Khadivi, Ramesh Periyathambi, Gholamreza Haffari

TL;DR

The paper tackles the challenge of environment-aware code generation by formalizing EACG, introducing the VersiBCB benchmark, and evaluating three adaptation strategies—RAG, MoE, and Memory—against tasks that require functional executability across diverse library versions. VersiBCB combines real-world Python environments with execution-verified generation and migration tasks across multiple libraries and versions, enabling evaluation of adaptability to deprecations and cross-version changes. Empirical results show that current LLMs struggle under environment constraints, but memory-augmented and mixture-of-experts approaches can improve executability and compatibility, with memory showing particular strength for migration and partial robustness to unseen configurations. The findings underscore the need for continual, software-aligned LLMs and runtime-aware integration to bridge the gap between research benchmarks and production software engineering needs, and they point to future work in runtime introspection, container-level profiling, and ecosystem expansion.

Abstract

Recent progress in large language models (LLMs) has improved code generation, but most evaluations still test isolated, small-scale code (e.g., a single function) under default or unspecified software environments. As a result, it is unclear whether LLMs can reliably generate executable code tailored to a user's specific environment. We present the first systematic study of Environment-Aware Code Generation (EACG), where generated code must be functionally correct and directly executable under arbitrary software configurations. To enable realistic evaluation, we introduce VersiBCB, a benchmark that is multi-package, execution-verified, and deprecation-aware, capturing complex and evolving environments that prior datasets often overlook. Using VersiBCB, we investigate three complementary adaptation axes: data, parameters, and cache, and develop representative strategies for each. Our results show that current LLMs struggle with environment-specific code generation, while our adaptations improve environment compatibility and executability. These findings highlight key challenges and opportunities for deploying LLMs in practical software engineering workflows.

Environment-Aware Code Generation: How far are We?

TL;DR

The paper tackles the challenge of environment-aware code generation by formalizing EACG, introducing the VersiBCB benchmark, and evaluating three adaptation strategies—RAG, MoE, and Memory—against tasks that require functional executability across diverse library versions. VersiBCB combines real-world Python environments with execution-verified generation and migration tasks across multiple libraries and versions, enabling evaluation of adaptability to deprecations and cross-version changes. Empirical results show that current LLMs struggle under environment constraints, but memory-augmented and mixture-of-experts approaches can improve executability and compatibility, with memory showing particular strength for migration and partial robustness to unseen configurations. The findings underscore the need for continual, software-aligned LLMs and runtime-aware integration to bridge the gap between research benchmarks and production software engineering needs, and they point to future work in runtime introspection, container-level profiling, and ecosystem expansion.

Abstract

Recent progress in large language models (LLMs) has improved code generation, but most evaluations still test isolated, small-scale code (e.g., a single function) under default or unspecified software environments. As a result, it is unclear whether LLMs can reliably generate executable code tailored to a user's specific environment. We present the first systematic study of Environment-Aware Code Generation (EACG), where generated code must be functionally correct and directly executable under arbitrary software configurations. To enable realistic evaluation, we introduce VersiBCB, a benchmark that is multi-package, execution-verified, and deprecation-aware, capturing complex and evolving environments that prior datasets often overlook. Using VersiBCB, we investigate three complementary adaptation axes: data, parameters, and cache, and develop representative strategies for each. Our results show that current LLMs struggle with environment-specific code generation, while our adaptations improve environment compatibility and executability. These findings highlight key challenges and opportunities for deploying LLMs in practical software engineering workflows.
Paper Structure (28 sections, 2 equations, 7 figures, 9 tables)

This paper contains 28 sections, 2 equations, 7 figures, 9 tables.

Figures (7)

  • Figure 1: Task definition covering both environment-aware code generation and code migration.
  • Figure 2: Overview of dataset construction via bidirectional environment traversal.
  • Figure 3: Distribution of VersiBCB tasks across domains, based on the presence of domain-specific libraries.
  • Figure 4: Three axes of environment-aware LLM customization. Left: Data-based (RAG) prepends retrieved context. Middle: Parameter-based (MoE) activates version-aware experts via gates. Right: Cache-based (Memory) injects layerwise key-value pairs learned from prior runs.
  • Figure 5: Task-wise Pass@1 across domains (e.g., data processing, computation, ML).
  • ...and 2 more figures