Metadata-Version: 2.4
Name: aiswarm-next
Version: 1.2.0
Summary: Production-grade AI agent orchestration system — Boss, Manager, Coder, Critics, and Worker pipeline
Author: AISwarm Contributors
License: MIT License
        
        Copyright (c) 2025 AISwarm Contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/abhinav00anand/aiswarm
Project-URL: Documentation, https://github.com/abhinav00anand/aiswarm#readme
Project-URL: Repository, https://github.com/abhinav00anand/aiswarm.git
Project-URL: Issues, https://github.com/abhinav00anand/aiswarm/issues
Keywords: ai,agents,orchestration,llm,swarm,code-generation,multi-agent
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Code Generators
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: anyio>=4.4
Requires-Dist: asyncio-throttle>=1.0.2
Requires-Dist: openai>=1.35
Requires-Dist: anthropic>=0.30
Requires-Dist: google-generativeai>=0.7
Requires-Dist: boto3>=1.34
Requires-Dist: httpx>=0.27
Requires-Dist: aiohttp>=3.9
Requires-Dist: pydantic>=2.7
Requires-Dist: pydantic-settings>=2.3
Requires-Dist: structlog>=24.2
Requires-Dist: rich>=13.7
Requires-Dist: redis[hiredis]>=5.0
Requires-Dist: chromadb>=0.5
Requires-Dist: sentence-transformers>=3.0
Requires-Dist: tiktoken>=0.7
Requires-Dist: tree-sitter>=0.22
Requires-Dist: pygments>=2.18
Requires-Dist: gitpython>=3.1
Requires-Dist: pyyaml>=6.0
Requires-Dist: python-dotenv>=1.0
Requires-Dist: omegaconf>=2.3
Requires-Dist: fastapi>=0.111
Requires-Dist: uvicorn[standard]>=0.30
Requires-Dist: python-multipart>=0.0.9
Requires-Dist: click>=8.1
Requires-Dist: typer>=0.12
Requires-Dist: opentelemetry-api>=1.25
Requires-Dist: opentelemetry-sdk>=1.25
Requires-Dist: opentelemetry-exporter-otlp>=1.25
Requires-Dist: prometheus-client>=0.20
Requires-Dist: python-telegram-bot>=21.3
Requires-Dist: cryptography>=42.0
Requires-Dist: tenacity>=8.3
Requires-Dist: cachetools>=5.3
Requires-Dist: humanize>=4.9
Requires-Dist: python-dateutil>=2.9
Requires-Dist: ujson>=5.10
Requires-Dist: xxhash>=3.4
Requires-Dist: aiofiles>=23.2
Requires-Dist: psutil>=5.9
Requires-Dist: pytest>=8.2
Requires-Dist: pytest-asyncio>=0.23
Requires-Dist: pytest-cov>=5.0
Requires-Dist: pytest-mock>=3.14
Requires-Dist: hypothesis>=6.103
Provides-Extra: dev
Requires-Dist: ruff>=0.5; extra == "dev"
Requires-Dist: mypy>=1.10; extra == "dev"
Requires-Dist: black>=24.4; extra == "dev"
Requires-Dist: pre-commit>=3.7; extra == "dev"
Requires-Dist: ipython>=8.25; extra == "dev"
Provides-Extra: gpu
Requires-Dist: torch>=2.3; extra == "gpu"
Requires-Dist: numpy>=1.26; extra == "gpu"
Dynamic: license-file

# 🐝 AISwarm-Next

<p align="center">
  <img src="https://raw.githubusercontent.com/abhinav00anand/aiswarm-next/main/assets/logo.jpg" alt="AISwarm logo" width="160" height="160" style="border-radius:24px; box-shadow: 0 8px 16px rgba(0,0,0,0.2);">
</p>

<p align="center">
  <b>Enterprise Multi-Agent AI Software Engineering Swarm</b><br>
  Transforming high-level objectives into compiled, fully-tested, security-scrubbed, native C++ & Python code bases.
</p>

