energy-system-agent:基于 LangChain Agent 的能源系统建模助手项目

An agent engineering project for natural language interaction construction energy system modeling based on langchain and oemof.solph

Branch1Tags0

Energy-system-agent

中文版 | English Version

Energy-system-agent is an intelligent energy system modeling assistant built on LangChain Agent. It encapsulates the powerful oemof.solph energy system modeling library into Agent tools, enabling users to quickly construct, test, and solve complex energy system optimization models through natural language interaction.


Core Features

  • Natural Language Modeling: Define Buses, Sources, Sinks, Converters, and Storages through conversation without writing complex Python code.
  • Intelligent Tool Integration: Based on LangChain Agent, it automatically calls the oemof toolchain for system initialization, component addition, model solving, and result visualization.
  • Persistent Modeling Environment: Built-in persistent IPython environment allows for reusing variables and step-by-step adjustment of model parameters during the conversation.
  • Multi-interface Support:
    • Terminal Interaction: Provides an interactive command-line interface.
    • Backend API: Supports a streaming FastAPI backend, making it easy to integrate into web applications.

Quick Start

1. Environment Configuration

Ensure Python 3.10+ is installed, and install the dependencies:

pip install -r requirements.txt

Create a .env file in the root directory and configure the necessary environment variables (refer to .env_example):

MODEL_NAME=your-model-name
OPENAI_BASE_URL=your-base-url
OPENAI_API_KEY=your-api-key
TEMPERATURE=0

2. Running the Project

Interactive Terminal Chat

Run the main entry script to start the terminal chatbot:

python main.py

Streaming Backend API

Start the FastAPI backend service (example):

python backend_main.py

3. Demos and Testing

The tests/ directory contains several example scripts demonstrating how to build different types of energy systems via the Agent:

  • test_microgrid_agent.py: Microgrid system modeling demo.
  • test_wind_solar_storage_agent.py: Wind-Solar-Storage system modeling demo.

oemof.solph Modeling Basics

oemof.solph is the core modeling engine of this project. Based on graph theory, it abstracts energy systems into:

  • Nodes:
    • Bus: Energy hub, follows energy conservation.
    • Source: Energy input (e.g., PV, Wind).
    • Sink: Energy demand (e.g., Electricity load).
    • Converter: Energy conversion (e.g., Electric boiler, Heat pump).
    • Storage: Energy throughput (e.g., Battery, Thermal storage).
  • Flows: Energy paths connecting the nodes.

Environment and Solver Installation Guide

At least one mathematical solver must be installed to run the optimization models correctly.

1. Install Open Source Solvers

On Linux (Ubuntu/Debian), it is recommended to install cbc or glpk:

# Install CBC Solver (Recommended)
sudo apt-get update
sudo apt-get install coinor-cbc

# Install GLPK Solver
sudo apt-get install glpk-utils

2. Verify Installation

You can run the following command to check the installation status of the oemof environment and solvers:

oemof_installation_test

3. Current Solver Status

Solver Status Description
cbc ✅ Installed Recommended open-source MILP solver
glpk ✅ Installed Open-source LP solver
gurobi/cplex ❌ Not Installed Commercial solvers (license required)

Directory Structure

  • main.py: Main interactive terminal chat script.
  • backend_main.py: Example streaming backend script.
  • tools/: Encapsulated oemof tools for the Agent.
  • tests/: Demos and functional test scripts.
  • docs/: Official oemof tutorials and reference docs.
  • oemof-solph/: oemof-solph core library source code.

Last updated: 2026-01-04

Introduction

An agent engineering project for natural language interaction construction energy system modeling based on langchain and oemof.solph

Customize your domain