Papa Programmer
Lesson 12 of 20

Designing tools an agent can use

8 min read

Optional

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

  1. One job per tool. A tool called manage_orders that lists, cancels and refunds forces the model to pick the action as well. Make three tools: list_orders, cancel_order and refund_order.
  2. A name that says the action. Use verbs and nouns, such as search_articles. Avoid names such as helper or run.
  3. 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.
  4. Few, strict inputs. Ask for the smallest set of arguments, and give each a type. Offer a fixed list of choices where possible.
  5. 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.

python
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.

Name and describe for the modelThe name and description are the whole interface, so say what the tool does and when to use it.
One job, few inputsSplit broad tools, type the inputs and offer fixed choices where you can.
Errors that teachSay what failed and what to try next, so the agent can fix itself.

Your reading position is saved

0%

0 of 20 complete

Contents

Learning tools