An intelligent AI coding agent powered by Google's Gemini API that can analyze, modify, and execute code projects autonomously.
This AI agent can perform the following operations on code projects:
- List files and directories - Explore the project structure
- Read file contents - Get the content of any file
- Write files - Create or update files with new content
- Run Python files - Execute Python scripts with optional command-line arguments
- Python 3.11 or higher
- Google Gemini API key
- Clone the repository:
git clone https://github.com/nikhilww3/aiagent.git
cd aiagent- Install dependencies using
uv(or your preferred package manager):
uv sync- Create a
.envfile in the project root:
cp .env.example .env- Add your Gemini API key to the
.envfile:
GEMINI_API_KEY=your_api_key_here
To get a Gemini API key, visit Google AI Studio.
Run the AI agent with a prompt:
uv run main.py "list files in the calculator directory"Get detailed information about token usage:
uv run main.py "your prompt here" --verbose# List all files in the project
uv run main.py "what files are in the root?"
# Read a specific file
uv run main.py "read the main.py file"
# Run a Python script
uv run main.py "run the tests in calculator/tests.py"
# Write a new file
uv run main.py "create a new file called example.txt with content 'Hello World'"aiagent/
├── main.py # Main entry point for the AI agent
├── call_function.py # Function calling handler
├── config.py # Configuration settings
├── functions/ # Available tool functions
│ ├── get_files_info.py # List files in a directory
│ ├── get_file_content.py # Read file contents
│ ├── write_file.py # Write/create files
│ └── run_python_file.py # Execute Python files
├── calculator/ # Example project directory
│ ├── main.py # Calculator application
│ ├── tests.py # Calculator tests
│ └── pkg/
│ ├── calculator.py # Calculator logic
│ └── render.py # Output formatting
└── .env # Environment variables (create this file)
- Prompt Input: You provide a natural language request
- Function Calling: The AI agent analyzes your request and decides which tools to use
- Tool Execution: The agent executes the appropriate functions
- Iterative Process: The agent can make multiple function calls in a loop (up to 20 iterations) to complete complex tasks
- Result Display: The final result or file contents are displayed
When you ask "list files in the calculator directory", the agent:
- Calls
get_files_info()with the directory parameter - Executes the function and retrieves file listings
- Displays the results
The AI agent operates within a working directory (default: calculator) for security reasons. All operations are restricted to this directory to prevent unauthorized access to system files.
You can change the working directory by modifying the working_directory variable in main.py or by setting the WORKING_DIRECTORY environment variable.
Lists all files and directories in the specified directory, showing file sizes and whether items are directories.
Reads and returns the contents of a file (up to 10,000 characters).
Writes content to a file, creating parent directories if needed.
Executes a Python script with optional command-line arguments.
To add a new tool function:
- Create a function in the
functions/directory - Create a schema using
types.FunctionDeclaration - Add the schema to
available_functionsinmain.py - Add the function mapping to
call_function()incall_function.py
Example:
# functions/my_tool.py
from google.genai import types
def my_tool(working_directory, param1):
# Your tool logic
return result
schema_my_tool = types.FunctionDeclaration(
name="my_tool",
description="Does something useful",
parameters=types.Schema(
type=types.Type.OBJECT,
properties={
"param1": types.Schema(
type=types.Type.STRING,
description="A parameter"
),
},
),
)Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
- Repository: https://github.com/nikhilww3/aiagent
- Google AI Studio: https://makersuite.google.com/app/apikey
- Nikhil Agarwal
Note: Make sure to never commit your .env file containing the API key. The .gitignore file is configured to prevent this.