Murder at the
Tech Mansion

Build an AI detective with the Reasoning Layer SDK

7 steps · 4 hours · Sorts → Terms → Inference → Negation → Fuzzy → Causal → Agents

Arrow keys to navigate · Esc for overview · F for fullscreen

Getting Started

1. Create an account & get your API key

Go to https://app.ovh.reasoninglayer.ai
Register → create a tenant → copy your Tenant ID and API Key

2. Clone the workshop repo & install

git clone https://gitlab.com/kortexya-pub/workshop.git
cd workshop
npm install

3. Configure your credentials in .env

REASONING_LAYER_URL=https://platform.ovh.reasoninglayer.ai/api/v1
REASONING_LAYER_TENANT_ID=your-tenant-id
REASONING_LAYER_API_KEY=your-api-key

Verify It Works

npx tsx step-01-sorts.ts

You should see: Case file opened! Created 10 sorts

ErrorFix
Cannot find moduleRun npm install again
401 UnauthorizedCheck your API key (no extra spaces)
fetch failedCheck URL — needs https://, no trailing slash
node: command not foundInstall Node.js 18+

The Case

Last night, billionaire tech CEO Marcus Chen was found dead
in the study of his mansion during a private dinner party.

Cause of death: cyanide poisoning in his wine glass.

6 guests were present. No one has left the property.

Your mission: build an AI detective to find the killer.

The Suspects

NameOccupationMotiveStudy key?Alibi
Dr. Sarah ParkChief Scientist$50M patent disputeYesLibrary (unconfirmed)
James ChenNephew$200M inheritanceYesGarden (says Elena there)
Elena VasquezChefAbout to be firedYesKitchen (contradicts James)
Prof. David OkaforProfessorStolen researchNoDining room (confirmed)
Tom ReevesLawyerSecret will changeNoDining room (confirmed)
Nina TorresSecurity consultantBitter breakupYesBathroom (no witness)

The Evidence

  • Poison vial found in study (wiped clean — no fingerprints)
  • Victim's wine glass contains cyanide traces
  • Muddy footprints from garden to study
  • Hair strand on victim's collar: female DNA, 94% match confidence
  • Staff member saw "dark-clothed figure near study around 8:40pm"
  • James and Elena give contradicting alibis
  • Study door was locked — only key holders could enter

What is the Reasoning Layer?

Traditional

SQL table → App code → ML model (data) (if/else) (uncertainty)

Reasoning Layer

Sort lattice → Inference → Fuzzy logic (types+data) (rules=data) (uncertainty=data)

Key idea: data, logic, and types are all the same thing — Psi-terms.

Key Analogies

You already knowReasoning LayerKey difference
SQL tableSortMultiple inheritance
SQL rowPsi-termCan be incomplete (residuation)
if/else in codeInference ruleRules are data — you can query them
NULLUninstantiated"I don't know yet" vs "doesn't exist"
ProbabilityFuzzy logicDegrees of truth, not chance

STEP 1

Setting Up the Case
Sorts

Define the types of things in your investigation.

Sorts are like classes, but with multiple inheritance that actually works.

File: step-01-sorts.ts · 25 min

STEP 1

The Sort Hierarchy

person / \ suspect witness \ / person_of_interest ← multiple inheritance!

No diamond problem — the system computes GLB automatically.

GLB(suspect, witness) = person_of_interest

STEP 1

What You Build

  • person, suspect, witness, person_of_interest
  • evidence, physical_evidence, forensic_evidence, testimony
  • location, room

Key methods

createSort() · isSubtype() · computeGlb()

Run: npx tsx step-01-sorts.ts

STEP 2

Building the Case File
Terms

Enter all 6 suspects, evidence, and testimonies as terms.

File: step-02-terms.ts · 20 min

STEP 2

Tagged Values (Storage Format)

Value.string("Alice")    →  {"type": "String",  "value": "Alice"}
Value.integer(35)        →  {"type": "Integer", "value": 35}
Value.boolean(true)      →  {"type": "Boolean", "value": true}
Value.uninstantiated()   →  {"type": "Uninstantiated"}

Residuation

Value.uninstantiated() = "I don't know yet."
The system suspends judgment. Fundamentally different from SQL NULL.

STEP 2

What You Build

  • 6 suspect terms with name, motive, alibi, key access
  • Physical evidence: poison vial, wine glass, footprints
  • Forensic evidence: hair strand with DNA match
  • Testimonies from each suspect
  • Room locations with camera info

