__init__() — langchain Function Reference
Architecture documentation for the __init__() function in tool_selection.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 74e81f5f_ce46_4e5d_763f_ed260d0dbec3["__init__()"] 888c953d_8f6f_ac7f_4274_ca04589e186a["LLMToolSelectorMiddleware"] 74e81f5f_ce46_4e5d_763f_ed260d0dbec3 -->|defined in| 888c953d_8f6f_ac7f_4274_ca04589e186a style 74e81f5f_ce46_4e5d_763f_ed260d0dbec3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/middleware/tool_selection.py lines 122–156
def __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:
"""Initialize the tool selector.
Args:
model: Model to use for selection.
If not provided, uses the agent's main model.
Can be a model identifier string or `BaseChatModel` instance.
system_prompt: Instructions for the selection model.
max_tools: 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.
always_include: Tool names to always include regardless of selection.
These do not count against the `max_tools` limit.
"""
super().__init__()
self.system_prompt = system_prompt
self.max_tools = max_tools
self.always_include = always_include or []
if isinstance(model, (BaseChatModel, type(None))):
self.model: BaseChatModel | None = model
else:
self.model = init_chat_model(model)
Domain
Subdomains
Source
Frequently Asked Questions
What does __init__() do?
__init__() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/tool_selection.py.
Where is __init__() defined?
__init__() is defined in libs/langchain_v1/langchain/agents/middleware/tool_selection.py at line 122.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free