# queryStorage()

Canonical URL: https://developers.iagenify.com/sdk/ref/tools/query-storage/
Language: en

`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.

Status: declaration only · free · read only

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 {#declaring}

```javascript
const agent = api.agents.create({
  model: { main: session },
  storages: [database],                 // what this run may read
  tools: { query_storage: api.tools.queryStorage },
  maxSteps: 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 {#arguments}

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

| request | On | Does |
| --- | --- | --- |
| `"collections"` | a document database | Lists the collections. |
| `{"collection":"leads","filter":{},"limit":10}` | a document database | Reads documents. |
| `{"sql":"SELECT …"}` | a relational database | Runs a statement. |
| `{"key":"invoices/2026.csv"}` | a bucket | Reads 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.

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

## Why the request travels as text {#json-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 {#read-only}

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 {#result}

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 {#prefer}

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.

- [The agent's query_storage](/sdk/agent/tools/query-storage): The wider version, with overview, schema and aggregate.
- [run()](/sdk/ref/connected-storage/run): Doing it yourself, with every action.
- [api.tools](/sdk/ref/tools): The fifteen, and the two ways to use them.

```python
agent = api.agents.create(
    model={"main": session},
    storages=[database],                  # what this run may read
    tools={"query_storage": api.tools.query_storage},
    max_steps=8,
)
```

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