Home / Function/ bind_tools() — langchain Function Reference

bind_tools() — langchain Function Reference

Architecture documentation for the bind_tools() function in model.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  1c6867c8_fc68_dc42_8f10_0e4a1e9630f1["bind_tools()"]
  67d9a14e_be69_a367_fd3c_cdb7f78dfa76["FakeToolCallingModel"]
  1c6867c8_fc68_dc42_8f10_0e4a1e9630f1 -->|defined in| 67d9a14e_be69_a367_fd3c_cdb7f78dfa76
  style 1c6867c8_fc68_dc42_8f10_0e4a1e9630f1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/model.py lines 74–111

    def bind_tools(
        self,
        tools: Sequence[dict[str, Any] | type | Callable[..., Any] | BaseTool],
        *,
        tool_choice: str | None = None,
        **kwargs: Any,
    ) -> Runnable[LanguageModelInput, AIMessage]:
        if len(tools) == 0:
            msg = "Must provide at least one tool"
            raise ValueError(msg)

        tool_dicts = []
        for tool in tools:
            if isinstance(tool, dict):
                tool_dicts.append(tool)
                continue
            if not isinstance(tool, BaseTool):
                msg = "Only BaseTool and dict is supported by FakeToolCallingModel.bind_tools"
                raise TypeError(msg)

            # NOTE: this is a simplified tool spec for testing purposes only
            if self.tool_style == "openai":
                tool_dicts.append(
                    {
                        "type": "function",
                        "function": {
                            "name": tool.name,
                        },
                    }
                )
            elif self.tool_style == "anthropic":
                tool_dicts.append(
                    {
                        "name": tool.name,
                    }
                )

        return self.bind(tools=tool_dicts, **kwargs)

Domain

Subdomains

Frequently Asked Questions

What does bind_tools() do?
bind_tools() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/model.py.
Where is bind_tools() defined?
bind_tools() is defined in libs/langchain_v1/tests/unit_tests/agents/model.py at line 74.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free