Can you spot the contradictions in the testimonies?

Run: npx tsx step-02-terms.ts

☕ Break — 10 min

We've covered knowledge representation (types + data).
Next: reasoning (rules + inference). That's where the magic happens.

STEP 3

The Deduction
Inference

Write logical rules. The engine deduces who could have done it.

File: step-03-inference.ts · 40 min

STEP 3

FORMAT SWITCH!

From this step on, inference uses the untagged format via psi().

TERMS (storage):      Value.string("Alice")         → {"type":"String","value":"Alice"}
INFERENCE (reasoning): psi('suspect', {name: "Alice"}) → "Alice"

NEVER mix them.

STEP 3

The Rules

  1. alibi_contradiction — A says with B at X, but B says Y
  2. confirmed_alibi — Two people corroborate each other
  3. had_opportunity — Has key to the study
  4. matches_dna — Female + had opportunity
  5. prime_suspect — Matches DNA + has motive

The engine chains them: prime_suspect → matches_dna → had_opportunity → facts

STEP 3

Backward Chaining

"Who is a prime suspect?" prime_suspect(?Name, ?Motive) ↓ matches_dna(?Name) + suspect(?Name, motive=?Motive) ↓ suspect(?Name, is_female) + had_opportunity(?Name) ↓ suspect(?Name, has_key_to_study=true)

The engine works backward from your question — like a detective following leads.

STEP 3

Expected Results

Confirmed alibis

David ↔ Tom
(both say dining room)

Contradictions

James claims garden with Elena,
but Elena says kitchen

Had opportunity: Sarah, James, Elena, Nina (have study keys)

DNA match: Sarah, Elena, Nina (female + study key)

Prime suspects: Sarah, Elena, Nina

Run: npx tsx step-03-inference.ts

CHALLENGE 3

Your Turn: Poison Access

Write a rule had_access_to_poison that identifies suspects who:

  • Had access to the kitchen (alibi_location = "kitchen")
  • OR had a chemistry/science background (occupation contains "Scientist")

Then query: who had access to poison AND matches DNA?

Hint

You'll need two separate rules with the same head sort —
the engine treats them as an OR. File: challenges/challenge-03-poison-access.ts

STEP 4

Eliminating the Innocent
Negation

A detective doesn't just find the guilty —
they eliminate the innocent.

NAF (Negation as Failure): if I can't prove it, it's false.

File: step-04-negation.ts · 15 min

STEP 4

Closed-World Assumption

// "Find suspects who are NOT prime suspects"
nafProve({
  literals: [
    { term: psi('suspect', {name: '?Name'}), negated: false },
    { term: psi('prime_suspect', {name: '?Name'}), negated: true },
  ]
})

Cleared

James (male → no DNA match)
David & Tom (confirmed alibis)

Still suspects

Sarah, Elena, Nina

Run: npx tsx step-04-negation.ts

CHALLENGE 4

Your Turn: Unverifiable Alibis

Write a NAF query to find suspects whose alibi
has no corroborating claim from anyone else.

Hint

Nina says she was in the bathroom, but no one filed
an alibi_claim placing her there. Use a positive literal
for "is a suspect" and a negative literal for "has a corroborating claim."

File: challenges/challenge-04-unverifiable-alibis.ts

STEP 5

Weighing Uncertain Evidence
Fuzzy Logic

Not all evidence is equally reliable.
DNA at 94% ≠ an eyewitness who "maybe saw someone."

File: step-05-fuzzy.ts · 25 min

STEP 5

Membership Functions

1.0 | /\ | / \ 0.5 | / \ | / \ 0.0 |---/--------\--- | 90 94 97 "DNA match confidence" Triangular(0.90, 0.94, 0.97)

DNA: Triangular(0.90, 0.94, 0.97)

Footprints: Triangular(0.4, 0.6, 0.75)

Eyewitness: Triangular(0.1, 0.3, 0.5)

STEP 5

What You Build

  • Value.fuzzyNumber(FuzzyShape.triangular(a, b, c))
  • fuzzyUnify() — similarity degree (0.0 – 1.0)
  • searchTopK() — find most similar evidence
  • fuzzyProve() — inference with truth degrees

Watch out

FuzzyShape uses "kind" as discriminator, not "type".

