Skip to content

Latest commit

Β 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Continuous Agent Logo

Continuous Agent

Autonomous Neuro-Symbolic Research & Algorithmic Discovery Engine

CI Suite Latest Release License: MIT Python Lean 4 Wasmtime

An autonomous neuro-symbolic continuous discovery system integrating a continuous execution heartbeat, cognitive memory with recursive compaction, RRF hybrid RAG search, multi-island evolutionary search (FunSearch), Counterexample-Guided Inductive Synthesis (CEGIS) with Z3, formal verification via Lean 4, dual-tier WASM/gVisor sandboxing, and automated GitHub GitOps PR publishing.


⚑ Architectural Overview

Continuous Agent Neuro-Symbolic Architecture

πŸ” View Interactive Mermaid Topology
flowchart TD
    %% Styling and Themes
    classDef control fill:#0f172a,stroke:#38bdf8,stroke-width:2px,color:#fff;
    classDef loop fill:#0f172a,stroke:#38bdf8,stroke-width:2px,color:#fff;
    classDef sched fill:#0f172a,stroke:#6366f1,stroke-width:2px,color:#fff;
    classDef memory fill:#0f172a,stroke:#38bdf8,stroke-width:2px,color:#fff;
    classDef engine fill:#064e3b,stroke:#10b981,stroke-width:2px,color:#fff;
    classDef prover fill:#581c87,stroke:#a855f7,stroke-width:2px,color:#fff;
    classDef sandbox fill:#0f172a,stroke:#10b981,stroke-width:2px,color:#fff;
    classDef gitops fill:#0f172a,stroke:#a855f7,stroke-width:2px,color:#fff;

    Deck["<b>FastAPI Real-Time Control Deck</b><br/>(WebSockets, SSE, Telemetry, CEGIS, Lean 4)"]:::control

    Loop["<b>Continuous Agent Loop</b><br/>β€’ Asynchronous Heartbeat<br/>β€’ Multi-Turn Tools<br/>β€’ Circuit Breaker"]:::loop
    Sched["<b>Task Scheduler (Cron)</b><br/>β€’ Live Countdown Deck<br/>β€’ Dynamic Croniter<br/>β€’ Nightly Discovery"]:::sched

    Mem["<b>Cognitive Memory</b><br/>β€’ Working Scratchpad<br/>β€’ Reflexion (Self-Learn)<br/>β€’ Episodic Compaction<br/>β€’ RRF Hybrid Search"]:::memory
    Evol["<b>Evolutionary Engine</b><br/>β€’ FunSearch Service<br/>β€’ Multi-Island Model<br/>β€’ Behavioral Probes<br/>β€’ Strategy Stagnation"]:::engine
    Symb["<b>Neuro-Symbolic & CEGIS</b><br/>β€’ AST-to-Z3 Transpiler<br/>β€’ Singularity / Monotonic<br/>β€’ Dynamic Suite Invariant<br/>β€’ Lean 4 Kernel Prover"]:::prover

    Sand["<b>Dual-Tier Sandboxing</b><br/>β€’ WebAssembly (Fuel Cap)<br/>β€’ 1-Page Linear Memory<br/>β€’ gVisor (runsc) Fallback"]:::sandbox
    Git["<b>GitOps PR Automation</b><br/>β€’ Auto Feature Branch<br/>β€’ Code + Lean Certificate<br/>β€’ GitHub REST API PR Open"]:::gitops

    Deck --> Loop
    Deck --> Sched

    Loop --> Mem
    Loop --> Evol

    Sched --> Evol
    Sched --> Symb

    Evol --> Sand
    Symb --> Git
    Symb -. "<b>CEGIS Invariant Feedback Loop</b>" .-> Evol
Loading

πŸ“‹ Mandatory Prerequisites

Layer Dependency Fallback / Impact If Missing
LLM Provider OPENAI_API_KEY (or Anthropic/Custom) in .env Island mutations and prompt synthesis require an active API key.
SMT & Formal Proofs elan (Lean 4 compiler) + z3-solver Synthesizes Lean 4 code; verification requires elan toolchain on PATH.
Container Sandbox Host Docker daemon with runsc (gVisor) runtime Automatic fallback: If Docker is offline, system automatically evaluates programs in-process via WebAssembly or local simulation.
WASM Runtime wasmtime Python wheel Sub-millisecond in-process evaluations (<40Β΅s).
GitOps (Optional) GITHUB_TOKEN + GITHUB_REPO Automated branch, commit, and PR creation via GitHub REST API.

