A minimal AI agent that evolves itself through GitHub issues and pull requests.
This agent:
- Monitors GitHub issues labeled
agent-task - Uses GPT-4o to generate shell scripts that modify its own code
- Creates pull requests with the proposed changes
- You review and merge to deploy new versions
- Process repeats - agent continuously evolves
- Python 3.8+
- Git configured (
git config user.nameanduser.emailset) - OpenAI API key (get one here)
- GitHub personal access token (create here)
- Required scopes:
repo(full control)
- Required scopes:
-
Clone this repository
git clone https://github.com/YOUR-USERNAME/agent-seed.git cd agent-seed -
Install dependencies
pip install -r requirements.txt
-
Configure environment
cp .env.example .env
Edit
.envwith your credentials:OPENAI_API_KEY=sk-your-key-here GITHUB_TOKEN=ghp_your-token-here REPO=YOUR-USERNAME/agent-seed
-
Create the
agent-tasklabelOn GitHub:
- Go to your repository
- Click "Issues" β "Labels"
- Click "New label"
- Name:
agent-task - Color: any color you prefer
- Save
-
Run the agent
python agent.py
You should see:
π€ Agent monitoring YOUR-USERNAME/agent-seed for 'agent-task' issues... Press Ctrl+C to stop
Create a new issue on GitHub:
- Title:
add logging to agent.log file - Labels:
agent-task - Body: (optional description)
Within 30 seconds:
- β Agent detects the issue
- β Generates evolution script
- β Creates
agent_v1.py - β Tests the new version
- β Creates a pull request
- β Closes the issue
Review the PR, then merge to deploy!
GitHub Issue β Agent Detects β GPT-4o Generates Script
β
Create agent_vN.py
β
Test New Version
β
Create PR β Pass? β Merge
β
Switch to New Version
- Detection: Agent polls GitHub every 30 seconds
- Generation: GPT-4o creates a bash script to implement the task
- Execution: Script creates new agent version + any helper files
- Testing: New version runs
--testflag to verify it works - PR Creation: Git branch created, changes committed, PR opened
- Human Review: You review the changes
- Deployment: Merge PR β agent switches to new version
The agent generates bash scripts instead of directly modifying Python. This enables:
- Creating multiple files (helpers, tests, configs)
- Surgical changes (use
sed,awkfor targeted edits) - Complex operations (install packages, setup infrastructure)
- Self-documenting evolution (git shows what changed)
Example evolution script:
#!/bin/bash
set -e
# Copy agent as base
cp agent.py agent_v1.py
# Add logging import
sed -i '3a import logging' agent_v1.py
# Create logging module
cat > logging_helper.py << 'EOF'
import logging
logging.basicConfig(filename='agent.log', level=logging.INFO)
EOF
chmod +x agent_v1.py
echo "β Agent v1 ready"The agent automatically retries failed evolutions:
- Up to 3 attempts per issue
- Each retry gets context about previous failures
- GPT-4o tries different approaches
If all attempts fail:
- Issue stays OPEN (not auto-closed)
agent-failedlabel added- Comment posted explaining what happened
To retry manually:
- Add
agent-retrylabel to the failed issue - Agent will try again on next poll
Try these in order:
add logging to agent.log file- Simple, tests the flowtrack version number in output- Adds self-awarenesscreate tests/ directory with pytest- Build test suiteadd error handling with retry logic- Improve robustnesscreate helpers.py and refactor- Modular architectureadd cost tracking for API calls- Monitor expensesimplement rate limiting- Prevent API overuse
DO NOT run this on your main development machine.
The agent executes arbitrary bash scripts generated by GPT-4o. While the PR review provides human-in-the-loop safety, you should run this in an isolated environment.
Option 1: Docker (Recommended)
docker run -it \
--rm \
--cpus=1 \
--memory=1g \
-v $(pwd):/app \
-w /app \
python:3.11-slim \
bash -c "pip install -r requirements.txt && python agent.py"Option 2: AWS EC2 Spot Instance
# Launch t3.micro spot (~$0.01/hour)
# SSH in, clone repo, run agent
# Terminate when doneOption 3: Local VM
# VirtualBox/UTM with Ubuntu
# Network mode: NAT (outbound only)
# Snapshot before runningBefore running:
- Running in isolated environment (not main laptop)
- Dedicated GitHub token (can revoke easily)
- OpenAI spending limit set ($50-100)
- Git configured (user.name and user.email)
- Ready to monitor resource usage
- Know how to emergency stop
Stop immediately if you see:
- Evolution scripts with
rm -rfor destructive commands - Network calls to unknown domains
- Attempts to modify
.gitignoreor.env - API costs spiking unexpectedly
- Credential exposure in git commits
# Test the agent
python agent.py --test
# Should output: OK
# Check environment
cat .env
# Verify all three variables are set- Wait 30 seconds (agent polls every 30s)
- Verify issue has
agent-tasklabel (case-sensitive) - Check
REPOin.envmatches your fork exactly
# Configure git
git config user.name "Your Name"
git config user.email "you@example.com"
# Verify GitHub token has 'repo' scope
# Create new token if needed- Check
evolve_vN.shfor errors - Review agent output for error messages
- Try adding
agent-retrylabel to retry
After a few evolutions:
agent-seed/
βββ agent.py # Current version (seed)
βββ agent_v1.py # First evolution
βββ agent_v2.py # Second evolution
βββ evolve_v1.sh # Script that created v1
βββ evolve_v2.sh # Script that created v2
βββ SYSTEM_PROMPT.md # Instructions for GPT-4o
βββ README.md # This file
βββ requirements.txt # Dependencies
βββ .env # Your secrets (gitignored)
βββ .env.example # Template
βββ .gitignore # Ignores secrets
This experiment explores:
- How many iterations before the agent breaks itself?
- What types of tasks succeed vs fail?
- Does code quality improve or degrade over time?
- What capabilities emerge without explicit programming?
- Can human-in-loop (PRs) constrain autonomous systems?
MIT License - fork freely and evolve your own version!
Found a bug in the seed (this initial version)? Open an issue or PR!
For your agent's evolution, that belongs in your fork - share interesting patterns in Discussions instead.
- Setup issues: Check Troubleshooting section above
- Bug in seed: Open an issue
- Evolution questions: Start a Discussion
- Security concerns: See Security section
Ready to evolve? Create your first agent-task issue and watch it grow! π±βπΏβπ³