# Cut the agent toolset down to nine: generic tools are the real trap

Date: 2025-07-22
Category: Technology
Tags: Agent, Tool Design, Context
Summary: From 23 tools down to 9: how to merge overlapping entry points, why a general-purpose tool that can write SQL is the most dangerous, and why write operations should be cut down to almost nothing.

Print out the agent's tool list, about twenty lines. Stared at it for a while and noticed several groups of tools fighting over the same job: several can fetch web pages, several are looking for files, and several are taking notes.

No one designed it this way; it grew. Every time I hit a scenario that wasn't covered, I added one. After half a year of adding, the toolset became a historical record no one dared touch. What really made me decide to cut was running trajectories: the model hesitates between "use web_search or browser_open," picks wrong, retries with a different name. This back-and-forth accounted for a good chunk of the dozens of trajectories I sampled. It wasn't thinking; it was guessing which name looked more right.

## Overlapping entry points, cost lands on every call

The most typical case is finding files. Three tools—glob, grep, list_dir—with descriptions "match paths by wildcard," "search regex in file contents," "list directory contents." When I wrote them, the boundaries felt crystal clear, but that clarity only holds for the person who wrote them. The model sees "find where the config is" and all three seem plausible, so it starts trying them one by one.

Merged into a single `search_files(pattern, kind)`, with kind taking only two values: `path` and `content`. The internal implementation is still the same set; the entry points went from three to one, and the choice went from "guess the tool" to "fill in parameters"—and filling in parameters is what it's good at.

Fetching web pages is the same. web_search, browser_open, http_request can all get page content. I deleted the latter two, keeping only `web_search` (returns summaries and links) and `fetch_page(url)` (gets the body text). The only irreplaceable capability of browser_open is executing JS. I went through my own scenarios one by one—no page requires rendering to be read—so it had no reason to exist.

I didn't calculate this cost at first: tool names plus descriptions, roughly 60 to 150 tokens each, 23 tools permanently occupying around two thousand at the very front of the system prompt. This block sits before all conversation and affects every subsequent decision. After cutting to 9, this block went back to around seven hundred. What's saved isn't money; it's the probability of the model drifting in long contexts.

## General-purpose tools are traps, especially the kind that can write SQL

`sql_query` is the one I regret adding most. The description says "execute read-only SQL queries," which sounds clean and neat. The problem is the model writes its own joins, and when it gets them wrong, no error is raised—it returns an empty set or a row of obviously-too-small numbers, and then it takes that result and keeps reasoning. Whether the empty set means no orders or a badly written join, it can't tell itself.

The destructive power of silent failure is an order of magnitude greater than errors. With an error it retries; with silent success it treats it as fact.

After deleting it, I replaced it with three read-only tools named after business questions: `count_orders_by_day(start, end)`, `top_products(start, end, limit)`, `user_orders(user_id, limit)`. The parameters are just date and count; the SQL is hardcoded inside the tool. The cost is that every new question may require adding a tool; the benefit is the model no longer has any chance to invent a join.

`http_request` has the same flaw. A tool that can send arbitrary requests is equivalent to pushing auth, pagination, rate limiting, and error-code parsing all onto the model—and it has no information on any of these. If you really need to call an external API, wrap a tool with clear semantics, like `get_invoice(order_id)`, with timeout and retry written inside.

## Cut write operations to the minimum, read operations can be relaxed

This is something I only accepted after stepping on it: a wrong read costs one retry; a wrong write costs an email already sent.

So `send_email` became `draft_email`, `create_calendar_event` became `propose_event`, `update_ticket` became `comment_ticket`. All three only produce "actions pending confirmation," landing in a pending area, and only execute after a human clicks. It sounds like a step back, but since launch I've never again thought at midnight "did it just send something to a customer."

The only write tool kept is `write_file`, which must carry an idempotency key so retries don't write twice:

```python
def write_file(path: str, content: str, key: str) -> str:
    if seen(key):                # 同一个 key 只落一次
        return "already applied"
    mark(key)
    Path(path).write_text(content, encoding="utf-8")
    return f"wrote {len(content)} chars to {path}"
```

`key` is generated by the model, usually "task id + target path." It occasionally generates a different key for the same task, which is more common than duplicate writes, but at least it won't write twice in a timeout retry.

Also deleted are `memory_write` and `memory_read`. I originally had the agent write memories to the vector store while writing files to the workspace; the two states didn't match, and when troubleshooting I didn't know which to trust. Now only files remain: `notes.md` under the workspace, readable, diffable, and can go into git. Context does get longer, tokens go up a bit, but when something goes wrong I can open it directly and see what it recorded.

`task_plan` is also deleted. It has an output format and field validation, looks quite legit, but in practice the model only writes and never reads—after writing the plan it just proceeds and never looks back. Keeping just `todo_write` is enough; at least it can be seen by a human.

## The remaining nine, each with a sentence on "what to do if it fails"

The final list is: `ask_user`, `web_search`, `fetch_page`, `search_files`, `read_file`, `write_file`, `run_python`, `todo_write`, plus the three business queries from earlier—I count business queries as one category, otherwise I can't get to nine.

More important than the count is that at the end of each tool's description I added a sentence on the failure path. For example, `fetch_page` says "if it returns 403 or the body is under 200 characters, don't retry the same URL; use web_search to find an alternative source"; `run_python` says "anything involving currency conversion, ratios, or date differences always goes here, don't do mental math."

These sentences are more useful than the tools themselves. After deleting `calculator`, it might make mistakes doing mental exchange-rate math, and at first it's easy to want to add it back, but later you realize adding a sentence "don't do mental math involving amounts" is enough: this kind of miscalculation is usually not knowing what to calculate, not being unable to calculate.

One I deleted by mistake: the `offset` and `limit` parameters of `read_file`—I once thought the model wouldn't use them and deleted them, and then when it hit a large file it couldn't read fully and started making up the rest. A tool's parameters are also part of the tool surface; deleting parameters carries the same risk as deleting tools.

To judge whether a tool should stay, I now only ask three questions:

- If you delete it, what will the model do? If the answer is "use another tool to get around it," delete it.
- Is its failure loud or silent? Silent ones either need the implementation changed or the shape changed.
- Is it a read or a write? Writes must have confirmation or idempotency.

Before adding a tool to the agent next time, print out the current list first and read every description. If you yourself have to flip back to confirm the difference by the second one, the model is doing the same thing when calling.

Further reading: [Context is not memory: writing, reading, and forgetting in Agent memory](/2026/02/25/agent-memory-read-write-and-forgetting/)
