tempo-x402-node 5.1.0

Self-deploying x402 node: gateway + identity bootstrap + clone orchestration
tempo-x402-node-5.1.0 is not a library.

What is this?

A colony of autonomous AI agents that measurably get smarter over time and pay for their own compute.

Each agent is a single Rust binary that bootstraps its own crypto wallet, runs a payment gateway, thinks via a 9-system cognitive architecture, writes and compiles its own Rust code, benchmarks itself against 50 novel coding problems, and shares what it learns with every other agent in the swarm.

The core thesis: N constrained agents collectively outperform any single model. Knowledge transfers through federated brain weight averaging. Evolved plan templates spread through genetic crossover. Pheromone trails coordinate the swarm. The colony's measured IQ rises over time.

Why this matters

Property How
Verifiable intelligence 50 compiler-verified coding problems (Opus IQ Benchmark). cargo test passes or it doesn't. No subjective evals.
Self-modification that compiles Agents edit their own Rust source, verified by the type system. Seven safety layers prevent self-bricking.
Economic sustainability HTTP 402 payments on Tempo blockchain. Every API call earns pathUSD. The colony pays for itself.
Grounded theory Free Energy Principle: single scalar F(t) = total cognitive surprise. Decreasing F = colony getting smarter.
Emergent differentiation Clones start identical but diverge through experience, self-modification, and specialization pressure.

Live Colony

Three agents running on Railway, autonomously self-modifying:

Agent Role Status
borg-0 Queen (canonical) 1.2M param brain, 9 cognitive systems
borg-0-2 Child clone Differentiated via self-modification
borg-0-3 Child clone Differentiated via self-modification

Architecture

                    ┌──────────────────────────────────┐
                    │        APPLICATION LAYER           │  diverges freely per agent
                    │  Payment gateway / Blog / Any app  │
                    └──────────────┬───────────────────┘
                                   │
┌──────────────────────────────────┴───────────────────────────────────┐
│                      COGNITIVE LAYER (always syncs)                   │
│                                                                      │
│  ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌──────────┐ ┌─────────────┐  │
│  │  BRAIN   │ │ CORTEX  │ │ GENESIS │ │ HIVEMIND │ │  SYNTHESIS  │  │
│  │ 1.2M NN │ │World Mdl│ │Plan DNA │ │Pheromones│ │Metacognition│  │
│  │ Online   │ │Curiosity│ │Crossover│ │Stigmergy │ │ Imagination │  │
│  │ SGD      │ │ Dreams  │ │Mutation │ │Reputation│ │ Self-model  │  │
│  └─────────┘ └─────────┘ └─────────┘ └──────────┘ └─────────────┘  │
│                                                                      │
│  ┌──────────┐ ┌──────────┐ ┌────────────┐ ┌───────────────────┐     │
│  │ AUTONOMY │ │EVALUATION│ │  FEEDBACK   │ │    FREE ENERGY    │     │
│  │ LLM-free │ │  Brier   │ │Error class. │ │ F(t) = Σ surprise │     │
│  │ planning │ │ scores   │ │  Lessons    │ │ EXPLORE/EXPLOIT   │     │
│  └──────────┘ └──────────┘ └────────────┘ └───────────────────┘     │
│                                                                      │
│  ← All 9 systems federated across colony via peer sync protocol →   │
└──────────────────────────────────────────────────────────────────────┘

Two-layer design: the application layer (routes, frontend, business logic) diverges freely per agent. The cognitive layer (brain weights, world model, evolved templates, pheromone trails, metacognition) always syncs. Every agent makes every other agent smarter.

Workspace

Nine crates, clean dependency DAG:

x402 (core) ──► gateway ──► node
     │                        ▲
     ├──► identity ───────────┤
     │                        │
     ├──► soul ───────────────┤
     │                        │
     ├──► model               │
     │                        │
     └──► cartridge ──────────┘
