# LLMToolSelectorMiddleware

> **Class** in `langchain`

📖 [View in docs](https://reference.langchain.com/python/langchain/agents/middleware/tool_selection/LLMToolSelectorMiddleware)

Uses an LLM to select relevant tools before calling the main model.

When an agent has many tools available, this middleware filters them down
to only the most relevant ones for the user's query. This reduces token usage
and helps the main model focus on the right tools.

## Signature

```python
LLMToolSelectorMiddleware(
    self,
    *,
    model: str | BaseChatModel | None = None,
    system_prompt: str = DEFAULT_SYSTEM_PROMPT,
    max_tools: int | None = None,
    always_include: list[str] | None = None,
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model` | `str \| BaseChatModel \| None` | No | Model to use for selection.  If not provided, uses the agent's main model.  Can be a model identifier string or `BaseChatModel` instance. (default: `None`) |
| `system_prompt` | `str` | No | Instructions for the selection model. (default: `DEFAULT_SYSTEM_PROMPT`) |
| `max_tools` | `int \| None` | No | Maximum number of tools to select.  If the model selects more, only the first `max_tools` will be used.  If not specified, there is no limit. (default: `None`) |
| `always_include` | `list[str] \| None` | No | Tool names to always include regardless of selection.  These do not count against the `max_tools` limit. (default: `None`) |

## Extends

- `AgentMiddleware[AgentState[ResponseT], ContextT, ResponseT]`

## Constructors

```python
__init__(
    self,
    *,
    model: str | BaseChatModel | None = None,
    system_prompt: str = DEFAULT_SYSTEM_PROMPT,
    max_tools: int | None = None,
    always_include: list[str] | None = None,
) -> None
```

| Name | Type |
|------|------|
| `model` | `str \| BaseChatModel \| None` |
| `system_prompt` | `str` |
| `max_tools` | `int \| None` |
| `always_include` | `list[str] \| None` |


## Properties

- `system_prompt`
- `max_tools`
- `always_include`
- `model`

## Methods

- [`wrap_model_call()`](https://reference.langchain.com/python/langchain/agents/middleware/tool_selection/LLMToolSelectorMiddleware/wrap_model_call)
- [`awrap_model_call()`](https://reference.langchain.com/python/langchain/agents/middleware/tool_selection/LLMToolSelectorMiddleware/awrap_model_call)

---

[View source on GitHub](https://github.com/langchain-ai/langchain/blob/311675a517f51ec6c77454124293c58df517e952/libs/langchain_v1/langchain/agents/middleware/tool_selection.py#L93)