magi-core
LLM-agnostic multi-perspective analysis system in Rust, inspired by the MAGI supercomputers from Neon Genesis Evangelion.
Three independent agents analyze content from complementary perspectives, then a consensus engine synthesizes their verdicts into a unified report.
"No single perspective is sufficient for good decision-making under uncertainty." See docs/MAGI-System-Documentation.md for the complete origin story, design philosophy, and Evangelion correspondence table.
| Agent | Codename | Perspective |
|---|---|---|
| Melchior | Scientist | Technical rigor & correctness |
| Balthasar | Pragmatist | Practicality & maintainability |
| Caspar | Critic | Risk, edge cases & failure modes |
Features
- LLM-agnostic — bring your own provider via the
LlmProvidertrait - Parallel execution — agents run concurrently via
tokio::spawnwithAbortGuardcancellation - Graceful degradation — if one agent fails, the remaining two still produce a result
- Weighted consensus — approve (+1), conditional (+0.5), reject (-1) scoring with epsilon-aware classification
- Finding deduplication — merges duplicate findings across agents, promotes severity
- Retry with backoff — opt-in
RetryProviderwrapper with exponential backoff - Feature-gated providers —
claude-api(HTTP) andclaude-cli(subprocess) ship as optional features - Zero unsafe in library code —
#![forbid(unsafe_code)]safe by design
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["rt-multi-thread", "macros"] }
# Enable one or both built-in providers:
# magi-core = { version = "0.1", features = ["claude-cli"] }
# magi-core = { version = "0.1", features = ["claude-api"] }
Basic Usage
use *;
use Arc;
async
With Builder
use *;
use Arc;
use Duration;
# async
Using the Built-in Claude CLI Provider
use *;
use Arc;
#
# async
Architecture
+-----------+
| Magi | Orchestrator
+-----+-----+
|
+-----------+-----------+
| | |
+----+----+ +----+----+ +----+----+
| Melchior| |Balthasar| | Caspar | Agents (parallel)
+----+----+ +----+----+ +----+----+
| | |
+-----+-----+-----+-----+
| |
+-----+-----+ +------+------+
| Validator | | Consensus |
+-----------+ +------+------+
|
+------+------+
| Reporting |
+-------------+
Module Dependency Graph
error (foundation — no internal deps)
schema (domain types: Verdict, Severity, Mode, AgentName, Finding, AgentOutput)
validate (field validation with regex zero-width stripping)
consensus (weighted scoring, classification, finding dedup)
reporting (ASCII banner + markdown report generation)
provider (LlmProvider trait, CompletionConfig, RetryProvider)
agent (Agent struct, AgentFactory, system prompt loading)
orchestrator (Magi, MagiBuilder — composes everything)
providers/
claude [feature: claude-api] — HTTP via reqwest
claude_cli [feature: claude-cli] — subprocess via tokio::process
Consensus Labels
| Score | Condition | Label |
|---|---|---|
| 1.0 | Unanimous approve | STRONG GO |
| > 0 | Has conditionals | GO WITH CAVEATS |
| > 0 | No conditionals | GO (N-M) |
| 0 | Tie | HOLD -- TIE |
| < 0 | Mixed | HOLD (N-M) |
| -1.0 | Unanimous reject | STRONG NO-GO |
In degraded mode (2/3 agents), STRONG labels are capped to their regular counterparts.
Implementing a Custom Provider
use *;
use async_trait;
;
The agent expects a JSON response matching the AgentOutput schema:
Feature Flags
| Feature | Default | Description |
|---|---|---|
claude-api |
off | HTTP provider via reqwest |
claude-cli |
off | Subprocess provider via tokio::process |
The core library (orchestrator, consensus, reporting, validation) compiles with no optional features enabled.
Example
# Run the included example with the CLI provider
# JSON output
Minimum Supported Rust Version
This crate uses Rust edition 2024 and requires Rust 1.91+.
License
Licensed under either of
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.