An AI-powered coding agent that uses Google's Gemini API to interact with the current working directory (hardcoded to /calculator inside the package when installed) through natural language and function calling.
- Python 3.11+
- Google Gemini API key
- Clone the repository:
git clone https://github.com/ManoloEsS/ai_agent.git
cd ai_agent- Create a virtual environment and activate it
python -m venv .venv #linux
py -m venv .venv #windows
source .venv/bin/activate- Install dependencies:
pip install -e .- Set up your API key:
export GEMINI_API_KEY="your-api-key-here"Or create a .env file in your working directory:
GEMINI_API_KEY=your-api-key-here
Run the AI agent with natural language commands:
# After installing with pipx, you can run from anywhere
ai-agent "list files in the calculator directory"More examples:
# Run the calculator
ai-agent "run the calculator with expression 3 + 5"
# Read a file
ai-agent "read the calculator.py file"
# Enable verbose mode for detailed logging
ai-agent --verbose "explain how the calculator works".
├── main.py # AI agent entry point
├── config.py # Configuration and constants
├── functions/ # Agent function tools
│ ├── call_function.py # Function router
│ ├── get_files_info.py # List directory contents
│ ├── get_file_content.py # Read files
│ ├── write_file.py # Create/modify files
│ └── run_python_file.py # Execute Python scripts
└── calculator/ # Demo calculator application
├── main.py # Calculator CLI
├── tests.py # Unit tests
└── pkg/
├── calculator.py # Calculator logic
└── render.py # Output formatting
For a comprehensive explanation of each function and their role in the program, see:
This detailed documentation includes:
- Complete function descriptions and their responsibilities
- Security features and design patterns
- Program flow and workflow examples
- Usage examples and best practices
- AI-Driven Interaction: Use natural language to interact with code
- Function Calling: AI automatically determines which functions to call
- Security: Path traversal protection and working directory constraints
- File Operations: List, read, and write files safely
- Code Execution: Run Python scripts with arguments
- Multi-Step Tasks: Agent can chain multiple operations
- Verbose Logging: Debug mode for detailed execution traces
- User provides a natural language prompt
- AI agent analyzes the request
- Agent calls appropriate functions (file operations, code execution)
- Results are returned to the AI
- AI generates a human-readable response
The agent can perform multiple operations in sequence to accomplish complex tasks.
ai-agent "what files are in the calculator directory?"ai-agent "run the calculator tests"ai-agent "read calculator.py and explain how it works"ai-agent "add support for exponentiation to the calculator"The agent includes multiple security layers:
- Operations are restricted to the
./calculatorworking directory - Path traversal protection prevents access to parent directories
- File operations validate paths before execution
- Script execution has a 30-second timeout
- File reading is limited to 10,000 characters
For detailed technical documentation, see FUNCTION_DOCUMENTATION.md