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

Threads and recovery

Restore a reusable conversation without replaying uncertain work.

Restore an agent thread after a reconnect or restart without pretending uncertain work has completed.

Restore one consistent snapshot

Loading a thread returns one consistent snapshot and matching journal checkpoint. The browser installs the snapshot completely, then reads records strictly after that checkpoint. Older history is finite, authenticated cursor pagination tied to the pinned snapshot.

/** Composes the offline support model, explicit order/native tools, todo middleware and shared checkpoint/memory drivers. */
import { defineAgent } from "@relkit/langchain";
import { todoListMiddleware } from "langchain";
import { supportInput, supportOutput } from "../../../platform/schemas.js";
import lookupOrder from "../tools/lookup-order.tool.js";
import cancelOrder from "../tools/cancel-order.tool.js";
import { createCommerceModel } from "./commerce-model.js";
import { orderCheckpoints, orderMemory } from "./order-agent-persistence.js";
import { orderStatus } from "./order-native-tool.js";

const orderSupport = defineAgent({
  // Inputs and final answers remain schema checked around the model call.
  input: supportInput,
  output: supportOutput,
  model: createCommerceModel("support"),
  instructions: "Answer order questions using the read-only order lookup tool.",
  // Only explicitly listed application tools are available to the agent.
  tools: [lookupOrder, cancelOrder, orderStatus],
  middleware: [todoListMiddleware()],
  checkpointer: orderCheckpoints,
  store: orderMemory,
  // Bound both tool use and total execution time.
  limits: { maxSteps: 4, maxToolCalls: 4, timeoutMs: 60_000 },
  stateProfile: "agents",
  client: { public: true, state: ["todos"] },
  chat: { input: "message", output: "answer" },
  controls: ["steer", "follow-up", "stop", "approve"],
});

export default orderSupport;

Keep uncertain work visible

Each execution segment has immutable run state. A settled segment returns its thread to idle when no approval or follow-up remains; approval and worker interruption stay visible. Lost responses are reconciled through scoped receipts. Claim expiry, generation loss, or an uncertain external effect never causes automatic restart.

Keep interrupted nodes safe to re-enter

LangGraph starts an interrupted node again when its thread resumes. RELKIT binds the reply to the persisted waiting revision, admits it once, and fences competing workers, but it cannot make an arbitrary database write, payment, email, or third-party request exactly once. Place the interrupt before an irreversible effect, or make the effect idempotent with a durable business key or a transaction that your application owns.

Every protected thread operation requires current resource authorization and verified ownership. Knowing a thread, run, checkpoint, or operation ID grants nothing.