← All projects

AI & Machine Learning · Software & Product Systems · Governance & Commercial Rules

Chomkar Decision Grid

A deterministic farm-lot decision engine — 62 unit tests, CI-gated, bilingual Khmer/English audit reports — where a human approves every recommendation.

Can farm-lot assembly be made fully auditable with deterministic code, designed failure cases, and human approval gates?

Status
Prototype
Deployment
Local only
Timeline
2026 — present

What problem this attacks

A buyer may need one to three tonnes of produce while individual farms declare only a few hundred kilograms each. Assembling the lot manually makes pricing, route risk, and fairness impossible to audit — and an AI that invents the numbers would be worse, not better.

Who it serves

Agricultural cooperators and coordinators who assemble multi-farm lots against buyer orders, and — as an audience for the method — anyone designing decision systems where a model must never own the arithmetic.

Why it matters

Coordination failures cost smallholder farmers real income. A recommendation system for money-adjacent decisions only deserves trust if every number can be re-derived, every refusal is honest, and a human explicitly approves the outcome.

What I actually did

My exact role

Framework design, the deterministic engine, the test suite, and the AI-assisted development workflow.

Team contributions

Built within the Chomkar product direction at CHNAI LAB; the synthetic scenario design draws on the team's field research.

What was researched and validated

Research

The volume-gap framing (farms declare 200–600 kg; buyers need 1–3 tonne lots) comes from the team's field research in Kampong Cham. The engineering question researched here: which decision-system patterns let a recommendation be audited by a non-programmer.

Validation so far

Validated against designed scenarios, including deliberate failure cases where the honest output is 'cannot fulfill' with a renegotiation recommendation. All data is synthetic and the repository says so plainly; no real orders, payments, or farmers run through it.

How the solution works

A deterministic, stdlib-only Python engine that models the workflow as Detect → Evaluate → Recommend → Act with an independent audit gate. AI explains the numbers; it never produces them. Every stage checkpoints state, and bilingual Khmer/English reports end with an explicit human-approval checklist.

User workflow

  1. Load farmer declarations and a buyer order
  2. Evaluate feasible lot combinations with zone-normalized scoring
  3. Rank recommendations — or refuse honestly when no lot satisfies the order
  4. Run the independent audit that re-derives payouts, allocation limits, coverage, and the winning score
  5. Review the bilingual report and give or withhold human approval

System architecture

Deterministic core with an audit gate that recomputes results from raw inputs through separate code paths. Pricing invariants are enforced in three places — pricing code, unit tests, and the audit — so a regression cannot pass silently. Pipeline stages hash their inputs and resume only from changed state.

Methods

Zone-normalized (min-max) scoring for cross-province comparability, designed failure cases as first-class scenarios, invariant-based testing, and human-gated calibration where weight changes are bounded proposals requiring manual approval.

Repository structure

chomkar-decision-grid/

The layout carries the argument: every number in a report is produced under tools/, the skills only explain those numbers, and the parameters a non-programmer has to approve sit in docs/business_rules.md.

