Give agents your app's own diagnostics and actions
Expose focused React Native app data and operations so agents can answer questions the built-in tools cannot.
Custom tools let an agent ask your JavaScript app code for a precise answer, such as the current debug user, or run a focused development operation. They use the same guarded remote-tool protocol as the native suites. Use Native Custom Tools for handlers implemented in Swift or Kotlin.
Register a Tool
const registration = Ansight.registerTool(
{
id: "app.current_user",
name: "Current User",
category: "app",
policy: "read",
description: "Returns the current debug user id.",
},
async (_args, context) => ({
success: true,
result: {
userId: session.currentUserId,
platform: context.platform,
},
}),
);
await registration.ready;
Call registration.unregister() or Ansight.unregisterTool(id) to remove a JS-backed custom tool.
Native tool entries report dynamic runtime availability and remediation through the shared catalog. JavaScript-backed custom tools are advertised as available while registered; when one becomes unusable, unregister it or return a stable failure errorCode from the handler. The JavaScript registration API does not currently expose a pre-invocation availability callback.
Registration API
registerTool(definition, handler): registers one JavaScript-backed tool.unregisterTool(id): unregisters one tool.listRegisteredTools(): returns registered JavaScript tool ids.clearRegisteredTools(): unregisters JavaScript-backed tools.
Specific Concerns
- Prefer narrow, app-specific operations.
- Keep native-only workflows in Swift or Kotlin with Native Custom Tools.
- Choose the correct policy:
"read","write", or"critical". - Handlers receive string arguments and a context object with request/session/platform metadata.
- Do not expose broad scripting, arbitrary file access, or secret access through custom tools.
- Registered tools are still hidden and unusable until the runtime guard allows their policy.
Tool Definition Checklist
- Stable tool id, usually under an app-owned prefix such as
app. - Clear name and description
- Category and keywords that match the workflow
- Correct policy
- Arguments and result schemas when callers need structured inputs or outputs
- Explicit failure messages for invalid arguments or unavailable app state
Authoring and Execution Context
registerTool(definition, handler) already supplies the concise form; there is no need for a class or a native wrapper for JavaScript-owned state. Define argumentsSchema and resultSchema, and keep the policy explicit. This bridge currently delivers flattened string argument values: parse and validate booleans, numbers, and JSON fields explicitly instead of assuming native JSON types.
Handlers execute in the JavaScript runtime. Await asynchronous work and return only after the state change completes. Native UI or engine operations must dispatch inside the native module to their owning queue. A bridge timeout does not guarantee cancellation of that work. JavaScript tools do not have a pre-invocation availability callback: unregister unavailable tools or return a stable failure such as scene_not_ready.
Expose a Domain Model
Start with scene.snapshot (read) returning a bounded JSON projection of scene id, selected entity, and transforms. Add scene.set_visible (write) taking one entity id and a boolean. Reject unknown ids and a loading scene with stable error codes, dispatch the change to the scene owner, and return the updated visibility. Read current state at invocation time rather than capturing a stale snapshot at registration.
Keep schemas, policy, and dispatch explicit even when using registerTool. Verify a successful read, a successful mutation, invalid arguments, an unavailable scene, and a denied write under a read-only guard. For a large model or a durable snapshot, use artifact publication from the app instead of embedding it in a tool result.