๐ 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.
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
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
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.
# 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,npmpermitted 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, andDEEPSEEK_API_KEYbeing empty means there is no cloud LLM the Coder agent can call. The router falls back to alocaladapter (Ollama/LM Studio on localhost); if that isn't running either, task submission fails at runtime withRuntimeError: All providers exhausted. Set at least one LLM API key before submitting real tasks โ the dashboard,/health, and/docsall 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 KEYto 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
- Fork the repo
- Create a feature branch:
git checkout -b feat/my-feature - Run the unit test suite:
pytest tests/unit/ -v - Run the stress suite:
pytest tests/stress/ -v - Run Sandbox integration tests:
pytest tests/integration/ -v -m integration - 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc6d3ce2d33a6bc3c9b00f52ac90d11c3fbb8ae2ac1fea8e9b424c5d96b7c701
|
|
| MD5 |
41948a3549fe37a0dd3baa8c43b4ad86
|
|
| BLAKE2b-256 |
d45403d27f1ddaebbe5eeca4436dddaf788d3b7aa4857fe888afb5803e5a9743
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e576f0c07b46b2ddb837f3878231e165eaa70287b750d91a5165b719dadb8dc4
|
|
| MD5 |
62819667f4f24b21282729b9c959d94e
|
|
| BLAKE2b-256 |
f88c2bd7ff39547c85a01925e18375499609d5dc3355b984a7538a41c287d77d
|