Metadata-Version: 2.5
Name: nacra
Version: 0.1.0.dev0
Summary: An open, agent-native control plane for agent evaluation and data generation runs.
Project-URL: Homepage, https://github.com/mendotaAI/nacra
Project-URL: Repository, https://github.com/mendotaAI/nacra
Project-URL: Issues, https://github.com/mendotaAI/nacra/issues
Author: Mendota AI
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agents,benchmarks,evaluation,harbor,mcp,rollouts
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.11
Requires-Dist: blake3>=1.0
Requires-Dist: cel-python>=0.5
Requires-Dist: duckdb>=1.1
Requires-Dist: fastapi>=0.115
Requires-Dist: httpx>=0.27
Requires-Dist: mcp<3,>=2.3
Requires-Dist: opendal>=0.46
Requires-Dist: pyarrow>=17
Requires-Dist: pydantic>=2.7
Requires-Dist: pyyaml>=6.0
Requires-Dist: pyzstd>=0.16
Requires-Dist: typer>=0.12
Requires-Dist: uvicorn>=0.30
Description-Content-Type: text/markdown

<p align="center">
  <img src="docs/assets/nacra-logo.png" alt="Nacra — Open-Source Control Plane for Agent Evaluation &amp; RL Environments" width="640">
</p>

<p align="center">
  <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache_2.0-0F4D92.svg" alt="License: Apache 2.0"></a>
  <img src="https://img.shields.io/badge/Python-3.11%2B-1D7A85.svg" alt="Python 3.11+">
  <img src="https://img.shields.io/badge/MCP-Native-23733B.svg" alt="MCP Native">
  <img src="https://img.shields.io/badge/Adapters-Harbor%20%7C%20OpenEnv%20%7C%20NeMo%20Gym-334155.svg" alt="Native Adapters">
</p>

<p align="center">
  <strong>Nacra</strong> is a lightweight, open-source control plane that decouples large-scale AI agent evaluation and reinforcement learning (RL) rollout generation from GPU inference and training.
</p>

<p align="center">
  <a href="#why-nacra">Why Nacra</a> &bull;
  <a href="#architecture">Architecture</a> &bull;
  <a href="#quickstart">Quickstart</a> &bull;
  <a href="#connect-ai-coding-agents-mcp">MCP Agents</a> &bull;
  <a href="#native-adapters">Adapters</a> &bull;
  <a href="#benchmarks">Benchmarks</a> &bull;
  <a href="#documentation">Docs</a> &bull;
  <a href="#citation">Citation</a>
</p>

---

## Why Nacra?

