A lightweight Python coding agent that uses OpenAI-compatible chat completions (via OpenRouter) and function/tool calling to inspect files, edit files, and execute Python scripts inside a constrained workspace.
This repository combines:
- An LLM orchestration loop in
./main.py - A dynamic tool dispatcher in
./call_function.py - Secure local tools in
./functions/ - A sample target workspace in
./calculator/
The agent receives a prompt, decides when to call tools, executes them, and feeds tool results back to the model until a final answer is produced.
-
OpenAI function/tool calling infrastructure
Registers tool schemas (get_files_info,get_file_content,write_file,run_python_file) and passes them tochat.completions.create(...). -
Loop-preventing iteration limits (multi-turn tool calling)
Supports chained tool calls across turns with a hard stop (for _ in range(20)) to prevent infinite loops. -
File I/O operations (reading/writing files)
Includes guarded file readers/writers that enforce path boundaries to keep access within the permitted working directory. -
Python code execution capabilities (
run_python_file)
Runs.pyfiles with optional arguments, captures stdout/stderr, and enforces path and file-type safety checks.
coding_agent/
├── main.py # LLM loop + tool-call orchestration
├── call_function.py # Tool dispatcher and schema registry
├── prompts.py # System prompt for agent behavior
├── config.py # Shared limits/constants
├── functions/
│ ├── get_files_info.py # Directory listing tool
│ ├── get_file_content.py # File read/write tools
│ └── run_python_file.py # Python execution tool
├── calculator/ # Example project the agent can operate on
│ ├── main.py
│ ├── tests.py
│ └── pkg/
└── test_*.py # Tool behavior demonstration scripts
Current visible history shows two foundational milestones:
feat(functions): introduce utility to dynamically call tool functions
Initial project structure, tool implementations, and dynamic dispatch.feat(llm): implement multi-turn tool calling with iteration limit
Added multi-step tool-call looping and maximum-iteration protection inmain.py.
git clone https://github.com/hseyinblgc/coding_agent.git
cd coding_agentpython3 -m venv .venv
source .venv/bin/activateOn Windows (PowerShell):
.\.venv\Scripts\Activate.ps1
Using uv (lockfile is included):
uv syncOr with pip:
pip install -U pip
pip install openai==2.44.0 python-dotenv==1.1.0Create a .env file in the repository root:
OPENROUTER_API_KEY=your_api_key_hereRun the agent with a natural-language task:
python main.py "Inspect the calculator project, run its tests, and summarize any failures."Verbose mode:
python main.py "List files and explain the project layout." --verboseExample workflow:
- Ask the agent to inspect
/calculatorand identify entry points. - The model calls
get_files_infoandget_file_contentto map the codebase. - The model calls
run_python_fileto executecalculator/tests.py. - If needed, it calls
write_fileto apply updates. - The loop continues until the model returns a final natural-language response (or reaches the iteration cap).
- Python requirement is
>=3.13(see./pyproject.toml). - Tool execution is sandboxed to an injected working directory (
./calculatorin current dispatcher logic).