Genetic Algorithm + LLM + Task-Aware Encoding
Author: Jonas Lin & Jacky Cen
Version: 0.2
License: MIT
GA-LLM is a modular hybrid optimization framework that combines Genetic Algorithms (GA) with Large Language Models (LLMs) to solve complex, structure-oriented content generation tasks. The system supports tasks like travel itinerary planning, academic proposal writing, and business reporting.
This project is designed to harness the creativity of LLMs and the convergence efficiency of evolutionary strategies, enabling automatic generation, mutation, and selection of structured outputs under constraints.
- ✅ Modular GA framework with abstract
Gene
class - ✅ LLM-driven population generation, mutation, and crossover
- ✅ Prompt templating system with variable injection
- ✅ Multi-level logging with per-run
.log
files - ✅ Parallelized scoring and generation with thread pools
- ✅ Constraint validator plug-in architecture
- ✅ Customizable scoring via LLM prompts
ga-llm/
├── ga_llm/ # Core GA-LLM framework
│ ├── base_gene.py # Abstract base class
│ ├── config.py # Evolution strategy configuration
│ ├── engine.py # Hybrid evolutionary engine
│ ├── evaluation.py # LLM-based scoring mechanism
│ ├── constraints.py # Constraint checker interface
│ ├── llm_utils.py # LLM calling interface
│ ├── logging_utils.py # Console + file logger
│ └── prompts/ # Prompt template manager
│ └── template_manager.py
├── demo/ # Task-specific examples
│ └── travel_demo.py # Travel itinerary optimization
├── logs/ # Auto-generated log files
├── requirements.txt
├── README.md
└── LICENSE
pip install -r requirements.txt
python demo/travel_demo.py
You will get an optimized 4-day trip to Shanghai using LLM-guided mutation and crossover.
Travel Itinerary:
- Days: 4 day program
- Hotels: Shanghai Family Hotel
- Total Cost: ¥4890.00
Detailed Schedule:
[
{
"date": "2024-07-01",
"activities": [
{"time": "09:00", "location": "Shanghai Museum", "description": "..."}
]
},
...
]
To support a new task:
-
Implement a new
YourTaskGene(BaseGene)
class -
Define
to_text
,parse_from_text
,crossover
,mutate
-
Provide appropriate prompt templates and constraints
-
Plug into the framework via
HybridEvolutionEngine
Contributions are welcome! Please:
-
Fork the repo
-
Create a feature branch
-
Open a pull request with detailed description
We welcome new task types, new scoring logic, prompt improvements, and performance enhancements.
This project is licensed under the MIT License.
© 2025 Jonas Lin & Jacky Cen