Open-source infrastructure for GPU model serving ([vLLM](https://github.com/vllm-project/vllm), [SGLang](https://github.com/sgl-project/sglang)) and distributed RL training ([verl](https://github.com/volcengine/verl), [OpenRLHF](https://github.com/OpenRLHF/OpenRLHF), [AReaL](https://github.com/inclusionAI/AReaL), [slime](https://github.com/THUDM/slime)) has matured rapidly. Yet the layer that executes interactive agent environments at scale—scheduling trials across heterogeneous compute and sandboxes, isolating infrastructure faults from model failures, catching reward hacking, versioning tasks, preventing credential leaks, and turning raw trajectories into queryable training datasets—still relies on brittle shell scripts and ad hoc log folders.

**Nacra** fills that gap with a single, deterministic, policy-neutral control plane:

- **Deterministic state, never in an agent's context:** A single control-plane daemon (`nacrad`) backed by SQLite WAL and an append-only, BLAKE3 hash-chained event log owns all runs, leases, verdicts, and decisions. Idempotent `op_id` deduplication and fenced leases keep execution crash-safe.
- **Uniform Human & AI Agent Control (CLI / HTTP / MCP):** Humans operate via the `nacra` CLI/HTTP API; AI coding agents (Claude Code, Codex, Gemini CLI) connect via a compact, role-filtered **22-tool MCP interface** with untrusted-text wrapping and **10 human-only ratification/approval gates**.
- **Honest Verdicts & Reward-Hacking Remediation:** A six-state verdict machine (`GENUINE_PASS`, `GENUINE_FAIL`, `PENDING`, `VOID`, `INFRA`, `STALE`) enforces in code that infrastructure faults, voided exploits, and stale runs carry **`reward = None`** (never `0`). Combine deterministic human-authored [CEL](https://cel.dev) policies with MCP-connected LLM judge agents to detect, quarantine, and patch reward hacking end to end.
- **Git-Subtree Task Versioning:** Tasks live in a bare Git repository decomposed into logical subtrees. Editing a task's test suite automatically marks dependent historical trials `STALE`, while editing reference solutions preserves valid agent evidence.
- **Secret-Scrubbed, Seekable Rollout Storage:** Workers inject leased credentials into read-only `tmpfs`, scrub spools against multi-encoding secret canaries before upload, pack rollouts into seekable `tar.zst` + BLAKE3 CAS bundles over [Apache OpenDAL](https://opendal.apache.org/) (local FS, S3, R2, GCS, B2), and materialize a rebuildable **Parquet / DuckDB** catalog.
- **Zero-Fork Native Adapters:** Ships native built-in JSON-RPC 2.0 adapters for **[Harbor](https://github.com/laude-institute/harbor)**, **[OpenEnv](https://github.com/meta-pytorch/OpenEnv)**, **[NVIDIA NeMo Gym](https://github.com/NVIDIA-NeMo/Gym)**, and arbitrary shell commands—plus a 294-LOC zero-dependency Python SDK (`nacra.sdk`) for custom harnesses.

---

## Architecture

<p align="center">
  <img src="docs/assets/architecture.png" alt="Nacra System Architecture" width="100%">
</p>

### Domain-Agnostic Task & Reward-Hacking Auditing

Nacra separates scheduling and storage from evaluation semantics, letting teams layer human-authored CEL policies and MCP-connected LLM judge agents across **Software & Coding**, **Science & Research**, **Physical Engineering (CAD)**, and **Knowledge Work (Legal, Finance, Docs)**:

<p align="center">
  <img src="docs/assets/policy-audit.png" alt="Domain-Agnostic Task and Data-Quality Auditing" width="100%">
</p>

---

## Quickstart

Runs locally on macOS or Linux with Python 3.11+ and `git`—no GPU, no container daemon, and no external API keys required for the built-in walkthrough.

### 1. Install

```bash
# Using uv (recommended)
uv tool install git+https://github.com/mendotaAI/nacra.git

# Or from a local clone for development
git clone https://github.com/mendotaAI/nacra.git
cd nacra
uv sync
source .venv/bin/activate
```

### 2. Initialize, Start Control Plane & Worker, and Run a Campaign

```bash
# 1. Initialize ~/.nacra and create your owner token (chmod 0600)
nacra init --token-file ~/.nacra/owner.token

cat > ~/.nacra/config.yaml <<'YAML'
client: {token_file: owner.token}
worker: {command_allow: [python3]}
YAML

# 2. Start the control plane (HTTP /v1 + MCP /mcp on 127.0.0.1:7733)
nacra serve &

# 3. Mint a worker token and start a local dial-out worker
nacra token create --role worker --token-file ~/.nacra/worker.token
nacra worker --token-file ~/.nacra/worker.token &

# 4. Copy bundled examples, import a task, load example CEL policies, and run a campaign
nacra examples ./nacra-examples
nacra task import ./nacra-examples/tasks/hello --name hello
nacra policy put ./nacra-examples/policies/*.cel

nacra campaign apply ./nacra-examples/campaign.yaml           # dry-run plan
nacra campaign apply ./nacra-examples/campaign.yaml --apply   # launch trials

# 5. Inspect progress and query rollouts with DuckDB SQL
nacra brief
nacra query "SELECT arm, verdict, COUNT(*) FROM trials WHERE state != 'cancelled' GROUP BY ALL"
```

---

## Connect AI Coding Agents (MCP)

Always issue a **least-privilege sub-token** for AI agents—never pass your owner token. Agents with the `controller` or `auditor` role can plan campaigns, stream events, inspect rollouts, and propose verdicts/decisions, but **cannot** ratify verdicts, approve plans, mint tokens, or overwrite guarded policies.

```bash
nacra token create --role controller --agent claude --harness claude-code \
  --token-file ~/.nacra/agents/claude-code.token

claude mcp add --transport http nacra http://127.0.0.1:7733/mcp \
  --header "Authorization: Bearer $(cat ~/.nacra/agents/claude-code.token)"
```

Run `nacra hookup` to print ready-to-paste MCP configuration snippets for **Claude Code**, **Codex**, **Gemini CLI**, and stdio clients.

---

## Native Adapters

Nacra wraps external evaluation harnesses and RL environment servers over a simple JSON-RPC 2.0 stdio protocol (`describe`, `prepare`, `run`, `collect`, `classify`, `shutdown`) without forking them:

| Adapter | Target Ecosystem | Built-in | Sandboxes / Runtime |
| --- | --- | :---: | --- |
| `harbor` | [Harbor](https://github.com/laude-institute/harbor) / Terminal-Bench | Yes | Docker, Podman, EC2, Modal |
| `openenv` | [OpenEnv](https://github.com/meta-pytorch/OpenEnv) (`reset`/`step`) | Yes | OCI containers / HTTP-WS |
| `nemogym` | [NVIDIA NeMo Gym](https://github.com/NVIDIA-NeMo/Gym) | Yes | Microservice / shared server |
| `command` | Any CLI executable writing `result.json` | Yes | Local / custom sandbox |
| Custom (`nacra.sdk`) | Your own harness (294-LOC zero-dep SDK) | Extensible | Any worker host |

---

## Benchmarks

Empirically validated on a single `nacrad` control-plane process (SQLite WAL, `FULL` synchronous mode) and a 7-layout rollout storage suite:

| Dimension | Measured Result |
| --- | --- |
| **Sustained Throughput** | **344 commits/min** (40-min soak, 6 slots, 3×1 Hz concurrent readers) |
| **Memory Stability** | **591 MB** peak RSS (1.08 MB/min tail slope with glibc allocator tuning) |
| **Rollout Compression** | **5.61×** smaller (`tar.zst` + compressed CAS: 705.9 MB → 125.9 MB) |
| **RL Training Scan (Parquet/DuckDB)** | **5× fewer bytes**, **9× faster** (7.4 MB / 47 ms vs. 37.6 MB / 432 ms) |
| **Per-Token Logprob Storage** | **16.4×** smaller (14.7 MB → 0.90 MB via BSS `float16` + zstd) |
| **Security & RBAC Audit** | **2,144 / 2,144** HTTP RBAC calls + **15 / 15** MCP role columns, **0 mismatches** |
| **Newcomer Onboarding** | **15.4 s** from `nacra init` to first `GENUINE_PASS` |

---

## Documentation

- [**Operator Guide**](docs/OPERATOR_GUIDE.md) — Full CLI, configuration, multi-host deployment, TLS/reverse proxy, and troubleshooting reference
- [**Architecture**](docs/architecture.md) — Control plane, worker lifecycle, fenced leases, and storage layout
- [**Design Specification**](docs/design.md) — Event log, verdict state machine, CEL policy hooks, and adapter contract
- [**Interfaces**](docs/INTERFACES.md) — HTTP `/v1`, MCP tool schemas, and JSON-RPC adapter protocol
- [**Examples**](examples/README.md) — Sample tasks, campaigns, CEL policies, and custom adapter templates

---

## Development & Testing

```bash
uv sync --all-groups
uv run ruff check src tests
uv run pytest -q
```

---

## Citation

If you use Nacra in your research or evaluation infrastructure, please cite:

```bibtex
@inproceedings{gao2027nacra,
  title     = {Nacra: Toward Large-Scale, Open-Source Infrastructure for Agent Evaluation and RL Environments},
  author    = {Gao, Yuan and Li, Junnan and Yi, Yongzhe Kindred and Sha, TianMing and Tang, Yanchuan and Li, Anhao and Liu, Ziqi and Sun, Zhaoting and Yang, Zeren},
  year      = {2027},
  note      = {Open-source software: \url{https://github.com/mendotaAI/nacra}}
}
```

---

## Contributing & License

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).

Nacra is released under the **Apache License 2.0**. See [LICENSE](LICENSE) for details.
