Remote tools
In shortRun agent tools in the browser: declare remote_tools schemas in 10xgraph.json, register handlers in the TypeScript client for geolocation or clipboard.
- 4 min read
- 8 sections
- Updated
- v1.0.0
- Markdown
Remote tools let your agent call functions that run in the browser or on the client machine. Use them for capabilities that only the client owns: geolocation, clipboard access, DOM manipulation, local file system access, or device sensors. Keep database, secrets, and backend work in server-side tools defined in your Python graph.
How it works
When you invoke or stream the agent:
- The Python graph calls a remote tool (one you declared in
10xgraph.json). - The server returns a
RemoteToolCallBlockto the client. - The client SDK finds your registered handler by name.
- Your handler executes locally and returns a result.
- The SDK wraps the result in a tool result message and sends it back.
- The server continues the graph with the tool result.
This loop repeats until the graph is done or hits the recursion limit (default 25 calls).
Step 1: Declare schemas in 10xgraph.json
Declare each tool’s name, description, JSON Schema parameters and the node of the ToolNode that offers it in remote_tools in the server’s 10xgraph.json, then restart the server. The server validates the entries at startup. Fields and rules: Remote tools on the server.
Step 2: Register matching handlers
On the client, register a handler function for each declared tool. Do this before calling invoke(), stream(), or wsStream():
import { TenxGraphClient, Message } from '10xgraph-client';
const client = new TenxGraphClient({
baseUrl: 'http://localhost:8000',
authToken: 'your-bearer-token', // if auth is enabled
});
// Geolocation handler
client.registerToolHandler('get_location', async ({ high_accuracy = false }) => {
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(
(position) => {
resolve({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
accuracy: position.coords.accuracy,
});
},
reject,
{ enableHighAccuracy: high_accuracy }
);
});
});
// Clipboard handler
client.registerToolHandler('read_clipboard', async () => {
const text = await navigator.clipboard.readText();
return { content: text };
});Handler requirements:
- Signature:
async (args: any) => Promise<any>: the async function receives the tool arguments as a single object and must return a JSON-serializable value. - Arguments: The model generates arguments based on the schema you declared in
10xgraph.json. Destructure them as shown, or access them as properties:args.high_accuracy. - Return value: Return JSON-safe data.
JSON.stringifydrops functions andundefined, and a circular value makes theinvoke()orstream()call throw. - Errors: If the handler throws, the error is caught and converted to a failed tool result. The agent sees the error message and can retry or handle it.
To check arguments in the client before your handler runs, use registerTool(), or pass the validate and maxArgsBytes options as the third argument of registerToolHandler(). parameters checks top-level types and required, validate refuses a call when it returns false or throws, and maxArgsBytes caps the argument size (default 1 MiB). A refused call reaches the model as a failed tool result, and the handler does not run.
client.registerTool({
name: 'read_clipboard',
handler: async () => ({ content: await navigator.clipboard.readText() }),
validate: () => document.hasFocus(), // refuse while the tab is in the background
});Step 3: Invoke normally
Call invoke() or stream() as usual. The client detects remote tool calls and handles them internally:
// Simple invoke
const result = await client.invoke([
Message.text_message("Where am I right now?", "user")
]);
console.log(result.messages);
// The agent has seen the location and replied.Or stream with an async loop:
const stream = client.stream([
Message.text_message("What's on my clipboard?", "user")
]);
for await (const chunk of stream) {
if (chunk.event === 'message') {
console.log('Agent:', chunk.message?.content);
} else if (chunk.event === 'updates') {
console.log('Update:', chunk.data);
}
}If a handler is missing, the SDK creates a failed tool result with the message Tool '{name}' not found. The agent sees this and may retry or ask for clarification.
Recursion limit
Each invoke(), stream() or wsStream() call runs at most recursion_limit tool rounds (default 25); pass another value in the options, for example { recursion_limit: 50 }. When the limit stops a loop that still has tool calls, invoke() returns recursion_limit_reached: true and stream() yields an error chunk with data.recursion_limit_reached.
Errors and missing handlers
If a handler throws, is not registered, or its arguments are refused (see registerTool() above), or a call id repeats:
- The exception is caught at the client.
- A failed
ToolResultBlockis created withis_error: trueand the error message. - The result is sent back to the server as a failed tool call.
- The agent sees the failure and can retry, ask for clarification, or continue.
Example:
// Handler throws
client.registerToolHandler('risky_tool', async () => {
throw new Error('Something went wrong');
});
// When called, the error is caught and sent to the agent as a ToolResultBlock:
// output: { error: 'Something went wrong' }, is_error: true, status: 'failed'Missing handlers produce a similar failure message:
// No handler registered for 'unregistered_tool'
// Agent receives output { error: "Tool 'unregistered_tool' not found" }, is_error: true, status: 'failed'Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Agent never calls the tool | Tool not declared in remote_tools or wrong node |
Add it to 10xgraph.json with the correct ToolNode name, then restart the API. |
Tool 'X' not found error |
Handler not registered or name mismatch | Register the handler with the exact name from remote_tools[].name before calling invoke() or stream(). Names are case-sensitive. |
| API startup fails with validation error | Typo in schema, duplicate tool name, or malformed parameters | Fix the remote_tools entry in 10xgraph.json. The startup log names the entry. |
Next steps
- See create-client for auth token options.
- See stream-responses for streaming patterns.
- See graph-utilities for stop, fix, and other utilities.
- See concepts/remote-tools for the underlying design.