bind_tools() — langchain Function Reference
Architecture documentation for the bind_tools() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 28eecd69_58db_770a_6b8b_ddbe1d0c5e20["bind_tools()"] 24cf3ac3_ed46_66ab_27f4_5b5d67f0b7f0["ChatMistralAI"] 28eecd69_58db_770a_6b8b_ddbe1d0c5e20 -->|defined in| 24cf3ac3_ed46_66ab_27f4_5b5d67f0b7f0 f73f8b04_5858_f84e_8eb8_98cd9e9ef152["with_structured_output()"] f73f8b04_5858_f84e_8eb8_98cd9e9ef152 -->|calls| 28eecd69_58db_770a_6b8b_ddbe1d0c5e20 style 28eecd69_58db_770a_6b8b_ddbe1d0c5e20 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/mistralai/langchain_mistralai/chat_models.py lines 784–823
def bind_tools(
self,
tools: Sequence[dict[str, Any] | type | Callable | BaseTool],
tool_choice: dict | str | Literal["auto", "any"] | None = None, # noqa: PYI051
**kwargs: Any,
) -> Runnable[LanguageModelInput, AIMessage]:
"""Bind tool-like objects to this chat model.
Assumes model is compatible with OpenAI tool-calling API.
Args:
tools: A list of tool definitions to bind to this chat model.
Supports any tool definition handled by [`convert_to_openai_tool`][langchain_core.utils.function_calling.convert_to_openai_tool].
tool_choice: Which tool to require the model to call.
Must be the name of the single provided function or
`'auto'` to automatically determine which function to call
(if any), or a dict of the form:
{"type": "function", "function": {"name": <<tool_name>>}}.
kwargs: Any additional parameters are passed directly to
`self.bind(**kwargs)`.
""" # noqa: E501
formatted_tools = [convert_to_openai_tool(tool) for tool in tools]
if tool_choice:
tool_names = []
for tool in formatted_tools:
if ("function" in tool and (name := tool["function"].get("name"))) or (
name := tool.get("name")
):
tool_names.append(name)
else:
pass
if tool_choice in tool_names:
kwargs["tool_choice"] = {
"type": "function",
"function": {"name": tool_choice},
}
else:
kwargs["tool_choice"] = tool_choice
return super().bind(tools=formatted_tools, **kwargs)
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does bind_tools() do?
bind_tools() is a function in the langchain codebase, defined in libs/partners/mistralai/langchain_mistralai/chat_models.py.
Where is bind_tools() defined?
bind_tools() is defined in libs/partners/mistralai/langchain_mistralai/chat_models.py at line 784.
What calls bind_tools()?
bind_tools() is called by 1 function(s): with_structured_output.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free