Run: npx tsx step-05-fuzzy.ts

CHALLENGE 5

Your Turn: Alibi Contradiction Evidence

Create a weighted_evidence term for the contradicting alibis:

  • Description: "James and Elena's stories don't match"
  • Points to both of them
  • Reliability: Gaussian(0.7, 0.15)

Then compare its similarity with the DNA evidence
using fuzzyUnify. Are these evidence types related?

File: challenges/challenge-05-alibi-contradiction-evidence.ts

☕ Break — 10 min

Types, data, inference, elimination, uncertainty — done.
Next: causal reasoning — why did it happen?

STEP 6

The Motive Chain
Causal Reasoning

WHY did it happen? Reconstruct the chain of events.

File: step-06-causal.ts · 20 min

STEP 6

Pearl's Ladder of Causation

Level 3: COUNTERFACTUAL "Would Marcus be alive if...?" (Imagining) Level 2: INTERVENTION "If we lock the poison cabinet..." (Doing) Level 1: CORRELATION "People with keys were near the study" (Seeing)

Each level is strictly more powerful than the last.

STEP 6

The Causal Graph

bitter_breakup → revenge →→ murder_motive → planned_murder → victim_dead patent_dispute → resentment ↑ ↑ about_to_be_fired → desperation ↑ access_to_poison ↑ inheritance → greed ↑ unconfirmed_alibi ↑

rootCause('victim_dead')
Traces backward to root causes

counterfactual(...)
"What if the breakup hadn't happened?"

Run: npx tsx step-06-causal.ts

CHALLENGE 6

Your Turn: Extended Causality

  1. Add a new causal chain:
    secret_will_changefinancial_fearmurder_motive
    (Tom Reeves' potential motive)
  2. Run rootCause again — does the picture change?
  3. Counterfactual: "Would the murder have happened if
    access_to_poison AND unconfirmed_alibi were both false?"

File: challenges/challenge-06-extended-causality.ts

STEP 7

Deploy Your AI Detective
Cognitive Agents

Your detective becomes an autonomous agent
with beliefs, goals, and intentions.

File: step-07-agents.ts · 20 min

STEP 7

BDI Architecture

Perceive → Believe → Desire → Intend → Act → Learn ↑ | +----------------------------------------------------+ Beliefs: evidence + deductions (with confidence scores) Goals: solve the murder, verify alibis, resolve contradictions Intentions: committed investigation plans Actions: verify alibis, check cameras, cross-reference testimony

STEP 7

What You Build

  • Holmes & Watson — two detectives with different theories
  • Beliefs from engine — prime suspects, contradictions, forensics
  • Investigation actions — verify alibi, check camera, cross-reference
  • Agent messaging — Holmes shares evidence with Watson
  • Human feedback — instructor evaluates the detective

Run: npx tsx step-07-agents.ts

The Reveal

CapabilityHow it helped
Sorts (types)Models people, evidence, locations with multiple inheritance
Terms (data)Stores suspects, evidence, testimonies as structured data
Inference (rules)Narrows 6 suspects to 3 prime suspects
Negation (NAF)Clears David, Tom, and James
Fuzzy logicRanks evidence by reliability
Causal reasoningTraces motive chains, tests "what if?"
Cognitive agentsAutonomous investigation with learning

Who killed Marcus Chen?

The evidence points to Nina Torres

  • Bitter breakup motive
  • Key to the study
  • No alibi — 45-minute gap, no witnesses
  • DNA match on victim's collar
  • Security background → explains wiped fingerprints

But can you prove it beyond reasonable doubt?
The kitchen camera footage might change everything...

What You Learned

Mystery conceptReasoning LayerReal-world use
Suspect typesSorts (lattice)Knowledge graph schemas
Case file entriesPsi-termsStructured data + validation
"Who had opportunity?"Backward chainingExpert systems
"Derive everything"Forward chainingMaterialized views
"Eliminate innocent"Negation as failureCompliance checking
"How reliable?"Fuzzy logicAnomaly detection
"Why did it happen?"Causal reasoningRoot cause analysis
"Investigate autonomously"BDI agentsAutonomous AI

Thank you!

Resources to go further:

  • Concept pages for deeper understanding
  • Advanced tutorials: Clinical Trial, Loan Approval, Incident Response
  • API Reference for method-level docs

Key takeaway: everything is a Psi-term.
Data = logic = constraints. That's homoiconicity.