This project, gptplan, is designed for automated radiotherapy treatment planning using advanced AI techniques. It integrates multi-agent systems, retrieval augmented generation, and specialized radiotherapy libraries to streamline and potentially optimize the planning process. You can find our paper A feasibility study of automating radiotherapy planning with large language model agents for more information.
The system uses AI agents, built with the pyautogen framework, to automate various aspects of treatment planning. Key functionalities include:
- Patient Data Management: Interacts with patient databases (e.g.,
database_Lung.pyfor lung cancer cases) to retrieve and manage necessary data. - AI Agent Collaboration: Employs a team of AI agents (
agent_team.py) that collaborate on planning tasks, guided by predefined prompts (prompts.py) and LLM configurations (llm_config.py). - Retrieval Augmented Generation (RAG): Utilizes RAG techniques (
rag.py) to provide agents with relevant information from a knowledge base, enhancing the quality and context-awareness of their decisions. - Radiotherapy Planning with PortPy: Leverages the
portpylibrary (use_portpy.py) for core radiotherapy calculations, plan optimization, and simulation, using specific configuration files found inportpy_config_files/.
The project is built in Python and relies on several external libraries.
- Python 3.x
- Key Libraries:
pyautogen: For building and managing AI agent teams. (Note:pyautogenhas undergone significant changes. The version specified inrequirements.txt(0.2.33) is recommended to ensure compatibility with this project.)portpy: For radiotherapy planning, optimization, and dose calculation.google-generativeai: For interacting with Google's Generative AI models.pandas,numpy,scipy: For data manipulation and scientific computing.cvxpy: For optimization.matplotlib,seaborn: For plotting and visualization.scikit-image: For image processing.- And others as listed in
requirements.txt.
-
Clone the Repository:
# git clone <repository_url> # cd gptplan
-
Install Dependencies: It is recommended to use a virtual environment.
python -m venv venv source venv/bin/activate # On Windows use `venv\\Scripts\\activate` pip install -r requirements.txt
-
LLM Configuration: The project uses Large Language Models (LLMs) via
pyautogen. You need to configure your LLM API keys.- Examine
llm_config.py. This file likely sets up the configuration for the LLM provider (e.g., Google Generative AI, given thegoogle-generativeaidependency). - You may need to create or update
llm_config.jsonor set environment variables with your API keys as required byllm_config.pyandpyautogen. Refer to thepyautogendocumentation for details on configuring LLM providers.
- Examine
The primary way to run a full auto-planning workflow is likely through the main execution scripts. Individual modules also contain test routines.
-
Main Auto-Planning Workflow: The script
auto_planning_patient48_rag.pyappears to be an example of an end-to-end automated planning process.python auto_planning_patient48_rag.py
Ensure your LLM configuration is correctly set up before running. This script will likely demonstrate the collaboration of agents, RAG, and PortPy for a specific patient case.
-
Running Individual Modules / Unit Tests: Several modules have
if __name__ == "__main__":blocks, often callingunit_test()functions. These can be run directly to test or demonstrate the functionality of that specific module:python agent_team.pypython database_Lung.pypython rag.pypython use_portpy.py
agent_team.py: Defines and manages the team of AI agents.auto_planning_patient48_rag.py: Example script for running the full auto-planning workflow with RAG.database.py/database_Lung.py: Handles database interactions and patient data.llm_config.py: Configures the Large Language Models forpyautogen.llm_config.json: (If used) Stores LLM API keys or other related configurations.prompts.py: Contains the prompts used to guide the AI agents.rag.py: Implements the Retrieval Augmented Generation logic.use_portpy.py: Demonstrates and utilizes functionalities of theportpylibrary.utils.py: Contains utility functions used across the project.portpy_config_files/: Directory containing configuration files forportpy, such as clinical criteria and optimization parameters.requirements.txt: Lists all Python package dependencies.README.md: This file.