AWS Builder Center

Agents for Humans, the budget my agent ignored because I only asked it nicely

The page budget in my Agents for Humans entry was a sentence in a prompt, and nothing enforced it. Where the rule went, the second hole I only found by looking for it, and the question I now ask of anything I put in a prompt.

This is the third thing I have written about Asterisk, my entry for the Agents
for Humans hackathon. The first was about three design mistakes. The second was
about the half of the tool that runs with no model at all. This one is about a
single line of prose that I mistook for a rule, and about what it cost me to
find out.
## The line
The agent's task text contained this.
Budget, at most 4 pages in total including this one.
I wrote it, I read it back, and I moved on. It looked like a constraint. It was
a sentence.
Nothing checked it. Nothing counted. A model that finds page four interesting
fetches page five, and the only thing that was ever going to stop it was a
paragraph asking politely. A prompt is a promise the program makes to itself,
and this one was being broken by the only party in the room who had not read it
carefully.
## Why this particular bug was embarrassing
Asterisk exists to read an offer page and show where that page takes back its
own headline. The free trial that is not free after the third paragraph. The
cancel any time that has a notice period further down.
So I had built a tool whose entire purpose is to find headlines contradicted by
their own fine print, and its agent could contradict its own headline. I did not
enjoy writing that sentence in the source, and I left it there on purpose,
because it is the most useful comment in the file.
## Where the rule went
Strands Agents has a hook registry, and the budget moved into it. The adapter
is five lines.
def before_tool(self, event: BeforeToolCallEvent) -> None:
name = (event.tool_use or {}).get("name")
if name != "audit_page":
return
url = ((event.tool_use or {}).get("input") or {}).get("url", "")
motif = self.budget.decide(url)
if motif:
self.refused.append(url)
event.cancel_tool = motif
The important word is `cancel_tool`. It turns a refusal into a refusal. Before,
the limit was advice the model could weigh against how interesting page five
looked. Now the call does not happen, and no amount of interest changes that.
Ranking links and checking a quote stay free. Only fetching a page is charged,
because only fetching a page costs anything.
## The second hole, which I only found because I went looking for it
Having moved the budget into a hook that guards `audit_page`, I asked a
question I recommend to anyone who has just closed one door. Which other tool
touches the network.
One did. `check_quote`, the tool that verifies a quotation really appears on a
page, used to fetch the page if it had not been read yet. That is a hole
straight through the budget. A model that wanted a fifth page only had to ask
for a quote from it.
A limit that one door enforces and another ignores is not a limit.
What makes this one worth telling is that refusing was also the right answer on
the merits, independently of any budget. You cannot quote a page you never
read. A check that silently fetches the page first is not checking the claim, it
is manufacturing the evidence for it. The bug and the correctness problem had
the same fix, which is usually a sign that the fix is the real one.
## Where the decision actually lives
The hook holds no rule. It is an adapter. The decision is twenty lines in a
separate module that needs no model, no network and no agent to exercise.
That was deliberate, and it is the part I would defend hardest. Logic that can
only be reached through a language model is logic nobody checks. You cannot
write a fast test for it, so you write a slow one, so you run it rarely, so it
rots. Put the decision somewhere a plain unit test can reach in a millisecond
and it gets tested every time, by accident, forever.
There are five tests on the budget alone. One of them exists because of a
mistake I made while writing the second refusal reason.
## The refusal I did not expect to need
The budget refuses two things, and the second is not about cost at all. It
refuses a page the agent has already audited.
In early runs that was the more common refusal of the two. The agent would
follow a terms link, find a pricing link on it, follow that, and arrive back
where it started by a different route. It cost a request and returned nothing.
And the subtle part, which a test now pins down. Refusing a repeat must not
spend a budget slot. Otherwise the budget shrinks through use, and an agent
that goes in a small circle three times has silently lost three of its four
pages without reading anything new.
## What I took from it
I had written the constraint down. I had read it back. I had even quoted it in
my own notes as though it were implemented. None of that is enforcement.
The question I now ask of anything I put in a prompt is short. If the model
ignored this sentence entirely, what in the program would notice. If the answer
is nothing, it is not a constraint, it is a wish, and it belongs in code where
a refusal can be a refusal.
Asterisk is at `github.com/thibaudlepan77-svg/asterisk`. Sixty nine tests, no
network and no key needed for the deterministic path.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article