Metadata-Version: 2.4
Name: btcu-harness
Version: 1.3.0
Summary: Balanced Ternary Cognitive Unit Harness - A cognitive architecture for LLM-based agents
Author: BTCU Harness Contributors
License-Expression: MIT
Project-URL: Homepage, https://github.com/q1z2q3-debug/btcu-harness
Project-URL: Repository, https://github.com/q1z2q3-debug/btcu-harness
Project-URL: Documentation, https://github.com/q1z2q3-debug/btcu-harness#readme
Project-URL: Issues, https://github.com/q1z2q3-debug/btcu-harness/issues
Project-URL: Changelog, https://github.com/q1z2q3-debug/btcu-harness/releases
Keywords: ternary,cognitive-architecture,agent,LLM,balanced-ternary,cognition,ai,memory-ecology,third-choice,emergent-semantics
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
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
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0
Requires-Dist: pydantic-settings>=2.0
Provides-Extra: openai
Requires-Dist: openai>=1.0; extra == "openai"
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.20; extra == "anthropic"
Provides-Extra: gemini
Requires-Dist: google-genai>=0.5; extra == "gemini"
Provides-Extra: llm
Requires-Dist: openai>=1.0; extra == "llm"
Requires-Dist: anthropic>=0.20; extra == "llm"
Requires-Dist: google-genai>=0.5; extra == "llm"
Provides-Extra: mongo
Requires-Dist: pymongo>=4.0; extra == "mongo"
Provides-Extra: api
Requires-Dist: fastapi>=0.100; extra == "api"
Requires-Dist: uvicorn[standard]>=0.20; extra == "api"
Provides-Extra: langchain
Requires-Dist: langchain>=0.2; extra == "langchain"
Requires-Dist: langchain-openai>=0.1; extra == "langchain"
Provides-Extra: docs
Requires-Dist: mkdocs>=1.5; extra == "docs"
Requires-Dist: mkdocs-material>=9.0; extra == "docs"
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: pytest-benchmark>=4.0; extra == "dev"
Requires-Dist: httpx>=0.24; extra == "dev"
Provides-Extra: all
Requires-Dist: openai>=1.0; extra == "all"
Requires-Dist: anthropic>=0.20; extra == "all"
Requires-Dist: google-genai>=0.5; extra == "all"
Requires-Dist: pymongo>=4.0; extra == "all"
Requires-Dist: fastapi>=0.100; extra == "all"
Requires-Dist: uvicorn[standard]>=0.20; extra == "all"
Requires-Dist: mkdocs>=1.5; extra == "all"
Requires-Dist: mkdocs-material>=9.0; extra == "all"
Requires-Dist: mkdocstrings[python]>=0.24; extra == "all"
Dynamic: license-file

# BTCU Harness

**Balanced Ternary Cognitive Unit Harness** — A cognitive architecture for LLM-based agents built on balanced ternary logic {-1, 0, +1}.

[![CI](https://github.com/q1z2q3-debug/btcu-harness/actions/workflows/ci.yml/badge.svg)](https://github.com/q1z2q3-debug/btcu-harness/actions)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![PyPI](https://img.shields.io/pypi/v/btcu-harness.svg)](https://pypi.org/project/btcu-harness/)
[![Tests](https://img.shields.io/badge/tests-336%20passed%20%7C%201%20skipped-brightgreen.svg)](#)

---

## What is BTCU?

BTCU Harness introduces a **structured, interpretable, and evolvable cognitive layer** between large language models (LLMs) and autonomous agents.

Instead of treating the agent's "mind" as an unstructured text buffer, BTCU provides:

- **19,683 discrete cognitive states** — completely enumerable, navigable, and comparable
- **Intrinsic transformation** — the VOID state encodes change itself (-1+1=0)
- **Emergent semantics** — state meanings arise from experience, never preset
- **Four-layer memory ecology** — episodic, procedural, capability, and biographical
- **Third-choice synthesis** — generates creative alternatives beyond binary conflicts
- **Growth model** — school → internalize → graduate, progressively reducing LLM dependency

## Installation

```bash
pip install btcu-harness

# With LLM providers
pip install "btcu-harness[openai]"      # OpenAI GPT
pip install "btcu-harness[anthropic]"   # Anthropic Claude
pip install "btcu-harness[gemini]"      # Google Gemini

# With REST API
pip install "btcu-harness[api]"

# With MongoDB
pip install "btcu-harness[mongo]"

# Everything
pip install "btcu-harness[all]"
```

## Quick Example

```python
from btcu_harness.agent import BTCUAgent
from btcu_harness.core.state import CognitiveState
from btcu_harness.llm.bridge import LLMBridge

# Create agent with callback (no API key needed for testing)
agent = BTCUAgent(growth_stage="school")
agent.init_project(
    domain="custom",
    dim_labels=["Speed", "Quality", "Cost", "Risk", "Innovation",
                "Team", "Deadline", "Scope", "Impact"],
)

# Process input
response = agent.process("Should we prioritize speed?")
print(f"State #{response.current_state.index}")
print(f"Polarity: {response.current_state.polarity}")
print(f"Self alignment: {response.self_alignment:.1%}")
```

Or run the quickstart script (no API key needed):

```bash
python examples/quickstart.py
```

## REST API

```bash
pip install "btcu-harness[api]"
uvicorn btcu_harness.api:app --port 8000
```

Endpoints: `POST /api/init`, `POST /api/project`, `GET /api/status`, `GET /api/explore`, and more. Interactive OpenAPI docs at `http://localhost:8000/docs`.

Or with Docker:

```bash
docker compose up
```

## Architecture

```
btcu_harness/
├── core/              # Trit, CognitiveState (19,683 states), CognitiveSpace
├── mapping/           # DimensionAdapter, InputProjector, PatternLearner
├── memory/            # StateMemory, TransitionMemory, Ecology, Trajectory, Climate
├── decision/          # Pathfinder, ThirdChoiceGenerator
├── self_layer/        # NLPSelfLayer (Dilts 8-level identity model)
├── llm/               # Multi-provider bridge (OpenAI/Claude/Gemini)
├── storage/           # PersistenceLayer (JSON), MongoPersistence (MongoDB)
├── api.py             # FastAPI REST interface
├── cli.py             # Command-line interface
└── agent.py           # BTCUAgent orchestrator
```

## Documentation

- [Quickstart](docs/quickstart.md) — 5-minute tutorial
- [Architecture](docs/architecture.md) — System design
- [Philosophy](docs/philosophy.md) — Dao, emptiness, and information theory
- [REST API](docs/rest_api.md) — Complete API reference
- [Paper](docs/BTCU_Harness_Paper_v1.0.md) — Full academic paper

## Configuration

All via environment variables with `BTCU_` prefix:

```bash
BTCU_LLM_PROVIDER=openai          # openai / anthropic / gemini
BTCU_LLM_API_KEY=sk-...
BTCU_LLM_MODEL=gpt-4o-mini
BTCU_MONGO_URI=mongodb://localhost:27017
```

Or use a `.env` file.

## Testing

```bash
pip install "btcu-harness[dev]"
pytest tests/ -v
```

## License

MIT License
