A small Python coding-agent that runs in an interactive terminal loop.\
The project is as a learning codebase for building coding agents from first principles.
- Python 3.10+
- An OpenAI API key
Create and activate a virtual environment:
python -m venv venv
source venv/bin/activateInstall dependencies:
pip install -r requirements.txtCreate a .env file in the project root:
OPENAI_API_KEY=your_api_key_hereThe app loads environment variables with python-dotenv, so secrets should stay in .env and out of version control.
Start the interactive agent:
python main.pyType a request at the You: prompt. Exit with Ctrl-C or EOF.
main.py builds a system prompt, sends the conversation to the OpenAI Responses API, and passes the registered tool schemas through the tools argument. When the model returns function calls, the agent:
- Adds the assistant output to the conversation.
- Runs
PRE_TOOL_USEhooks. - Executes the requested local tool if it is allowed.
- Appends a
function_call_outputmessage with the tool result. - Calls the model again until it returns final text.
When final text is produced, the agent prints it and logs the message through the hook system.
The permissions hook reads:
.my-coding-agent/tool-use-config.json
The file is created automatically if it does not exist. To disable a tool, add a tools object with the tool name and a deny status:
{
"tools": {
"run_shell_command": {
"status": "deny"
}
}
}When a tool is denied, the model receives a structured error instead of a tool result.
- Add a new tool name in
tools/types/tool_names.py. - Create an implementation in
tools/implementations/. - Export a
TOOLvalue using theTooldataclass. - Register it in
tools/tool_registry.py.
Each tool provides:
name: aToolNameenum value.description: a short description passed to the model.parameters: JSON schema for the function call arguments.decode_params: argument normalization and defaults.exec: the Python function that performs the work.
- Create a hook implementation in
hooks/implementations/. - Export a
Hookvalue. - Register it in
_HOOK_REGISTRYinhooks/hook_registry.py. - Choose the appropriate event from
hooks/types/hook_event.py.
Current hook events include:
PRE_TOOL_USEPOST_MESSAGE_SENT
Runtime state is written under:
.my-coding-agent/
This directory contains session logs and tool permission config. It is local runtime state and usually should not be committed.