Designing tools an agent can use
8 min read
The model reads your tool like a manual
A person using a tool can ask a colleague what it does. A model cannot. It has only the name, the description and the list of inputs. If those are vague, the model will guess, and it will sometimes guess wrong.
So write a tool for a reader who has no other context. The test is simple. If a new colleague could not tell when to use the tool from its description alone, the model cannot either.
Five habits
- One job per tool. A tool called
manage_ordersthat lists, cancels and refunds forces the model to pick the action as well. Make three tools:list_orders,cancel_orderandrefund_order. - A name that says the action. Use verbs and nouns, such as
search_articles. Avoid names such ashelperorrun. - A description that says when. Say what the tool does and when to use it. Add when not to use it if two tools look alike.
- Few, strict inputs. Ask for the smallest set of arguments, and give each a type. Offer a fixed list of choices where possible.
- A short, useful result. Return what the next step needs, not everything the system knows. Long output fills the context window.
Before and after
The two definitions below describe the same function. The second one gives the model what it needs.
vague = {
"name": "run",
"description": "Does stuff with orders.",
"parameters": {"input": "string"},
}
clear = {
"name": "cancel_order",
"description": "Cancel one order that has not shipped yet. Use refund_order for orders that have shipped.",
"parameters": {
"order_id": {"type": "string", "description": "The order number, such as 1042"},
"reason": {"type": "string", "enum": ["changed_mind", "wrong_item", "other"]},
},
}
print(clear["name"], list(clear["parameters"]))The clear version has an exact name, a description that says when to use it and when to use another tool, a described order_id and a fixed list of reasons. The model can no longer invent a reason such as "banana".
Make errors helpful
A tool will fail sometimes, and the message is part of the design. Compare two replies to the same mistake.
- Unhelpful.
Error 400 - Helpful.
order_id 10X2 was not found. Order numbers are four digits. Try list_orders to find it.
The second reply tells the model what went wrong and what to do next. Agents with good error messages recover on their own, and agents with bad ones loop.
Last, keep the total small. Ten clear tools usually work better than forty overlapping ones, because each extra tool is one more chance to pick the wrong one.
Which tool is better?
You can write one tool, `manage_orders`, or three: `list_orders`, `cancel_order` and `refund_order`.
A single broad tool forces the model to choose the action as well. One job per tool is clearer.
What improves this description?
The tool `cancel_order` says only: "Does stuff with orders."
The model reads the description like a manual. If a new colleague could not tell when to use the tool, neither can the model.
How should the `reason` input be defined?
A cancel tool takes a reason, and you do not want invented values.
Fixed choices keep the model from inventing values, such as a reason that your system does not know.
Your reading position is saved
0 of 20 complete
Lesson complete
Designing tools an agent can use
Up next