Self-Evolving AI Agent System
A Next.js implementation of the SuperInstance architecture for local-first, continuously improving AI agents.
Quick Start β’ Documentation β’ API Reference β’ Architecture
- Overview
- Features
- Quick Start
- Architecture
- Core Concepts
- API Reference
- Configuration
- Development
- Roadmap
- Contributing
AI Ranch is a self-evolving AI agent system that runs continuously, improving its performance through nightly evolution cycles. Inspired by natural selection, the system maintains a population of specialized AI "species" that compete, breed, and evolve based on task performance.
| Feature | AI Ranch | Traditional Agents |
|---|---|---|
| Evolution | β Self-improving | β Static |
| Local-first | β Runs on edge | β Cloud-dependent |
| Small binary | β Single deployment | β Multiple services |
| DNA-driven | β breed.md configs | β Hard-coded |
| Multi-species | β 8 agent types | β Single agent |
8 specialized agent types, each optimized for different tasks:
| Species | Icon | Role | Key Traits | Best For |
|---|---|---|---|---|
| Cattle | π§ | Heavy Reasoning | patience: 0.9, speed: 0.3 | Analysis, email processing, document review |
| Duck | π¦ | Network | speed: 0.8 | API calls, webhooks, HTTP requests |
| Goat | π§ | Navigation | balanced | Pathfinding, spatial reasoning, mapping |
| Sheep | βοΈ | Consensus | patience: 0.9 | Voting, mediation, group decisions |
| Horse | β‘ | ETL | thoroughness: 0.9 | Data pipelines, batch processing |
| Falcon | ποΈ | Search | speed: 0.95 | Quick lookups, reconnaissance |
| Hog | π | Diagnostics | thoroughness: 0.95 | Logging, debugging, tracing |
| Chicken | π₯ | Monitoring | speed: 0.9 | Alerts, health checks, watchdog |
Intelligent routing system that analyzes intent and dispatches to the optimal species:
User Intent β Keyword Analysis β Species Scoring β Fitness Weighting β Selection
β β β β β
βΌ βΌ βΌ βΌ βΌ
"Analyze this "analyze", cattle: 0.85 Γ 0.75 fitness β cattle
email..." "email" duck: 0.42
Features:
- Keyword-based matching with confidence scoring
- Species fitness consideration (better performers get priority)
- Alternative species suggestions for fallback
- Real-time routing decisions
Define agent behavior through simple markdown configuration:
# species
cattle
# name
Email Analyst
# description
Specialized in email processing and analysis
# capabilities
- email_processing (weight: 1.0)
- analysis (weight: 0.9)
- summarization (weight: 0.7)
- priority_detection (weight: 0.8)
# personality
tone: professional
verbosity: concise
creativity: 0.3
risk_tolerance: 0.2
# model
base_model: phi-3-mini
lora: cattle-reasoning-v1
temperature: 0.5
max_tokens: 1024
# evolution
mutation_rate: 0.1
crossover_rate: 0.7
selection_pressure: 0.3
elite_count: 2
# constraints
- forbidden: Do not send emails without approval
- required: Always include a summary
- preferred: Use bullet points for clarityDaily evolution cycle running at 02:00 AM:
ββββββββββββββ ββββββββββ ββββββββββ ββββββββββββ
β EVALUATE ββββββΊβ CULL ββββββΊβ BREED ββββββΊβ DISTILL β
β Score fit β β Remove β β Create β β Train β
β β β weak β βoffspringβ β β
ββββββββββββββ ββββββββββ ββββββββββ ββββββββββββ
β
βΌ
ββββββββββββββ ββββββββββββββ βββββββββββββ
β COMPLETE βββββββ PROMOTE ββββββββββββββQUARANTINE β
β β β Add to pop β β Test β
ββββββββββββββ ββββββββββββββ βββββββββββββ
| Phase | Description | Duration |
|---|---|---|
| Evaluate | Score species fitness based on task history | ~100ms |
| Cull | Remove species below 0.3 fitness threshold | ~50ms |
| Breed | Create offspring from top performers via crossover | ~100ms |
| Distill | Cloud training for new offspring | ~100ms |
| Quarantine | Test offspring in sandbox (80% pass rate) | ~50ms |
| Promote | Add successful offspring to population | ~50ms |
Real-time monitoring interface built with React and Tailwind CSS:
Features:
- Species Panel: View all species with traits, capabilities, fitness scores
- Task Manager: Create tasks, view routing decisions, see results
- Evolution Panel: Monitor Night School cycles, trigger manual evolution
- Metrics Bar: Real-time system metrics (requests, latency, tokens/s)
- Node.js 18+ or Bun
- npm, yarn, or bun package manager
# Clone the repository
git clone https://github.com/SuperInstance/ai-ranch.git
cd ai-ranch
# Install dependencies
bun install
# or
npm install
# Start development server
bun run dev
# or
npm run dev-
Open the Dashboard
Navigate to
http://localhost:3000in your browser. -
Submit Your First Task
In the Task Panel, enter:
Analyze this email and extract key action itemsWatch as the Collie routes it to the cattle species.
-
Explore Species
Click the "Species" tab to see all 8 agent types with their traits.
-
Trigger Evolution
Click "Run Evolution" in the Evolution tab to see Night School in action.
# Create a task
curl -X POST http://localhost:3000/api/ranch/tasks \
-H "Content-Type: application/json" \
-d '{"content": "Search for recent AI news"}'
# Get all species
curl http://localhost:3000/api/ranch/species
# Trigger evolution
curl -X POST http://localhost:3000/api/ranch/evolutionai-ranch/
βββ src/
β βββ app/ # Next.js App Router
β β βββ api/ranch/ # REST API endpoints
β β β βββ species/ # Species CRUD
β β β βββ tasks/ # Task management
β β β βββ evolution/ # Evolution control
β β βββ globals.css # Global styles
β β βββ layout.tsx # Root layout
β β βββ page.tsx # Dashboard page
β β
β βββ components/ # React Components
β β βββ ranch/ # Ranch-specific
β β β βββ dashboard.tsx
β β β βββ species-panel.tsx
β β β βββ task-panel.tsx
β β β βββ evolution-panel.tsx
β β βββ ui/ # Reusable primitives
β β
β βββ lib/ # Core Library
β β βββ breed-parser.ts # breed.md parser
β β βββ collie.ts # Orchestrator
β β βββ night-school.ts # Evolution system
β β βββ species.ts # Species registry
β β βββ utils.ts # Utilities
β β
β βββ types/ # TypeScript Types
β βββ ranch.ts # All type definitions
β
βββ docs/ # Documentation
β βββ api-reference.md # API docs
β βββ quick-start.md # Getting started
β
βββ templates/ # breed.md Templates
β βββ email-analyst.md
β βββ quick-search.md
β βββ data-pipeline.md
β
βββ package.json
βββ tsconfig.json
βββ tailwind.config.ts
βββ README.md
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT LAYER β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Web Dashboard (React) β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββ β β
β β β Species β β Task β β Evolution β β β
β β β Panel β β Panel β β Panel β β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β HTTP/WebSocket
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β API LAYER β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β /species β β /tasks β β /evolution β β
β β route.ts β β route.ts β β route.ts β β
β ββββββββ¬βββββββ ββββββββ¬βββββββ ββββββββ¬βββββββ β
βββββββββββΌβββββββββββββββββΌβββββββββββββββββΌβββββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CORE LIBRARY β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Species Registry β β
β β ββββββββββ ββββββββββ ββββββββββ ββββββββββ ββββββββββ β β
β β β cattle β β duck β β goat β β sheep β β horse β ... β β
β β β fitnessβ β fitnessβ β fitnessβ β fitnessβ β fitnessβ β β
β β ββββββββββ ββββββββββ ββββββββββ ββββββββββ ββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β² β
β β β
β ββββββββββββββββββββ βββββββ΄ββββββ ββββββββββββββββββββ β
β β Breed Parser ββββββ Collie βββββΊβ Night School β β
β β (breed.md DNA) β βOrchestratorβ β (Evolution) β β
β ββββββββββββββββββββ βββββββββββββ ββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββ β
β βTask Queue β β
β βββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. User submits task intent
βββΊ Task Panel β POST /api/ranch/tasks
2. Collie analyzes and routes
βββΊ CollieOrchestrator.route(intent) β RoutingDecision
3. Task is created and queued
βββΊ CollieOrchestrator.createTask(intent) β Task
4. Species processes task
βββΊ CollieOrchestrator.processTask(taskId) β TaskResult
5. Fitness is updated
βββΊ SpeciesRegistry.updateFitness(species, newFitness)
6. Night School evolves population (02:00 AM)
βββΊ NightSchool.runCycle() β EvolutionCycle
A Species represents a specialized AI agent with unique traits:
interface Species {
name: SpeciesName; // cattle, duck, goat, etc.
description: string; // Purpose description
capabilities: string[]; // Skills this species has
modelHint: string; // Recommended model
loraAdapter?: string; // LoRA adapter name
traits: {
patience: number; // 0-1
thoroughness: number; // 0-1
creativity: number; // 0-1
speed: number; // 0-1
};
fitness: number; // Performance score (0-1)
generation: number; // Evolution generation
}The Collie Orchestrator routes intents using keyword matching:
// Routing keywords per species
const ROUTING_KEYWORDS = {
cattle: ['analyze', 'explain', 'review', 'email', 'reasoning'],
duck: ['api', 'fetch', 'request', 'http', 'webhook'],
goat: ['navigate', 'path', 'route', 'find', 'location'],
sheep: ['consensus', 'vote', 'agree', 'decide', 'group'],
horse: ['process', 'transform', 'batch', 'pipeline', 'etl'],
falcon: ['search', 'find', 'quick', 'lookup', 'retrieve'],
hog: ['debug', 'log', 'diagnose', 'error', 'trace'],
chicken: ['monitor', 'watch', 'alert', 'notify', 'status'],
};Night School improves the population through genetic algorithms:
Fitness Calculation:
compositeScore =
successRate * 0.4 + // Task success rate
impactWeight * 0.2 + // Task importance
latencyScore * 0.2 + // Response time
qualityScore * 0.2; // Output qualityCrossover:
offspring.traits.patience =
(parent1.traits.patience + parent2.traits.patience) / 2
+ (Math.random() - 0.5) * 0.1; // Mutationhttp://localhost:3000/api/ranch
| Method | Endpoint | Description |
|---|---|---|
GET |
/species |
List all species |
GET |
/species?name=cattle |
Get specific species |
POST |
/species |
Update species |
Examples:
# List all species
curl http://localhost:3000/api/ranch/species
# Update fitness
curl -X POST http://localhost:3000/api/ranch/species \
-H "Content-Type: application/json" \
-d '{"name": "cattle", "updates": {"fitness": 0.85}}'| Method | Endpoint | Description |
|---|---|---|
GET |
/tasks |
List recent tasks |
GET |
/tasks?active=true |
Get active tasks |
GET |
/tasks?id=xxx |
Get specific task |
POST |
/tasks |
Create new task |
Examples:
# Create task
curl -X POST http://localhost:3000/api/ranch/tasks \
-H "Content-Type: application/json" \
-d '{"content": "Analyze this dataset"}'
# Get active tasks
curl "http://localhost:3000/api/ranch/tasks?active=true"| Method | Endpoint | Description |
|---|---|---|
GET |
/evolution |
Get evolution history |
GET |
/evolution?current=true |
Get current cycle |
POST |
/evolution |
Trigger evolution |
Examples:
# Get history
curl http://localhost:3000/api/ranch/evolution
# Trigger manual evolution
curl -X POST http://localhost:3000/api/ranch/evolutionCreate a .env file in the root directory:
# Server
PORT=3000
NODE_ENV=development
# Evolution
NIGHT_SCHOOL_HOUR=2
MIN_FITNESS_THRESHOLD=0.3
MAX_FITNESS_THRESHOLD=0.95
# Model (future)
TENSORRT_ENABLED=false
DEFAULT_MODEL=phi-3-miniSee the /templates directory for examples:
email-analyst.md- Email processing agentquick-search.md- Fast search agentdata-pipeline.md- ETL agent
bun run dev # Start development server
bun run build # Build for production
bun run start # Start production server
bun run lint # Run ESLint| Technology | Purpose |
|---|---|
| Next.js 15 | React framework with App Router |
| TypeScript | Type safety |
| Tailwind CSS 4 | Styling |
| Radix UI | Accessible primitives |
| Lucide React | Icons |
Each directory has its own README for detailed documentation:
/src- Source code overview/src/app- Next.js App Router/src/components- React components/src/lib- Core library/src/types- Type definitions/docs- Documentation/templates- breed.md templates
- Species Registry with 8 agent types
- Collie Orchestrator with keyword routing
- breed.md DNA parser
- Night School evolution system
- Web dashboard
- REST API
- TensorRT-LLM integration for real inference
- LoRA hot-swap for runtime adapter changes
- Discord/Telegram channel connectors
- CUDA Graph reflex cache for <5ms latency
- Real benchmarks on Jetson hardware
- Multi-Jetson synchronization
- CRDT Memory Pasture for distributed state
- Cloud distillation integration
- Community gene pool
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Use TypeScript strict mode
- Follow existing code patterns
- Add JSDoc comments for public functions
- Update documentation for API changes
MIT License - see LICENSE for details.
- Inspired by SuperInstance architecture
- UI components from shadcn/ui
- Icons from Lucide
Built with β€οΈ for the edge AI community