> ## Documentation Index
> Fetch the complete documentation index at: https://docs.larkx.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> LarkX is open-source execution infrastructure for on-device AI agents. It is not an inference engine, an LLM wrapper, a cloud-only agent framework, or a replacement for LangGraph or Cactus.
> Install the public SDK with npm install @larkxai/react-native. The published version is the sdkVersion variable on the Installation page. Import createRuntime, defineTool, scriptedModel, sqlite, remoteAgent, and larkxCloud from @larkxai/react-native. Import cactusModel from @larkxai/react-native/cactus only when the app uses local inference.
> Do not import @larkxai/node, @larkxai/host, @larkxai/protocol, @larkxai/telemetry, or @larkxai/cactus. Those packages are private. Swift and Kotlin SDKs are not published.
> Hello World uses scriptedModel and does not download a model or need Cloud. A Cactus agent needs cactus-react-native 1.13.1, react-native-nitro-modules 0.33.9 or newer, download(), and init() before start. Expo Go cannot load the native module.
> Recovery opens a new createRuntime on the same SQLite file, registers the same agent name and version, then calls resume. Do not call resume on a runtime that has already been closed. Do not describe external effects as exactly-once. A killed process does not keep running.
> Cloud telemetry is optional. Pass larkxCloud({ projectId, apiKey }) only after a local run already works. The key must start with lkx_ing_.

# Crash recovery

> Open a new runtime on the same database, register the same agent, and resume the run.

Recovery does not run inside the killed process. The operating system has already stopped it. Recovery runs when your application starts again, opens the same SQLite file, registers the same agent name and version, and resumes the stored run id.

The first runtime in this example is closed to stand in for that process ending. The second `createRuntime` is the restart. Do not call `resume` on a runtime after `close()` has resolved.

```typescript theme={"dark"}
import { createRuntime, defineTool, scriptedModel, sqlite } from "@larkxai/react-native";

const database = sqlite();
const definition = {
  name: "notes",
  version: 1,
  instructions: "Read the note and answer in one line.",
} as const;

const readNotes = defineTool({
  name: "read_notes",
  description: "Read the local inspection notes.",
  effects: "pure",
  schema: { type: "object", properties: {} },
  handler: () => ({ notes: ["Seal weeps above 80 psi."] }),
});

const first = await createRuntime({ storage: database, ownerId: "notes" });
const agent = first.createAgent({
  ...definition,
  model: scriptedModel([
    {
      message: null,
      finish: "tool_calls",
      calls: [{ id: "call-1", name: "read_notes", arguments: {} }],
    },
    { message: "Seal needs service.", finish: "stop", calls: [] },
  ]),
  tools: [readNotes],
});
const run = await agent.start({ message: "Inspect pump 12", runId: "notes-1" });
console.log((await run.result()).message);
await first.close();

const restarted = await createRuntime({ storage: database, ownerId: "notes" });
let repeated = 0;
restarted.createAgent({
  ...definition,
  model: scriptedModel([]),
  tools: [
    defineTool({
      name: "read_notes",
      description: "Read the local inspection notes.",
      effects: "pure",
      schema: { type: "object", properties: {} },
      handler: () => {
        repeated += 1;
        return { notes: ["this call means a committed step ran again"] };
      },
    }),
  ],
});

const saved = await restarted.listRuns();
const existing = saved.find((item) => item.runId === "notes-1");
if (existing !== undefined && existing.status !== "COMPLETED") {
  const resumed = await restarted.resume(existing.runId);
  console.log((await resumed.result()).message);
}
await restarted.close();
```

After a completed Hello World run, `existing.status` is `"COMPLETED"`, `repeated` stays `0`, and the stored message is still `"Seal needs service."` Resume is for a run that did not finish. A completed run has nothing left to execute, so this snippet does not resume it. The second handler exists to show that opening the database does not replay a committed tool.

To watch a resume, stop the process after a step has committed and before `result()` resolves. On the next launch, `status` is not `"COMPLETED"`. `resume` continues that run. The committed tool is not called again.

## What resume does

* A committed step is returned from the database. Its handler does not run.
* A `pure` or `idempotent` step that was in flight may retry. An idempotent retry keeps the same `operationId`.
* A `non-idempotent` step that was in flight becomes `UNKNOWN_OUTCOME`. The run is `BLOCKED` until `reconcile`.
* A remote task that already has a stored task id is polled. It is not submitted again.
* A remote send whose acknowledgement was lost follows the capabilities stored with that delegation. HTTP `dedupe` and `lookup` stay off unless you declared them.

`reconcile` is how the application resolves an unknown outcome. Pass `resolution: "retry"`, `"complete"`, or `"fail"`. That is an application decision. The runtime cannot see whether the external effect happened.

An effect that left the device before the commit is not exactly-once. The process can die after the effect and before the write.

## What this repository has tested

Node process-death tests stop an example with `SIGKILL` and reopen the database. Those tests stand in for mobile process death. They are not a phone run.

A development build on a physical iPhone or Android phone, real Cactus inference, and force-quit recovery on a device are still open. The checklist is in the repository at `docs/validation/on-device-agent.md`. It is an engineering document, not a claim that the phone run is done.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.