Metadata-Version: 2.4
Name: mgia
Version: 0.2.1
Summary: MGIA 4.0 — Strategic Macro-Geopolitical Intelligence OS (autonomous agent)
Author-email: ooopalladiumsb <ooopalladiumsb@gmail.com>
License-Expression: BUSL-1.1
Project-URL: Homepage, https://github.com/ooopalladiumsb/magi
Project-URL: Repository, https://github.com/ooopalladiumsb/magi
Project-URL: Issues, https://github.com/ooopalladiumsb/magi/issues
Project-URL: Changelog, https://github.com/ooopalladiumsb/magi/blob/main/CHANGELOG.md
Keywords: geopolitics,intelligence,scenario-analysis,bayesian,llm
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic<3.0,>=2.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-cov>=5.0; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Requires-Dist: mypy>=1.10; extra == "dev"
Requires-Dist: build>=1.0; extra == "dev"
Dynamic: license-file

# MGIA 4.0 — Strategic Macro-Geopolitical Intelligence OS

[![CI](https://github.com/ooopalladiumsb/magi/actions/workflows/ci.yml/badge.svg)](https://github.com/ooopalladiumsb/magi/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/ooopalladiumsb/magi/branch/main/graph/badge.svg)](https://codecov.io/gh/ooopalladiumsb/magi)
![python](https://img.shields.io/badge/python-3.12-blue)
![license](https://img.shields.io/badge/license-BUSL--1.1-blue)

Autonomous intelligence agent built on the principle:

> The LLM is not the system's intelligence. It is an analytical interface over an intelligence
> infrastructure. `DATA → EVIDENCE → CAUSALITY → SCENARIOS → ADVERSARIAL → MEMORY → ANALYSIS`

See `ARCHITECTURE.md` for the full technical reference and `magi v4.txt` for the source spec.

## Status

**v0.2.1** — platform complete, first PyPI release. All 6 layers + orchestration, governance,
observability, live data, and delivery surfaces. **233 tests passing** (ruff + mypy clean).

| Layer / Component | Status |
|-------------------|--------|
| L1 Data Collection (JSON file · RSS/Atom · JSON-API/NewsAPI · Reddit · GDELT) | ✅ |
| L2 Trust & Validation | ✅ |
| L3 Causal Intelligence | ✅ |
| L4 Scenario Intelligence | ✅ |
| L5 Institutional Memory | ✅ |
| L6 Strategic Analysis (Mock + real DeepSeek/OpenAI-compat LLM) | ✅ |
| Observability + Governance engines | ✅ |
| Master Orchestrator + CLI | ✅ |
| Reproducibility cache · fault-tolerant collection | ✅ |
| HTTP serve (auth · rate-limit · HTML dashboard) | ✅ |
| Report export (Markdown · HTML · PDF) | ✅ |
| Packaged wheel/sdist (BUSL-1.1) | ✅ |

## Verified on a live provider

In addition to the mock-based automated test suite, MGIA has been
validated end-to-end against a live DeepSeek endpoint.

The validation exercised the complete six-layer pipeline, including
governance (`validated=True`). Numerical metrics (including confidence)
are produced deterministically by the pipeline, while the LLM is used
only to generate the narrative report.

See [`docs/live-smoke-v0.2.1.md`](docs/live-smoke-v0.2.1.md).

## Quickstart

```bash
cd projects/magi
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"          # or: make install
python -m pytest -q               # 233 tests
```

## CLI Usage

```bash
# Ask a strategic question (full 6-layer pipeline)
python -m mgia ask "What are the implications of BRICS expansion?"

# Deployment mode / output formats
python -m mgia ask "Question?" --mode institutional
python -m mgia ask "Question?" -f json
python -m mgia ask "Question?" -f html -o report.html
python -m mgia ask "Question?" -f pdf  -o report.pdf

# Load a config file (live feeds, cache, source APIs, LLM provider)
python -m mgia --config examples/config.json ask "Question?"

# Reproducibility check (same input twice)
python -m mgia --config examples/config.json verify "Question?"

# System status / institutional memory / governance lint
python -m mgia status
python -m mgia memory
python -m mgia lint

# HTTP API (optional auth + rate limit); dashboard at /dashboard
python -m mgia --config examples/config.json serve --port 8080 \
    --token "$MGIA_API_TOKEN" --rate-limit 60

# Version
python -m mgia --version
```

Real LLM (DeepSeek / OpenAI-compatible): set `MGIA_LLM_API_KEY` (or `DEEPSEEK_API_KEY`)
and use `--config examples/config.deepseek.json`.

## Python API

```python
from mgia.config import MGIAConfig, DeploymentMode
from mgia.orchestrator import MGIA

# Initialise with defaults
mgia = MGIA()

# Full pipeline
report, markdown = mgia.ask("What are the implications of BRICS expansion?")
print(report.confidence_summary.overall_confidence)
print(markdown[:200])

# System status
status = mgia.status()
print(status["layers"])

# Governance checks
lint = mgia.lint()
print(lint["all_passed"])

# Memory summary
mem = mgia.memory_status()
print(mem["learning_count"], "learnings stored")
```

## Deployment Modes

| Mode | Red Team | Scenario Killers | Governance |
|------|----------|-----------------|------------|
| `calibration` | 50% | aggressive | relaxed |
| `standard` | 35% | normal | relaxed |
| `institutional` | 100% | mandatory | strict |

## Configuration

Via `MGIAConfig` (pydantic model, load from JSON, env vars, or defaults):

```python
from mgia.config import MGIAConfig, DeploymentMode

config = MGIAConfig(
    mode=DeploymentMode.STANDARD,
    data_dir="examples",
    memory_path="memory/custom_memory.json",
    log_dir="reports/logs",
)

# Or from environment variables: MGIA_MODE, MGIA_DATA_DIR, etc.
config = MGIAConfig.from_env()

# Or from file:
config = MGIAConfig.from_file("config.json")
```

## Project Structure

```
projects/magi/
  ARCHITECTURE.md            Technical reference
  IMPLEMENTATION_PLAN.md     Step-by-step build plan
  magi v4.txt                Source specification (frozen)
  README.md                  This file
  pyproject.toml             Package metadata + CLI entry point
  LICENSE                    Business Source License 1.1
  CHANGELOG.md               Release notes
  Makefile                   test / lint / typecheck / run / serve / build
  mgia/
    __init__.py              __version__
    config.py                MGIAConfig, DeploymentMode, LLMConfig
    orchestrator.py          MGIA — master orchestrator
    cli.py                   CLI: ask, status, memory, lint, verify, serve
    server.py                HTTP API (serve) + dashboard + auth/rate-limit
    report_export.py         Markdown/HTML/PDF export
    observability.py         ObservabilityEngine, MetricsCollector
    governance.py            GovernanceEngine, GovernancePolicy
    layer1_data/             Sources (file · RSS · JSON-API/NewsAPI · Reddit · GDELT · cache), collector
    layer2_trust/            Source trust, data quality, bias auditor
    layer3_causal/           Event graph engine, confidence, builder
    layer4_scenario/         Bayesian, adversarial, scenario killer, orchestrator
    layer5_memory/           Pattern store, learning loop, persistence
    layer6_strategic/        LLM interface (Mock + OpenAICompatBrain), report builder
  examples/                  config.json, config.deepseek.json, config.live.json, …
  tests/                     test suite
```

## License

MGIA 4.0 is licensed under the **Business Source License 1.1** (BUSL-1.1) — see
[`LICENSE`](./LICENSE).

- Source-available: you may **copy, modify, and make non-production use** freely.
- **Production use requires a commercial license** from the Licensor (ooopalladiumsb)
  until the Change Date — *Additional Use Grant: None*.
- On the **Change Date (2030-07-08)**, each released version automatically converts to
  the **Apache License 2.0**.

For commercial-license inquiries, contact the Licensor.
