Skip to main content

Autonomous Distributed Computing Operating System with Reinforcement Learning

Project description

MarlOS

Decentralized, self-organizing compute network powered by Multi-Agent Reinforcement Learning

CI


MarlOS is a peer-to-peer distributed computing OS where every node is autonomous, cryptographically authenticated, and makes its own bidding decisions using reinforcement learning — with no central orchestrator, no Kubernetes, no cloud controller.

When a job enters the network, nodes independently decide whether to Bid, Forward, or Defer. The winner is determined by a decentralized auction. Payment flows automatically via a token economy. Nodes that fail get replaced by backups. Nodes that misbehave get quarantined.

# Try it in 30 seconds
git clone https://github.com/ayush-jadaun/MarlOS.git && cd MarlOS
pip install -r requirements.txt
python scripts/demo.py

Features

Core System

  • RL-Driven Scheduling — PPO policy on 25D state vector (BID/FORWARD/DEFER)
  • Decentralized Auctions — Ed25519-signed bids, deterministic winner selection
  • Token Economy — MarlCredits with staking, progressive taxation, UBI
  • Trust & Reputation — 0.0-1.0 scores, automatic quarantine of bad actors
  • Self-Healing — Backup node takeover, heartbeat monitoring, checkpoint recovery
  • Predictive Pre-Execution — RL-powered speculation cache for near-zero latency

New in v1.1

  • REST API — HTTP endpoints for jobs, peers, wallet, trust, pipelines (docs)
  • MCP Server — Claude and AI agents can submit jobs via Model Context Protocol (docs)
  • Job Pipelines (DAGs) — Chain jobs with dependencies, output flows between steps (docs)
  • Result Aggregation — Submit batch jobs, get combined results (docs)
  • Plugin System — Drop a .py file in plugins/, restart, new runner available (docs)
  • File Transfer — P2P chunked transfer with SHA-256 integrity verification
  • Online Learning — Exploration decay, behavioral cloning from successful experiences
  • D3.js Network Visualization — Force-directed graph in the dashboard
  • JavaScript SDKnpm install marlos-sdk for Node.js/browser integration (docs)
  • Economic Whitepaper — Formal token model with simulation results (docs)

Proven by Simulation

Metric Fairness ON Fairness OFF
Gini Coefficient 0.549 0.822
Participation Rate 100% 27%
Adversarial Detection 100%
False Positive Rate 0%
Online Learning Win Rate +9.2pp improvement over 500 jobs

Charts: docs/charts/


Architecture

┌─────────────────────────────────────────────────────────────────┐
│                         MarlOS Node                              │
│                                                                  │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────────┐    │
│  │  P2P     │  │  RL      │  │ Bidding  │  │  Executor    │    │
│  │ ZMQ      │  │ PPO      │  │ Auction  │  │  Shell       │    │
│  │ Ed25519  │  │ 25D state│  │ Scorer   │  │  Docker      │    │
│  │ Gossip   │  │ Online   │  │ Router   │  │  Security    │    │
│  │ FileTx   │  │ Learning │  │          │  │  Plugins     │    │
│  └──────────┘  └──────────┘  └──────────┘  └──────────────┘    │
│                                                                  │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────────┐    │
│  │  Token   │  │  Trust   │  │Pipeline  │  │  Interfaces  │    │
│  │ Economy  │  │ Reputat. │  │ DAG      │  │  Dashboard   │    │
│  │ Wallet   │  │ Quarant. │  │ Aggreg.  │  │  REST API    │    │
│  │ Tax/UBI  │  │ Watchdog │  │ FileTx   │  │  MCP Server  │    │
│  └──────────┘  └──────────┘  └──────────┘  └──────────────┘    │
└─────────────────────────────────────────────────────────────────┘

Data Flow

Job Submitted → P2P Broadcast → All Nodes Receive
                                      │
                          ┌───────────┼───────────┐
                          ▼           ▼           ▼
                        BID        FORWARD      DEFER
                    (RL decides) (RL decides) (RL decides)
                          │
                          ▼
                 Decentralized Auction
                 Ed25519-signed bids
                          │
                          ▼
                 Winner Claims Job → Stakes tokens → Executes
                          │
                    ┌─────┴─────┐
                    ▼           ▼
                Success       Failure
                Pay winner   Slash stake
                +trust       Backup takes over

Quick Start

Demo (one command)

python scripts/demo.py --nodes 3 --jobs 2
# or
marl demo

This starts 3 nodes on localhost, submits jobs, shows the full auction lifecycle, token transfers, and trust updates.

Run a Node

# Single node
NODE_ID=my-node python -m agent.main

# With peers
NODE_ID=node-1 BOOTSTRAP_PEERS="tcp://192.168.1.100:5555" python -m agent.main

Submit Jobs

# Via CLI
marl execute "echo hello"

# Via REST API
curl -X POST http://localhost:3101/api/jobs \
  -H "Content-Type: application/json" \
  -d '{"job_type": "shell", "payload": {"command": "echo hello"}, "payment": 50}'

# Via JavaScript SDK
import { MarlOSClient } from 'marlos-sdk';
const client = new MarlOSClient('http://localhost:3101');
const result = await client.submitAndWait('shell', { command: 'echo hello' });

Submit a Pipeline (DAG)

curl -X POST http://localhost:3101/api/pipelines \
  -H "Content-Type: application/json" \
  -d '{
    "name": "security-scan",
    "steps": [
      {"id": "scan", "job_type": "port_scan", "payload": {"target": "10.0.0.0/24"}},
      {"id": "analyze", "job_type": "shell", "payload": {"command": "python analyze.py"}, "depends_on": ["scan"]}
    ]
  }'

