Advancing Generative Artificial Intelligence and Large Language Models for Demand Side Management with Electric Vehicles

Hanwen Zhang, Ruichen Zhang, Wei Zhang, Dusit Niyato, Yonggang Wen · DOI

Executive Summary

Demand Side Management (DSM) is a cornerstone of modern microgrid operations, facilitating the balance between energy supply and demand in an era of increasing renewable penetration and electric vehicle (EV) adoption. However, the complexity of translating high-level user objectives into rigorous mathematical optimization models has traditionally required significant expert intervention. This paper introduces a transformative framework that leverages Large Language Models (LLMs) and Retrieval-Augmented Generation (RAG) to automate the entire DSM lifecycle—from natural language query to executable optimization code.

The Evolving Role of AI in Energy Management

The integration of Artificial Intelligence into Energy Management Systems (EMS) has historically focused on discriminative tasks such as load forecasting and anomaly detection. While effective, these models are often "static" and struggle to adapt to changing user preferences without manual reconfiguration by engineers.

Overview of AI applications in Energy Management Systems (EMS)

As shown in Figure 1, the emergence of Generative AI (GenAI) and LLMs offers a new paradigm. Beyond simple prediction, these technologies can assist in complex decision-making and generative tasks, such as formulating optimization problems and generating the code necessary to solve them. This shift allows for a more dynamic and user-centric approach to energy management.

The "Expert-in-the-Loop" Bottleneck

Implementing effective DSM currently relies on a manual pipeline. An engineer must interpret a user's goal (e.g., "minimize my electricity bill while ensuring my car is ready by 8 AM"), formulate it as a Mixed-Integer Linear Programming (MILP) problem, and then write error-free Python code to interface with solvers. This process is time-consuming and creates a barrier to entry for non-experts. Furthermore, if a user’s schedule changes, the entire process must often be repeated manually.

Proposed Framework: LLM-RAG for Automated DSM

To address these challenges, the authors propose a three-stage workflow powered by GPT-4o and a specialized Retrieval-Augmented Generation (RAG) framework. This system bridges the gap between natural language and technical execution.

The proposed three-module framework for LLM-based EMS automation

The framework consists of three primary modules:

  1. Module A: Perception: This module serves as the interface, receiving natural language queries from developers or end-users. It utilizes prompt engineering and text encoders to transform these queries into semantic vectors for processing.
  2. Module B: Expertise Knowledge (RAG Core): To mitigate the risk of "hallucinations"—where LLMs generate plausible but mathematically incorrect equations—the system queries a dedicated RAG database. This database provides the "ground truth" technical knowledge (MILP constraints) and executable knowledge (code templates).
  3. Module C: Answer Generation: The LLM synthesizes the user query with the retrieved technical context to generate a formal optimization model and an executable Python script. An integrated interpreter renders the mathematical formulation for human review, while an executor runs the script using real-time cloud data, such as weather forecasts and electricity prices.

Validation and Key Results

The framework was validated using real-world data from the Customer Led Network Revolution (CLNR) project and Energy Stats UK. The results highlighted several critical advantages:

  • Accuracy through RAG: The baseline LLM often failed to account for complex variables like grid-selling revenue or specific appliance constraints. The RAG-enhanced model successfully incorporated these elements by grounding the generation in verified technical documentation.
  • Economic Efficiency: In a case study focused on EV charging, the LLM-generated schedule achieved an 8.13% reduction in operating costs compared to standard manufacturer strategies (£23.27 vs. £25.33).
  • Dynamic Adaptability: The system demonstrated a high degree of responsiveness to user-defined constraints. For example, it could automatically adjust charging schedules to avoid peak price hours while still meeting a user's specific State of Charge (SoC) deadline.

Conclusion

By shifting the interface of energy management from complex coding to natural language conversation, this framework significantly reduces the engineering effort required for smart microgrids. While future work must address scalability to multi-agent systems and implement more robust safety guardrails to prevent "hallucinated" constraints, this research marks a significant step toward autonomous, user-centric Demand Side Management.

Summary updated

BibTeX
@article{zhang2026advancing,
  author = {Hanwen Zhang and Ruichen Zhang and Wei Zhang and Dusit Niyato and Yonggang Wen},
  title = {{Advancing Generative Artificial Intelligence and Large Language Models for Demand Side Management with Electric Vehicles}},
  journal = {IEEE Internet of Things Journal},
  year = {2026},
  doi = {10.1109/jiot.2026.3685302},
}
Figure