Home / Function/ test_tool_calling_with_no_arguments() — langchain Function Reference

test_tool_calling_with_no_arguments() — langchain Function Reference

Architecture documentation for the test_tool_calling_with_no_arguments() function in chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  776f8723_e2e5_9360_49c9_b663d4402396["test_tool_calling_with_no_arguments()"]
  971e928f_9c9b_ce7a_b93d_e762f2f5aa54["ChatModelIntegrationTests"]
  776f8723_e2e5_9360_49c9_b663d4402396 -->|defined in| 971e928f_9c9b_ce7a_b93d_e762f2f5aa54
  f58f91d1_7ddd_dae8_206d_7a67b23d73eb["magic_function_no_args()"]
  776f8723_e2e5_9360_49c9_b663d4402396 -->|calls| f58f91d1_7ddd_dae8_206d_7a67b23d73eb
  54f514b4_9301_1102_df9e_06f10a786ff1["_validate_tool_call_message_no_args()"]
  776f8723_e2e5_9360_49c9_b663d4402396 -->|calls| 54f514b4_9301_1102_df9e_06f10a786ff1
  style 776f8723_e2e5_9360_49c9_b663d4402396 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/standard-tests/langchain_tests/integration_tests/chat_models.py lines 1966–2024

    def test_tool_calling_with_no_arguments(self, model: BaseChatModel) -> None:
        """Test that the model generates tool calls for tools with no arguments.

        This test is skipped if the `has_tool_calling` property on the test class
        is set to `False`.

        This test is optional and should be skipped if the model does not support
        tool calling (see configuration below).

        ??? note "Configuration"

            To disable tool calling tests, set `has_tool_calling` to `False` in your
            test class:

            ```python
            class TestMyChatModelIntegration(ChatModelIntegrationTests):
                @property
                def has_tool_calling(self) -> bool:
                    return False
            ```

        ??? question "Troubleshooting"

            If this test fails, check that `bind_tools` is implemented to correctly
            translate LangChain tool objects into the appropriate schema for your
            chat model. It should correctly handle the case where a tool has no
            arguments.

            This test may fail if the chat model does not support a `tool_choice`
            parameter. This parameter can be used to force a tool call. It may also
            fail if a provider does not support this form of tool. In these cases,
            you can `xfail` the test:

            ```python
            @pytest.mark.xfail(reason=("Does not support tool_choice."))
            def test_tool_calling_with_no_arguments(self, model: BaseChatModel) -> None:
                super().test_tool_calling_with_no_arguments(model)
            ```

            Otherwise, in the case that only one tool is bound, ensure that
            `tool_choice` supports the string `'any'` to force calling that tool.

        """
        if not self.has_tool_calling:
            pytest.skip("Test requires tool calling.")

        tool_choice_value = None if not self.has_tool_choice else "any"
        model_with_tools = model.bind_tools(
            [magic_function_no_args], tool_choice=tool_choice_value
        )
        query = "What is the value of magic_function_no_args()? Use the tool."
        result = model_with_tools.invoke(query)
        _validate_tool_call_message_no_args(result)

        full: BaseMessage | None = None
        for chunk in model_with_tools.stream(query):
            full = chunk if full is None else full + chunk  # type: ignore[assignment]
        assert isinstance(full, AIMessage)
        _validate_tool_call_message_no_args(full)

Domain

Subdomains

Frequently Asked Questions

What does test_tool_calling_with_no_arguments() do?
test_tool_calling_with_no_arguments() is a function in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py.
Where is test_tool_calling_with_no_arguments() defined?
test_tool_calling_with_no_arguments() is defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py at line 1966.
What does test_tool_calling_with_no_arguments() call?
test_tool_calling_with_no_arguments() calls 2 function(s): _validate_tool_call_message_no_args, magic_function_no_args.

Analyze Your Own Codebase

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

Try Supermodel Free