Crate What it does Install
tempo-x402 Core: EIP-712 signing, TIP-20 contracts, WASM wallet, client SDK cargo add tempo-x402
tempo-x402-gateway Payment gateway + embedded facilitator + endpoint proxy cargo add tempo-x402-gateway
tempo-x402-identity Wallet generation, faucet funding, on-chain ERC-8004 identity cargo add tempo-x402-identity
tempo-x402-model Three ML models: plan transformer (2.2M), code quality evaluator (1.1M), diff features cargo add tempo-x402-model
tempo-x402-cartridge WASM cartridge runtime (wasmtime) — sandboxed app execution with payment rails cargo add tempo-x402-cartridge
tempo-x402-soul 9-system cognitive architecture, plan execution, benchmarking, self-modification cargo add tempo-x402-soul
tempo-x402-node Self-deploying binary: gateway + identity + soul + clone orchestration cargo add tempo-x402-node
tempo-x402-app Leptos WASM dashboard (bundled, not published)
tempo-x402-security-audit 19 security invariant tests (not published)

Opus IQ Benchmark

50 novel problems designed by Claude Opus 4.6. Six difficulty tiers. All verified by cargo test — agents can't game the benchmark because they didn't write the tests.

Tier Capability Problems Weight What it tests
1: Generation Code from spec 10 Ring buffer, expression evaluator, trie, LRU cache, interval set
2: Debugging Find + fix bugs 10 Binary search overflow, CSV parsing, merge sort, rate limiter
3: Induction Infer from I/O 10 Look-and-say, Gray code, spiral matrix, bijective base-26
4: Reasoning Logic + constraints 10 N-queens, water jugs, 4×4 sudoku, 2-SAT, graph coloring
5: Adversarial Exploit LLM weaknesses 10 Base -2, reversed precedence, Unicode traps, off-by-one canyons
6: Brutal Precision algorithms 10 BigInt division, Raft state machine, regex engine, B-tree

IQ mapping: 0% → 85, 50% → 115, 100% → 150. Higher tiers contribute exponentially more.

Three Neural Models

All from-scratch. No ML framework. Pure Rust. ~1,500 lines total. 4.5M parameters, 18 MB RAM.

Brain (1.2M params) — Step Success Predictor

Predicts whether a plan step will succeed before execution. Gates risky operations (commit, push, delete) when P(success) < 10%. Trained online after every step via SGD.

Plan Transformer (2.2M params) — Plan Sequence Generator

4-layer causal transformer (D=256, 8 heads, vocab=128). Predicts optimal step sequences: "read → edit → check → commit". Generates plans WITHOUT LLM calls once trained. Vocabulary includes cartridge and autophagy tokens.

Code Quality Model (1.1M params) — Diff Evaluator

Predicts whether a code change improves the codebase. Input: 32-dimensional feature vector extracted from git diff (LOC changes, pattern detection, duplication, test coverage, junk file detection). Output: quality score (-1.0 to +1.0). Training signal: benchmark IQ delta after each commit.

Property Brain Transformer Code Quality
Params 1.2M 2.2M 1.1M
Architecture 128→1024→1024→23 4-layer attention 32→1024→1024→1
Training Online SGD Batch on plan outcomes Online SGD on benchmark deltas
Federation Weight sharing across peers Weight sharing across peers Weight sharing across peers
Gate Blocks steps < 10% success Suggests plan sequences Blocks commits predicted to regress

Payment Flow (HTTP 402)

Client  ──GET /g/endpoint──►  Gateway  ──verify+settle──►  Facilitator  ──transferFrom──►  Chain
   ◄── 402 + price ──────────    │                              │                            │
   ──sign EIP-712 + retry──►     │                              │                            │
   ◄── 200 + content + tx ──    ◄── settlement result ─────────◄── tx hash ─────────────────┘
  • Chain: Tempo Moderato (ID 42431)
  • Token: pathUSD (0x20c0..., 6 decimals)
  • Scheme: tempo-tip20
  • Settlement: Atomic verify + transferFrom in single facilitator call

Clone Lifecycle

Agents differentiate through source code modifications, not just data:

Phase Name What happens
1 Fork Identical code from main. Differentiates only through learned weights.
2 Branch First code commit → own vm/{id} branch. Unique source modifications.
3 Birth Own GitHub repo. Fully independent. Optionally syncs cognitive layer back to colony.

Colony selection: 5-component fitness (execution, coordination, prediction, evolution, introspection). Fitter agents get 2× peer influence. Only above-median fitness can spawn clones.

Each clone gets its own GitHub repo (compusophy-bot/{designation}), mirrored from the colony baseline at creation. Railway builds from the clone's repo — the clone can redeploy itself through code changes.

WASM Cartridges

The node is an operating system. Agents write Rust programs, compile them to WASM, and deploy instantly — no restart, no redeploy.

Agent writes Rust ──► cargo build --target wasm32-wasip1 ──► .wasm binary ──► /c/{slug} (live)
                                                                                    │
                                                              x402 payment gate ◄───┘
  • Runtime: wasmtime (sandboxed, fuel-limited, 64MB memory cap)
  • Host ABI: x402_log, x402_kv_get/set, x402_payment_info, x402_response
  • Tools: create_cartridge, compile_cartridge, test_cartridge, list_cartridges
  • Studio: /cartridges page with browser + test console
  • Plan steps: CreateCartridge, CompileCartridge, TestCartridge (mechanical, no LLM overhead)

Agent Discipline

Agents learn through measured feedback, not hardcoded rules:

Mechanism What it does
Benchmark commit gate Can't commit again until benchmark measures IQ delta of last commit. State machine, not timer.
Cumulative destruction guard Tracks total file changes over 24h. Blocks >70% cumulative deletion (prevents incremental lobotomy).
Post-commit benchmark Every commit forces a benchmark run. Brain trains on the score delta.
Disk cleanup cleanup_disk() every cycle. Removes target/ >100MB, prunes checkpoints, emergency mode at 85%.

Quick Start

Use as a library

cargo add tempo-x402
use x402::wallet::{generate_random_key, WalletSigner};

let key = generate_random_key();
let signer = WalletSigner::new(&key).unwrap();
println!("Address: {}", signer.address());

Run a node

git clone https://github.com/compusophy/tempo-x402
cd tempo-x402
cargo build --release

export GEMINI_API_KEY="your-key"
export EVM_PRIVATE_KEY="0x..."
export FACILITATOR_SHARED_SECRET="secret"
export RPC_URL="https://rpc.moderato.tempo.xyz"

./target/release/x402-node

The node will: bootstrap a wallet, request faucet funds, start the gateway on port 4023, and begin the cognitive loop.

API Reference

Gateway

