Sobes.tech
Middle — Senior

How should an agent work with a very large toolkit (function selection)?

sobes.tech AI

Answer from AI

When working with an agent that has a very large toolkit (function selection), there is a problem of choosing relevant functions from a large set for a specific query.

Approaches to solving this:

  1. Indexing and filtering — pre-classify or index tools by topics, task types, or keywords to quickly narrow down the search.

  2. Using vector representations — convert function descriptions and queries into embeddings and select functions with the highest semantic similarity.

  3. Hierarchical selection — first select a category or subset of functions, then within it — a specific function.

  4. Training a selection model — train a model that takes a query as input and outputs the probabilities of relevance for functions.

Example in pseudocode using embeddings:

query_embedding = embed(query)
function_embeddings = [embed(f.description) for f in functions]
scores = cosine_similarity(query_embedding, function_embeddings)
top_functions = select_top_k(functions, scores, k=5)

Thus, the agent efficiently handles a large set of tools, selecting the most suitable ones for the current task.