ToolsIntegrationTests#

class langchain_tests.integration_tests.tools.ToolsIntegrationTests[source]#

Base class for tools integration tests.

Attributes

tool_constructor

Returns a class or instance of a tool to be tested.

tool_constructor_params

Returns a dictionary of parameters to pass to the tool constructor.

tool_invoke_params_example

Returns a dictionary representing the "args" of an example tool call.

Methods

test_async_invoke_matches_output_schema(tool)

If ainvoked with a ToolCall, the tool should return a valid ToolMessage content.

test_async_invoke_no_tool_call(tool)

If ainvoked without a ToolCall, the tool can return anything but it shouldn't throw an error

test_invoke_matches_output_schema(tool)

If invoked with a ToolCall, the tool should return a valid ToolMessage content.

test_invoke_no_tool_call(tool)

If invoked without a ToolCall, the tool can return anything but it shouldn't throw an error

async test_async_invoke_matches_output_schema(tool: BaseTool) None[source]#

If ainvoked with a ToolCall, the tool should return a valid ToolMessage content.

For debugging tips, see test_invoke_matches_output_schema().

Parameters:

tool (BaseTool)

Return type:

None

async test_async_invoke_no_tool_call(tool: BaseTool) None[source]#

If ainvoked without a ToolCall, the tool can return anything but it shouldn’t throw an error

For debugging tips, see test_invoke_no_tool_call().

Parameters:

tool (BaseTool)

Return type:

None

test_invoke_matches_output_schema(tool: BaseTool) None[source]#

If invoked with a ToolCall, the tool should return a valid ToolMessage content.

If you have followed the custom tool guide, this test should always pass because ToolCall inputs are handled by the langchain_core.tools.BaseTool class.

If you have not followed this guide, you should ensure that your tool’s invoke method returns a valid ToolMessage content when it receives a dict representing a ToolCall as input (as opposed to distinct args).

Parameters:

tool (BaseTool)

Return type:

None

test_invoke_no_tool_call(tool: BaseTool) None[source]#

If invoked without a ToolCall, the tool can return anything but it shouldn’t throw an error

If this test fails, your tool may not be handling the input you defined in tool_invoke_params_example correctly, and it’s throwing an error.

This test doesn’t have any checks. It’s just to ensure that the tool doesn’t throw an error when invoked with a dictionary of kwargs.

Parameters:

tool (BaseTool)

Return type:

None