A command-line AI coding assistant built with Python, the OpenAI Python SDK, and OpenRouter. This project demonstrates how modern AI agents such as Claude Code and Cursor work under the hood by combining large language models with secure tool calling.
The agent can inspect project files, read source code, modify files, execute Python programs, and iteratively solve coding tasks while operating within a restricted working directory for safety.
- π€ AI-powered command-line coding assistant
- π List files and directories
- π Read file contents safely
- βοΈ Create and overwrite project files
βΆοΈ Execute Python programs with optional arguments- π Secure sandboxed file operations
- π§ Multi-step reasoning using iterative tool calls
- π Verbose mode for debugging and development
- π Environment-based API key management
- Python 3.10+
- OpenAI Python SDK
- OpenRouter API
- python-dotenv
- argparse
- JSON Schema (Tool Definitions)
- subprocess
- uv (Python package manager)
ai_agent/
βββ calculator
β βββ lorem.txt
β βββ main.py
β βββ pkg
β β βββ calculator.py
β β βββ morelorem.txt
β β βββ __pycache__
β β β βββ calculator.cpython-313.pyc
β β β βββ render.cpython-313.pyc
β β βββ render.py
β βββ README.md
β βββ tests.py
βββ call_function.py
βββ config.py
βββ functions
β βββ get_file_content.py
β βββ get_files_info.py
β βββ __pycache__
β β βββ get_file_content.cpython-313.pyc
β β βββ get_files_info.cpython-313.pyc
β β βββ run_python_file.cpython-313.pyc
β β βββ write_file.cpython-313.pyc
β βββ run_python_file.py
β βββ write_file.py
βββ LICENSE
βββ main.py
βββ prompts.py
βββ __pycache__
β βββ call_function.cpython-313.pyc
β βββ config.cpython-313.pyc
β βββ prompts.cpython-313.pyc
βββ pyproject.toml
βββ README.md
βββ test_get_file_content.py
βββ test_get_files_info.py
βββ test_run_python_file.py
βββ test_write_file.py
βββ uv.lock
7 directories, 32 files
The agent follows an iterative workflow:
- Receives a coding request from the user.
- Sends the request to an LLM through OpenRouter.
- The model decides which tool(s) to use.
- The application securely executes the requested function.
- The function result is returned to the model.
- The process repeats until the model produces a final answer.
This tool-calling loop enables the agent to inspect code, modify files, execute programs, and verify fixes before responding.
Displays the contents of directories inside the working directory.
get_files_info()
Reads the contents of project files with a configurable maximum character limit.
get_file_content()
Creates or overwrites files while preventing writes outside the allowed project directory.
write_file()
Runs Python scripts with optional command-line arguments and captures both standard output and error output.
run_python_file()
Clone the repository.
git clone https://github.com/ikwukao/ai_agent.git
cd ai_agentCreate a virtual environment.
uv venvActivate it.
Linux/macOS
source .venv/bin/activateWindows
.venv\Scripts\activateInstall the dependencies.
uv syncCreate a .env file in the project root.
OPENROUTER_API_KEY="your_api_key_here"Never commit this file to version control.
Run the agent with a prompt.
uv run main.py "Explain how the calculator renders results."Enable verbose mode.
uv run main.py "Run the calculator tests." --verboseExample requests:
List all files in the project.
Read calculator/main.py.
Run the calculator tests.
Create a README file.
Fix the bug where 3 + 7 * 2 returns 20.
The agent is intentionally sandboxed.
It cannot:
- Read files outside the configured working directory.
- Write files outside the project.
- Execute non-Python files.
- Access arbitrary locations on the host system through tool calls.
These safeguards reduce the risk of accidental or malicious file access while allowing the LLM to operate effectively within the project.
This project demonstrates practical experience with:
- Large Language Model integration
- Function (tool) calling
- OpenAI-compatible APIs
- Prompt engineering
- Secure filesystem operations
- Python subprocess management
- Multi-module Python applications
- Command-line application development
- Environment variable management
- Iterative AI agent workflows
- Conversation memory
- Streaming responses
- Additional developer tools
- Git integration
- Shell command execution
- Unit and integration testing
- Syntax-aware code editing
- Support for multiple LLM providers
- Conversation logging
This project was built as part of the Boot.dev Backend Developer learning path and is inspired by modern AI coding assistants such as Claude Code, Cursor, and GitHub Copilot.
This project is intended for educational and portfolio purposes.
Watch the AI Coding Agent in action: