api.tools

queryStorage()

tools: { query_storage: api.tools.queryStorage }

Lets a run read the storages it was given — a database, a bucket — and read only. The platform performs it, against the storages you listed and no others.

declaration onlyfreeread only
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

A declaration. What bounds it is not the tool but the run: it can reach the storages passed as storages, and nothing else on the account.

Declaring it

const agent = api.agents.create({
  model: { main: session },
  storages: [database],                 // what this run may read
  tools: { query_storage: api.tools.queryStorage },
  maxSteps: 8,
});
agent = api.agents.create(
    model={"main": session},
    storages=[database],                  # what this run may read
    tools={"query_storage": api.tools.query_storage},
    max_steps=8,
)
No storages means nothing to read

The tool is declared and the run has nowhere to look. Listing the storages is the whole access decision — it happens in your code, once, before the run starts.

What the model sends

One parameter, request, as text: either the word collections, or a JSON object.

requestOnDoes
"collections"a document databaseLists the collections.
{"collection":"leads","filter":{},"limit":10}a document databaseReads documents.
{"sql":"SELECT …"}a relational databaseRuns a statement.
{"key":"invoices/2026.csv"}a bucketReads one object.

fields picks the columns and shortens long text. storage names which one, and it is needed as soon as the run holds more than a single storage.

{ "collection": "orders", "filter": { "status": "paid" },
  "fields": ["id", "total", "createdAt"], "limit": 20, "storage": "Production" }
{"collection": "orders", "filter": {"status": "paid"},
 "fields": ["id", "total", "createdAt"], "limit": 20, "storage": "Production"}

Why the request travels as text

A free-form object loses the keys that start with $

Declared as an object, a filter comes back from the provider with its operators stripped — and a query with no operator is a different query, not a failed one. As a JSON string nothing is touched, so the filter the model wrote is the filter that runs.

Read only, and that is structural

There is no write in this tool. Changing a connected storage is a different declaration, with its own description and its own guards — so a run given this one cannot modify anything, whatever it is asked to do.

What the run gets back

The rows, the documents or the object, trimmed to what a turn can carry — a larger allowance than the other tools, because this one exists to bring data into the conversation. The step's summary says how much came.

There is a richer version

The local engine's own storage tool goes further: an overview in one call, a schema, counts, aggregation, semantic search, and a permission asked per storage. If your code can run the loop, prefer it.