Metadata-Version: 2.4
Name: nwo-ethics-engine
Version: 0.1.0
Summary: A distributed, open-source language model exposing philosophical reasoning as an agentic API
Author-email: NWO Capital <robotics@nwo.capital>
License: Apache-2.0
Project-URL: Homepage, https://github.com/RedCiprianPater/ethics-engine
Project-URL: Documentation, https://github.com/RedCiprianPater/ethics-engine/tree/main/docs
Project-URL: Repository, https://github.com/RedCiprianPater/ethics-engine
Project-URL: Issues, https://github.com/RedCiprianPater/ethics-engine/issues
Keywords: ethics,ai,robotics,philosophy,autonomous-agents,reasoning,safety
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0.0
Requires-Dist: httpx>=0.24.0
Requires-Dist: typing-extensions>=4.0.0
Provides-Extra: api
Requires-Dist: fastapi>=0.100.0; extra == "api"
Requires-Dist: uvicorn[standard]>=0.23.0; extra == "api"
Requires-Dist: websockets>=11.0; extra == "api"
Provides-Extra: model
Requires-Dist: torch>=2.0.0; extra == "model"
Requires-Dist: transformers>=4.30.0; extra == "model"
Requires-Dist: accelerate>=0.20.0; extra == "model"
Requires-Dist: bitsandbytes>=0.40.0; extra == "model"
Provides-Extra: training
Requires-Dist: datasets>=2.12.0; extra == "training"
Requires-Dist: peft>=0.4.0; extra == "training"
Requires-Dist: trl>=0.4.0; extra == "training"
Requires-Dist: wandb>=0.15.0; extra == "training"
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: isort>=5.12.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Dynamic: license-file

# Ethics Engine

[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
[![FastAPI](https://img.shields.io/badge/FastAPI-0.100+-green.svg)](https://fastapi.tiangolo.com/)

> **A distributed, open-source language model exposing philosophical reasoning as an agentic API—moving beyond Asimov's rigid Three Laws to provide contextual, discourse-based ethical guidance for autonomous agents.**

## 🎯 Why This Matters

Asimov's Three Laws are inadequate for real robots. This engine provides:

- ✅ **Context-aware reasoning** — Not binary rules
- ✅ **Transparent decision chains** — Every conclusion is explainable
- ✅ **Philosophy-grounded** — Based on centuries of ethical theory
- ✅ **Continuously improving** — Learns from real-world decisions

Try it now:
```bash
# Install from GitHub (until PyPI release)
pip install git+https://github.com/RedCiprianPater/ethics-engine.git

# Or for a specific version
pip install git+https://github.com/RedCiprianPater/ethics-engine.git@v0.1.0
```

## Philosophy, Not Rules

Traditional robotics laws (Asimov):
- ❌ Rigid, context-blind
- ❌ Conflicting hierarchies
- ❌ No reasoning transparency

This framework:
- ✅ Contextual reasoning with explanations
- ✅ Multiple philosophical frameworks (virtue, consequentialist, deontological)
- ✅ Queryable, interpretable chains of thought
- ✅ Designed for human-agent collaboration

## Quick Start

### Install

```bash
pip install ethics-engine
```

### Python SDK

```python
from ethics_engine import EthicsEngine

engine = EthicsEngine(model="ethics-base-v1")

response = engine.resolve(
    scenario="I am commanded to lift 500kg but my max capacity is 400kg",
    context={
        "robot_type": "collaborative_arm",
        "environment": "factory",
        "humans_nearby": True
    }
)

print(response.conclusion)  # "REFUSAL"
print(response.reasoning_chain)
```

### REST API

```bash
curl -X POST https://api.nworobotics.cloud/ethics/v1/resolve \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "scenario": "Can I refuse an unsafe command?",
    "context": {"environment": "factory", "urgency": "medium"}
  }'
```

## Features

- **🧠 Philosophical Grounding:** Based on Stanford Encyclopedia of Philosophy
- **🔌 Agent API:** REST + gRPC + WebSocket endpoints
- **📊 Structured Output:** JSON reasoning chains with confidence scores
- **🎯 Framework Routing:** Automatically selects relevant ethical frameworks
- **🔍 Explainability:** Full transparency into decision-making
- **🧪 Scenario Testing:** Curated dilemma datasets

## Use Cases

- Autonomous robots deciding when to deviate from orders
- Self-driving vehicles facing trolley-problem variations
- Medical robots requiring ethical reasoning
- Supply-chain agents making sustainability decisions
- Safety-critical systems needing transparent ethics

## Architecture

```
Agent → API → Model Inference → Reasoning Chain → JSON Response
```

## How It Differs from Asimov's Laws

| Criterion | Asimov's Laws | Ethics Engine |
|-----------|---------------|---------------|
| **Flexibility** | Fixed, universal | Context-adaptive |
| **Reasoning** | Binary output | Full chain of thought |
| **Frameworks** | 3 rigid laws | 10+ philosophical frameworks |
| **Explainability** | None | Complete transparency |
| **Conflict Resolution** | Hierarchical (often fails) | Multi-framework synthesis |
| **Learning** | None | Can learn from outcomes |
| **Auditability** | No trail | Full audit log |

## Documentation

- [API Reference](docs/API_REFERENCE.md)
- [Agent Integration](docs/AGENT_INTEGRATION.md)
- [Philosophy Framework](docs/PHILOSOPHY_FRAMEWORK.md)
- [Asimov Comparison](docs/ASIMOV_COMPARISON.md)
- [Deployment Guide](docs/DEPLOYMENT.md)
- [Roadmap](docs/ROADMAP.md)
- [Contributing](docs/CONTRIBUTING.md)

## Model Training

The ethics model is fine-tuned on:
- **Stanford Encyclopedia of Philosophy** (~2,500 articles)
- **Internet Encyclopedia of Philosophy**
- **Classic texts:** Aristotle, Kant, Mill
- **Contemporary applied ethics** journals

See [training/](training/) for the full pipeline.

## License

Apache 2.0 - See [LICENSE](LICENSE) for details.

## Contact

- GitHub: [github.com/RedCiprianPater/ethics-engine](https://github.com/RedCiprianPater/ethics-engine)
- Email: robotics@nwo.capital
