Home / Function/ test_always_include_tools_present() — langchain Function Reference

test_always_include_tools_present() — langchain Function Reference

Architecture documentation for the test_always_include_tools_present() function in test_tool_selection.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  5c760ec7_1408_6a23_d909_a355873179cf["test_always_include_tools_present()"]
  ee17f352_671b_7645_71f1_b7942fb8e4d0["TestAlwaysInclude"]
  5c760ec7_1408_6a23_d909_a355873179cf -->|defined in| ee17f352_671b_7645_71f1_b7942fb8e4d0
  style 5c760ec7_1408_6a23_d909_a355873179cf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_selection.py lines 340–393

    def test_always_include_tools_present(self) -> None:
        """Test that always_include tools are always present in the request."""
        model_requests = []

        @wrap_model_call
        def trace_model_requests(
            request: ModelRequest, handler: Callable[[ModelRequest], ModelResponse]
        ) -> ModelResponse:
            model_requests.append(request)
            return handler(request)

        # Selector picks only search_web
        tool_selection_model = FakeModel(
            messages=cycle(
                [
                    AIMessage(
                        content="",
                        tool_calls=[
                            {
                                "name": "ToolSelectionResponse",
                                "id": "1",
                                "args": {"tools": ["search_web"]},
                            }
                        ],
                    ),
                ]
            )
        )

        model = FakeModel(messages=iter([AIMessage(content="Done")]))

        # But send_email is always included
        tool_selector = LLMToolSelectorMiddleware(
            max_tools=1, always_include=["send_email"], model=tool_selection_model
        )

        agent = create_agent(
            model=model,
            tools=[get_weather, search_web, send_email],
            middleware=[tool_selector, trace_model_requests],
        )

        agent.invoke({"messages": [HumanMessage("test")]})

        # Both selected and always_include tools should be present
        assert len(model_requests) > 0
        for request in model_requests:
            tool_names = []
            for tool_ in request.tools:
                assert isinstance(tool_, BaseTool)
                tool_names.append(tool_.name)
            assert "search_web" in tool_names
            assert "send_email" in tool_names
            assert len(tool_names) == 2

Domain

Subdomains

Frequently Asked Questions

What does test_always_include_tools_present() do?
test_always_include_tools_present() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_selection.py.
Where is test_always_include_tools_present() defined?
test_always_include_tools_present() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_selection.py at line 340.

Analyze Your Own Codebase

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

Try Supermodel Free