Skip to main content

When building complex AI agents, it’s common to provide the model with a massive list of available functions (e.g., search_database, send_email, calculate_math, create_ticket). However, sending 50 tool definitions in a single request when the user just said “Hello” causes two major problems:
  1. Token Waste: Defining tools consumes a massive amount of input tokens.
  2. Hallucination Risk: The more tools a model sees, the more likely it is to get confused and try to call the wrong tool.
LLM Router’s Tools Optimization engine solves this by actively scoring and filtering your tools array before sending it to the upstream model.

How Tool Optimization Works

When a request containing a tools array arrives, our internal Gateway AI acts as a Tool Selector Agent.
  1. It analyzes the user’s prompt against the descriptions of all provided tools.
  2. It assigns a Relevance Score (0.0 to 1.0) to each tool.
  3. It detects Dependencies (e.g., if create_element requires get_context, both are scored highly).
  4. If a tool’s score falls below your configured threshold (acceptScore), it is stripped from the request entirely.

Configuration

You configure this behavior inside the gateway.toolOptimization object.
TypeScript

What happens in this example?

  1. The user asks a math question.
  2. The Gateway scores calculator at 1.0. It scores send_email at 0.0.
  3. It sees search_db in your alwaysInclude array.
  4. Result: The router strips send_email and sends ONLY calculator and search_db to Claude. You save tokens, and Claude doesn’t get distracted.

Configuration Properties

The toolOptimization Object