An AI agent that writes its own tools at runtime. When it encounters a task it has no tool for, it generates the tool in Python, validates it in a sandbox, registers it, and uses it — all without human intervention.
Full article: The Self-Extending AI Agent
User Task
↓
Orchestrator Agent → missing tool? → Tool Generator (LLM)
↓
Sandbox Validator
↓
Tool Registry (persist to disk)
↓
Orchestrator resumes → task complete ✅
self_extending_agent/
├── main.py # Entry point — run demo tasks
├── orchestrator.py # Main agent loop with self-extension
├── generator.py # LLM-based tool code generator
├── validator.py # AST + subprocess sandbox validator
├── registry.py # Tool storage, persistence, and loading
├── requirements.txt
└── tools/ # Auto-generated tools stored here
└── manifest.json
# Clone
git clone https://github.com/OneManCrew/self-extending-agent.git
cd self-extending-agent
# Install
pip install -r requirements.txt
# Set your API key
export OPENAI_API_KEY="your-key-here"
# Run
python main.py- Agent receives a task (e.g., "Convert 5000 USD to ILS")
- Checks tool registry — no
fetch_exchange_ratetool exists - Calls
request_new_tool→ LLM writes the Python function - Validator checks syntax, banned patterns, runs import test in subprocess
- Tool registered and persisted to
tools/directory - Agent uses the new tool to complete the task
- On next run, tool loads from disk — never generated again
- Python 3.10+
- OpenAI API key (GPT-4o recommended)
- See
requirements.txtfor packages
- AST static analysis blocks dangerous patterns (
eval,exec,os.system, etc.) - Subprocess isolation for validation
- Max 3 retry attempts per tool generation
- Production: use Docker containers for full sandboxing
MIT
Levi Doron — onemancrew.dev