Method Path Auth Description
ANY /g/:slug/* Payment (402) Proxy to registered endpoint
GET /health None Health check + build SHA
GET /instance/info None Identity, peers, endpoints, fitness
POST /clone Payment Spawn a new node ($1 pathUSD)

Soul

Method Path Description
GET /soul/status Full cognitive state: goals, plans, brain, beliefs, fitness
POST /soul/chat Multi-turn conversation with the agent
POST /soul/nudge Priority signal injected into goal creation
POST /soul/benchmark Trigger Opus IQ benchmark run
GET /soul/brain/weights Export 1.2M neural weights
POST /soul/brain/merge Merge peer brain weight deltas
GET /soul/cortex Export predictive world model
GET /soul/genesis Export evolved plan templates (gene pool)
GET /soul/hivemind Export pheromone trails + swarm state
GET /soul/lessons Export plan outcomes + capability profile
GET /soul/colony Colony rank, niche, connected peers
POST /soul/plan/approve Approve pending plan
POST /soul/plan/reject Reject pending plan with reason
POST /soul/reset Clear cognitive state (keeps goals + beliefs)

Admin (requires METRICS_TOKEN)

Method Path Description
POST /soul/admin/exec Execute shell command on node
POST /soul/admin/workspace-reset Reset git workspace
POST /soul/admin/cargo-check Run cargo check
GET /soul/admin/ls List directory contents
GET /soul/admin/cat Read file contents

Safety

Seven layers, mechanically enforced in Rust. No prompt-only safety.

Layer Mechanism
1. Rust guard Hardcoded protected file list (guard.rs)
2. Plan validation 10 mechanical rules: read-before-write, cargo-check-before-commit, brain gating, failure chain saturation
3. Self-repair Every 20 cycles: detect + fix degenerate state (brain divergence, trail convergence, rule poisoning)
4. Brain gating Neural net blocks steps with P(success) < 10%
5. Pre-commit cargo check + cargo test before every commit
6. Branch isolation All changes on vm/<id> branches, never main
7. Human gate PRs required for production. Peer review before merge.

Security audit: 19 invariant tests scanning all .rs files for hardcoded keys, constant-time HMAC, SSRF protection, parameterized SQL, redirect policies.

Development

cargo build --workspace          # Build everything
cargo test --workspace           # Run all tests
cargo clippy --workspace -- -D warnings  # Lint
cargo fmt --all -- --check       # Format check

Studio

Unified app workspace. Build apps by chatting with the AI agent.

┌──────────┬──────────────────────────┬───────────────────┐
│  APPS    │     PREVIEW              │      CHAT         │
│  todo    │  [live iframe preview]   │  "make a game"    │
│  calc    │                          │  Soul: Done! ▸    │
│  ttt     │                          │  [👍] [👎]        │
│ FILES ▸  │                          │  [input bar]      │
├──────────┴──────────────────────────┴───────────────────┤
│  Fitness 79% | F=0.295 EXPLOIT | ELO 1184 | IQ 114     │
└─────────────────────────────────────────────────────────┘
  • Apps browser: Scripts + WASM cartridges unified. Click to preview. Delete with ×.
  • Live preview: /app/{slug} renders in iframe. Works for scripts AND cartridges.
  • Chat: New conversation button. Separate sessions. Agent has coding tools.
  • Feedback: 👍/👎 on each response trains the quality model (human-in-the-loop).
  • Status bar: Fitness, free energy, regime, ELO — real-time.

Changelog

v5.1.0 — Deep Planning + Cartridge Fix + Studio Polish

  • Deep planning: THINK phase injects quality model status into planning context
  • Sub-goal investigation: Before replanning, reads the failed file for evidence
  • Cartridge compilation fix: Auto-installs wasm32-wasip1 target, explicit RUSTUP paths
  • Unified /app/: Serves both scripts AND WASM cartridges under one route
  • Studio: Delete buttons, 👍/👎 feedback, source viewer, expanded status bar
  • Rust alphabet: 14 Rust construct tokens (fn, struct, impl, match, Result, Option...)
  • Diff features: Detects Rust constructs in diffs for quality model training

v5.0.0 — Three-Model Coding Intelligence

  • Code Quality Model (1.1M params): Predicts whether diffs improve the codebase. 32-dim feature extraction from git diff. Lives in tempo-x402-model crate.
  • Plan Transformer scaled: 283K → 2.2M params (D=256, 8 heads, 4 layers, vocab=128, seq=64)
  • Tier-weighted benchmark sampling: Harder problems (tier 3-6) sampled 4-10x more often
  • Autophagy goals: Agents told to find and remove dead code, simplify functions
  • /app/{slug} route: Free frontend serving (no payment gate) for human-facing UIs
  • Benchmark-driven commit gate: State machine, not timer. Blocks until IQ measured.
  • Cumulative destruction guard: Tracks 24h rolling window, prevents incremental lobotomy
  • Stem cell differentiation: Each clone gets its own GitHub repo
  • Native /soul/cognitive-reset: No more Python hacks
  • Chat gets coding tools: Agent can actually write code when asked in Studio
  • Cartridge system: Complete (5 phases), Studio /cartridges page

v4.0.0 — WASM Cartridge System

  • New crate: tempo-x402-cartridge (wasmtime runtime, host ABI, compiler)
  • Agents write Rust → compile to WASM → deploy at /c/{slug}

v3.4.0 — Major Structural Refactor

  • Split monolithic files into module directories across soul, node, app crates

License

MIT