Repository evidence

  • CLAUDE.mdProject brain: role, domain profile, workflow, verification checklist
  • AGENTS.mdOperating rules for any AI agent — recommends, never decides
  • .claude/
  • commands/Slash commands, one per stage of the loop
  • run-dera.mdThe full loop — resumable and audited
  • audit-order.mdDetect
  • match-farmers.mdEvaluate: lot assembly
  • price-order.mdEvaluate: 0%-cut pricing
  • analyze-route.mdEvaluate: route and spoilage risk
  • decision-report.mdRecommend and Act
  • outcome.mdRecord results, propose calibration
  • skills/One skill, one job — cite the tool, never compute in prose
  • data-auditor/Detect reasoning
  • farmer-matcher/Lot-assembly reasoning
  • pricing-analyst/Pricing reasoning
  • route-risk-analyst/Route and perishability reasoning
  • decision-grid/Grid-ranking reasoning
  • report-writer/The final report and its quality checklist
  • recommendation-auditor/Adversarial review on top of the deterministic audit
  • calibration-analyst/Outcome recording and weight-proposal explanation
  • settings.jsonAgent permissions, scoped to the tools and tests
  • docs/
  • product_brief.mdThe Chomkar model and what this project adds to it
  • data_dictionary.mdEvery CSV column, its units, ranges, and worked examples
  • business_rules.mdAuditable formulas and the human-approved parameters
  • dera_framework.mdStage definitions, grid math, and the resume contract
  • testing_checklist.mdAutomated and manual validation steps
  • data/Synthetic only — no real orders, payments, or farmers
  • farmers.csvPre-harvest declarations, sub-tonne and multi-province
  • buyer_orders.csvOrders including the designed failure cases
  • transport_costs.csvZone-to-zone routes
  • weather_sample.csvZone-day weather rows
  • market_prices.csvReference wholesale and retail prices
  • outcomes.csvAppend-only realized-outcome ledger that feeds calibration
  • tools/Deterministic core — the source of truth for every number
  • run_dera.pyOrchestrator: Detect, Evaluate, Recommend, Act, Audit
  • dera_state.pyCheckpoint and resume engine; stages skip on unchanged input hashes
  • validate_data.pyDetect: schema, ranges, and the volume-gap blocker
  • assemble_lots.pyCandidate-lot assembly — the money decision lives in code, not prose
  • calculate_price.py0%-cut cost build-up and the handling-fee sweep
  • route_risk.pyRoute and perishability risk with rainy-season weights
  • evaluate.pyEvaluate assembler
  • score_grid.pyZone-normalized weighted grid
  • generate_report.pyBilingual report plus the pending-approval artifact
  • audit_recommendation.pyIndependent invariant re-check — the audit gate
  • record_outcome.pyAppend validated outcomes to the ledger
  • calibrate_weights.pyProposes bounded weight nudges; a human applies them
  • lint_skills.pyEnforces the skill and command conventions in CI
  • config.pyBusiness parameters, mirrored from business_rules.md
  • dataio.pyShared CSV loading and parsing
  • tests/Unit tests over invariants, edge cases, and negative paths
  • notebooks/Experiments — they import the tools, never re-implement the math
  • 01_data_cleaning.ipynbDataset audit and the volume-gap picture
  • 02_order_feasibility.ipynbLot assembly, risk, grid ranking, all-orders sweep
  • 03_pricing_profit_split.ipynbThe 0%-cut split of the blended price and fee sensitivity
  • scripts/
  • generate_synthetic_data.pyDeterministic generator — re-running produces identical bytes
  • reports/Generated bilingual decision reports
  • outputs/Per-order run state, gitignored and regenerated by the tools
  • .github/workflows/ci.ymlCI: tests, lint, an audited end-to-end run, and notebook execution

Business, rules, and risk

Business value

Demonstrates the trust architecture a real coordination product would need before touching real money: auditable pricing, honest refusal, and approval gates. The commercial hypothesis itself is tested separately under Chomkar OrderLoop.

Contracts & policy considerations

The engine deliberately does not authorize purchases, payments, or deliveries — recommendations are inputs to a human decision, which keeps the accountability boundary clean. A CI linter even prevents money arithmetic from appearing inside report prose.

Data & privacy

All bundled farmer, buyer, price, weather, and route data are synthetic. Testing the schema with real cooperator data would require redaction or documented consent first — that boundary is stated in the repository.

Risks

  • Provisional decision weights could be mistaken for field-calibrated ones
  • A polished prototype could be misread as an operating platform
  • Synthetic scenarios may encode assumptions real deliveries will contradict

What exists and what the evidence shows

Technical decisions

  1. Deterministic Python stdlib core; AI explains rather than invents the numbers
  2. Detect → Evaluate → Recommend → Act with an independent audit gate as the workflow model
  3. Designed failure cases so 'cannot fulfill' is a valid, tested output
  4. Synthetic-only data with the limitation stated in the README rather than hidden

Completed work

The receipts

Results

What limits it, and what I learned

Constraints (imposed)

  • All bundled data are synthetic; real cooperator data requires consent and redaction work that has not happened yet
  • Decision weights are provisional until compared against observed spoilage and delivery outcomes

Tradeoffs (chosen)

  • Stdlib-only Python keeps the core auditable and dependency-free at the cost of convenience libraries
  • Recommend-only scope (no payments, no orders) limits immediate usefulness but keeps accountability with humans while trust is unearned

Lessons learned

  • An audit that re-derives results through separate code paths catches classes of bugs tests alone miss
  • Designing failure cases first makes honest refusal a feature instead of an afterthought
  • Bilingual reporting is a product requirement, not a translation task — the approval checklist must be readable by the person accountable

What gets validated next

  • Test the data schema with a real cooperator using redacted or consented data
  • Compare route-risk estimates against observed spoilage and delivery outcomes
  • Run usability testing with non-technical cooperative officers