<p align="center">
  <a href="https://pypi.org/project/aiswarm-next/"><img src="https://img.shields.io/pypi/v/aiswarm-next.svg?style=for-the-badge&logo=pypi&logoColor=white&color=blue" alt="PyPI Package"></a>
  <a href="https://github.com/abhinav00anand/aiswarm-next"><img src="https://img.shields.io/badge/github-aiswarm--next-black.svg?style=for-the-badge&logo=github" alt="GitHub Repository"></a>
  <a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13-3776AB.svg?style=for-the-badge&logo=python&logoColor=white" alt="Python Version"></a>
  <a href="./LICENSE"><img src="https://img.shields.io/badge/License-MIT-green.svg?style=for-the-badge" alt="License: MIT"></a>
</p>

---

## 🚀 Key Features

*   **🦙 Zero-Cloud-Key Local Fallback**: Dynamic disk measurement auto-provisions Ollama (`llama3.1:8b`, `llama3.2:3b`, or `llama3.2:1b`) when no cloud API keys are present.
*   **🔌 Explicit Local Adapter URL**: Seamlessly point to any in-notebook OpenAI-compatible API endpoint (e.g. running vLLM, Hugging Face, or local model servers) via `--adapter-url` or `OPENAI_API_ADAPTER_URL`.
*   **📓 Optimized Notebook Mode**: Turn on `--notebook` or `AISWARM_NOTEBOOK_MODE=1` to disable Ollama auto-installations, limit CPU thread contention (`OMP`/`MKL`), cap generation tokens, and fall back to safe small models.
*   **🛡️ Multi-Agent Auditing**: Production pipeline routes code through **8 domain-specialized Critic Agents** (Security, Architecture, Performance, Maintainability, Reliability, Style, Testing, and Documentation).
*   **🔒 Zero-Trust Execution Sandbox**: Scopes files and process isolation, allowlisting compilation processes to strictly prevent environment breakouts.
*   **📜 Audit Ledger**: Generates a cryptographically traceable, JSONL-formatted immutable audit log of all system decisions.

---

## 🏗️ Swarm Architecture & Execution Lanes

Tasks submitted to the Swarm automatically pass through the **Host-1 Router** to decide the optimal execution lane:

```mermaid
graph TD
    NLTask[Submit Natural Language Task] --> Router[Host-1 Router]
    
    subgraph Execution Lanes
        Router -->|Fast Lane| Host2[Host-2 C++ Engine]
        Router -->|Production Lane| Boss[Boss Validation]
        Router -->|Hybrid Lane| Decomposer[Hybrid Decomposer]
    end
    
    Host2 --> Scaffolder[SCScaffolder] --> Sandbox[Isolated Sandbox]
    
    Boss --> Mgr[Manager Planning] --> Coder[Coder Generation] --> Compiler[Compiler Verify]
    Compiler --> Critics[8 Parallel Critics] --> Cond[Confidence & Self-Healing] --> Sandbox
    
    Decomposer --> Segment[Subtask Segmentation] --> Host2
    Decomposer --> Segment --> Boss
    
    Sandbox --> Audit[Immutable Audit Ledger]
```

### 1. Fast Lane (`FAST`)
- **Latency**: ~0.1 seconds
- **Best For**: Direct code scaffolding, minor edits, and utility functions.
- **Engine**: Invokes compiled C++ Native module engines (`host2_engine.cpp`) via the `Host2CapabilityManager`.

### 2. Production Lane (`PRODUCTION`)
- **Latency**: Variable (LLM execution dependent)
- **Best For**: Complex features, security boundaries, and multi-file codebases.
- **Engine**: Executes the complete 12-Stage Swarm pipeline driven by the Boss, Manager, Coder, and 8 Parallel Critics.

### 3. Hybrid Lane (`HYBRID`)
- **Latency**: Variable
- **Best For**: Complex goals that combine boilerplate structure with core critical algorithms.
- **Engine**: Boss Agent decomposes the objective, delegating basic tasks to Host-2 while reserving main execution blocks for the Boss pipeline.

---

## 🧐 The 8 Domain Critics

During the verification phase of the Production Lane, 8 specialized Critic agents validate the code concurrently:

