Home / Function/ bind_tools() — langchain Function Reference

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
  ba87ba6a_45d8_03fe_9522_138432f5eb38["bind_tools()"]
  1a5cd25a_9420_c6b2_ec8d_2b53c6427514["ChatFireworks"]
  ba87ba6a_45d8_03fe_9522_138432f5eb38 -->|defined in| 1a5cd25a_9420_c6b2_ec8d_2b53c6427514
  539ec970_fba6_1286_7920_4016594274ca["with_structured_output()"]
  539ec970_fba6_1286_7920_4016594274ca -->|calls| ba87ba6a_45d8_03fe_9522_138432f5eb38
  style ba87ba6a_45d8_03fe_9522_138432f5eb38 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/fireworks/langchain_fireworks/chat_models.py lines 661–708

    def bind_tools(
        self,
        tools: Sequence[dict[str, Any] | type[BaseModel] | Callable | BaseTool],
        *,
        tool_choice: dict | str | bool | None = None,
        **kwargs: Any,
    ) -> Runnable[LanguageModelInput, AIMessage]:
        """Bind tool-like objects to this chat model.

        Assumes model is compatible with Fireworks 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,
                `'auto'` to automatically determine which function to call
                with the option to not call any function, `'any'` to enforce that some
                function is called, or a dict of the form:
                `{"type": "function", "function": {"name": <<tool_name>>}}`.
            **kwargs: Any additional parameters to pass to
                `langchain_fireworks.chat_models.ChatFireworks.bind`
        """  # noqa: E501
        strict = kwargs.pop("strict", None)
        formatted_tools = [
            convert_to_openai_tool(tool, strict=strict) for tool in tools
        ]
        if tool_choice is not None and tool_choice:
            if isinstance(tool_choice, str) and (
                tool_choice not in ("auto", "any", "none")
            ):
                tool_choice = {"type": "function", "function": {"name": tool_choice}}
            if isinstance(tool_choice, bool):
                if len(tools) > 1:
                    msg = (
                        "tool_choice can only be True when there is one tool. Received "
                        f"{len(tools)} tools."
                    )
                    raise ValueError(msg)
                tool_name = formatted_tools[0]["function"]["name"]
                tool_choice = {
                    "type": "function",
                    "function": {"name": tool_name},
                }

            kwargs["tool_choice"] = tool_choice
        return super().bind(tools=formatted_tools, **kwargs)

Domain

Subdomains

Frequently Asked Questions

What does bind_tools() do?
bind_tools() is a function in the langchain codebase, defined in libs/partners/fireworks/langchain_fireworks/chat_models.py.
Where is bind_tools() defined?
bind_tools() is defined in libs/partners/fireworks/langchain_fireworks/chat_models.py at line 661.
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