Skip to main content
Glama
vikranthviki

Causal Decision Agent

by vikranthviki
README.md
# Causal Decision Agent

[![CI](https://github.com/your-username/causal-decision-agent/actions/workflows/ci.yml/badge.svg)](https://github.com/your-username/causal-decision-agent/actions)
[![Python Version](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Code Style: Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

An AI decision-analysis agent that takes a business question, connects it to experiment and metric data, investigates using statistical tools, and produces an evidence-backed **decision** (`rollout | hold | investigate`) with a reproducible audit trace.

---

## šŸ›ļø Project Architecture & Layout

```
CausalAI/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ stat_runtime/              # Pure statistical execution engine (Numbers only, no verdicts)
│   │   ā”œā”€ā”€ data/
│   │   │   ā”œā”€ā”€ schema.py          # Data profiles & column metadata
│   │   │   └── profiling.py       # Data-type detection & variable association profiling
│   │   ā”œā”€ā”€ experiment/
│   │   │   ā”œā”€ā”€ srm.py             # Sample Ratio Mismatch (SRM) Chi-Square test
│   │   │   ā”œā”€ā”€ balance.py         # Standardized Mean Difference (SMD) covariate balance
│   │   │   ā”œā”€ā”€ ab_test.py         # Welch's t-test A/B estimation with robust CIs
│   │   │   └── cuped.py           # Pre-experiment variance reduction (CUPED)
│   │   ā”œā”€ā”€ causal/
│   │   │   ā”œā”€ā”€ did.py             # Difference-in-Differences (DiD) regression
│   │   │   ā”œā”€ā”€ dml.py             # Double Machine Learning (Chernozhukov et al.)
│   │   │   └── refutation.py      # Placebo treatment & bootstrap stability refuters
│   │   ā”œā”€ā”€ metrics/
│   │   │   └── definitions.py     # Aggregations, windows, and guardrail definitions
│   │   └── provenance/
│   │       └── artifact.py        # Reproducible execution & audit trace capture
│   │
│   └── causal_agent/              # Agent logic, decision layer, and protocol interfaces
│       ā”œā”€ā”€ data/
│       │   ā”œā”€ā”€ base.py            # DataSource abstract interface
│       │   └── duckdb_source.py   # DuckDB canonical schema implementation
│       ā”œā”€ā”€ evidence/
│       │   └── state.py           # EvidenceState (findings, warnings, unresolved, estimates)
│       ā”œā”€ā”€ decision/
│       │   └── engine.py          # DecisionEngine (rollout | hold | investigate + guardrail priority)
│       ā”œā”€ā”€ planner/
│       │   ā”œā”€ā”€ base.py            # AnalysisPlan & AnalysisPlanner interface
│       │   └── deterministic.py   # Rule-based planner batching runtime calls
│       ā”œā”€ā”€ eval/
│       │   ā”œā”€ā”€ synthetic_data.py  # Canonical benchmark scenarios generator (10 scenarios)
│       │   └── harness.py         # Scoring harness (minimizes false-positive rollouts)
│       └── server/
│           └── mcp_server.py      # Business-level MCP server interface
│
ā”œā”€ā”€ tests/
│   ā”œā”€ā”€ unit/                      # Fast unit tests for statistical routines & engine
│   ā”œā”€ā”€ eval/                      # Benchmark evaluation suite
│   └── conftest.py                # Pytest fixtures
│
ā”œā”€ā”€ plan.md                        # Master system design & engineering plan
ā”œā”€ā”€ pyproject.toml                 # Package configuration & test runners
ā”œā”€ā”€ requirements.txt               # Core production dependencies
ā”œā”€ā”€ requirements-dev.txt           # Testing & linting dependencies
└── .gitignore                     # Ignore files for Python, DuckDB, and IDEs
```

---

## ⚔ Core Invariants & Principles

1. **LLM never computes statistics**: All numerical computations occur inside `stat_runtime`.
2. **Tools return measurements, not verdicts**: Structured JSON with numbers, p-values, and bounds.
3. **Guardrails take precedence**: A statistically significant regression on a guardrail forces `HOLD` regardless of primary metric lift.
4. **False-Positive Rollout Minimization**: The harness explicitly optimizes for 0% false-positive rollouts on corrupted, underpowered, or mismatched experiments.

---

## šŸš€ Getting Started

### 1. Activate Environment
```powershell
.\.venv\Scripts\Activate.ps1
```

### 2. Run Tests
```powershell
.\.venv\Scripts\pytest
```

### 3. Run Benchmark Harness
```powershell
.\.venv\Scripts\python -m pytest tests/eval/test_eval_scenarios.py -s
```

---

## šŸ¤ Contributing

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for development guidelines, testing instructions, and pull request workflow.

Please also review our [Code of Conduct](CODE_OF_CONDUCT.md).

---

## šŸ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

TDQS

C2.6/5.0

Scored across 548 tools

Disambiguation1/5

Hundreds of tools are exact or near-exact duplicates: bjs is the same estimator as borusyak_jaravel_spiess and did_imputation; gardner_did duplicates did_2stage; frontdoor duplicates front_door; rosenbaum_bounds and rosenbaum_gamma share identical descriptions; postestimation_contract and postestimation_report are identical; and there are dozens of R-style or article-facing aliases (synthdid_estimate, sc_estimate, did_estimate, xlearner, psm). An agent cannot reliably distinguish the intended tool among so many overlapping aliases and variants.

Naming Consistency2/5

Names are mostly snake_case, but the convention is inconsistent: some are concise verbs (did, regress, test, contrast), some are bare nouns (bridge, panel, rate), some are R-package aliases (synthdid_estimate, did_estimate), and some use different spellings of the same concept (frontdoor vs front_door, psm vs psmatch2 vs match). Abbreviated and opaque names like discos, megamma, sqreg, and rlassologit_effects break any predictable verb_noun pattern.

Tool Count1/5

548 tools is an extreme mismatch for any server purpose, far beyond even the 50+ upper bound. The surface is a sprawling econometrics library rather than a curated decision-agent toolset, and an agent would face a prohibitive selection problem before doing any actual analysis.

Completeness5/5

For the causal-inference domain, coverage is effectively exhaustive: DiD (2x2, staggered, continuous, DDD, event studies), RD (sharp/fuzzy/multi-cutoff/bunching), IV (k-class, weak-instrument, shift-share, MR), synthetic control variants, matching and weighting, mediation, decompositions, sensitivity analysis, survival, time series, CATE/meta-learners, causal discovery, and offline policy learning are all represented. There are no obvious methodological gaps; the problem is surplus, not scarcity.

Maintenance

ActivityMaintained
ResponsivenessNo issues