- Overview
- ⚙️ Architecture
- 🚀 Features
- 📁 Project Structure
- 🛠️ Installation
- 🔧 Configuration
- 🛠️ Available Tools
- 💻 Usage Examples
- 🏗️ Architecture
- 🧪 Testing
- 🐛 Troubleshooting
A modular, extensible AI Agent implementation built from scratch using Python and OpenAI's API. This project demonstrates how to create a functional AI agent with tool integration, proper error handling, and clean architecture.
- Modular Design: Clean separation of concerns with dedicated modules for tools, models, and core functionality
- Tool Integration: Built-in support for calculator and file operations tools
- Extensible Architecture: Easy to add new tools and capabilities
- Error Handling: Robust error handling and logging
- Type Safety: Full type hints using Pydantic models
- Interactive CLI: User-friendly command-line interface
ai-agent-math-calculator/
├── config/
│ └── settings.py # Configuration and settings
├── core/
│ ├── agent.py # Main AI Agent implementation
│ └── llm_client.py # OpenAI API client
├── models/
│ └── schemas.py # Pydantic data models
├── tools/
│ ├── base.py # Base tool class
│ ├── calculator.py # Calculator tool implementation
│ ├── file_operations.py # File operations tool
│ └── manager.py # Tool manager
├── data/ # Directory for file operations
├── tests/ # Unit and Integration Test cases
├── main.py # Main entry point
├── requirements.txt # Python dependencies
├── setup.py # Package setup
├── .env.example # Environment variables example
└── README.md # This file
-
Clone the repository:
git clone <repository-url> cd ai-agent-math-calculator
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
cp .env.example .env # Edit .env and add your OpenAI API key -
Run the agent:
python main.py
Create a .env file in the root directory with your OpenAI API key:
OPENAI_API_KEY=openai_api_keyOptional configurations:
OPENAI_MODEL: Model to use (default: gpt-4)OPENAI_TEMPERATURE: Temperature for responses (default: 0.7)OPENAI_MAX_TOKENS: Maximum tokens per response (default: 1000)
Perform mathematical calculations including:
- Basic arithmetic operations (+, -, *, /, **, %)
- Mathematical functions (sqrt, sin, cos, tan, log, exp, abs, round)
Example usage:
- "Calculate 25 * 4 + sqrt(16)"
- "What is 15% of 250?"
- "Solve: 2^3 + log(100)"
Handle file operations securely:
- Read file contents
- Write content to files
- List files in the data directory
Example usage:
- "Write 'Hello World' to a file called greeting.txt"
- "Read the contents of greeting.txt"
- "List all files"
👤 You: What is the square root of 144?
🤖 Agent: I'll calculate that for you.
The square root of 144 is 12.
👤 You: Calculate the area of a circle with radius 5
🤖 Agent: I'll calculate the area of a circle with radius 5.
Using the formula A = π × r², where r = 5:
A = π × 5² = π × 25 ≈ 78.54
The area of a circle with radius 5 is approximately 78.54 square units.
👤 You: Create a file called "notes.txt" with a list of programming languages
🤖 Agent: I'll create a file called "notes.txt" with a list of programming languages.
Successfully wrote to notes.txt
The agent follows a clean, modular architecture:
- Core: Contains the main agent logic and LLM client
- Tools: Modular tool system with base classes and implementations
- Models: Pydantic schemas for type safety and data validation
- Config: Centralized configuration management
Run tests
python -m pytest tests/- API Key Error: Make sure your OpenAI API key is set in the
.envfile - Import Errors: Ensure all dependencies are installed with
pip install -r requirements.txt - File Permission Errors: Check that the
data/directory has proper write permissions

