Skip to main content

AISwarm logo

๐Ÿ AISwarm

Production-grade multi-agent AI orchestration system
A hierarchical pipeline that turns a natural-language task into merged, production-ready code โ€” automatically reviewed, compiled, tested, and benchmarked.

Python 3.11+ License: MIT Code style: ruff Zero-Trust Security 191 unit tests passed 176 stress tests passed 17 agents registered

Architecture โ€ข Critics โ€ข Safety โ€ข Tests โ€ข Stress Tests โ€ข Quick Start โ€ข API


Overview

AISwarm coordinates a team of specialized AI agents that behave like a real software engineering organization: a Boss who resolves conflicts, a Manager who plans, a Coder who writes, 8 Critics who review in parallel, and a Merge Controller that only lets code through 5 independent safety gates. Nothing reaches disk unless it compiles, passes its tests, meets its performance budget, and clears a security veto.

๐Ÿ— Architecture

AISwarm implements a strict 12-stage hierarchical pipeline. Every stage must pass before the next runs. Failures trigger retries with exponential back-off; exhausted retries escalate to the Boss agent for deadlock resolution.

USER TASK
  โ”‚
  โ–ผ
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘  BOSS    โ•‘  Validates task, resolves deadlocks, architectural decisions
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  โ”‚
  โ–ผ
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ MANAGER  โ•‘  Decomposes goals into subtasks, advises on folder structure
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  โ”‚
  โ–ผ
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ TASK PLANNER โ•‘  Creates implementation blueprint BEFORE code is written
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  โ”‚
  โ–ผ
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ CONTEXT SELECTOR โ•‘  RAG-powered file selection (max 15 files / 8000 tokens)
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  โ”‚
  โ–ผ
โ•”โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ CODER โ•‘  Generates production-grade code from blueprint + context
โ•šโ•โ•โ•โ•โ•โ•โ•โ•
  โ”‚
  โ–ผ
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ PRE-CHECKโ•‘  AST + regex static analysis (blocks critics if failed)
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  โ”‚
  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ–ผ          โ–ผ          โ–ผ          โ–ผ          โ–ผ          โ–ผ          โ–ผ          โ–ผ
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•—โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•—โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•—โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•—โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•—โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•—โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•—โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘Architectโ•‘Performanceโ•‘Securityโ•‘ Testingโ•‘Reliabilโ•‘Maintainโ•‘  Docs  โ•‘ Style  โ•‘
โ•‘        โ•‘โ•‘        โ•‘โ•‘  VETO  โ•‘โ•‘        โ•‘โ•‘  -ity  โ•‘โ•‘  -ity  โ•‘โ•‘        โ•‘โ•‘        โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•
                โ† All 8 Critics run in parallel โ†’
  โ”‚
  โ–ผ
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ COMPILER โ•‘  Python AST parse + import validation (or g++/rustc)
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  โ”‚
  โ–ผ
โ•”โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ TESTS โ•‘  pytest discovery and execution
โ•šโ•โ•โ•โ•โ•โ•โ•โ•
  โ”‚
  โ–ผ
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ BENCHMARK โ•‘  pytest-benchmark performance measurement
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  โ”‚
  โ–ผ
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ MERGE CONTROLLER โ•‘  5-gate guard: hash ยท critics ยท compile ยท tests ยท benchmark
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  โ”‚
  โ–ผ
โœ… MERGED (atomic file write)

Pipeline Stages & States

Stage State Description
Submitted NEW Task entered the system
Boss reviewed PROMPTED Blueprint approved by Boss
Code generated GENERATED Coder produced first/revised code
Static analysis PRECHECKED AST + regex scan passed
Critics REVIEWED โ‰ฅ2/3 critics approved (security veto respected)
Compiled COMPILED Code passed compilation
Tested TESTED All unit tests passed
Benchmarked BENCHMARKED Performance within tolerance
Done MERGED 5-gate merge guard passed, files written
Terminal REJECTED / DEADLOCK / CANCELLED Terminal failure states

๐Ÿง  The 8 Critic Agents

All critics run in parallel after PreCheck. The Security critic has unconditional veto power.

Critic Focus Veto Power
Architecture SOLID, DRY, coupling, separation of concerns No
Performance O(n) complexity, memory usage, concurrency bottlenecks No
Security OWASP Top 10, injection, secrets, CVEs YES
Testing Test coverage, isolation, mocking, assertions, determinism No
Reliability Error handling, retries, timeouts, resource cleanup, idempotency No
Maintainability Naming, function length, cyclomatic complexity, dead code No
Documentation Module/class/function docstrings, type hints, examples No
Style PEP 8, import ordering, naming conventions, formatting No

Each critic outputs a structured JSON decision (APPROVE / REJECT / ESCALATE) with a score (0โ€“100), optional fatal_flaw, and mandatory_fix.


