Skip to main content Announcing Tool Policies: AI agent permissions down to the field Read the announcement
Guillaume Lebedel Guillaume Lebedel · · 7 min read
Two bars to scale: the same agent used 269.7M tokens with live list calls and 134.6M with Deep Query on 1,345 tasks.

How to reduce AI agent token usage on large datasets

Table of Contents

Ask an agent how many people joined last quarter and most of the tokens it spends go to records it never needed. It pages through every employee the HR system returns, reads each page and then counts. The answer is one number. The bill is the whole dataset.

That pattern behind how many, how much and which ones is where most of an agent’s spend on business data goes, and it’s the part most token advice skips. Guides on cutting MCP costs mostly cover tool definitions. On large datasets, the bigger cost is usually the tool results.

Describe what your agent does in the AI agent token optimizer, and it ranks the fixes for your own task and harness.

Here are the five changes that cut the most, in the order I’d make them on an agent that works over your business systems’ data.

Why are large data questions so expensive for agents?

A list action returns records a page at a time. An agent calling it as a tool reads each page into its context (one running code over the results keeps the pages in its sandbox, but still pays for every call). At 200 records a page, counting 1,000 employees takes 5 calls and 10,000 takes 50. The work grows with the system, while the answer stays the same size.

It’s slow as well. In StackOne production traffic a live action call takes 2.9 seconds on average, and fetching one page of 500 employees from an HR system takes 24 seconds. Agents also fail partway through long paging runs, which is the cost that never shows up in a per-call price.

1. Run counts, filters and totals where the data lives

The biggest saving comes from not sending the records to the model at all. If the question is a count, a sum or a group-by, the tool should do the arithmetic and return the result.

This is why we built Deep Query. Every action synced with Data Sync gets a companion query tool, {action}_s1query, which filters, searches and aggregates the synced records inside StackOne’s index. Open pipeline by stage in Pipedrive is one call to pipedrive_list_deals_s1query:

{
  "filter": { "term": { "status": "open" } },
  "aggs": {
    "by_stage": {
      "terms": { "field": "stage_id" },
      "aggs": { "value": { "sum": { "field": "value" } } }
    }
  }
}

The agent reads five totals, one per stage, instead of every open deal.

On our benchmark of 1,345 agent tasks across seven connectors, the same agent with Deep Query available used 134.6M tokens against 269.7M and completed 85% of tasks against 57%. Per connector the saving ran from 33% to 74%. A Deep Query read takes 0.3 seconds on average in production. Your numbers will depend on the agent, the harness and the model, which is what the optimizer estimates.

If you build your own tools, the same principle applies: give the agent a way to ask for a count or a total, so it doesn’t have to compute one from raw pages.

2. Return the fields the answer needs

A record from an HR or CRM system can carry dozens of fields, and most questions use two or three. Tools that return whole records make the agent read all of them.

Deep Query tools take a source parameter that names the fields to return. When someone asks Humaans for every document’s name and issue date, the agent sends:

{ "source": ["name", "issueDate"] }

In our benchmark run, the live route read 1.33M tokens to build that list. Deep Query read 18.9K for the same correct answer, 98% fewer.

For tools you write yourself, add field selection or a concise response mode, and say in the tool description when to use it. Agents follow the description.

3. Load the tools the task needs

Tool definitions are a fixed cost on every request. Connect a few large MCP servers and the model can read tens of thousands of tokens of schemas before it reads the question, and it picks the wrong tool more often as the list grows.

Load tools on demand: give the agent a search tool and let it pull in full definitions when it needs them. We cover the options and their trade-offs in MCP token optimization, and StackOne does this with tool discovery.

4. Keep intermediate results out of the model’s context

In code mode the model writes a script that calls tools, and intermediate results stay in the sandbox instead of the context window. It’s a good fit for multi-step questions, such as joining stage names to deal totals.

It works when the script knows what each tool returns. Most tools don’t publish an output schema, so the script guesses field names or pulls raw data to learn the shape, which costs the tokens you were trying to save. Every Deep Query tool exposes its full input schema, and list_s1query_queryable_fields lists each field, its type and when the records were last synced, so a script can compose several queries without guessing. More on the architecture in MCP code mode.

5. Measure cost per completed task

Tokens per call is the wrong number to optimise. A run that uses fewer tokens and fails more often costs more per answer, because someone runs it again.

Measure tokens, wait time and completion rate together, on the same set of tasks, before and after each change. That’s how we read our own benchmark: half the tokens matters more because completion went from 57% to 85% at the same time. Where your agent’s tokens actually go walks through the measurement, and cost per task covers how to compare models on it.

When should the agent still call the live action?

Deep Query reads the records Data Sync has stored, so results reflect the last sync, and deletions show up after the next full re-sync. For the provider’s state right now, such as whether a ticket closed a minute ago, the agent calls the live action. Both tools stay available, and the agent picks per question.

Try it on your own task

Start with the token optimizer: describe what your agent does and it ranks the fixes that apply, Deep Query among them when your questions cover many records. To turn it on, sync a list action your agent already uses, and the matching _s1query tool is available over MCP and the API after the first run. Deep Query is included on the Team and Enterprise plans.

For the exact settings in one harness, such as Claude Code or n8n, see the harness guides on usefewertokens.com.

Frequently Asked Questions

Ready to put your agents to work?