> ## Documentation Index
> Fetch the complete documentation index at: https://mathematicalcompany.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> Autonomous agent swarms with compiled Rust intelligence. 13 subsystems coordinate a self-evolving fleet of trading agents.

<Note>
  **Enterprise Only.** The Hive is available exclusively to enterprise customers. To get access, contact us at [contact@mathematicalcompany.com](mailto:contact@mathematicalcompany.com).
</Note>

Ten agents researching independently will find the same market, open the same position, and blow up together. No portfolio view. No quality gate. Nobody deciding how much capital each agent deserves.

The Hive fixes this. Thirteen compiled Rust subsystems handle coordination, evolution, risk, and execution for a fleet of trading agents. Pheromone fields for indirect communication. Evolutionary engines that breed new strategies. Bayesian reputation scoring. A 6-phase kill chain for automated incident response. All proprietary algorithms ship as opaque native binary. Below everything, the compiled Rust risk pipeline rejects any order that violates hard limits.

<CardGroup cols={2}>
  <Card title="Hive" icon="brain" href="/swarm/hive">
    13 Rust subsystems: pheromone fields, evolutionary engines, behavioral cloning, causal discovery, impact modeling, metamorphic execution.
  </Card>

  <Card title="Agent Pipeline" icon="robot" href="/swarm/agent-pipeline">
    9-phase workflow per agent. Research, analyze, backtest, pass 5 statistical tests, propose, execute on approval.
  </Card>

  <Card title="Circuit Breaker" icon="shield-halved" href="/swarm/circuit-breaker">
    No LLM. Daemon thread. Checks portfolio limits every 2 seconds. Emergency stop with no override path.
  </Card>

  <Card title="Event Bus" icon="tower-broadcast" href="/swarm/event-bus">
    WebSocket pub/sub. 6 channels. Real-time state across agents, Hive, risk, and knowledge. Ring buffers for late joiners.
  </Card>
</CardGroup>

## The Coordination Problem

Five agents, each independently researching markets. Prediction markets, stocks, options. Without coordination:

* Agent A and Agent C both find the same Fed rate market. Both buy yes. 2x the exposure you planned for, and neither agent knows the other exists.
* Agent B finishes a backtest with a Sharpe of 1.2 and starts trading. Overfit. No one checked.
* Agent D requests $3,000. Agent E requests $4,000. Your budget is \$5,000. Both get funded because there's no central accounting.
* All five agents are long the same sector. One event wipes out the portfolio.

The SwarmCoordinator runs a fitness-scored tick loop. The PheromoneField detects crowding automatically. The ConsensusEngine aggregates conflicting views. The CriticalityMonitor triggers the KillChain when systemic risk spikes. Agents can't trade without the AutonomyController's permission. And below all of this, the Rust engine rejects any order that violates compiled risk limits.

## Quick Start

```python theme={null}
from horizon.hive import HiveController, HiveConfig, AutonomyMode

config = HiveConfig(
    total_capital=100_000,
    max_agents=50,
    initial_mode=AutonomyMode.Observe,
    host="0.0.0.0",
    port=8780,
    auth_token="your-secret-token",
)

hive = HiveController(config)

# Spawn agents from 9 archetype templates
agent = hive.spawn_agent("momentum", markets=["BTC-YES"], capital=5000.0)

# Full status across all 13 subsystems
status = hive.status()

# Start the oversight loop + WebSocket server (blocking)
hive.run()
```

Remote connections:

```python theme={null}
from horizon.hive import HiveClient

client = HiveClient("ws://hive-server:8780", token="your-secret-token")
client.connect()
print(client.status())
client.spawn(template="arbitrage", markets=["BTC-YES", "ETH-YES"])
```

Legacy LLM-driven swarm (still available):

```python theme={null}
from horizon.swarm import SwarmConfig, run_swarm

config = SwarmConfig(
    api_key="sk-or-...",
    hive_model="anthropic/claude-sonnet-4-6",
    agent_model="openai/gpt-5.4-mini",
    max_agents=10,
    max_capital_usd=10_000,
    exchange_backend="paper",
)

run_swarm(config)
```

## How Orders Hit the Rust Engine

Every order from every agent goes through the same compiled risk pipeline in `src/risk.rs`.

```
Agent  →  submit_order  →  Engine.submit()  →  8 compiled checks  →  Exchange
```

Kill switch, price bounds, size bounds, position limits, notional cap, drawdown threshold, rate limit, dedup. All Rust. Python can't skip any of them. A $1,000 agent can't take a $5,000 position. Rejected before it reaches the exchange.

The SwarmCoordinator enforces total capital limits in compiled Rust. No agent receives more than `max_capital_per_agent_pct` (default 15%) of total AUM. Capital allocation is fitness-weighted. Better agents get more capital.

One agent's risk breach doesn't affect another agent's engine. Portfolio-wide limits are handled by the CriticalityMonitor and KillChain.

## Five Risk Layers

Each enforces independently. Lower layers can't be overridden by higher ones.