πŸš€ Quickstart

Clone the repository and run the automated bootstrap script:

git clone https://github.com/AmithKumar1/continuous-agent.git
cd continuous-agent
chmod +x setup.sh
./setup.sh

(Windows users can run .\setup.ps1 in PowerShell)

1. Configure Secrets

Edit the generated .env file with your API credentials:

nano .env  # Add your OPENAI_API_KEY, AGENT_API_TOKEN, etc.

2. Launch the Discovery Agent

Activate the isolated environment and boot the FastAPI control dashboard:

source .venv/bin/activate
python main.py

Open http://localhost:8000 in your browser to access the live telemetry pipeline, interactive Z3 invariant probe, and evolutionary island controls.

3. Alternative: Run via Docker Compose

docker compose up --build -d

Path B: Bare-Metal Local Machine

If running directly on macOS, Linux, or Windows without Docker:

  1. Install Lean 4 via elan (macOS/Linux):

    curl -sSf https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh | sh -s -- -y --default-toolchain leanprover/lean4:stable
    source $HOME/.elan/env
  2. Install Python requirements:

    pip install -r requirements.txt
  3. Run pre-flight verification:

    python preflight.py
  4. Start the daemon:

    python main.py

🎨 Interactive Control Deck Components

The FastAPI dashboard (http://localhost:8000) provides real-time telemetry over WebSockets:

  1. Dynamic Animated SVG Pipeline Flowchart:

    • Live visual progression: Islands βž” WASM Sandbox βž” Z3 SMT Prover βž” Lean 4 Kernel βž” GitOps Dispatch.
    • Reverse rose-tinted CEGIS counterexample feedback beam on invariant violations.
    • Dynamic stage controller with glowing SVG filters.
  2. High-DPI Canvas Radar Chart (Island Population Dynamics):

    • Multi-axis behavioral tracking across 5 dimensions: Peak Fitness, Cluster Diversity, AST Parsimony, Throughput, and Invariant Soundness.
    • Retina-scaled rendering (devicePixelRatio).
    • Euclidean distance hit-testing (<18px) with pulsing halos and floating glassmorphic tooltip.
  3. Nightly Discovery Scheduler:

    • Live countdown display for cron-scheduled discovery runs (default 0 2 * * *).
    • Preset buttons and manual immediate dispatch trigger.
  4. Neuro-Symbolic CEGIS & Lean 4 Prover:

    • Interactive heuristic editor with Singularity test presets.
    • Live Z3 SMT contract checking with counterexample extraction.
    • Lean 4 formal proof certificate generation and GitHub PR creation.

πŸ› οΈ Testing & Verification

# Test WebAssembly JIT execution & fuel limits
python test_wasm_sandbox.py

# Test Lean 4 proof synthesis
python test_lean_verify.py

# Run empirical benchmark suite (Falkenauer U120 + Weibull Burst)
python benchmark_efficacy.py

πŸ“Š Empirical Verification & Benchmark Baselines

Continuous Agent is benchmarked against classic online bin packing suites (Falkenauer U120 and Weibull Burst distribution streams) comparing discovered heuristics against established human baselines:

Algorithm / Heuristic Benchmark Set Average Utilization Optimal Bins Delta Proof Status
Next Fit (NF) Falkenauer U120 74.8% +32.4% bins Baseline
First Fit (FF) Falkenauer U120 91.7% +8.0% bins Baseline
Best Fit (BF) Falkenauer U120 92.0% +7.6% bins Baseline
Discovered Heuristic #1 Falkenauer U120 92.0% +7.6% bins Lean 4 Verified
Next Fit (NF) Weibull Burst 80.1% +22.7% bins Baseline
First Fit (FF) Weibull Burst 95.1% +3.3% bins Baseline
Best Fit (BF) Weibull Burst 95.7% +2.7% bins Baseline
Discovered Heuristic #1 Weibull Burst 95.7% +2.7% bins Lean 4 Verified

⚑ Token Optimization & Defense-in-Depth

  1. Two-Tier Model Routing (80–90% Cost Reduction):
    • Routine island mutations are offloaded to local open-weight coding models (qwen2.5-coder:7b via Ollama/vLLM).
    • Frontier models (gpt-4o-mini) are reserved exclusively for supervisor reflection and population restarts.
  2. Expression-Only AST Diff Prompting:
    • Prompting is restricted to mathematical return expressions (return ...), avoiding ~350 tokens of repetitive boilerplate per evaluation cycle.
  3. Semantic AST Memoization:
    • Canonicalizes variable names (bin_capacity $\rightarrow c$, item $\rightarrow i$) and deduplicates structurally identical heuristics in SQLite before evaluation.
  4. Staged Fail-Fast Pipeline:
    • Evaluates cheap gates first: AST Allowlist (<1ms) $\rightarrow$ WASM Smoke (<50Β΅s) $\rightarrow$ Z3 Probe (<15ms) $\rightarrow$ Full Benchmarks (<2ms) $\rightarrow$ Lean 4 Proofs.
  5. Zero-Trust AST Guard:
    • Pure mathematical allowlist (agent/ast_guard.py) strictly blocks import, exec(), eval(), open(), loops, and dunder attribute access before code execution.

πŸ“‘ API Reference

Method Endpoint Description
GET / Web operator dashboard UI
GET /api/status Current heartbeat iteration and agent state
POST /api/pause Pause agent heartbeat loop
POST /api/resume Resume agent heartbeat loop
POST /api/trigger Trigger immediate single-cycle step
GET /api/memory/core Read active working scratchpad
POST /api/memory/core Set or update working scratchpad key/value
GET /api/memory/heuristics Fetch learned operational rules
GET /api/memory/search?q=... Hybrid RRF episodic memory search
POST /api/funsearch/start Launch multi-island evolutionary search
GET /api/funsearch/telemetry Real-time evolutionary search telemetry
POST /api/cegis/probe Run Z3 contract verification on heuristic code
POST /api/verify/lean Synthesize and check Lean 4 proof certificate
POST /api/gitops/create-pr Open GitHub PR for verified heuristic
GET /api/scheduler/status Cron schedule status and live countdown
POST /api/scheduler/update Update cron schedule pattern
POST /api/scheduler/trigger-now Launch overnight discovery pipeline immediately
GET /api/evolution/pareto-profile Live non-dominated Pareto frontier and island entropy diagnostics
GET /api/evolution/policy-audit Historical record of adaptive policy shifts and parallel beam evaluations
GET /metrics Prometheus exposition endpoint with live SQLite state sync
WS /ws/telemetry Real-time WebSocket event stream

πŸ“Š Production Observability & Prometheus Telemetry

Continuous Agent exposes research-grade telemetry and alerting via native Prometheus exposition on /metrics:

  • Evolutionary Population Health: continuous_agent_island_fitness_best, continuous_agent_island_fitness_mean, continuous_agent_island_phenotypic_entropy, continuous_agent_island_pareto_count, and continuous_agent_island_stagnation_generations.
  • AST Cache & Transpiler Efficiency: continuous_agent_ast_cache_lookups_total (hit/miss counters) and continuous_agent_ast_cache_hit_ratio.
  • Formal Verification Outcomes: continuous_agent_lean_proofs_total (success, kernel_error, timeout) and continuous_agent_cegis_probes_total (verified, refuted, timeout).
  • Execution Cost Profiling: continuous_agent_wasm_fuel_consumed histogram tracking instruction fuel consumption distribution.

Dashboards & Alerting Infrastructure

  • Grafana Dashboard: Pre-configured definition in deploy/grafana-dashboard.json provides an 8-panel overview with Pareto convergence, entropy gauges, and verification latency.
  • Prometheus Alert Rules: Pre-configured alerts in deploy/prometheus-alerts.yml covering phenotypic entropy decay (< 0.6), severe monoculture (< 0.2), prolonged fitness plateaus, Lean 4 proof kernel crashes, and process downtime.
  • Promtool Unit Testing: Comprehensive synthetic unit tests in tests/test_prometheus_alerts.yml validated via CI.

🧬 NSGA-II Multi-Objective Optimization & Island Profiling

  • Bi-Objective Pareto Dominance: Evaluates heuristics balancing Packing Ratio ($f_{\text{pack}} \in [0, 1]$, maximize) against WASM Instruction Fuel ($f_{\text{cost}}$, minimize) without arbitrary scalar weights.
  • Fast Non-Dominated Sorting & Crowding Distance: Partitions populations into Pareto fronts ($F_1, F_2, \dots$) and preserves diverse boundary trade-offs via crowding distance metrics.
  • Phenotypic Shannon Entropy Decay: Tracks discrete decision cluster distribution over sliding generation windows; detects diversity collapse and flatlined fitness velocity:
    • H < H_threshold $\rightarrow$ triggers Ring Migration between islands.
    • Severe stagnation ($&gt; 2W$ generations) $\rightarrow$ triggers Cataclysmic Paradigm Restart.
  • Automated Schema Migration: scripts/migrate_nsga2_schema.py provides non-destructive online upgrades adding pareto_rank, crowding_distance, and composite index idx_heuristics_pareto.

⚑ Autonomous Supervisory Remediation & Adaptive Sampling

  • Ring Migration Topology: When an island's Shannon entropy or fitness velocity plateaus, execute_ring_migration() transfers non-dominated Pareto exemplars to downstream neighbor islands ($i \to (i+1)%N$), injecting novel decision phenotypes without losing accumulated elite fitness.
  • Cataclysmic Paradigm Restarts: Under severe prolonged stagnation ($&gt; 2W$ generations), execute_cataclysmic_restart() purges non-Pareto individuals, preserves top Pareto stars, and switches the island's LLM mutation paradigm across orthogonal strategies (INVERSE_FIT_DIVERGENCE, STOCHASTIC_SCATTER, COMPACT_GREEDY).
  • Entropy-Driven Thermal & Multi-Parameter Sampling Policy: Synchronously scales generation parameters based on the normalized entropy deficit $D(H) = \max(0, 1 - H/H_{\text{target}})$:
    • Temperature: $T \in [0.20, 0.95]$
    • Nucleus Sampling: $top_p \in [0.70, 0.98]$
    • Mutation Beam Width: $K \in [1, 4]$ parallel mutation proposals per prompt.
  • Policy Audit Trail: All adaptive parameter transitions and parallel beam candidate yields are persisted to the supervisor_policy_audit table with composite indexing for inspection via GET /api/evolution/policy-audit.

πŸ”’ Security Architecture

  • Isolated Storage: Local SQLite databases (agent_state.db) and ChromaDB vector collections (chroma_data/) are isolated and omitted from source control.
  • Scope Restriction: Autonomous security audits enforce explicit host allowlisting (SECURITY_SCAN_ALLOWED_HOSTS).
  • Deadlock-Free Lock Ordering: Distributed tool execution enforces ordered resource locks to prevent concurrency deadlocks.
  • Resource Limits: WASM execution enforces explicit fuel depletion bounds; gVisor fallback enforces read-only root filesystems and process limits.
  • Authentication: REST API and WebSocket channels secured via X-API-Key or Authorization: Bearer <token>.

πŸ—„οΈ Storage Concurrency & Disaster Recovery

  • SQLite WAL Mode & Concurrency: agent_state.db runs with PRAGMA journal_mode = WAL, busy_timeout = 10000, and synchronous = NORMAL, enabling lock-free concurrent reads during heavy evolutionary mutation batches.
  • Zero-Downtime Hot Backups: scripts/backup_db.py leverages SQLite's native backup() API with incremental 250-page slices, PRAGMA integrity verification, gzip compression, and rolling 14-snapshot rotation.
  • Automated Systemd Supervision: Automated 6-hour backups scheduled via deploy/continuous-agent-backup.service and deploy/continuous-agent-backup.timer.
  • Safe Disaster Recovery: scripts/restore_db.py executes staged restore in isolated sandboxes with pre-restore active archival, --dry-run schema census, and automated rollback upon swap failure:
    # Inspect snapshot without modifying active state
    python scripts/restore_db.py --dry-run
    
    # Restore latest snapshot with confirmation prompt
    python scripts/restore_db.py
    
    # Automated CI/CD restore
    python scripts/restore_db.py --source backups/agent_state_20260905_060000Z.db.gz --yes

πŸ“„ License

MIT License. See LICENSE for details.

About

Autonomous neuro-symbolic research agent synthesizing, verifying, and sandboxing algorithms with FunSearch, CEGIS (Z3), Lean 4 proofs, and Wasmtime JIT

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages