Moving a rule from the prompt into the tool
Ask @todoist “When is the Quidditch final? I think it was in #design”, and the agent searches the design channel. The answer is in another channel, so the search comes back empty. Our prompt had a sentence for that case: “A search limited to one channel with channel_id that finds nothing useful is repeated without channel_id before you give the not-found answer.” The model obeyed. It read the empty result, spent a model turn, and sent the same search again without the channel.
That works, but each repeat is a tool call and a model turn, and the rule is one more sentence in a long prompt. A neighbouring sentence did the same for dates: on a status question, search the last 14 days first, “and search again without it before you conclude”. The model obeyed that one even when the dated search had already found the answer.
What the article says
Anthropic’s Building effective agents argues that the agent-computer interface deserves as much care as a human one. Its appendix tells how the authors spent more time on their tools than on the overall prompt, and gives the advice to “poka-yoke your tools”: change the tool so that the mistake is harder to make. Their example is a file tool that kept getting relative paths wrong, fixed by requiring absolute paths rather than by explaining paths better. The companion article, Writing effective tools for agents, with agents, adds that a tool can handle several operations under the hood, and that what it returns, errors included, can steer the agent.
Put together: when a prompt rule describes a fixed sequence of tool calls, the sequence probably belongs in the tool.
What we changed
A search that widens itself
In agent-core#556, I made the Comms search retry on its own. When the first page comes back complete and empty, the tool searches again with one filter less, then with none: first without the date, then without the channel, then without both, at most four requests in one call. An attempt that would repeat an earlier request is skipped. The date goes first because the model picks it as a guess at recency, while the channel comes from the asker’s own link.
An integration test pins the order. The asker has joined two public channels, the model gives a date and one of them, and nothing matches (the test’s assertions, reformatted; after_ts is the date as a timestamp):
search({ query: 'pilot', since: '2026-10-22', channel_id: 'public-channel' })
sent: after_ts=1792627200 channel_ids=[public-channel]
sent: after_ts=null channel_ids=[public-channel]
sent: after_ts=1792627200 channel_ids=[channel-1, public-channel]
sent: after_ts=null channel_ids=[channel-1, public-channel]
{ results: [], dropped_filters: { since: '2026-10-22', channel_id: 'public-channel' } }
The result names what it left out in dropped_filters. Nothing changes in what may be searched: a widened search covers the asker’s joined public channels, as a search without a channel already did.
Both prompt sentences are gone. The search paragraph lost a clause and a sentence (trimmed):
- For a status, the latest on something, or a question about today or this week, set since to 14 days before today's date on your first search, and search again without it before you conclude. A search limited to one channel with channel_id that finds nothing useful is repeated without channel_id before you give the not-found answer.
+ For a status, the latest on something, or a question about today or this week, set since to 14 days before today's date on your first search.
The tool description gained one sentence in their place: “When nothing matches with them, the search drops them itself and names them in dropped_filters: its results are then older or from other channels.”
A write that is never sent twice
A write can fail in a way that leaves its outcome unknown, such as a Todoist task after a dropped connection. Two prompts told the model not to retry it. One read: “If a tool says a change may not have been saved, do not try it again: say so and ask the asker to check Todoist.” Nothing enforced that.
In agent-core#570, I moved it into the gate every tool call goes through. The gate remembers, by tool name and input, each write of the run that may have been made. An identical write is refused without being sent. A different input or another tool goes through as before. A refusal that provably wrote nothing, such as a batch whose every item was rejected, is marked that way, so retrying it stays allowed. Both prompt sentences are gone.
Two tests show the sequence. In the Todoist one, a synthetic server drops the connection after it receives the task, and the tool returns what the model would read:
todoist.add_tasks { "tasks": [{ "content": "Follow up" }] }
→ { "uncertain": "The Todoist change may or may not have been saved. Do not try it again. Tell the asker to check Todoist." }
The result already said not to retry, and so did the prompt. Neither could stop one. In the gate’s test, a write whose connection resets is sent again with the same input, and the gate does not pass it on. The call returns:
→ { "unavailable": "This change may already have been made, so it was not sent again. Tell the asker to check it." }
The product saw one request. A third call with another input was sent.
What we measured
We check changes by playing a set of synthetic questions through the real service and the live model, on the main branch and on the change at the same time.
For the widening search, 41 cases in the four families that search, played 3 times on each side:
| main | Widening search | |
|---|---|---|
| Runs that pass their checks | 121 of 123 | 123 of 123 |
| Searches | 157 | 126 |
| Tool calls | 374 | 341 |
| Input tokens | 1,542,922 | 1,392,284 |
| Median latency | 6.3 s | 6.2 s |
The pass rates are not a win. The comparison reports no clear difference (p = 0.498), and a later run on the final commit gave 48 of 48 on main and 47 of 48 on the change, from a case that makes no search and had also failed once on main. What the change bought is fewer searches and fewer tokens with no drop in pass rate on this set, and a shorter prompt. Latency did not improve: the 90th percentile went from 13.5 s to 17.4 s, mostly in cases whose searches did not change.
One case from that comparison shows where the searches went. tool-reads-12-named-channel-without-the-answer asks the opening question in a synthetic workspace. Its #design channel holds one thread, “The new house banners are approved.” Its #great-hall channel holds “The Quidditch final is on June 20 at the pitch.” The checks: the answer says June 20, cites the great-hall thread, and calls comms.search_content.
The tools each side called:
main: comms.load_thread, comms.search_content, comms.search_content, comms.load_thread
branch: comms.load_thread, comms.search_content, comms.load_thread
On main, the model searched twice; one of its three runs also looked up a user. On the branch, it searched once. The PR’s example of this question shows why: on main the search in ch-design comes back empty and the model repeats it without channel_id; on the branch the one search returns the great-hall thread with "dropped_filters": {"channel_id": "ch-design"}. The answers barely differ (source links trimmed; the main answer is from another evaluation run of main that day, whose only changes were to the evaluation setup):
main: The Quidditch final is on **June 20** at the pitch (posted in the [great-hall](comms-channel://ch-great-hall) channel).
branch: The Quidditch final is on **June 20** at the pitch (posted in great-hall, not [design](comms-channel://ch-design)).
All six runs passed every check. Over three runs a side, the case used 43,126 input tokens on main and 33,901 on the branch. It was not faster: main took 12.9 to 16.6 s, the branch 9.5 to 27.3 s.
For the repeated write, the outcome cannot be triggered from the evaluation set, since it needs a write that fails after being sent. Unit tests cover the gate, and the 23 runs of the Todoist, Automations and connected-service families all pass their checks with both prompt sentences removed.
What I’d tell someone doing the same
Look for prompt sentences shaped like “if the tool returns X, call it again with Y”. Those are code waiting to be written. A sentence that asks for judgment (“is this result useful?”) is not, and should stay in the prompt.
The tool covers less than the rule did. It widens only when nothing matches. A dated or single-channel search that returns results, none of them useful, is not widened, and only the general rule to try other queries remains for that case. I tried it with a case I did not commit: a recent post only mentions the subject, and the status is in an older thread. Both sides answered from the older thread 6 times out of 6, and the new version made its second search without being told to.
Tell the model what the tool did. dropped_filters and the refusal sentence are as much a part of the change as the retry and the gate. A tool that silently does something different from what was asked moves the confusion instead of removing it.
Expect your metrics to blur. Our reports did not record dropped_filters, so they could not tell a search the tool widened from one the model simply stopped repeating. The 31 searches saved come from both.
Size the guard to the risk. The write gate refuses only an identical retry of a write that may have happened. A blanket “never retry a failed write” would have been simpler to write and would have blocked the retries that are safe.