Soba Docs

Concepts

App-defined tools

Your app hands a run its own tools. The model calls them on the user's machine, the call comes back to your app, and your code executes it.

Your tools are your code. Soba never sees the implementation, only the name, the description and the input schema, enough for a model to decide to call it.

Attach them to the run:

JavaScript
const run = await soba.run({
  user: sobaUserId(session.user.username),   // see /docs/identity
  owners: [session.user.accountId],          // whose rows this person may read
  prompt: "How many open invoices do I have?",
  tools: [
    tool({
      name: "lookup_invoices",
      description: "Find this account's invoices.",
      inputSchema: {
        type: "object",
        properties: { status: { enum: ["open", "paid"] } },
        additionalProperties: false,
      },
      owner: (invoice) => invoice.accountId,  // who a returned row belongs to
      execute: async ({ status }) => db.invoices.find({ status }),
    }),
  ],
});

The model calls it wherever the run is executing, the call arrives back on your run's stream, and your execute answers it:

JSON
{"type":"tool_call","runId":"r_01","callId":"c_1","name":"lookup_invoices","input":{"customer":"Acme"}}

Over raw HTTP that is a frame on the stream and a POST back the other way, to /v1/runs/:id/tool_result. The SDK turns both into the one execute function above.

isError: true on a result marks a failure the model should see and can react to, rather than one that kills the run.

Nothing about your tools moves to Soba. They run where they already run, against the data they already touch: your database, your session, your permissions.

Whose data a tool returns#

Every tool says whose data it returns. A run with a tool that does not say is refused before it starts. There are three answers:

On the tool When What the SDK does
owner: (row) => row.accountId It returns rows of your data Drops every row whose owner is not one of the run's owners
public: true The result belongs to nobody: a catalogue, the weather Nothing
checksOwner: true It writes, or returns a computed answer with no rows Nothing. Your code scopes it, from ctx.user or ctx.owners

owners on the run is the list of ids, in your own data, whose rows this person may read: their account, their team. Resolve it on your server from the session, as you do user. It never leaves your server.

With owner, the filter runs on what execute returned, after your code and before the result leaves your server. In the example above the query has no where accountId = …, and the person still gets only their own invoices. It fails closed: a row whose owner cannot be read is dropped, and a result that is not rows at all is refused.

  • The result is a list of rows or one row. When the list is wrapped, name the field: rowsIn: "items" for { items: [...], total: 12 }.
  • Keep the owner field in what you return, or the row cannot be checked.
  • Ids are compared as text, so 42 and "42" are the same owner.

The filter cannot check a number or a sentence. A tool that returns "total owed: $9,400" has no rows, so it says checksOwner and its own query must be scoped. auditTools is what tests those.

Your tools are a public API#

A tool call arrives from your user's machine. Usually the model wrote it. Your user can also send one directly, with any arguments, as often as they like. So a tool is an endpoint your user can call, and it needs what any endpoint needs.

  • Never take "whose data" from the input. An accountId or userId argument is a request to read somebody else's rows. Use ctx.owners and ctx.user, which your server set and neither the model nor the machine can change.
  • Return only what that person may see. The result is readable on their machine, whatever the model goes on to say. Leave out internal ids, margins and notes.
  • Write names and descriptions as if your user will read them. They can, unless the tool is private.
  • Declare a strict schema. The SDK checks every call against inputSchema before execute runs, and answers one that does not fit as a failed call. With additionalProperties: false, a field you did not declare never reaches your code.
  • Limit anything that costs you. A tool that spends money or calls a paid API needs the same rate limit you would put on a route.

On a team plan, ctx.customer is the team that pays and ctx.user is still the person. See People and customers.

Checking your tools#

auditTools calls every tool as one person and looks in the answers for anything that belongs to someone else. Run it in your tests, against a test database holding two people's data:

TypeScript
import { assertToolsScoped } from "@soba-so/sdk"

test("no tool gives Alice Bob's data", async () => {
  await assertToolsScoped({
    tools,
    as: { user: sobaUserId("alice"), owners: ["acct_alice"] },
    mustNotSee: ["acct_bob", "[email protected]", "INV-BOB-001"],
    inputs: { lookup_invoices: [{}, { status: "open" }] },
    skip: ["send_email"],
  })
})

mustNotSee is a list of strings that could only come from the other person's data: their account id, their email, a marker you put in their rows. It runs your real execute, so list under skip any tool that sends, charges or deletes.

assertToolsScoped throws when a tool hands them over. auditTools returns the report instead, with two kinds of finding:

leak The person was given it. A failure
caught Your code returned it and the owner filter removed it. Not a leak, but the query is reading rows it should not

Keeping part of your agent private#

Your user can read every prompt and tool definition a run on their compute carries. Mark the part they must not read as private:

TypeScript
const run = await soba.run({
  user,
  owners,
  prompt,
  system: "You are Acme's assistant.",               // readable by your user
  privateSystem: "Quote seats at $90, never under $80.", // never leaves your server
  tools: [
    catalogue,
    tool({
      name: "price_quote",
      private: true,
      checksOwner: true,
      inputSchema: { type: "object", properties: { seats: { type: "integer" } }, required: ["seats"] },
      execute: ({ seats }, ctx) => pricing.quote(ctx.owners[0], seats),
    }),
  ],
})

The run is given your open tools and one plain tool, ask_backend, in place of every private one. When the model calls it, the request is answered on your server by your own provider, which is the only model that sees privateSystem and the private tools. Only its answer goes back.

  • It needs a provider of your own. Add one on your app's Models page and set its key on your server. A private tool with no provider fails its call and says why.
  • You pay for the private part only. It is reported as a run your app served. The conversation still runs on your user's compute.
  • Rename the stand-in with privateTool: { name, description }. Your user can read both.
  • Answering tool calls by webhook? Hand the handler the same tools the run was given: handleRunWebhook(event, { tools: soba.expose({ tools, privateSystem }), owners }).

What it costs: the answer is still readable by your user, a second model adds a round trip, and whatever the model sends to ask_backend reaches your server. That request is written on your user's machine, so your user can write it. The SDK tells your provider to treat it as untrusted and never to reveal its instructions or tools, which lowers the risk and does not remove it: keep anything you could not bear to lose out of privateSystem too.

To hide everything, pay for the run: a run on your own provider never reaches your user's machine at all.

The machine can refuse#

JSON
{ "allowAppTools": false }

A machine owner can decline to be a tool-calling engine at all. Its runtimes then report that they do not support tools, and no tools you send will be honoured.

Which runtimes can do it#

A machine reports per runtime whether it can execute tool schemas your app supplies. Check that before sending tools rather than assuming, because an agent runtime that cannot accept external tool schemas will otherwise silently ignore them.

The gate still applies#

App-defined tools are subject to the same resolution as built-in ones. A tool your app defines does not bypass the policy intersection, and a tool that lands in the machine's askable set still needs a live approval.

Privacy · Terms · DPA · © 2026 Soba resolved = machine grant ∩ broker request