Prefer Search/Filter Over List-Everything

Give agents a search or filter interface rather than a tool that returns a full list — agents that list everything then scan results are burning context on data they'll mostly discard.

What it is

A common tool design mistake is providing a "list all" operation and expecting the agent to iterate through the results to find what it needs. The agent calls list_files(), receives 400 file paths, loads them into context, and then scans for the two files it actually cares about. The 398 irrelevant paths consume tokens, crowd out working content, and force the model to attend across a large noisy payload to extract a small useful signal. Search-over-list replaces this pattern with a targeted interface: instead of list_files(), provide find_files(pattern=...) or search_files(query=...). The agent specifies what it is looking for; the tool does the filtering; the response contains only the relevant results. This moves work from the model's context to the tool's implementation — exactly the right direction. The cost of filtering at the tool layer is near zero; the cost of filtering inside a model's context window is measured in tokens, latency, and reasoning quality. The principle extends beyond file systems: any tool that could return a large collection benefits from a search or filter parameter. Databases should expose queries, not table dumps. Event logs should support time range and type filters, not full dumps. Configuration stores should support key lookup, not serialization of the entire config.

When to reach for it

When NOT to

Exemplars

Related