| Critic Agent | Focus Area | Veto Power | Critical Scopes Checked |
| :--- | :--- | :---: | :--- |
| 🛡️ **Security Critic** | Security & Compliance | **YES** | Audits for Injection, XSS, Path Traversal, secrets leaks, and unsafe imports. |
| 🏛️ **Architecture Critic** | Structure & Modularity | No | Enforces SOLID design principles, modularity, and clean layer separation. |
| ⚡ **Performance Critic** | Memory & Speed | No | Assesses CPU bottlenecks, space/time complexity, and loop efficiency. |
| 🧹 **Maintainability Critic** | Style & Cleanliness | No | Tracks cyclomatic complexity, code duplication, and clean naming conventions. |
| 🛡️ **Reliability Critic** | Error Resilience | No | Enforces robust exception boundaries, fallback mechanisms, and null checks. |
| 🎨 **Style Critic** | Standards Consistency | No | Assesses strict compliance with PEP 8 and Python/C++ type declarations. |
| 🧪 **Testing Critic** | Unit Testing Depth | No | Validates unit coverage, mocking parameters, and edge-case boundaries. |
| 📝 **Documentation Critic** | Clarity & Docs | No | Checks docstrings, inline code comments, and API explanations. |

---

## 🔌 Running in Notebooks (Kaggle / Colab)

To run AISwarm-Next in offline or memory-restricted notebook environments, you can start a lightweight local Hugging Face adapter and point the orchestrator directly to it:

### 1. Launch the Secure Local HF Adapter
In a separate background process or cell, start our provided secure FastAPI proxy hosting a model like `distilgpt2`:

```python
# Set environment config
import os
os.environ["ADAPTER_MODEL_NAME"] = "distilgpt2"
os.environ["ADAPTER_API_KEY"] = "my-secure-notebook-token"

# Start the adapter
!python examples/local_adapter.py
```

### 2. Run AISwarm pointed to the local Adapter
Configure the orchestrator using environment variables or CLI flags:

```bash
export OPENAI_API_ADAPTER_URL="http://127.0.0.1:8000"
export OPENAI_API_KEY="my-secure-notebook-token"
export AISWARM_NO_OLLAMA=1
export AISWARM_NOTEBOOK_MODE=1

aiswarm run "Write an efficient factorial function and tests"
```

*See the comprehensive [`examples/kaggle.ipynb`](./examples/kaggle.ipynb) notebook for a complete, runnable notebook environment script.*

---

## ⚡ Quick Start Guide

### Installation

```bash
pip install aiswarm-next
```

### Running with Cloud API Keys

Configure any supported cloud provider key:

```bash
export OPENAI_API_KEY="sk-proj-..."
# OR
export ANTHROPIC_API_KEY="sk-ant-..."
# OR
export GOOGLE_API_KEY="AIzaSy..."

aiswarm run "Write a quicksort helper and unit tests"
```

### Running with Zero-Keys (Auto-Provisioned Local Ollama)
If no cloud API keys or adapters are configured, AISwarm-Next will automatically measure disk space, launch Ollama, download an optimal model, and execute the task completely locally:

```bash
# Just run directly!
aiswarm run "Write an AST parser in Python"
```

### CLI Command Reference

*   `aiswarm run "<task_description>"`: Submit a software engineering task to the orchestrator.
    *   `--adapter-url <url>`: Override the OpenAI-compatible local adapter endpoint.
    *   `--no-ollama`: Skip Ollama auto-provision fallbacks.
    *   `--notebook`: Run in resource-conserving notebook mode.
*   `aiswarm providers`: List all configured LLM providers and their availability status.
*   `aiswarm audit`: Output the last 50 entries from the immutable audit ledger.

---

## 📊 System Benchmarks

| Benchmark Suite | Total Runs | Passed | Skipped | Pass Rate |
| :--- | :---: | :---: | :---: | :---: |
| **Unit Test Suite** | 231 | **228** | 3 | **100%** |
| **Stress & Fuzzing Suite** | 134 | **131** | 3 | **100%** |
| **Concurrency Benchmark** | 5 | **5** | 0 | **100%** |
| **TOTAL** | **370** | **364** | **6** | **100%** |

### Event Core Performance
- **EventBus Throughput**: `6,700` events/sec
- **TaskScheduler Throughput**: `23,800` tasks/sec
- **AuditLedger Write Speed**: `12,300` events/sec
- **SecretRedactor Scrub Speed**: `18,200` secrets/sec

---

## 📜 License

AISwarm-Next is open-source software licensed under the [MIT License](./LICENSE).