๐Ÿ›ก Production Safety

Cost Guard

Circuit breaker that halts all LLM calls when budget limits are hit:

  • Daily limit (default: $100/day) โ€” tracked in Redis across processes
  • Session limit (default: $10/session) โ€” per-process accumulator
  • Token limit (default: 10M tokens/session)
  • Alert at 80% of any limit before hard stop
  • Per-provider spend breakdown available at GET /cost/status

Rate Limiter

Per-provider token-bucket rate limiting:

  • Configurable RPM and concurrent request caps per provider
  • Automatic backoff on HTTP 429 responses
  • Transparent to calling agents โ€” async with limiter.acquire("provider"):

Redis Task Store

  • Tasks persisted to Redis on every state transition
  • In-memory fallback when Redis is unavailable
  • Cross-process task visibility (horizontal scaling)
  • 7-day TTL on terminal tasks

๐Ÿ“Š Operator Dashboard

The operator dashboard is served at GET / (port 5000) and provides:

  • Live task table โ€” state badges, retry counts, cost per task
  • Budget meter โ€” real-time daily spend vs limit
  • Force-merge button โ€” bypass all gates with mandatory reason (audit-logged)
  • Cancel & Retry โ€” cancel in-flight tasks or re-queue deadlocked ones
  • Auto-refreshes every 10 seconds

Force-merge requires a non-empty reason and is permanently recorded in the task audit trail. Use for break-glass situations only.


๐Ÿ”Œ LLM Providers

Provider Status Models Notes
Novita Supported llama-3.1-405b, llama-3.1-70b, llama-3.1-8b OpenAI-compatible adapter
OpenAI Supported gpt-4o, gpt-4o-mini Standard OpenAI API
Anthropic Supported claude-3-5-sonnet, claude-3-5-haiku Native Anthropic SDK
Gemini Supported gemini-2.0-flash, gemini-1.5-pro google-generativeai SDK
DeepSeek Supported deepseek-chat, deepseek-coder OpenAI-compatible
AWS Bedrock Optional claude-3-5, llama-3 boto3 in thread pool
Local Optional Any Ollama/LM Studio model localhost adapter

Provider routing: ordered fallback with per-provider failure tracking, rate limiting, and cost accounting. The router transparently falls back to the next provider on any error. Any provider above can be set as primary via environment variables โ€” none is hardcoded as default.


๐Ÿ”’ Security Architecture

  • Security Critic has unconditional veto power โ€” a single REJECT blocks merge regardless of other critic scores
  • 5-gate Merge Controller: code hash integrity โ†’ critic approval โ†’ compilation โ†’ test pass โ†’ benchmark pass
  • Static Code Scanner: pre-LLM OWASP pattern detection (eval, pickle, os.system, shell=True, hardcoded secrets, verify=False, etc.)
  • State Machine: explicit valid-transition table โ€” no silent state corruption possible
  • Deadlock Detection: background scanner with full attempt history for Boss escalation
  • Atomic writes: merge uses write-then-rename to prevent partial file corruption
  • Force-Merge Audit: every operator override permanently logged with reason, operator identity, and timestamp

โœ… Test Results

AISwarm ships with a large, deliberately granular unit test suite โ€” one behavior per test, no shared mutable state, deterministic, sub-100ms โ€” plus a live Docker / Sandbox integration suite.

๐Ÿ“‹ View the full per-test results (213 individual tests) โ†’ TEST_RESULTS.md

Unit Tests

191 passed, 3 skipped

Tested on Python 3.11.14, pytest 9.1.1 โ€” fully offline, no network required.

Module Tests Covers
test_code_scanner 8 OWASP pattern detection, AST scanning, severity classification
test_event_bus 5 Pub/sub, wildcard handlers, error isolation
test_merge_controller 10 5-gate guard + path traversal prevention
test_retry_engine 6 Exponential back-off, exhaustion, reset, history
test_state_machine 8 FSM transitions, terminals, history recording
test_task_schema 10 Task lifecycle, critic voting, security veto, serialization
test_cost_guard 7 Daily/session limits, Redis fallback, concurrent safety
test_rate_limiter 6 Token-bucket RPM, concurrency caps, 429 backoff
test_critics 16 All 8 critics โ€” approve/reject/parse, JSON resilience
test_force_merge 5 Break-glass bypass, audit trail, idempotency
test_rag_retriever 2 (3 skipped) RAG init, keyword fallback
test_hashing 11 SHA-256/xxhash content addressing, determinism
test_timing 8 Timer start/stop/elapsed, exception safety
test_scheduler 8 Priority ordering, FIFO tie-break, backpressure
test_events 10 Event immutability, UUID uniqueness, validation
test_python_compiler 8 Syntax errors, import errors, subprocess timeout
test_schemas_review 13 Critic review schemas, score bounds, defaults
test_schemas_metrics 10 Agent/pipeline/system telemetry schemas
test_schemas_benchmark 9 Benchmark suite/run schemas, defaults
test_working_memory 13 Ephemeral task memory store, isolation
test_failure_memory 9 Failure-pattern persistence, similarity matching
test_checkpoint 13 Atomic save/load, corrupted-file recovery

Result: 191 passed, 3 skipped, 0 failed โ€” the 3 skips are environment-only (an optional vector database dependency is unavailable in this sandbox) and are not counted as failures.

Docker / Sandbox Integration Tests

22 passed, 3 skipped

Verified live against the real Sandbox REST API v1 โ€” authentication, dataset search/listing/pagination, and kernel-push payload validation all confirmed working end-to-end. The 3 skips relate to one account-level prerequisite outside the codebase and are not code failures.

Test Class Tests What It Verifies
TestSandboxAuthentication 4 Credentials present, API reachable, auth header format
TestSandboxDatasets 9 List, search, sort, pagination, URL validity, ratings, user datasets
TestSandboxNotebook 3 Kernel push endpoint reachable, payload validation
TestAISwarmSandboxIntegration 4 Metadata parseable for RAG, latency, tag structure, concurrent calls
TestSandboxNotebookCreation 5 Notebook JSON (nbformat v4), AISwarm markers, payload schema, endpoint

๐Ÿ”ฅ Stress Test Results

AISwarm includes a 176-test production-grade stress suite (tests/stress/) written to the same standards used by engineering teams at high-scale technology companies. Every subsystem is hammered with concurrency, fault injection, resource exhaustion, and edge cases that only surface under real operating conditions.

176 stress tests passed asyncio real components

# Run the full stress suite (~90 seconds, no API keys required)
pytest tests/stress/ -v

Design Philosophy

The stress suite is modelled on battle-hardened test strategies used by engineering teams building distributed systems:

Principle How It's Applied
Real components, not mocks Core logic (CostGuard, StateMachine, RetryEngine, Scheduler, MergeController, DeadlockDetector) is tested against real implementations, not doubles
Concurrency as a first-class concern Every subsystem is hit with 50โ€“1000 simultaneous coroutines to expose races, contention, and ordering violations
Exhaustive state-space coverage The StateMachine test enumerates every single valid and invalid (from_state, to_state) pair โ€” no transitions are left untested
Fault injection at every layer Network failures, provider outages, Redis crashes, malformed responses, 429 floods, OOM errors, and budget exhaustion are all simulated
Boundary and off-by-one precision Limits are tested at exactly N, Nโˆ’1, and N+1 with round numbers that avoid floating-point accumulation drift
No timing-dependent assertions Tests use deterministic completion signals and event counts rather than sleep()-based timing assumptions
Isolation verification 100-task batches run in parallel and each task's state history is verified to contain only its own entries โ€” cross-contamination fails immediately

Stress Test Files

File Tests Subsystem Key Scenarios
test_cost_guard_stress.py 18 CostGuard circuit breaker 500 concurrent record() calls, exact boundary at session limit, token limit, 80% alert fires once, Redis failure mid-flight, Redis flapping, daily limit via mocked Redis, 5-provider simultaneous hammering
test_retry_engine_stress.py 22 RetryEngine + backoff 100 concurrent tasks succeed first try, 50 concurrent tasks each fail twice then recover, exponential delay grows 1โ†’2โ†’4โ†’8โ†’16s, jitter band [50%, 100%] of base, max-delay cap, zero-delay policy is fast, exhausted tasks are independent, on-failure callback propagation
test_rate_limiter_stress.py 17 ProviderRateLimiter Concurrency cap never exceeded (30 workers on 5-slot semaphore), 5 providers simultaneously independently capped, 429 delay โ‰ฅ 60 ms, multiple 429s take the longest, backoff expiry, one provider's backoff does not block others, all-providers 429 cascade, stats accuracy, unknown-provider on-demand creation
test_state_machine_stress.py 20 StateMachine FSM Every valid transition accepted (exhaustive), every invalid transition raises TaskStateError (exhaustive), 50 concurrent full happy-path pipelines, full retry loop ร— 5 cycles, deadlock โ†’ escalated โ†’ Boss restart chain, force-merge from deadlock/escalated, every pausable state can pause, audit trail correct with evidence after 100 concurrent tasks
test_event_bus_stress.py 16 EventBus pub/sub 1000 events to single handler, fan-out 50 handlers ร— 200 events = 10 000 invocations, crashing handler does not drop other handlers, slow handler (100 ms) does not block fast handler, stats published/failed accurate, typed handler receives only its type, wildcard receives all types, concurrent subscribe mid-stream does not lose pre-registered handlers
test_scheduler_stress.py 14 TaskScheduler Queue-full at exact limit, 1000 concurrent enqueues, CRITICAL always dequeued before LOW, full priority ordering verified, FIFO tie-break within same priority, producer/consumer race (200 tasks, no deadlock), 5 concurrent consumers โ€” no duplicates, no loss
test_merge_controller_stress.py 20 MergeController 50 concurrent merges to separate files, every merge target verified on disk, 10 traversal attack vectors all blocked individually, 5 absolute-path vectors blocked, all 5 merge gates fail independently (no code, hash tamper, security veto, compile fail, tests fail, numeric fail, benchmark fail), benchmark gate optional when absent, multi-file merge writes all files, nested directory creation
test_deadlock_detector_stress.py 24 DeadlockDetector Retry-count trigger, timeout trigger, state-change resets the clock, terminal tasks never mis-detected, callbacks fire on detection, crashing callback does not stop others, forget() removes tracking, concurrent scan() + notify_state_change() without corruption, 500-task scan in < 2 seconds, 1000-task mixed scan correct count, DeadlockPacket content and prompt-block format
test_provider_router_stress.py 15 ProviderRouter All providers down โ†’ RuntimeError, fallback order respected (3 providers tried in sequence), unavailable provider skipped, unknown provider in preference skipped, CostLimitExceeded not swallowed on budget breach, 100 concurrent calls halt when budget exhausted, stats accumulate correctly, 429 detection triggers notify_rate_limited, rate-limit error string patterns (429 and rate limit) both detected, failure counter increments per provider, counter clears on success, list_available() excludes unavailable
test_network_failure_stress.py 17 Network failure simulation Complete outage (all 5 providers down), sequential provider failures all tried, outage does not corrupt cost state, flapping provider (3 transient errors then success), 50 concurrent flapping calls all recover, stable fallback used when primary flaps, all-providers timeout raises, retry exhaustion on persistent timeout, timeout does not charge budget, cascading 429 across all providers, 429 recovery after backoff expires, budget exhaustion stops concurrent requests, CostLimitExceeded prevents fallback, wrong-type response falls back, OOM error falls back
test_pipeline_stress.py 17 Full pipeline integration 50 concurrent tasks run full 7-stage pipeline, 50 concurrent merge-controller completions, event bus fires on each stage transition, retry loop (precheck fails twice then passes), deadlock detection mid-pipeline, 30 concurrent retry loops no state bleed, scheduler dispatches CRITICAL first, 100-task scheduler + state-machine drain completes, cancel from every non-terminal state, budget exhaustion halts concurrent pipeline stages, 100 independent pipeline state machines no cross-contamination, event IDs not cross-contaminated across 50 concurrent tasks

Sample Test Output

tests/stress/test_cost_guard_stress.py ..................             [ 10%]
tests/stress/test_deadlock_detector_stress.py .....................  [ 23%]
tests/stress/test_event_bus_stress.py ................              [ 33%]
tests/stress/test_merge_controller_stress.py ..................      [ 43%]
tests/stress/test_network_failure_stress.py .................        [ 53%]
tests/stress/test_pipeline_stress.py ...............                 [ 61%]
tests/stress/test_provider_router_stress.py ...............          [ 69%]
tests/stress/test_rate_limiter_stress.py .................           [ 78%]
tests/stress/test_retry_engine_stress.py ..................          [ 88%]
tests/stress/test_scheduler_stress.py ..............                 [ 96%]
tests/stress/test_state_machine_stress.py ..................         [100%]

================= 176 passed, 10 warnings in 86.29s (0:01:26) =================

What Each Scenario Tests

CostGuard โ€” Concurrency & Budget Protection

# 500 simultaneous record() calls must serialize correctly
async def test_500_concurrent_records_exact_total():
    guard = CostGuard(max_session_usd=1000.0, max_session_tokens=100_000_000)
    tasks = [guard.record(provider="novita", tokens=100, cost_usd=0.001)
             for _ in range(500)]
    await asyncio.gather(*tasks)
    status = guard.check_budget_remaining()
    assert status["session_tokens"] == 500 * 100   # no lost updates
    assert status["session_cost_usd"] == approx(0.50, rel=1e-4)

StateMachine โ€” Exhaustive Transition Coverage

# Every (from, to) NOT in VALID_TRANSITIONS must raise
def test_every_invalid_transition_raises():
    all_states = list(TaskState)
    for from_state, to_state in product(all_states, all_states):
        if (from_state, to_state) in VALID_TRANSITIONS:
            continue
        task = Task(title="t", description="d", state=from_state)
        with pytest.raises(TaskStateError):
            StateMachine.transition(task, to_state, "test", "test")
    # 14 states ร— 14 states โˆ’ |VALID_TRANSITIONS| pairs all confirmed invalid

Network Failure โ€” Provider Outage Cascade

# CostLimitExceeded must propagate immediately โ€” no fallback to p2
async def test_cost_guard_does_not_fallback_on_budget_error():
    p1_calls = [0]
    p2_calls = [0]

    async def p1_chat(*a, **k):
        p1_calls[0] += 1
        return _response(cost=0.01)   # over budget

    router = _router({"p1": p1, "p2": p2}, cost_guard=tight_guard)
    with pytest.raises(CostLimitExceeded):
        await router.chat(messages=..., provider_preference=["p1", "p2"])
    assert p2_calls[0] == 0           # p2 must never have been tried

MergeController โ€” Path Traversal Attack Vectors

MUST_BLOCK_TRAVERSAL = [
    "../../etc/passwd",
    "../../../etc/shadow",
    "subdir/../../etc/passwd",
    "a/b/c/../../../../../../../etc/passwd",
    "foo/bar/../../../../etc/crontab",
    "../../proc/self/environ",
    "a/./../../etc/passwd",
    "./../../etc/passwd",
    # ... 10 total
]

def test_every_traversal_vector_is_blocked():
    mc = MergeController(repo_root=tmp)
    for vector in MUST_BLOCK_TRAVERSAL:
        with pytest.raises(MergeGateError, match="traversal|absolute"):
            mc._safe_dest(vector)   # zero exceptions to this rule

Scheduler โ€” Priority Correctness Under Load

# 100 mixed-priority tasks: dequeue order must be non-decreasing weight
async def test_100_mixed_priority_tasks_correct_order():
    sched = TaskScheduler(max_queue=500)
    for _ in range(100):
        await sched.enqueue(Task(priority=random.choice(TaskPriority)))
    prev_weight = -1
    for _ in range(100):
        t = await sched.next()
        w = PRIORITY_WEIGHT[t.priority]
        assert w >= prev_weight   # CRITICAL (0) always before LOW (3)
        prev_weight = w

๐Ÿš€ Running Tests

# Unit tests (no API key required)
pytest tests/unit/ -v

# Stress tests (no API key required, ~90 seconds)
pytest tests/stress/ -v

# Enterprise security tests (no API key required)
pytest tests/unit/test_api_key_enforcement.py tests/unit/test_sandbox.py tests/unit/test_host_routing.py tests/unit/test_governor.py -v

# Full pipeline integration test (requires any LLM API key)
pytest tests/integration/test_full_pipeline.py -v -m integration

# All tests
pytest tests/ -v

Environment Variables for Tests

# Required for full pipeline integration test (any one is enough)
export NOVITA_API_KEY=your_novita_key
# or
export OPENAI_API_KEY=your_openai_key
# or
export ANTHROPIC_API_KEY=your_anthropic_key
# or
export GEMINI_API_KEY=your_gemini_key

# Optional
export REDIS_URL=redis://localhost:6379/0

๐Ÿ”’ Enterprise Security & Sandbox

AISwarm integrates enterprise-grade security at every layer:

1. API Key Enforcement

The aiswarm/security/auth.py module enforces mandatory API key configuration at startup. AISwarm refuses to start if no valid provider key is present.

2. Production Execution Sandbox

The aiswarm/security/sandbox.py module provides a production-grade isolated execution environment:

  • Workspace directory isolation (path traversal blocked)
  • CPU wall-clock timeout and subprocess termination
  • Command allowlisting (only python, pytest, ruff, git, gcc, node, npm permitted by default)
  • Network egress restriction (default deny for outbound access)
  • Secret scrubbing of all subprocess output

3. Host-1 / Host-2 Multi-Lane Routing

All tasks are routed by the Host-1 Global Router into one of three execution lanes:

  • FAST: Low-risk single-file tasks โ†’ Host-2 Capability Manager
  • PRODUCTION: Security/auth/database/release tasks โ†’ Full Boss pipeline
  • HYBRID: Multi-file architecture tasks โ†’ Boss coordinates, Host-2 executes subtasks

4. Engineering Governor

The aiswarm/security/governor.py enforces platform-wide safety: budget caps, capability spawn permissions, and Human-in-the-Loop (HITL) gates for high-risk operations.

5. Immutable Audit Ledger

All route decisions, capability spawns, escalations, and merges are recorded to the AuditLedger (accessible via GET /audit).


๐Ÿ“ Project Structure

aiswarm/
โ”œโ”€โ”€ aiswarm/
โ”‚   โ”œโ”€โ”€ agents/
โ”‚   โ”‚   โ”œโ”€โ”€ boss/agent.py             # Reviews tasks, resolves deadlocks
โ”‚   โ”‚   โ”œโ”€โ”€ manager/agent.py          # Goal decomposition โ†’ TaskSpec list
โ”‚   โ”‚   โ”œโ”€โ”€ planner/agent.py          # Implementation blueprint (JSON)
โ”‚   โ”‚   โ”œโ”€โ”€ context_selector/         # RAG file selection (max 15 files)
โ”‚   โ”‚   โ”œโ”€โ”€ coder/agent.py            # Code generation + revision
โ”‚   โ”‚   โ”œโ”€โ”€ precheck/agent.py         # Static analysis gate
โ”‚   โ”‚   โ””โ”€โ”€ critics/
โ”‚   โ”‚       โ”œโ”€โ”€ architecture/         # SOLID/DRY coupling review
โ”‚   โ”‚       โ”œโ”€โ”€ performance/          # O(n), memory, concurrency
โ”‚   โ”‚       โ”œโ”€โ”€ security/             # OWASP Top 10 โ€” VETO POWER
โ”‚   โ”‚       โ”œโ”€โ”€ testing/              # Coverage, isolation, mocking
โ”‚   โ”‚       โ”œโ”€โ”€ reliability/          # Errors, retries, timeouts
โ”‚   โ”‚       โ”œโ”€โ”€ maintainability/      # Complexity, naming, dead code
โ”‚   โ”‚       โ”œโ”€โ”€ documentation/        # Docstrings, type hints
โ”‚   โ”‚       โ””โ”€โ”€ style/                # PEP 8, formatting
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ”œโ”€โ”€ orchestrator.py           # Central control plane
โ”‚   โ”‚   โ”œโ”€โ”€ state_machine.py          # Explicit FSM (TaskStateError on violations)
โ”‚   โ”‚   โ”œโ”€โ”€ event_bus.py              # Async pub/sub with wildcard subscriptions
โ”‚   โ”‚   โ”œโ”€โ”€ retry_engine.py           # Exponential back-off with jitter
โ”‚   โ”‚   โ”œโ”€โ”€ deadlock_detector.py      # Background scanner โ†’ Boss escalation
โ”‚   โ”‚   โ”œโ”€โ”€ merge_controller.py       # 5-gate merge guard
โ”‚   โ”‚   โ”œโ”€โ”€ force_merge.py            # Break-glass operator override
โ”‚   โ”‚   โ”œโ”€โ”€ cost_guard.py             # Daily spend circuit breaker
โ”‚   โ”‚   โ”œโ”€โ”€ rate_limiter.py           # Per-provider token-bucket
โ”‚   โ”‚   โ”œโ”€โ”€ redis_task_store.py       # Redis-backed persistence
โ”‚   โ”‚   โ”œโ”€โ”€ workflow_engine.py        # Full pipeline driver
โ”‚   โ”‚   โ”œโ”€โ”€ scheduler.py              # Priority min-heap with backpressure
โ”‚   โ”‚   โ”œโ”€โ”€ checkpoint.py             # Atomic task serialization + restore
โ”‚   โ”‚   โ””โ”€โ”€ lifecycle.py              # Ordered startup/shutdown + signal handlers
โ”‚   โ”œโ”€โ”€ llm/
โ”‚   โ”‚   โ”œโ”€โ”€ adapter.py                # BaseLLMAdapter ABC
โ”‚   โ”‚   โ”œโ”€โ”€ openai.py                 # OpenAI + Novita (OpenAI-compatible)
โ”‚   โ”‚   โ”œโ”€โ”€ anthropic.py              # Anthropic native adapter
โ”‚   โ”‚   โ”œโ”€โ”€ gemini.py                 # Google Gemini adapter
โ”‚   โ”‚   โ”œโ”€โ”€ deepseek.py               # DeepSeek (extends OpenAI adapter)
โ”‚   โ”‚   โ”œโ”€โ”€ bedrock.py                # AWS Bedrock (boto3 thread-pool)
โ”‚   โ”‚   โ”œโ”€โ”€ local_models.py           # Ollama / LM Studio adapter
โ”‚   โ”‚   โ””โ”€โ”€ provider_router.py        # Fallback + cost guard + rate limiter
โ”‚   โ”œโ”€โ”€ memory/
โ”‚   โ”‚   โ”œโ”€โ”€ working_memory.py         # Ephemeral per-task scratch state
โ”‚   โ”‚   โ””โ”€โ”€ failure_memory.py         # Persisted failureโ†’resolution patterns
โ”‚   โ”œโ”€โ”€ rag/
โ”‚   โ”‚   โ”œโ”€โ”€ retriever.py              # Semantic + keyword hybrid search
โ”‚   โ”‚   โ”œโ”€โ”€ repository_indexer.py     # Full-repo crawl + index
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ worker/
โ”‚   โ”‚   โ”œโ”€โ”€ dispatcher.py             # CPUโ†’GPU Redis bridge
โ”‚   โ”‚   โ”œโ”€โ”€ local_worker.py           # Local subprocess executor (sandbox-wrapped)
โ”‚   โ”‚   โ””โ”€โ”€ docker_worker.py          # Isolated Docker executor
โ”‚   โ”œโ”€โ”€ security/
โ”‚   โ”‚   โ”œโ”€โ”€ auth.py                   # API key enforcement (fail-fast startup)
โ”‚   โ”‚   โ”œโ”€โ”€ sandbox.py                # Production execution sandbox
โ”‚   โ”‚   โ”œโ”€โ”€ governor.py               # Engineering governor & policy gates
โ”‚   โ”‚   โ”œโ”€โ”€ audit.py                  # Immutable audit ledger
โ”‚   โ”‚   โ”œโ”€โ”€ redaction.py              # Secret scrubbing engine
โ”‚   โ”‚   โ””โ”€โ”€ policy.py                 # Central policy rules engine
โ”‚   โ”œโ”€โ”€ bootstrap/
โ”‚   โ”‚   โ””โ”€โ”€ startup.py                # Wires all 17 agents
โ”‚   โ””โ”€โ”€ ...
โ”‚
โ”œโ”€โ”€ apps/
โ”‚   โ”œโ”€โ”€ api/main.py                   # FastAPI REST server (12 endpoints)
โ”‚   โ”œโ”€โ”€ dashboard/main.py             # Operator dashboard HTML UI
โ”‚   โ””โ”€โ”€ cli/main.py                   # Typer CLI (aiswarm entrypoint)
โ”‚
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ unit/                         # 191 tests, 3 skipped
โ”‚   โ”œโ”€โ”€ stress/                       # 176 tests โ€” concurrency, faults, exhaustion
โ”‚   โ”œโ”€โ”€ integration/                  # Docker / Sandbox + full pipeline tests
โ”‚   โ””โ”€โ”€ conftest.py
โ”‚
โ”œโ”€โ”€ configs/
โ”‚   โ”œโ”€โ”€ default.yaml
โ”‚   โ”œโ”€โ”€ production.yaml
โ”‚   โ”œโ”€โ”€ development.yaml
โ”‚   โ””โ”€โ”€ ...
โ”‚
โ”œโ”€โ”€ assets/
โ”‚   โ””โ”€โ”€ logo.jpg
โ”‚
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ pyproject.toml
โ””โ”€โ”€ requirements.txt

๐Ÿ”— API Endpoints

Method Endpoint Description
POST /tasks Submit a new task
GET /tasks List all tasks (optional ?state= filter)
GET /tasks/{id} Get full task detail
POST /tasks/{id}/cancel Cancel a running task
POST /tasks/{id}/force-merge Operator force-merge (requires reason)
POST /tasks/{id}/retry Reset and re-queue a failed task
GET /health Liveness check + agent count
GET /metrics/summary System-wide metrics (tasks by state)
GET /cost/status Budget consumption + remaining allowances
GET /providers LLM provider health + stats
GET /rag/status RAG index health + document count
GET / Operator dashboard (HTML)

โšก Quick Start

1. Install

git clone https://github.com/abhinav00anand/aiswarm
cd aiswarm
pip install -r requirements.txt

2. Configure

cp .env.example .env
# Required โ€” set at least one LLM provider:
# NOVITA_API_KEY=your_novita_key
# or OPENAI_API_KEY / ANTHROPIC_API_KEY / GEMINI_API_KEY / DEEPSEEK_API_KEY

3. Run the API server

uvicorn apps.api.main:app --host 0.0.0.0 --port 5000
# Operator dashboard: http://localhost:5000/
# API docs:          http://localhost:5000/docs

4. Submit a task (REST)

curl -X POST http://localhost:5000/tasks \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Write a Python binary search function",
    "description": "Implement binary search with full type hints and docstring",
    "target_files": ["output/search.py"],
    "target_language": "python",
    "priority": "HIGH",
    "acceptance_criteria": [
      "O(log n) complexity",
      "Returns index or -1",
      "Full type annotations"
    ]
  }'

5. Check cost status

curl http://localhost:5000/cost/status
# {"session_cost_usd": 0.0042, "session_remaining_usd": 9.9958, "daily_limit_usd": 100.0, ...}

6. Run with Docker Compose

docker compose up -d

โš™๏ธ Environment Variables

โš ๏ธ The server starts fine with zero environment variables set โ€” but every one of NOVITA_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY, and DEEPSEEK_API_KEY being empty means there is no cloud LLM the Coder agent can call. The router falls back to a local adapter (Ollama/LM Studio on localhost); if that isn't running either, task submission fails at runtime with RuntimeError: All providers exhausted. Set at least one LLM API key before submitting real tasks โ€” the dashboard, /health, and /docs all work without one, but code generation does not.

Variable Required Description
NOVITA_API_KEY / NOVITA_TOKEN At least one LLM key required Novita LLM API key
OPENAI_API_KEY At least one LLM key required OpenAI provider
ANTHROPIC_API_KEY At least one LLM key required Anthropic provider
GOOGLE_API_KEY / GEMINI_API_KEY At least one LLM key required Google Gemini provider
DEEPSEEK_API_KEY At least one LLM key required DeepSeek provider
AISWARM_API_KEY Optional Platform master key (overrides individual provider keys)
REDIS_URL Optional Redis URL (default: redis://localhost:6379/0)
SESSION_SECRET Reserved Reserved for dashboard session auth
MAX_DAILY_SPEND_USD Optional Daily LLM budget cap (default: 100.0)
MAX_SESSION_SPEND_USD Optional Per-session spend cap (default: 10.0)
LOG_LEVEL Optional DEBUG/INFO/WARNING (default: INFO)
LOG_FORMAT Optional json/console (default: console)
TELEGRAM_BOT_TOKEN Optional For task completion alerts

โš ๏ธ API Key Enforcement: AISwarm will refuse to start (sys.exit(1)) if no valid API key is found. Pass --api-key KEY to the CLI or set any of the provider environment variables above.

What runs without any LLM key

Works without an LLM key Fails without an LLM key
Server startup Task submission (POST /tasks) โ€” generates code
Operator dashboard (GET /) Any pipeline stage that calls the Coder/Critics
GET /health, GET /docs
GET /cost/status, GET /providers

๐Ÿงญ Key Design Decisions

8-Critic Parallel Review

All 8 critics (Architecture, Performance, Security, Testing, Reliability, Maintainability, Documentation, Style) run in parallel after the PreCheck gate. The Security critic has veto power โ€” a single REJECT blocks merge unconditionally.

Cost Guard Circuit Breaker

Every LLM call goes through CostGuard.record() after completion. If daily or session spend exceeds the configured limit, CostLimitExceeded is raised immediately and the provider router does NOT fall back to another provider โ€” budget protection takes absolute priority.

Explicit State Machine

All valid (from_state, to_state) transitions are enumerated. Attempting any other transition raises TaskStateError, preventing silent state corruption. Force-merge bypasses the FSM directly โ€” this is intentional for break-glass scenarios.

Redis CPUโ†”GPU Bridge

The worker subsystem uses Redis as a message queue between the orchestrator (CPU) and GPU workers (local, Docker, or Sandbox). This decouples the orchestrator from worker lifecycle management.

RAG-Powered Context Selection

Instead of injecting the entire codebase into every prompt, the ContextSelectorAgent uses an LLM to select the 15 most relevant files (capped at 8000 tokens). This keeps prompts focused and reduces cost.

Sandbox Integration Tests

Integration tests use the Sandbox REST API v1 directly (no Python SDK dependency). Tests are structured to skip gracefully when an optional account prerequisite is unmet โ€” they never fail the CI pipeline due to account state.


๐Ÿค Contributing

  1. Fork the repo
  2. Create a feature branch: git checkout -b feat/my-feature
  3. Run the unit test suite: pytest tests/unit/ -v
  4. Run the stress suite: pytest tests/stress/ -v
  5. Run Sandbox integration tests: pytest tests/integration/ -v -m integration
  6. Submit a PR โ€” the security critic will review it ๐Ÿ˜„

๐Ÿ“„ License

MIT License โ€” see LICENSE.

Download files

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

Source Distribution

aiswarm_next-1.0.0.tar.gz (157.2 kB view details)

Uploaded Source

Built Distribution

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

aiswarm_next-1.0.0-py3-none-any.whl (192.0 kB view details)

Uploaded Python 3

File details

Details for the file aiswarm_next-1.0.0.tar.gz.

File metadata

  • Download URL: aiswarm_next-1.0.0.tar.gz
  • Upload date:
  • Size: 157.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for aiswarm_next-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fc6d3ce2d33a6bc3c9b00f52ac90d11c3fbb8ae2ac1fea8e9b424c5d96b7c701
MD5 41948a3549fe37a0dd3baa8c43b4ad86
BLAKE2b-256 d45403d27f1ddaebbe5eeca4436dddaf788d3b7aa4857fe888afb5803e5a9743

See more details on using hashes here.

File details

Details for the file aiswarm_next-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: aiswarm_next-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 192.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for aiswarm_next-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e576f0c07b46b2ddb837f3878231e165eaa70287b750d91a5165b719dadb8dc4
MD5 62819667f4f24b21282729b9c959d94e
BLAKE2b-256 f88c2bd7ff39547c85a01925e18375499609d5dc3355b984a7538a41c287d77d

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