nkshirsa's picture
Add ECC Harness: phd_research_os/ARCHITECTURE.md
dd0b0be verified
# PhD Research OS β€” Architecture Map
> **WAKE-UP INSTRUCTION**: This file is the ground truth for all file locations,
> API configurations, and system topology. Read this FIRST before touching anything.
## System Topology
```
phd-research-os-brain/
β”œβ”€β”€ ARCHITECTURE.md ← YOU ARE HERE (project map)
β”œβ”€β”€ AGENTS.md ← Agent role registry & contracts
β”œβ”€β”€ MEMORY.md ← Persistent cross-session state
β”œβ”€β”€ plan.md ← Current task plan (mutable)
β”œβ”€β”€ HARNESS_EVOLUTION.md ← ECC rule amendments log
β”‚
β”œβ”€β”€ train.py ← SFT training script (Qwen2.5-3B + QLoRA)
β”œβ”€β”€ generate_dataset.py ← Synthetic dataset generator (1900 examples)
β”‚
β”œβ”€β”€ phd_research_os/ ← CORE PACKAGE
β”‚ β”œβ”€β”€ __init__.py ← v1.0.0
β”‚ β”œβ”€β”€ db.py ← SQLite data layer (Phase 0)
β”‚ β”‚ Tables: claims, sources, goals, conflicts,
β”‚ β”‚ decisions, overrides, experiments,
β”‚ β”‚ api_usage_log, calibration_log, embedding_cache
β”‚ β”‚ + companion_agents, agent_tasks, agent_audit_log
β”‚ β”œβ”€β”€ agents.py ← Original 6-role AI brain (ResearchOSBrain)
β”‚ β”œβ”€β”€ agent_os.py ← ECC HARNESS ORCHESTRATOR (companion AI factory)
β”‚ β”‚ CompanionAgent lifecycle: spawn β†’ preflight β†’
β”‚ β”‚ plan β†’ execute β†’ postflight β†’ retire
β”‚ β”œβ”€β”€ pipeline.py ← Paper ingestion (PDF β†’ claims)
β”‚ β”œβ”€β”€ obsidian_export.py ← Obsidian vault export (one-directional)
β”‚ β”œβ”€β”€ evaluation.py ← Golden dataset eval harness + regression gate
β”‚ β”œβ”€β”€ conflict_detector.py ← Pairwise contradiction detection
β”‚ └── backup.py ← SQLite backup & restore
β”‚
β”œβ”€β”€ tests/
β”‚ β”œβ”€β”€ test_db.py ← 22 unit tests (data layer)
β”‚ └── test_agent_os.py ← ECC harness integration tests
β”‚
└── output/
└── research_os/
└── db.py ← Symlink/alias β†’ phd_research_os/db.py
```
## API Configuration
| Provider | Env Variable | Default Model | Use Case |
|----------|-------------|---------------|----------|
| Anthropic | `ANTHROPIC_API_KEY` | claude-sonnet-4-20250514 | Primary brain + companion agents |
| OpenAI | `OPENAI_API_KEY` | gpt-4o-mini | Fallback |
| OpenRouter | `OPENROUTER_API_KEY` | (configurable) | Multi-model companion agents |
| HF Local | (model path) | nkshirsa/phd-research-os-brain | Fine-tuned local inference |
## Database Schema (db.py)
### Core Tables (Research OS)
- `claims` β€” Scientific claims with fixed-point confidence (Γ—1000)
- `sources` β€” Paper metadata (DOI, journal tier, study type)
- `goals` β€” Research goals with priority ordering
- `conflicts` β€” Claim contradiction pairs (hypothesis_confidence ALWAYS "low")
- `decisions` β€” Proposed research actions with info gain scores
- `overrides` β€” Expert confidence overrides (lock mechanism)
- `experiments` β€” Lab data objects (manual approval required)
- `api_usage_log` β€” Cost tracking per API call
- `calibration_log` β€” Brier score data collection
- `embedding_cache` β€” Semantic cache (text_hash β†’ embedding)
### ECC Harness Tables (agent_os.py)
- `companion_agents` β€” Registry of spawned companion AIs
- `agent_tasks` β€” Task lifecycle tracking (preflight β†’ done)
- `agent_audit_log` β€” Every action, decision, and deviation logged
## Key Invariants (NEVER violate)
1. **Fixed-Point Math**: All probabilities stored as INTEGER Γ— 1000. No floats in DB.
2. **Provenance**: All AI output is Level 5 (LLM Hypothesis). Human required for promotion.
3. **Hypothesis Confidence**: Conflict hypotheses are ALWAYS "low". Never auto-promote.
4. **Expert Override**: Once set, system cannot overwrite. Only human can change.
5. **Schema Version**: Every record carries `schema_version` tag.
6. **Companion Agent Isolation**: Companions cannot modify claims directly β€” they propose, humans approve.