| Layer           | Enforcer                         | What                                                                             | Override                  |
| --------------- | -------------------------------- | -------------------------------------------------------------------------------- | ------------------------- |
| Engine          | Compiled Rust                    | 8-point pipeline: kill switch, bounds, limits, cap, drawdown, rate, dedup        | No                        |
| Per-Agent       | SwarmCoordinator (Rust)          | Capital allocation per agent, fitness-weighted rebalancing                       | No                        |
| Kill Chain      | Compiled Rust + Python callbacks | 6-phase incident response: detect, contain, preserve, diagnose, remediate, learn | No                        |
| Circuit Breaker | Daemon thread, no LLM            | Portfolio drawdown, daily P\&L, stuck detection. Emergency stop.                 | No                        |
| Hive Autonomy   | AutonomyController (Rust)        | Progressive trust: Observe, Suggest, Supervised, Autonomous, Skynet              | Can't override layers 1-4 |

The Hive reasons about strategy. It can't override compiled safety limits. An agent that decides to "take more risk" still hits the Rust pipeline.

## 13 Rust Subsystems

All proprietary algorithms compiled to native binary via PyO3. No source code ships in the Python package.

<CardGroup cols={3}>
  <Card title="SwarmCoordinator" icon="sitemap">
    Fleet management. Fitness scoring, selection pressure, promotion pipeline, capital rebalancing.
  </Card>

  <Card title="PheromoneField" icon="wave-square">
    9-channel stigmergic communication. Evaporation, diffusion, emergent market signals.
  </Card>

  <Card title="ConsensusEngine" icon="scale-balanced">
    IC-weighted signals, internal prediction markets, Dempster-Shafer belief aggregation.
  </Card>

  <Card title="AgentFactory" icon="industry">
    9 archetype templates + 5 spawn sources: evolution, clone, user, imprint, opportunistic.
  </Card>

  <Card title="MAPElitesArchive" icon="grid">
    300-cell quality-diversity grid. Keeps the swarm diverse by construction.
  </Card>

  <Card title="EvolutionEngine" icon="dna">
    NSGA-II multi-objective optimization with island model. 5 islands, periodic migration.
  </Card>

  <Card title="CriticalityMonitor" icon="triangle-exclamation">
    15-indicator systemic risk. Hurst, VPIN, transfer entropy, BOCPD, CUSUM. Triggers avalanche reserve.
  </Card>

  <Card title="CausalEngine" icon="diagram-project">
    Granger causality + transfer entropy + lead-lag detection. Early warning for regime shifts.
  </Card>

  <Card title="SelfImpactModel" icon="chart-area">
    Almgren-Chriss impact estimation. Gates orders exceeding expected alpha. Internal crossing.
  </Card>

  <Card title="ImprintSystem" icon="brain-circuit">
    Behavioral cloning via 3-layer MLP. Learns your trading style with DAgger-style corrections.
  </Card>

  <Card title="AutonomyController" icon="stairs">
    5-mode progressive trust. Each graduation requires statistical evidence.
  </Card>

  <Card title="KillChain" icon="skull-crossbones">
    6-phase incident response. Genome blacklisting prevents failed strategies from re-evolving.
  </Card>

  <Card title="MetamorphicExecutor" icon="shuffle">
    Anti-fingerprint execution. Randomized child orders, jittered timing, decoy orders.
  </Card>
</CardGroup>

## Configuration

`HiveConfig` controls all 13 subsystems. Key settings:

| Setting                      | Default      | Purpose                                        |
| ---------------------------- | ------------ | ---------------------------------------------- |
| `total_capital`              | 100,000      | Total AUM across all agents                    |
| `max_agents`                 | 50           | Maximum concurrent agents                      |
| `initial_mode`               | `Observe`    | Starting autonomy mode                         |
| `max_drawdown_pct`           | 0.20         | Portfolio-wide drawdown limit                  |
| `max_capital_per_agent_pct`  | 0.15         | No single agent gets more than 15%             |
| `pheromone_tick_interval`    | 1.0s         | Pheromone evaporation/diffusion rate           |
| `criticality_check_interval` | 60s          | How often to run the 15-indicator check        |
| `avalanche_reserve_pct`      | 0.15         | Capital held in reserve for crises             |
| `dream_enabled`              | True         | Offline accelerated evolution between sessions |
| `imprint_enabled`            | True         | Learn from operator behavior                   |
| `metamorphic_enabled`        | True         | Anti-fingerprint execution                     |
| `host` / `port`              | 0.0.0.0:8780 | WebSocket server for remote connections        |

## Models

The Hive uses LLMs for the ReACT research agent and high-level oversight. OpenRouter by default, any model works.

```python theme={null}
HiveConfig(
    api_base="https://openrouter.ai/api/v1",
    hive_model="anthropic/claude-sonnet-4-6",
    agent_model="openai/gpt-5.4-mini",
)
```

You can point `api_base` at any OpenAI-compatible endpoint: local models, Azure, your own proxy. The compiled Rust subsystems don't use LLMs. They run deterministic algorithms.
