A CLI-based AI agent built with Python that can autonomously explore, read, execute, and modify code in your codebase.
This project is an AI agent that uses Google's Gemini API to assist with coding tasks. The agent can:
- List files and directories
- Read file contents
- Execute Python files with optional arguments
- Write or overwrite files
The agent operates in a loop, making function calls to interact with your codebase until it completes the requested task.
- Python 3.13+
- A Google Gemini API key
- Clone the repository
git clone https://github.com/minjk25/python-ai-agent.git cd python-ai-agent - Install dependencies using uv:
uv sync
- Create a
.envfile in the project root and add your Gemini API key:GEMINI_API_KEY="your_api_key_here"
Run the agent with a prompt:
uv run main.py "Your prompt here"Enable verbose output to see token usage and function call details:
uv run main.py "Your prompt here" --verbose├── main.py # Entry point and main agent loop
├── prompts.py # System prompt configuration
├── config.py # Configuration constants
├── call_function.py # Function call dispatcher
├── functions/ # Available tool functions
│ ├── get_file_content.py
│ ├── get_files_info.py
│ ├── run_python_file.py
│ └── write_file.py
├── calculator/ # Sample calculator app for testing (replace with your own project)
│ ├── main.py
│ └── pkg/
│ ├── calculator.py
│ └── render.py
└── pyproject.toml # Project dependenciesThis example demonstrates how the AI agent:
- Executes a user request
- Detects incorrect output caused by a bug
- Inspects project files
- Fixes the bug
- Re-runs the program successfully
The agent runs the calculator and produces an incorrect result due to a precedence bug:
The agent inspects calculator.py, corrects the precedence logic, and re-runs the program:
After the fix, the calculator correctly evaluates:
5 + 4 * 2 = 13
This demonstrates the agent's ability to:
- Read project files
- Modify source code
- Execute Python programs
- Iteratively improve results
This agent is not limited to the included calculator example. You can configure it to work with any project directory.
To use the agent with a different codebase:
- Update the working directory path in your configuration (config.py -->
WORKING_DIRvariable) - Place your project files in the desired directory
- Run the agent with your new context
The agent will:
- Inspect files
- Modify source code
- Execute Python scripts
- Iterate based on results
⚠️ This agent currently supports Python-based projects only.
By default, the agent uses: gemini-2.5-pro inside the generate_content() call in main.py.
This project currently works with:
gemini-2.5-flashgemini-2.5-pro
You can switch to gemini-2.5-flash or gemini-2.5-pro AI model by updating the model name in main.py.
⚠️ After switching models, make sure your API key has access to the selected model and is properly configured in your environment.
google-genai- Google Gemini API clientpython-dotenv- Environment variable managementrich- Beautiful terminal formatting and output
This is an educational project. The AI agent has the ability to:
- Read any file in the working directory
- Overwrite or create files
- Execute Python code
Recommendations:
- Run the agent in a sandboxed environment or container
- Avoid running it in directories with sensitive data
- Review the agent's actions using
--verbosemode - Always back up important files before running the agent
- Do not use in production environments without proper safeguards




