Hello there :D
I present to you a toy version of Claude Code, or much rather a command line codding agent built from scratch on top of a pre-trained LLM.
Diclaimer: This project does not train or build an LLM. It uses a free model via OpenRouter (through the OpenAI Python SDK) as the reasoning engine, and wraps it in an agent loop: the model is given a coding task, a set of tools, and the autonomy to call those tools repeatedly until the task is done.
Give the agent a task to perform in plain English and it will:
- Accept the task as a prompt (e.g.
"fix my calculator app, it's not working correctly") - Reason about which four of it's tools to call next
- Call that tool, read the result and decide the next step
- Repeat (upto 20 iterations) until it produces a final result
The agent never touches your file system directly. Every tool call is confined to the sandbox/ directory, and each tool call checks that the resolved path stays inside it before doing anything.
| Tool | What it does |
|---|---|
get_files_info |
Lists files/directories in a given path, with size and directory status |
get_file_content |
Reads a file's contents (truncated at MAX_CHARS, 10,000 chars) |
write_file |
Creates or overwrites a file |
run_python_file |
Executes a Python file, with optional CLI args, and returns its output |
main.py— entry point: loads env vars, builds the OpenRouter client, parses CLI args, kicks off the loopagent.py— the loop itself (agent_loop), capped atMAX_ITERATIONS(20)client.py— builds the OpenAI-SDK client pointed at OpenRouter's APIprompts.py— the system prompt defining the agent's rules and available toolsconfig.py—MAX_ITERATIONSandMAX_CHARStools/— the 4 tool implementations + their function-calling schemassandbox/— the only directory the agent is allowed to read, write, or execute inside (includes a sample buggycalculatorapp to test the agent on)
- Python 3.10+
- uv — Python project/package manager (install docs)
- A Unix-like shell (
bash/zsh); Windows users need WSL 2 - An OpenRouter account (free tier works: ~50 requests/day)
git clone https://github.com/RichieBuilds/ai-agent.git
cd ai-agent
uv sync
cp .env.example .env
# then edit .env and add your OPENROUTER_API_KEYuv run main.py "<describe the task you want the agent to do>"
# with verbose output (prints each function call + token usage totals)
uv run main.py "<task>" -v