Skip to content

singularity-ng/singularity-genesis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Singularity Genesis

Hot-reloadable adaptive planner with evolutionary learning for self-evolving agent systems.

Overview

Singularity Genesis is an adaptive planning and evolutionary improvement system that sits on top of Singularity Workflow to automatically optimize how task DAGs are generated and executed.

Key Features:

  • 🧠 Adaptive Planning - Goals β†’ Task DAGs using learned patterns or LLM
  • πŸ”„ Evolutionary Learning - Continuously improves planner variants via fitness-driven evolution
  • πŸ”₯ Hot Reload - Live code updates without stopping running workflows
  • πŸ“Š Measurable Fitness - Success Γ— Speed Γ— Cost Γ— Determinism scoring
  • 🎯 Deterministic Replay - Verify and improve reproducibility

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  singularity.genesis (THIS)      β”‚
β”‚  β”œβ”€ AdaptivePlanner                β”‚ ← LLM/Pattern-based planning
β”‚  β”œβ”€ EvolutionEngine                β”‚ ← Fitness, mutation, selection
β”‚  └─ HotReloadManager               β”‚ ← Live code updates
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚ emits task graphs
               ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  singularity_workflow (SPINE)      β”‚ ← Stable runtime
β”‚  β”œβ”€ Orchestrator (HT-DAG)          β”‚
β”‚  β”œβ”€ DAG Execution                  β”‚
β”‚  └─ Lineage Tracking               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Components

AdaptivePlanner

Converts goals into task DAGs using:

  • Pattern Cache - Fast lookup of successful patterns (ETS)
  • LLM Integration - Claude, OpenAI, or local models for novel goals
  • Automatic Learning - Updates patterns based on execution outcomes
{:ok, task_graph} = AdaptivePlanner.plan(
  "Build authentication system",
  %{resources: %{workers: 8}}
)

EvolutionEngine

Improves planner variants through:

  • Fitness Evaluation - Score variants on benchmark suite
  • Tournament Selection - Pick best performers
  • Genetic Operators - Mutation and crossover for breeding
  • Hot Reload - Load improved variants without downtime
{:ok, result} = EvolutionEngine.trigger_evolution(
  population_size: 10,
  survivors: 3,
  mutation_rate: 0.3
)

HotReloadManager

Live code updates via:

  • Module Generation - Create new planner from variant parameters
  • Safe Reload - Compile, verify, load without affecting running workflows
  • Rollback Support - Return to previous version if needed
  • History Tracking - Audit trail of all reloads
{:ok, result} = HotReload.reload_planner(variant)
{:ok, _} = HotReload.rollback(steps: 1)

Core Principles

  1. ONE RUNTIME - Never modify singularity_workflow, only emit task graphs
  2. HOT RELOAD - Planner logic reloads live, workflows continue uninterrupted
  3. EVOLUTIONARY MEMORY - Every DAG run stored with fitness in lineage
  4. MEASURABLE FITNESS - Success, speed, cost, determinism tracked per generation
  5. SAFE MUTATION - Planner mutates policies, not execution semantics
  6. DETERMINISTIC REPLAY - Use Lineage.replay/2 for exact reproduction

Fitness Scoring

Multi-dimensional fitness from execution metrics:

fitness = 0.5 * success_score +
          0.3 * speed_score +
          0.1 * cost_score +
          0.1 * determinism_score

Where:

  • Success - 1.0 if completed, 0.0 if failed
  • Speed - 1.0 / (duration_sec + 1)
  • Cost - 1.0 / (task_count + 1)
  • Determinism - 1.0 if replay matches, 0.0 otherwise

Installation

def deps do
  [
    {:singularity.genesis, git: "https://github.com/Singularity-ng/singularity.genesis.git"}
  ]
end

Usage Examples

Simple Planning

# Plan with learned patterns or LLM fallback
{:ok, task_graph} = Singularity.Evolution.AdaptivePlanner.plan(
  "Build REST API for product catalog",
  %{resources: %{workers: 4}}
)

Execute and Learn

# Automatically plan, execute, and improve
{:ok, result} = Singularity.Evolution.AdaptivePlanner.execute_and_learn(
  "Build REST API for product catalog",
  MyApp.Repo,
  learn: true
)

Evolutionary Improvement

# Trigger evolution cycle
{:ok, evolution} = Singularity.Evolution.EvolutionEngine.trigger_evolution(
  population_size: 10,
  survivors: 3,
  mutation_rate: 0.3
)

IO.puts("Best fitness: #{evolution.avg_fitness}")
IO.puts("Generation: #{evolution.generation}")

Hot Reload

# Live reload improved planner
{:ok, reload} = Singularity.Evolution.HotReload.reload_planner(new_variant)

# Rollback if needed
{:ok, _} = Singularity.Evolution.HotReload.rollback()

Configuration

# config/config.exs
config :singularity.genesis,
  evolution: [
    enabled: true,
    auto_evolve: true,
    evolution_interval_hours: 24,
    population_size: 20,
    survivors: 5
  ],
  llm: [
    default_provider: :claude,
    claude: [
      api_key: System.get_env("ANTHROPIC_API_KEY"),
      model: "claude-sonnet-4-5-20250929",
      max_tokens: 4096
    ]
  ],
  pattern_cache: [
    max_size: 10_000,
    eviction_policy: :lru,
    persist_to_db: true
  ]

Integration with Singularity Workflow

Singularity Genesis uses the Lineage API from Singularity Workflow:

# Get execution history for learning
{:ok, lineage} = Singularity.Workflow.Lineage.get_lineage(run_id, repo)

# Replay workflow for determinism check
{:ok, replay_run_id} = Singularity.Workflow.Lineage.replay(lineage, step_functions, repo)

# Calculate fitness
fitness = FitnessEvaluator.calculate(lineage)

Development

# Setup
mix deps.get
mix ecto.create

# Test
mix test

# Code quality
mix quality   # Runs format, credo, dialyzer, sobelow
mix test.coverage

# Docs
mix docs

Testing Strategy

  • Unit Tests - Individual functions with mocks
  • Integration Tests - Full planning β†’ execution β†’ learning cycles
  • Benchmark Tests - Evolution effectiveness on standard problems

Roadmap

  • Core module scaffolding
  • AdaptivePlanner implementation (Week 1-2)
  • LLM client integration (Week 2-3)
  • Pattern cache and learning (Week 3-4)
  • EvolutionEngine implementation (Week 4-5)
  • Hot reload system (Week 5-6)
  • Benchmark suite and metrics (Week 6-7)
  • Production hardening (Week 7-8)

License

MIT

References

About

Singularity workflows - PostgreSQL-based DAG execution engine with 100% feature parity

Topics

Resources

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 6

Languages