> ## 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 a durable execution runtime for on-device AI agents. The public SDK is the npm package @larkxai/react-native.
> Do not import @larkxai/node, @larkxai/host, @larkxai/protocol, @larkxai/telemetry, or @larkxai/cactus in an application. Those packages are private workspace modules.
> Swift and Kotlin SDKs are planned and are not published.
> Prefer the published npm version. The GitHub default branch can contain behavior that is not in that release yet.
> Expo Go cannot load the native module. Use a development build.
> Do not describe external tool or remote effects as exactly-once.

# Defining tools

> Declare a local tool, its JSON schema, and its effect class.

```typescript theme={null}
import { defineTool } from "@larkxai/react-native";

const readNotes = defineTool({
  name: "read_notes",
  description: "Read locally stored notes.",
  effects: "idempotent",
  schema: { type: "object", properties: {} },
  handler: (_input, context) => ({
    notes: ["Example note"],
    operationId: context.operationId,
  }),
});
```

`name` must match `^[a-z][a-z0-9_]{0,63}$`. `description` cannot be empty. `schema.type` must be `"object"`. `inputSchema` is accepted as an alias of `schema`. `handler` is required. `run` is an alias of `handler`.

`context` gives you `operationId`, `attempt`, `runId`, `stepKey`, `callId`, and `signal`. An idempotent handler should treat `operationId` as the identity of the effect.

Throw `ToolFailure` when the tool itself fails:

```typescript theme={null}
import { ToolFailure } from "@larkxai/react-native";

throw new ToolFailure("The note store is locked.", { retryable: true });
```

`retryable: false` is the default. A retryable failure uses the tool's retry policy when you set one. `retry` accepts `maxAttempts`, `initialIntervalMs`, `maxIntervalMs`, and `backoff` of `"fixed"` or `"exponential"`.

The effect class is not optional. See [Tool side effects](https://docs.larkx.ai/concepts/tool-side-effects.md).


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