Offer Only the Tools This Request Needs
Implement pick_tools(request, catalog, k=5), which returns the k tools from catalog most likely to handle a customer's message, best first. Each tool is a spec: {"name": ..., "description": ..., "input_schema": {...}}. Return the specs unchanged, with no repeats.
The support agent now has 30 tools in CATALOG. Sending them all costs thousands of tokens on every call, and a model choosing among 30 gets worse at it, so each call sends only the few that fit.
How you choose is up to you:
embedder.embed(texts): a real embedding model. A list of strings in, one vector each out;cosine(a, b)compares two. One call however long the list.jev.ask(state, questions): a decision model. Ascorequestion rates the content on a rubric you write, and one call can carry a question per tool.llm.ask(prompt): the real chat model. Show it the numbered catalog, ask it to rank, and pull the numbers out of its reply.- Plain Python, if you think shared words are enough. Customers write i can't remember the word i use to get in; the tool says Email a link for choosing new sign-in credentials.
The tests
- Over two sets of six messages, the right tool is in your five for at least five of each six.
- At most two model calls per message, across all three.
- Your five cost at most a quarter of the whole catalog's tokens.
- A real model, offered only your five, calls the right tool for at least three of four messages.
- It works on a catalog it has not seen, so no list of names in your code.
The catch. A tool's name is often not enough to find it. reroute_parcel looks nothing like can it go to my office instead. What you compare the message against decides how well this works.