AI Agent Integration (MCP)

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "marlos": {
      "command": "python",
      "args": ["-m", "agent.mcp.server"],
      "env": {"MARLOS_API_URL": "http://localhost:3101"}
    }
  }
}

Then Claude can: "Submit a port scan of 192.168.1.0/24 to MarlOS"


Network Modes

Private Mode (default)

Connect to specific peers. Good for labs, teams, home networks.

NODE_ID=node-1 BOOTSTRAP_PEERS="tcp://192.168.1.100:5555,tcp://192.168.1.101:5555" python -m agent.main

Public Mode

DHT-based global discovery. Anyone can join.

NODE_ID=node-1 NETWORK_MODE=public DHT_ENABLED=true \
  DHT_BOOTSTRAP="bootstrap1.example.com:5559" python -m agent.main

Sybil resistance: minimum stake (10 AC) and per-subnet peer limits.


Job Types

Type Runner Example
shell Shell commands {"command": "echo hello"}
docker Docker containers {"image": "python:3.11", "command": "python -c 'print(1)'"}
docker_build Container builds {"dockerfile": ".", "tag": "myapp"}
port_scan Network scanning {"target": "192.168.1.0/24"}
malware_scan File analysis {"file_path": "/tmp/suspicious.bin"}
hash_crack Hash cracking {"hash": "5f4dcc3b...", "algorithm": "md5"}
threat_intel Threat lookups {"indicator": "evil.com"}
Custom plugins Drop in plugins/ See Plugin Guide

Running Tests

# Unit tests (fast, ~30s)
python -m pytest test/ --ignore=test/integration -v

# API tests
python -m pytest test/api/ -v

# Pipeline/DAG tests
python -m pytest test/pipeline/ -v

# Plugin tests
python -m pytest test/plugins/ -v

# Integration tests (3-node real network, ~3 min)
python -m pytest test/integration/ -v

# Benchmark
python scripts/benchmark.py --nodes 3 --jobs 10

# Economic simulation (generates charts)
python scripts/economic_simulation.py

# Adversarial resistance demo
python scripts/adversarial_demo.py

236+ tests passing across unit, API, pipeline, plugin, economic, adversarial, and integration tests.


Configuration

Three layers (highest priority wins):

Layer Source Example
1 (lowest) Dataclass defaults pub_port=5555
2 YAML: ~/.marlos/nodes/{NODE_ID}/config.yaml Custom per-node
3 (highest) Environment variables PUB_PORT=6000

Key env vars: NODE_ID, PUB_PORT, SUB_PORT, DASHBOARD_PORT, NETWORK_MODE, BOOTSTRAP_PEERS, DHT_ENABLED, DHT_BOOTSTRAP

See docs/CONFIG_ARCHITECTURE.md for details.


Documentation

Getting Started

Deployment

API & Integration

Architecture

Configuration


Technology Stack

Layer Technology
Language Python 3.11+ (async/await)
P2P ZeroMQ PUB/SUB
Crypto Ed25519 (PyNaCl)
RL PyTorch + Stable-Baselines3 (PPO)
API aiohttp (REST) + MCP SDK
Execution Shell, Docker, custom plugins
Storage SQLite (wallet), JSON (ledger)
Dashboard React + D3.js + WebSockets
SDK JavaScript/TypeScript

Project Structure

agent/                 # Core agent
  p2p/                 # ZMQ networking, Ed25519, file transfer
  rl/                  # PPO policy, online learner, state calc
  bidding/             # Auction, scoring, routing
  executor/            # Job runners (shell, docker, security)
  tokens/              # Wallet, ledger, economy
  trust/               # Reputation, watchdog, quarantine
  pipeline/            # DAGs, aggregator
  plugins/             # Plugin loader
  api/                 # REST API server
  mcp/                 # MCP server for AI agents
  dashboard/           # WebSocket server
  predictive/          # Speculation cache
cli/                   # marl CLI
scripts/               # Demo, benchmark, simulations
plugins/               # Custom runner plugins
sdk/js/                # JavaScript SDK
dashboard/             # React + D3.js frontend
test/                  # 236+ tests
docs/                  # Documentation

Contributing

See CONTRIBUTING.md for guidelines, code style, and how to write a new runner.


Contributors

Team async_await


License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

marlos-1.1.1.tar.gz (430.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

marlos-1.1.1-py3-none-any.whl (334.4 kB view details)

Uploaded Python 3

File details

Details for the file marlos-1.1.1.tar.gz.

File metadata

  • Download URL: marlos-1.1.1.tar.gz
  • Upload date:
  • Size: 430.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for marlos-1.1.1.tar.gz
Algorithm Hash digest
SHA256 0703c4a0c8a498d13ad64a4c00f3f02680e24d7dee9ae2424a72bde128ef92bb
MD5 a474d8a337a5da0fc902633fd2ffbd03
BLAKE2b-256 dc2549428fdbef0230eb748016bc3ce26b37708de1825eecbff781511a0e148f

See more details on using hashes here.

File details

Details for the file marlos-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: marlos-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 334.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for marlos-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b830dc31e68a1ad42c05109c6a9d180a26fbfec5cfa25aaa571c4fca9f02d805
MD5 179176ae9e9c055a49cdd7db9ac3f37b
BLAKE2b-256 811f16693b9ffa7bb9615f2fa69ab258ed849c125ec916c203a7eb9b59ccabc2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page