Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Unsprawl /ʌn-sprɔːl/ (verb): The act of applying computational intelligence to chaotic systems to maximize flow and minimize entropy.

License

Notifications You must be signed in to change notification settings

unsprawl/unsprawl

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unsprawl
Autonomous. Discerning. Virtuous.

Gemini 3 OWL-RL + Z3 LiveKit Voice License

Autonomous critical-thinking platform that extracts entities, reasons over knowledge graphs, and generates intervention strategies — all driven by Gemini 3.

Unsprawl ships 8 missions spanning legal defense, child safety, immigration, and civil rights. Each mission is a self-contained manifest: JSON Schema entities, OWL-RL ontology rules, Z3 constraints, and data source definitions. No code changes required to add a new domain — just a new manifest.json.

Built for the Gemini 3 Hackathon.


How It Works

A single unsprawl wow command runs the full autonomous pipeline end-to-end:

Phase 1  Entity Extraction ──── Gemini function_calling + JIT tool generation
    │
Phase 2  Reasoning ───────────── OWL-RL closure → SPARQL rules → Z3 constraint solving
    │
Phase 3  Deep Research ───────── Google Search grounding + thought signature continuity
    │
Phase 4  Strategy ────────────── Structured JSON generation with response_schema
    │
Phase 5  Pattern Detection ───── Cross-case SPARQL joins detect shared adversaries
    │
Sweep    Mission Sweep ───────── Runs extraction across 3 additional missions
    │
Summary  Gemini Integration ──── Token breakdown, features used, thought chains carried

Every Gemini API call prints a [GEMINI] label with the feature used, tokens consumed, and thinking level — making integration depth visible in the demo video.


Gemini 3 Integration

Unsprawl uses 6 distinct Gemini 3 capabilities across the pipeline, not just chat completion:

Capability Where Used Purpose
Function Calling Phase 1 Entity extraction with JIT-generated tool schemas from manifests
Google Search Grounding Phase 3 Live legal research with citations
Structured JSON (response_schema) Phase 4 Type-safe strategy generation via Pydantic → JSON Schema
ThinkingConfig All phases Per-phase thinking levels: LOW (extraction), MEDIUM (research), HIGH (strategy)
Thought Signatures Phase 1→3→4→5 Cross-phase reasoning chains via prior_thought_parts
System Instructions All phases Mission-specific persona per manifest

Gemini-as-Judge gates local model training: the TrainerActor samples 20 training pairs, sends them to Gemini for quality scoring, and rejects batches below 70% approval before QLoRA fine-tuning proceeds.


Architecture

Four engine actors communicate exclusively through NATS JetStream — no direct imports between engines:

