π First Place Winner - MIT Energy and Climate Hack 2023
Unbiased Cathode is an LLM-powered framework that helps battery researchers answer "what-if" questions about material selection and supply chain optimization. Researchers can ask questions in plain text (e.g., "What happens if we increase the nickel content in our NMC cathode by 20%?" or "How would switching to a different lithium supplier affect our production costs?"), and the framework uses optimization models to provide quantitative answers.
This project won first place at the MIT Energy and Climate Hack in 2023, demonstrating its innovative approach to solving critical challenges in battery material supply chain optimization through the integration of large language models and mathematical optimization.
Battery research and development involves exploring new cathode materials, anode materials, electrolytes, and other battery components. Each material choice has critical implications for battery performance, cost, and supply chain viability. As researchers develop new battery chemistries (e.g., NMC, LFP, sodium-ion, solid-state), they need to understand how material selection impacts production costs, material availability, and supply chain resilience.
Battery material supply chains are complex, involving considerations of:
- Material availability: Critical minerals (lithium, cobalt, nickel, manganese) and their geographic distribution
- Material quality: Purity requirements, particle size, and electrochemical properties
- Cost optimization: Balancing material costs with performance requirements
- Supply chain risks: Geopolitical factors, mining capacity, and supplier diversification
Unbiased Cathode addresses these challenges by providing a natural language interface to optimization models, allowing researchers to:
- Explore different material compositions and their cost implications
- Analyze supply chain scenarios and material availability constraints
- Optimize battery material selection based on quality, cost, and availability
- Answer "what-if" questions about material properties and supply chain changes
Key Features:
- Battery-material focused: Specialized for cathode materials, anode materials, electrolytes, and battery component supply chains
- Privacy-preserving: Runs optimization locally without sending proprietary data to external LLMs
- Quantitative insights: Uses Gurobi optimization to provide precise cost and feasibility analysis
- Natural language interface: Ask questions in plain English about material compositions and supply chain scenarios
Unbiased Cathode uses a multi-agent architecture to process natural language questions and generate optimization code. The system follows an iterative workflow:
- User submits a question in natural language about battery materials or supply chain optimization
- Commander agent receives the question and orchestrates the workflow
- Writer agent generates Python code to modify the optimization model based on the question
- Safeguard agent reviews the generated code for safety and correctness
- Commander agent processes the code and executes it to get results
- Results are interpreted and presented back to the user in human-readable format
This process repeats iteratively until the question is fully answered or a timeout occurs, allowing for refinement and error correction.
The system uses a multi-agent architecture with three specialized agents:
βββββββββββ
β User β
ββββββ¬βββββ
β β User Question
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Commander Agent β
β (Orchestrates workflow and coordinates) β
ββββββ¬ββββββββββββββββββββββββ¬βββββββββββββ
β β
β β‘ Question β β£ Code
βΌ βΌ
ββββββββββββββββ ββββββββββββββββ
β Writer Agent β βSafeguard Agentβ
β (Generates β β (Reviews code β
β code/answers)β β for safety) β
ββββββββ¬ββββββββ ββββββββ¬ββββββββ
β β
β β’ Code, β¦ Ans β β€ Clearance
ββββββββββββ¬ββββββββββββ
β
β (Iterative loop)
β
βββββββββββββββββββ΄βββββββββββββββββββββββ
β Repeat until question answered β
β or timeout β
βββββββββββββββββββββββββββββββββββββββββ
β
β β§ Final Answer
βΌ
βββββββββββ
β User β
βββββββββββ
- Commander Agent: The central orchestrator that receives user questions, coordinates between Writer and Safeguard agents, executes code, and formulates final answers
- Writer Agent: Specialized in generating Python code to modify Gurobi optimization models based on natural language questions
- Safeguard Agent: Reviews generated code for safety, correctness, and adherence to constraints before execution
- User submits a question β Commander receives it
- Commander sends question β Writer generates code
- Writer sends code β Commander forwards to Safeguard
- Safeguard reviews code β Provides clearance to Commander
- Commander executes code β Gets optimization results
- Commander interprets results β Sends answer to User
- Process repeats if clarification is needed
-
Clone the repository:
git clone <repository-url> cd UnbiasedCathode
-
Install Python dependencies:
# Option 1: Install from requirements.txt pip install -r requirements.txt # Option 2: Install as a package (recommended) pip install -e .
-
Install Gurobi Optimizer:
- Download Gurobi Optimizer from https://www.gurobi.com/
- Get a free academic license or purchase a commercial license
- Install the Python package:
pip install gurobipy - Verify installation:
python -c "import gurobipy; print(gurobipy.gurobi.version())"
-
Set up environment variables:
# Copy the example environment file cp .env.example .env # Edit .env and add your OpenAI API key # OPENAI_API_KEY=your_actual_api_key_here
-
Verify installation:
# Run quick test python test_quick.py
-
Prepare your optimization model:
- Create a Gurobi optimization model in Python (see
benchmark/application/materials.pyfor an example) - The model should define variables, constraints, and an objective function
- Create a Gurobi optimization model in Python (see
-
Load the model and create an agent:
from optiguide.optiguide import OptiGuideAgent from flaml.autogen.agentchat import UserProxyAgent import os from dotenv import load_dotenv load_dotenv() # Load your optimization model code with open("benchmark/application/materials.py", "r") as f: source_code = f.read() # Create the OptiGuide agent agent = OptiGuideAgent( name="Battery Material Agent", source_code=source_code, llm_config={ "config_list": [{ "model": "gpt-3.5-turbo", "api_key": os.getenv("OPENAI_API_KEY") }] } ) # Create a user proxy user = UserProxyAgent("user", max_consecutive_auto_reply=0, human_input_mode="NEVER", code_execution_config=False) # Ask a question user.initiate_chat(agent, message="What happens if we increase NMC622 usage by 20%?")
-
Use the Jupyter notebook:
jupyter notebook notebook/optiguide_example.ipynb
Follow the notebook cells to interact with the system interactively.
- "What happens if we increase the nickel content in NMC811 by 15%?"
- "How would the production cost change if we switch from LCO to LFP?"
- "What if the quality threshold increases by 10%?"
- "How does reducing cobalt usage affect the optimal material composition?"
Quick test:
python test_quick.pyFull test suite:
python test_materials.pyTest the notebook:
jupyter notebook notebook/optiguide_example.ipynbSee TESTING.md and HOW_TO_TEST.md for detailed testing instructions.
UnbiasedCathode/
βββ optiguide/ # Core package
β βββ optiguide.py # Main OptiGuideAgent implementation
β βββ version.py # Version information
βββ benchmark/ # Example optimization models
β βββ application/ # Optimization model files
β β βββ materials.py # Battery materials optimization example
β βββ QAs/ # Question-answer benchmarks
βββ notebook/ # Jupyter notebooks
β βββ optiguide_example.ipynb # Interactive example
βββ test_quick.py # Quick test script
βββ test_materials.py # Full test suite
βββ requirements.txt # Python dependencies
βββ setup.py # Package setup
βββ README.md # This file
- Python 3.8+
- Gurobi Optimizer (with valid license)
- OpenAI API key (for LLM functionality)
- See
requirements.txtfor Python package dependencies
- TESTING.md - Comprehensive testing guide
- HOW_TO_TEST.md - Step-by-step testing instructions
MIT License - See LICENSE file for details
If you use this work, please cite:
@article{optiguide2023,
title={OptiGuide: LLM-based assistant for optimization modeling},
author={Li, Beibin and others},
journal={arXiv preprint arXiv:2307.03875},
year={2023}
}
Contributions are welcome! Please feel free to submit a Pull Request.