← Daily

Concept · No. 048 · December 4, 2026

Large tool results belong behind a handle, not in the context

When a tool returns everything it found, the agent pays for it in tokens, attention and silent truncation. Returning a reference plus a small, honest preview keeps the full data reachable without forcing the model to read all of it.

The idea

Most agent tools are written like functions: run the query, return the rows. That works until a result is large. Then the whole payload lands in the context window, crowds out the instructions and earlier reasoning, costs tokens on every later turn, and often gets cut off by a harness limit the model never hears about.

The alternative is to keep the full result outside the model. The tool stores it server-side and returns a handle: an opaque id, the row count, the schema, a few representative rows and a short note on what was left out. Separate narrow tools let the agent work against that handle, filtering, slicing or aggregating, so it only pulls into context the part it actually needs.

An example

An agent is asked why checkout failures rose overnight. It calls search_logs for the failing service.

  • Without a handle, the tool returns a very large block of log lines. The harness truncates it, the agent sees the first page, and it concludes the cause is whatever error happened to appear there.
  • With a handle, the tool returns result_id, a total count, the field names, the top error codes with their counts, and a handful of sample lines.
  • The agent sees one error code dominating and calls aggregate(result_id, group_by="region"). The failures cluster in one region.
  • It calls slice(result_id, where="region = 'eu' and code = 'TIMEOUT'", limit=5) and reads five lines that point to a single upstream dependency.

The agent read a few hundred tokens instead of the whole log, and its answer rests on the full data rather than an accidental first page.

Where it breaks

A handle is a snapshot. If the agent reasons over it for many turns, the underlying data may have moved on, and it will report a stale picture with confidence.

The store is now state you have to secure. A handle that any session can dereference is a way to read another user's results, so handles need the same authorization as the original query.

The preview is a choice, and a biased one can hide the row that matters. First rows by insertion order are rarely representative.

Some tasks need the whole text. Reviewing a diff or summarizing a short document gains nothing from indirection and loses a round trip. Below a modest size, return the payload directly.

In practice

I would start with a size threshold measured in estimated tokens, not rows, and switch to a handle only above it.

  • Return a fixed shape: handle, total count, schema, summary statistics, a small sample, and an expiry time.
  • Pick samples deliberately: include the most frequent values and the extremes, not just the first rows.
  • Never truncate silently. If anything was omitted, say how much and which tool reaches it.
  • Scope every handle to the session and the principal that created it, and check that on each dereference.
  • Keep the query that produced the handle so a result can be regenerated after expiry.
  • When a handle has expired, the error should name the original query and tell the agent to rerun it.
  • Keep the inspection tools few and composable: filter, aggregate, slice is usually enough.
Give the model a reference, a count and an honest sample, and let it pull the rest through narrow tools rather than pushing every row into the context.