SSyncropel Docs

The run_code tool

Let a member run write a small JavaScript program that calls its granted tools and returns structured data. What it is, when it is used, and its limits.

What it is

run_code is a tool a run can be granted. Instead of making one tool call per step, the run writes a short JavaScript program that calls its other granted tools, and your workspace runs it. The program's tool calls follow the same rules as direct calls: the program cannot reach a tool the run was not granted.

The point is speed on repetitive work. When a task means "read sixty records, count the ones that match, and report the total", the usual way is sixty separate tool calls. The program does it in one call and hands back a number.

A run can use run_code only when it has been given it: the member's definition has to list run_code in its tools, and the workspace has to have the tool switched on (see When it is offered).

When a model uses it instead of separate calls

A model uses run_code when the work is a loop over many items, and separate calls when the work is a handful of distinct steps. For example, a task over twelve records tends to use twelve to fifteen separate calls; the same task over sixty records tends to use one program. The model decides; you don't.

Two facts keep programs reliable:

  • A program receives data, not prose. A tool answer carries a data field beside the text. run_code hands the program that JSON, so a program reads records[i].body instead of parsing a paragraph. query_thread gives {thread, total, shown, truncated, records: [...]}, read_record gives one such record, search_records gives {total, records}.
  • Each of those answers is limited to 256 KiB. A program that asks for more gets a shortened result marked truncated: true.

Use a program for bulk work you can check afterward: read the data field of each tool answer, and check the result against the records.

The runtime it runs on

Programs run in a sandboxed JavaScript runtime that your workspace installs once. To see what yours runs on:

spl runtime status
pinned:    StarlingMonkey 0.3.0 (ecef7726...)
path:      /home/you/.syncro/runtimes/javascript.wasm
installed: yes, and it matches the pin

Programs run in the sandboxed runtime.

offered:   yes (config topic run_code enabled)

Each version of spl is tied to one exact runtime, and the download is checked after fetching:

spl runtime install            # fetch and install the pinned runtime
spl runtime install --from ./javascript.wasm   # from a local file, still checked
spl runtime remove             # fall back to the built-in interpreter

If no runtime is installed, programs use a built-in interpreter, which is less capable but works. A tool result names which one it ran on (ran on the compute substrate or embedded interpreter).

When it is offered

run_code is off until you turn it on, and a run only sees it when all three of these hold:

  1. The workspace has the run_code config topic enabled (offered: yes in spl runtime status).
  2. The run's definition declares run_code in its tools.
  3. The run is on a tier that includes it.

If the switch is off, or the definition never listed it, the tool is simply not available to the run. Nothing fails; the model works with its other tools.

What your workspace can reach

A program can only call tools your workspace declares and the run was granted. To see them without making a call:

spl tool list

Each row shows whether the tool's credential works and whether the tool has been switched off after repeated failures, so you can tell a tool that cannot run right now from one that is simply not set up. For one tool in full:

spl tool show <tool_id>

Limits

  • A program runs in the same sandbox as the run. On the sandboxed transport that is a separate process with no network and no view of your home directory.
  • Its tool calls follow the same rules as direct calls: no tool the run lacks, and every call is checked before it runs.
  • Each structured tool answer is capped at 256 KiB.
  • A program uses the run's own budget and turn limit, so it cannot outspend the run that wrote it.

See also

On this page