DEV Community

Sui Gn
Sui Gn

Posted on

How to Build Your Own Context-Aware Robot with .me

This guide walks you through creating a robot that truly understands context — just like in the Robots_Contexts.ts demo.
Robots Demo Github

The 14 claims in the guide were verified against the actual source code of npm install this.me v3.8.0, and they all work.

One minor detail worth mentioning in the guide—although it doesn’t change anything functionally:

import ME from "this.me" — the default export is a factory wrapper (ThisMe) that wraps the internal ME class. For pure TypeScript, you can use as any (as the guide already does), or use import { ME } from "this.me" if you want the direct type.

Everything else — pointers ["->"], broadcast policies ["[i]"]["="], me.explain(), filter queries [condition == true], and automatic reactivity — is implemented and in production in the package.

You’ll learn how to:

Model a shared world (objects + environments)

Give robots individual capabilities and pointers

Declare policies that apply automatically
Use me.explain() to see why a robot makes a decision
Watch everything react live when the world changes

1. Setup (2 minutes)

git clone https://github.com/neurons-me/.me.git
cd .me/npm
npm install
node tests/Demos/Robots_Contexts.ts 
Enter fullscreen mode Exit fullscreen mode

Create a new file: my-robot.ts

import ME from "this.me";
const me = new ME() as any;
Enter fullscreen mode Exit fullscreen mode

2. Build the Shared World

me.objects.package.name("Mystery Box");
me.objects.package.massKg(8);
me.objects.package.fragile(true);
me.objects.package.valuable(false);
me.objects.package.sterile(false);

// Different contexts / environments
me.contexts.warehouse.name("Warehouse");
me.contexts.warehouse.pickupZone(true);
me.contexts.warehouse.sterileZone(false);
me.contexts.warehouse.busyTraffic(false);
me.contexts.hospital.name("Hospital");
me.contexts.hospital.pickupZone(false);
me.contexts.hospital.sterileZone(true);
me.contexts.hospital.busyTraffic(false);
me.contexts.street.name("City Street");
me.contexts.street.pickupZone(false);
me.contexts.street.sterileZone(false);
me.contexts.street.busyTraffic(true);
Enter fullscreen mode Exit fullscreen mode

3. Create Your Robots

function createRobot(id: string, config: any) {
  const r = me.robots[id];
  r.name(config.name);
  r.liftCapacityKg(config.liftCapacityKg);
  r.hasSoftGrip(config.hasSoftGrip);
  r.requiresSterile(config.requiresSterile);
  r.requiresPrecision(config.requiresPrecision);

  // Pointers — this is the magic
  r.target["->"]("objects.package");// points to the shared object
  r.context["->"](config.contextPath); // points to its environment
}

createRobot("loader", {
  name: "LoaderBot",
  liftCapacityKg: 25,
  hasSoftGrip: true,
  requiresSterile: false,
  requiresPrecision: false,
  contextPath: "contexts.warehouse"
});

createRobot("medic", {
  name: "MedicBot",
  liftCapacityKg: 12,
  hasSoftGrip: false,
  requiresSterile: true,
  requiresPrecision: true,
  contextPath: "contexts.hospital"
});

createRobot("delivery", {
  name: "DeliveryDrone",
  liftCapacityKg: 15,
  hasSoftGrip: false,
  requiresSterile: false,
  requiresPrecision: false,
  contextPath: "contexts.street"
});
Enter fullscreen mode Exit fullscreen mode

4. Declare Context-Aware Policies (The Brain)

This is where your robots become intelligent:

//Apply the same rule template to ALL robots
me.robots["[i]"]["="]("canLift", "target.massKg <= liftCapacityKg");

me.robots["[i]"]["="]("needsSoftGrip", "target.fragile && (context.pickupZone || requiresPrecision)");
me.robots["[i]"]["="]("softGripReady", "!needsSoftGrip || hasSoftGrip");

me.robots["[i]"]["="]("needsSterileHandling", "context.sterileZone && !target.sterile");
me.robots["[i]"]["="]("mustWaitForTraffic", "context.busyTraffic");

me.robots["[i]"]["="]("needsHumanReview", 
  "needsSterileHandling || mustWaitForTraffic || (requiresPrecision && !hasSoftGrip)"
);
me.robots["[i]"]["="]("canProceed", 
  "canLift && softGripReady && !needsHumanReview && !mustWaitForTraffic"
);
Enter fullscreen mode Exit fullscreen mode

These rules are declarative and broadcast. Every robot gets them automatically.

5. Watch It Work + Use explain()

console.log("\n=== Initial State ===");
console.log("Loader can proceed?",

me("robots.loader.canProceed"));
console.log("Medic can proceed?", me("robots.medic.canProceed"));
console.log("Delivery can proceed?", me("robots.delivery.canProceed"));

// The most powerful feature: explain()
const trace = me.explain("robots.medic.canProceed");
console.log("\n=== Why did MedicBot decide that? ===");
console.dir({
  value: trace.value,
  expression: trace.derivation?.expression,
  inputs: trace.derivation?.inputs,
  dependsOn: trace.meta?.dependsOn
}, { depth: null });
Enter fullscreen mode Exit fullscreen mode

explain() shows the full reasoning chain — exactly like a transparent AI.

6. Live Updates — Change the World

console.log("\n=== Changing the World ===");
// Sterilize the package
me.objects.package.sterile(true);

// Clear traffic
me.contexts.street.busyTraffic(false);

// No extra code needed — everything reacts automatically!
console.log("Delivery can proceed now?", me("robots.delivery.canProceed"));
console.log("Medic can proceed now?", me("robots.medic.canProceed"));
Enter fullscreen mode Exit fullscreen mode

All robots instantly re-evaluate based on the new reality.

Full Mini Example You Can Copy-Paste

import ME from "this.me";
const me = new ME() as any;

// ... (add objects, contexts, createRobot, policies as above)
console.log("All robots that can proceed:");
console.log(me("robots[canProceed == true].name"));

// Query by condition
console.log("Robots that need sterile handling:");
console.log(me("robots[needsSterileHandling == true].name"));
Enter fullscreen mode Exit fullscreen mode

Next-Level Ideas You Can Build

Personal Assistant Robot: Understands your mood, location, calendar, and energy level.

Smart Factory Swarm: Hundreds of robots reacting to machine status, inventory, and orders.

Game NPC: One enemy that behaves differently based on player level, time of day, or story progress.

Home Care Robot: Adapts behavior based on who is home, time, and health sensor data.

Research Agent: Different "researcher" personas that interpret the same paper differently.

Pro Tips
Use me.explain() heavily while developing — it’s your debugger.

Pointers (["->"]) are extremely powerful. You can point to anything.

Collection queries (robots[condition]) feel like magic.

Everything stays reactive — no manual onChange listeners needed.

You can nest contexts deeply:
me.buildings.hospital .floors[3].rooms.or1

You just built a robot that understands context.

Not hardcoded if-statements.
Not brittle event systems.

Just meaning + relationships + live rules.

This is the core idea behind .me and monads: make context first-class.

Build something cool and share it!

https://www.npmjs.com/package/this.me

Top comments (0)