Skip to content
Beta. This surface may change before GA; breaking changes are dated in the changelog.

Reopen rules and offers when a rate sheet changes

A commercial real estate agent reads a rent rule and a derived offer at $32 per square foot per year. Both records quote the rate sheet directly. When version 2 replaces those words with a $36 rate, both records reopen for a person to review. A link to the rule alone would track changes to the rule itself. Each record needs its own quote to react to the document revision.

Use Node.js 24 or newer and a management key. Choose a new scratch space handle. The script creates it and mints a separate read-only key for the quoting agent.

Terminal window
mkdir vertical-ai-changing-facts
cd vertical-ai-changing-facts
npm init -y
npm pkg set type=module
npm install @nicia-ai/client@^0.1.1

Save this as recipe.ts.

import { setTimeout } from "node:timers/promises";
import { NiciaOrgClient, NiciaSpaceClient } from "@nicia-ai/client";
const sheetId = "harborview-rate-sheet";
const ruleId = "harborview-suite-410-rate";
const offerId = "harborview-suite-410-draft-offer";
const recordIds = [ruleId, offerId];
const rateLine = (rate: number) =>
`Suite 410 asking rent is $${rate} per square foot per year.`;
async function uploadSheet(
space: NiciaSpaceClient,
version: number,
rate: number,
) {
await space.writeDocuments({
id: sheetId,
text: `# Harborview rate sheet\n\n${rateLine(rate)}`,
});
for (let attempt = 0; attempt < 30; attempt++) {
const { document } = await space.getDocument(sheetId);
if (document.version === version && document.status === "indexed") return;
if (document.status === "rejected") throw new Error(document.error);
await setTimeout(1_000);
}
throw new Error(`Rate sheet v${version} did not become indexed`);
}
export async function runRateSheetDemo(
baseUrl: string,
managementKey: string,
handle: string,
) {
const org = new NiciaOrgClient({ baseUrl, managementKey });
await org.putSpace(handle, {
name: "Harborview rate sheet demo",
ifExists: "conflict",
});
const operator = new NiciaSpaceClient({
baseUrl,
handle,
credential: managementKey,
});
const { secret } = await org.mintSpaceKey(handle, {
name: "Harborview quoting agent",
capabilities: ["read"],
});
if (!secret) throw new Error("Reader key mint returned no secret");
const agent = new NiciaSpaceClient({ baseUrl, handle, credential: secret });
const v1Rate = 32;
await uploadSheet(operator, 1, v1Rate);
const evidence = [{ document: { id: sheetId }, quote: rateLine(v1Rate) }];
const { change } = await operator.writeRecords({
records: [
{
id: ruleId,
kind: "rule",
label: "Harborview Suite 410 asking rent",
fields: { status: "active", body: rateLine(v1Rate) },
evidence,
},
{
id: offerId,
kind: "decision",
label: "Harborview Suite 410 draft offer",
fields: {
status: "active",
body: `Draft 2,000 square feet at $${v1Rate * 2_000} annual base rent.`,
},
evidence,
},
],
});
if (change.status !== "applied")
throw new Error(`Draft write: ${change.status}`);
const before = await agent.getContext({
prompt: "Harborview Suite 410 asking rent and draft offer annual base rent",
format: "items",
consumerId: "harborview-draft-410",
});
await uploadSheet(operator, 2, 36);
const { items } = await operator.getAttention({ reason: "reopened" });
const reopened = items.filter(
({ subject }) =>
subject.type === "record" && recordIds.includes(subject.id),
);
const [{ receipt }, now] = await Promise.all([
agent.getReceipt(before.receipt),
agent.getReceiptChanges(before.receipt),
]);
if (
!recordIds.every(
(id) =>
reopened.some(({ subject }) => subject.id === id) &&
now.answers.some(
(answer) => answer.id === id && answer.since === "grounds_moved",
),
)
)
throw new Error("Expected both v1 records to reopen");
return { reopened, receipt: receipt.id, servedTo: receipt.key, now };
}
if (import.meta.main) {
const { NICIA_MANAGEMENT_KEY: key, NICIA_SPACE: handle } = process.env;
if (!key || !handle)
throw new Error("Set NICIA_MANAGEMENT_KEY and a new NICIA_SPACE");
const baseUrl = process.env.NICIA_API_URL ?? "https://api.nicia.ai";
console.log(
JSON.stringify(await runRateSheetDemo(baseUrl, key, handle), null, 2),
);
}
Terminal window
export NICIA_SPACE='harborview-rates-demo'
read -rsp 'Nicia management key: ' NICIA_MANAGEMENT_KEY; printf '\n'; export NICIA_MANAGEMENT_KEY
node recipe.ts

The output lists the two records in Attention with the reason reopened. now.answers reports grounds_moved on the original receipt. The receipt ID and servedTo identify which key was served the v1 context. A person can use Attention in Review to decide how to update the rule and the offer.

The client uses getReceiptChanges for the receipt’s /now endpoint and getReceipt to read the key ID and name from the original receipt.

Review and Attention · Receipts