An intelligent command-line utility for developers that enables seamless Python code creation, editing, execution, and file management using natural language, powered by the Gemini API's advanced function calling.
This agent uses a function-calling architecture to translate natural language commands into specific file system and execution operations, acting as a powerful developer utility.
| Feature | Description | Technical Implementation |
|---|---|---|
| 📝 Create File | Generates a new Python script with code content specified via natural language. | Utilizes the Gemini API for reliable code generation, ensuring proper syntax before writing to disk. |
| 📖 Read File | Displays the contents of an existing file back to the user for review. | A dedicated system tool that reads the file and returns its content as observation. |
| ✏️ Overwrite/Edit | Modifies the content of an existing file based on instructions like "fix bug" or "add function." | The agent sends the existing file content + the user's instruction to the LLM to output the complete, revised code. |
| Executes the specified Python file safely within a controlled subprocess environment. | Employs Python's built-in subprocess module (subprocess.run()) to capture and return the stdout (output) and stderr (errors). |
|
| ⚡ Python-Only Focus | The agent's prompt is heavily engineered to constrain its outputs strictly to valid Python 3.x logic, maximizing reliability. | A strong system instruction is used to enforce the agent's persona, its available tools, and the single-language scope. |
The application is structured into key components that manage the interaction loop between the user, the Gemini LLM, and the local file system tools.
| File / Component | Purpose | Functionality |
|---|---|---|
agent.py |
Core Execution Loop | Initializes the Gemini model, manages the chat history, and orchestrates the tool-calling workflow. |
tools.py |
Agent Tools Library | Contains the actual Python functions (create_file, read_file, overwrite_file, run_file) that define the agent's capabilities. |
requirements.txt |
Dependencies | Lists all required Python libraries, primarily google-genai and related utilities. |
.env |
Configuration | Stores the required GEMINI_API_KEY for secure access to the LLM. |
- Python 3.8+
- Gemini API Key: Obtain a key from Google AI Studio.
- Google-genai: To use function calling and Gemini API
-
Clone the repository:
git clone [YOUR-REPO-URL] cd gemini-ai-coding-agent -
Create and activate a virtual environment:
python -m venv venv .\venv\Scripts\activate # Windows # source venv/bin/activate # macOS/Linux
-
Install dependencies:
pip install -r requirements.txt
-
Configure Environment Variables (
.envfile): Create a file named.envin the root directory and add your API key:GEMINI_API_KEY=your_gemini_api_key_here
The agent operates as a persistent, interactive chat session in your terminal, allowing for rapid iteration on code.
Run this command in your terminal:
py agent.pyThanks to @freecodecamp and @boot.dev for providing the knowledge and guidance for this project