LangEx.Middleware.ToolSelector (LangEx v0.11.3)

Copy Markdown View Source

Middleware that narrows a large tool set before the model call.

When the agent carries more than :max_tools tools, a cheap LLM call picks the subset relevant to the current task and only those are offered to the main model — cutting prompt size and tool-selection errors. Below the threshold the model sees every tool and no extra call is made, so this only earns its keep once a tool surface grows large (~15+ tools).

Implemented as a wrap_model_call hook, so it composes with other middleware and always defers to the real model call. If the selector call fails or returns nothing usable, it falls back to offering every tool. Its own (small) token usage is not added to :llm_usage.

Options

  • :model / :provider - the selector model (required; a fast, cheap model is ideal)
  • :max_tools - offer at most this many tools to the main model (default 7); the selector runs only when more than this are available
  • :always_include - tool names always kept regardless of selection
  • :resilient and other options are forwarded to the selector call

Summary

Functions

Builds a tool-selection middleware. See the module doc for options.

Functions

new(opts)

@spec new(keyword()) :: LangEx.Middleware.t()

Builds a tool-selection middleware. See the module doc for options.