Home / Function/ test_duplicate_tool_selection_deduplicated() — langchain Function Reference

test_duplicate_tool_selection_deduplicated() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  31e7b88f_288b_3f1b_84af_0fa51bf0c2b7["test_duplicate_tool_selection_deduplicated()"]
  35f5015e_df33_4916_06b8_dc32a7e06b79["TestDuplicateAndInvalidTools"]
  31e7b88f_288b_3f1b_84af_0fa51bf0c2b7 -->|defined in| 35f5015e_df33_4916_06b8_dc32a7e06b79
  style 31e7b88f_288b_3f1b_84af_0fa51bf0c2b7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_selection.py lines 516–572

    def test_duplicate_tool_selection_deduplicated(self) -> None:
        """Test that duplicate tool selections are deduplicated."""
        model_requests = []

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

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

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

        tool_selector = LLMToolSelectorMiddleware(max_tools=5, model=tool_selection_model)

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

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

        # Duplicates should be removed
        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 tool_names == ["get_weather", "search_web"]
            assert len(tool_names) == 2

Domain

Subdomains

Frequently Asked Questions

What does test_duplicate_tool_selection_deduplicated() do?
test_duplicate_tool_selection_deduplicated() 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_duplicate_tool_selection_deduplicated() defined?
test_duplicate_tool_selection_deduplicated() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_selection.py at line 516.

Analyze Your Own Codebase

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

Try Supermodel Free