Skip to content
Spacefolder Docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Recover an inventory lookup

Navigation quality, TypeScript SDK example and recorded choice for the tools benchmark.

KPI · Probability of delivering a valid inventory response in five seconds.

Navigation score by prior navigations per World.

After 1,000 navigations per World

Spacefolder chose the highest-value action on 96 of 96 held-out navigations.

Approach Expected utility Score / 100
Spacefolder 0.667 100.00
Vector search + SQL for matching situations¹ 0.667 100.00
SQL for all situations¹ 0.550 54.69
First listed action 0.455 48.96
Ground truth 0.667 100.00

¹ Stack analogies. The replay averaged each action’s outcomes in memory, grouping by exact situation for the first baseline and pooling all situations for the second.

TypeScript SDK example

TypeScript SDK · Navigate API

import { SpacefolderClient } from "@spacefolder/sdk";

const sf = new SpacefolderClient();
const navigation = await sf.navigate({
  nav_id: crypto.randomUUID(),
  world_id: "tools_example",
  entity_type: "tool_attempt",
  entity_id: "tools-001",
  context: { scene: "Primary service recovering after a timeout" },
  actions: {
    retry_primary: {"name": "tools.action", "data": {"choice": "retry_primary"}},
    refresh_cache: {"name": "tools.action", "data": {"choice": "refresh_cache"}},
    query_replica: {"name": "tools.action", "data": {"choice": "query_replica"}},
  },
  predictions: {
    on_time: {"event": "inventory.valid_response", "horizon": "5s"},
  },
});

let chosen: string | undefined;
let best = -Infinity;
for (const action of ["retry_primary", "refresh_cache", "query_replica"] as const) {
  const on_time = navigation.actions?.[action]?.predictions.on_time;
  if (!on_time || !("probability" in on_time) || typeof on_time.probability !== "number") continue;
  const utility = on_time.probability;
  if (utility > best) {
    best = utility;
    chosen = action;
  }
}
console.log(JSON.stringify({ chosen }, null, 2));

Example output

Primary service recovering after a timeout

{
  "chosen": "retry_primary"
}

After the timeout, issue exactly one lookup through the selected path. Record a success only when a valid inventory response arrives within five seconds.