GemPilot is an LLM-powered command-line program capable of reading, updating, and running Python code using the Gemini API. It provides a conversational interface for code manipulation and execution within a secure sandboxed environment.
GemPilot leverages Google's Gemini 2.5 Flash model to understand natural language requests and perform various file operations and Python code execution tasks. The system is designed with security in mind, restricting all operations to a designated working directory.
- File System Operations: List files and directories, read file contents, and write or overwrite files
- Python Code Execution: Run Python files with optional command-line arguments
- Conversational Interface: Natural language interaction with the AI assistant
- Security Sandboxing: All operations are restricted to a predefined working directory
- Verbose Mode: Detailed logging and token usage information
- get_files_info: Lists files and directories in a specified path with metadata
- get_file_content: Reads the contents of a file (up to 10,000 characters)
- write_file: Creates or overwrites files with specified content
- run_python_file: Executes Python scripts with optional arguments
- Python 3.13 or higher
- Gemini API key from Google AI Studio
- UV package manager (recommended)
-
Clone the repository:
git clone https://github.com/veyrix-Tr/GemPilot.git cd GemPilot -
Create and activate virtual environment:
uv venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
uv sync
-
Set up environment variables:
cp .env.example .env # Edit .env and add your GEMINI_API_KEY -
Run the application:
uv run main.py "your prompt here"
# Read a file
uv run main.py "read the contents of main.py"
# Write a new file
uv run main.py "create a new file called hello.py with print('Hello, World!')"
# Run a Python file
uv run main.py "execute the test.py file"
# List directory contents
uv run main.py "show me all files in the current directory"Enable verbose output to see detailed information including function calls and token usage:
uv run main.py "read main.py" --verboseAll file operations are restricted to the ./calculator directory by default for security reasons. The AI cannot access files outside this directory.
GemPilot/
├── main.py # Main application entry point
├── call_function.py # Function calling dispatcher
├── constants.py # System prompts and constants
├── functions/ # Available function implementations
│ ├── get_files_info.py
│ ├── get_file_content.py
│ ├── write_file.py
│ └── run_python_file.py
├── calculator/ # Example working directory
│ ├── main.py # Calculator application
│ ├── pkg/
│ │ ├── calculator.py # Calculator logic
│ │ └── render.py # Output formatting
│ └── tests.py # Test suite
├── config.py # Configuration constants
├── pyproject.toml # Project dependencies
└── .env # Environment variables
- Main Application (
main.py): Handles user interaction, API communication, and conversation flow - Function Dispatcher (
call_function.py): Maps function calls to appropriate implementations - Security Layer: Each function validates paths to ensure they remain within the working directory
- AI Integration: Uses Gemini API with function calling capabilities
- Path Validation: All file paths are validated to prevent directory traversal attacks
- Working Directory Restriction: Operations are confined to a predefined directory
- File Type Validation: Only regular files can be read, only Python files can be executed
- Timeout Protection: Python execution has a 30-second timeout limit
GemPilot uses the Google Gemini API with the following configuration:
- Model: gemini-2.5-flash
- Temperature: 0 (deterministic responses)
- Function Calling: Enabled for tool usage
- System Instruction: Predefined prompt for consistent behavior
The project includes a calculator application in the calculator/ directory that demonstrates GemPilot's capabilities:
# Run calculator directly
uv run calculator/main.py "3 + 7 * 2"
# Use GemPilot to fix calculator bugs
uv run main.py "Fix the calculator precedence bug where 3 + 7 * 2 gives 20 instead of 17"GEMINI_API_KEY: Your Gemini API key (required)
google-genai==1.12.1: Google Gemini API clientpython-dotenv==1.1.0: Environment variable management
The application includes comprehensive error handling for:
- API quota limits and rate limiting
- File system permissions and path validation
- Python execution errors and timeouts
- Invalid function calls and arguments
# Run individual test files
uv run test_get_files_info.py
uv run test_get_file_content.py
uv run test_run_python_file.py
uv run test_write_file.py
# Run calculator tests
uv run calculator/tests.py- Create a new function file in the
functions/directory - Implement the function with security validations
- Create a schema definition using
types.FunctionDeclaration - Add the function to
available_functionsincall_function.py - Update the system prompt in
constants.py
- API Quotas: Subject to Gemini API rate limits and quotas
- File Size: Large files are truncated at 10,000 characters
- Execution Time: Python scripts have a 30-second timeout
- Working Directory: All operations are restricted to the configured directory
- Network Access: Python execution cannot make network requests
- API Key Errors: Ensure
GEMINI_API_KEYis set correctly in.env - Quota Exceeded: Wait for API quota reset or upgrade to paid plan
- Path Errors: Verify files exist within the working directory
- Import Errors: Ensure all dependencies are installed correctly
Use the --verbose flag to see detailed function calls, API responses, and token usage information.
This project is licensed under the terms specified in the LICENSE file.