flowchart TB
    subgraph bus["NATS JetStream — mission.{id}.{engine}.*"]
        direction LR
        B[Control Bus]
    end

    MC[Mission Control] -->|Genesis Charter| B

    B --> R["Refinery
    Entity extraction
    ProvenanceGuard
    Hippocampus"]

    B --> S["Sentinel
    Fact validation
    Safety vetoes"]

    B --> SO["Solver
    Intervention plans
    Wrangler artifacts"]

    B --> O["Orchestrator
    Session state
    Tick loop"]

    B --> T["Trainer
    Gemini-as-Judge
    QLoRA fine-tuning"]

    R -->|ExtractResult| B
    S -->|ValidateResult| B
    SO -->|InterventionPlanResult| B
    O -->|SessionStateUpdate| B
    T -->|AdapterUpdate| B
Loading

Pipeline Flow

sequenceDiagram
    participant MC as Mission Control
    participant R as Refinery
    participant PG as ProvenanceGuard
    participant S as Sentinel
    participant SO as Solver
    participant W as Wrangler
    participant T as Trainer

    MC->>R: ExtractCommand (Genesis Charter)
    R->>R: Gemini function_calling → entities
    R->>PG: filter_ingest (credibility gate)
    PG-->>R: Enriched facts (score, tier, reason)
    R->>S: ExtractResult
    S->>S: Validate facts + safety checks
    S-->>T: Vetoed facts (negative DPO signal)
    S->>SO: ValidateResult (approved facts)
    SO->>SO: OWL-RL → SPARQL → Z3 → strategy
    SO->>W: Generate artifacts (PDFs, code)
    W->>W: Gemini codegen → sandbox → self-heal
    SO->>MC: InterventionPlanResult
    T->>T: Gemini-as-Judge → QLoRA → hot-swap adapter
Loading

Neurosymbolic Reasoning Engine

The reasoning layer combines three formal systems — none of this is prompt engineering:

OWL-RL Inferencerdflib + owlrl compute the deductive closure over extracted entities. Inverse properties (belongsToCase), transitive relations, and class hierarchies are inferred automatically from the manifest ontology.

SPARQL Rules — Manifest-defined queries run against the closed knowledge graph. Example from Aegis:

SELECT ?case ?adversary WHERE {
  ?case1 :hasAdversary ?adversary .
  ?case2 :hasAdversary ?adversary .
  FILTER(?case1 != ?case2)
}

This detects when two unrelated tenants face the same landlord — a pattern invisible to keyword search.

Z3 Constraints — SMT formulas from strategy_constraints block gate which strategies are valid. Example: DEFEND only if arrears_amount < 25000. The solver proves satisfiability, not just checks conditions.


The 8 Missions

Each mission is a complete domain defined by a single manifest.json — entities, ontology, rules, constraints, data sources, and safety vetoes:

Mission Domain What It Does
Aegis Legal Defense Tenant eviction defense. Validates notice periods against CA Civil Code 1941-1942.5, detects retaliatory evictions within 180 days
Amber Child Safety Missing child response. Geo-fenced tip lines, probability maps from phone pings + transit schedules. Vetoes public broadcasts (predator risk)
Chronicle Language Preservation Endangered language recording with tremor compensation. Detects unique phonemes, blocks unprotected uploads (AI scraping risk)
Compass Foster Youth Youth aging out of foster care. First-night survival logic: shelter → ID → bank account. Chafee Act compliance
Nightshift Education & Family Law School suspension appeals. Detects 3rd-suspension → CPS → license review cascade. Vetoes DV disclosure in discoverable venues
Sanctuary Immigration DACA renewal errors and clerical corrections. Vetoes direct USCIS calls (self-incrimination on recorded lines). Cites APA 555(e)
Shield ICE Raid Response Real-time encounter guidance. Classifies warrant types: administrative (I-200, no entry authority) vs judicial (forced entry). 95% of ops use administrative warrants
Watchlist Gang Database Defense False CalGang/GangNet entries. Vetoes police contact (creates corroborating entries). 42% of CalGang entries lack documentation

Adding a new mission requires zero code changes — create missions/{name}/manifest.json with your entities, rules, and constraints.


ProvenanceGuard — Memory Firewall

Every fact entering the knowledge graph passes through ProvenanceGuard, a credibility gate that prevents hallucinated or adversarial data from contaminating reasoning:

  • Static domain classification — reuters.com (Tier 5: Verified), reddit.com (Tier 3: 2x corroboration), theonion.com (Tier 0: Satire)
  • LLM fallback — Unknown domains classified by Gemini for tone/credibility
  • Dispute-driven learning — Downstream engines call dispute(domain, penalty) when facts fail validation; penalties accumulate with 30-day half-life decay
  • Hard gate — Facts scoring below 0.5 are rejected and warnings published to sys.warn.provenance

No external code can inject data that bypasses this filter. The extension model is manifests, not plugins.


Wrangler — Self-Healing Artifact Generator

The Wrangler takes high-level plans and autonomously generates working artifacts (PDFs, infographics, data adapters):

  1. Gemini codegen — Generates complete Python scripts from plan descriptions
  2. Sandboxed execution — Runs in subprocess with 60s timeout, AST-based security scanning
  3. Metacognition loop — On failure, feeds the traceback back to Gemini for self-repair (up to 3 retries with adaptive temperature 0.2 → 0.8)
  4. Smart AST fixes — Targeted repairs (e.g., deprecated API patterns) before full regeneration
  5. Code cache — SHA256 content-hash deduplication avoids regenerating identical plans

Security guardrails block os.system, subprocess.Popen, exec(), eval(), and __import__ at both regex and AST levels.


Voice Pipeline

Real-time voice interface built on LiveKit + Gemini Live:

Browser/Mic → LiveKit Room → Gemini Live (STT/TTS) → NATS Bus → Engine Actors
                                                                       ↓
                                                        Response → TTS → Speaker
  • Speaker verification — SpeechBrain X-vector embeddings, enrollment in 14 languages
  • Emotion tracking — Audio-based emotion detection for adaptive responses
  • Turn prediction — Voice Activity Projection (VAP) model for interruption-free conversation
  • Conversation naturalness — Backchannel generation ("mm-hmm"), disfluency injection, adaptive timing
  • Avatar support — FaceFormer (CPU) → blend shapes → TalkingHead (browser WebGL, zero GPU required)

Tech Stack

Layer Technology
AI Gemini 3 via google-genai SDK — function calling, search grounding, structured output, thinking, thought signatures
Reasoning rdflib + owlrl (OWL-RL), z3-solver (SMT constraints)
Messaging NATS JetStream (control bus between engine actors)
Framework FastStream (engine actors), FastAPI (HTTP + WebSocket API)
Voice LiveKit Agents + livekit-plugins-google (Gemini Live), Silero VAD, SpeechBrain
Compute NVIDIA CUDA 12.6 (GPU inference), Ollama (local LLM)
Storage PostgreSQL (core DB), DuckDB (Armory artifact store), LanceDB (vector embeddings), SQLite (thought signatures)
Frontend React + Kedro-Viz (pipeline visualization), xterm.js (browser console)
Observability OpenTelemetry + Logfire (traces every Gemini call, engine message, and pipeline phase)
Deployment Docker Compose — 13 services including self-hosted LiveKit, NATS, PostgreSQL, Ollama, OTel Collector, Caddy, Timeplus Proton

Project Structure

unsprawl/
├── cli.py                          # CLI commands including `wow` pipeline
├── api.py                          # FastAPI app, WebSocket endpoints, tick loop
├── core/
│   ├── factory.py                  # EntityFactory — JIT tool generation from manifests
│   ├── deep_research.py            # Gemini Deep Research API integration
│   ├── rate_limiter.py             # gated_generate — chokepoint for all Gemini calls
│   ├── observability.py            # OpenTelemetry + Logfire instrumentation
│   └── messages.py                 # Pydantic message schemas (control bus)
├── engines/
│   ├── refinery/
│   │   ├── actor.py                # Entity extraction, collection, local LLM
│   │   ├── provenance.py           # ProvenanceGuard (memory firewall)
│   │   └── hippocampus.py          # In-memory fact store
│   ├── sentinel/
│   │   └── actor.py                # Fact validation, safety vetoes
│   ├── solver/
│   │   ├── actor.py                # OWL-RL + SPARQL + Z3 → intervention plans
│   │   ├── wrangler.py             # Self-healing artifact generator
│   │   └── armory.py               # DuckDB artifact storage
│   ├── trainer/
│   │   └── actor.py                # Gemini-as-Judge, QLoRA fine-tuning, DPO
│   └── orchestrator/
│       ├── actor.py                # Session state management
│       └── mission_control.py      # Mission loading, genesis event
├── missions/
│   ├── aegis/manifest.json         # Legal Defense
│   ├── amber/manifest.json         # Child Safety
│   ├── chronicle/manifest.json     # Language Preservation
│   ├── compass/manifest.json       # Foster Youth
│   ├── nightshift/manifest.json    # Education & Family Law
│   ├── sanctuary/manifest.json     # Immigration Defense
│   ├── shield/manifest.json        # ICE Raid Response
│   ├── watchlist/manifest.json     # Gang Database Defense
│   └── wow_fixtures.py             # Demo fixture data per mission
├── voice/
│   ├── pipeline.py                 # LiveKit + Gemini Live voice agent
│   └── speaker_verify.py           # SpeechBrain X-vector enrollment
├── data_sources/
│   ├── adapters/                   # REST, GraphQL, scraper, static adapters
│   └── registry.py                 # Adapter registration and discovery
└── simulation/
    └── advect.py                   # NVIDIA Warp differentiable physics

web/                                # React frontend (Kedro-Viz + xterm.js console)

Deployment

Prerequisites

  • Docker with NVIDIA Container Toolkit (GPU access)
  • A Gemini API key (GEMINI_API_KEY)
  • Python 3.12+ and uv

Deploy with unsprawl deploy

The deploy command handles everything: preflight checks, config generation, Docker orchestration, and optional Cloudflare Tunnel setup.

# 1. Clone and install
git clone https://github.com/unsprawl/unsprawl.git
cd unsprawl
uv pip install -e ".[engine]"

# 2. Set your API key
cp .env.example .env
# Edit .env — set GEMINI_API_KEY (required), LOGFIRE_API_KEY (optional)

# 3. Deploy locally
unsprawl deploy localhost --no-tunnel

# Or deploy to a public domain with Cloudflare Tunnel
unsprawl deploy unsprawl.io --install

# Or deploy without GPU
unsprawl deploy myapp.dev --no-tunnel --cpu

unsprawl deploy will:

  1. Run preflight checks (Docker, GPU/CUDA, cloudflared)
  2. Auto-install missing prerequisites when --install is passed
  3. Generate .env, Caddyfile, livekit.yaml, and cloudflared.yml from the domain
  4. Generate a CPU-only compose override if no GPU is detected (or --cpu)
  5. Provision LiveKit TLS certs and install renewal cron (remote deploys)
  6. Start all 13 Docker services via docker compose up

Services

Service Port Purpose
api 8000 FastAPI server + CLI (GPU)
frontend Vite build (served by Caddy)
caddy 80 Reverse proxy, TLS, SPA serving
livekit 7880 Self-hosted WebRTC server
voice-agent LiveKit Python agent (Gemini Live)
nats 4222 Event bus (JetStream)
db 5432 PostgreSQL
ollama 11434 Local LLM inference (GPU)
proton 3218 Streaming SQL engine
otel-collector 4317 OpenTelemetry collector
kedro-viz 8888 Pipeline DAG visualization
docs Sphinx docs (served by Caddy at /docs)

Voice UI is opt-in: docker compose --profile voice-ui up

Manual Docker (without unsprawl deploy)

cp .env.example .env
# Edit .env — set GEMINI_API_KEY
docker compose up --build

Local-Only (no Docker)

uv pip install -e ".[engine]"
export GEMINI_API_KEY=your-key-here
unsprawl wow --mission aegis

For voice: uv pip install -e ".[voice]" and a running LiveKit + NATS instance.


Running the Demo

CLI Demo (unsprawl wow)

The primary demo path — runs the full autonomous pipeline in your terminal:

# Inside the API container (recommended)
docker exec -it unsprawl-api-1 python -m unsprawl.cli wow aegis

# Or locally if installed
unsprawl wow --mission aegis

This runs all 7 phases end-to-end: entity extraction, OWL-RL reasoning, deep research, strategy generation, pattern detection, mission sweep, and Gemini integration summary. Every Gemini API call prints a [GEMINI] label with the feature used and tokens consumed.

Other missions

# Any of the 8 missions
unsprawl wow --mission amber      # Missing child response
unsprawl wow --mission sanctuary  # Immigration defense
unsprawl wow --mission shield     # ICE raid response
unsprawl wow --mission compass    # Foster youth
unsprawl wow --mission chronicle  # Language preservation
unsprawl wow --mission nightshift # Education & family law
unsprawl wow --mission watchlist  # Gang database defense

Voice Demo

# Start the voice agent (inside Docker)
docker compose --profile voice-ui up

# Open the voice frontend
# https://unsprawl.io/voice (production) or http://localhost:3001 (local)

Speak naturally — the agent uses Gemini Live for real-time speech-to-speech, with speaker verification, emotion tracking, and document OCR via the camera feed.

Web Dashboard

Navigate to http://localhost (or https://unsprawl.io in production). The dashboard shows the knowledge graph, pipeline DAG, dataset grid, and live WebSocket streaming from the API.


Built for the Gemini 3 Hackathon. All AI powered by Gemini 3.

About

Unsprawl /ʌn-sprɔːl/ (verb): The act of applying computational intelligence to chaotic systems to maximize flow and minimize entropy.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.