From ca9dcee9400eec3464550849b564c32d4406a983 Mon Sep 17 00:00:00 2001 From: Bagatur <22008038+baskaryan@users.noreply.github.com> Date: Fri, 9 Aug 2024 13:00:14 -0700 Subject: [PATCH] standard-tests[patch]: test ToolMessage.status="error" (#25210) --- .../integration_tests/chat_models.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/libs/standard-tests/langchain_standard_tests/integration_tests/chat_models.py b/libs/standard-tests/langchain_standard_tests/integration_tests/chat_models.py index ffec9dc90bc..bcb47a4c151 100644 --- a/libs/standard-tests/langchain_standard_tests/integration_tests/chat_models.py +++ b/libs/standard-tests/langchain_standard_tests/integration_tests/chat_models.py @@ -481,3 +481,31 @@ class ChatModelIntegrationTests(ChatModelTests): ), ] model.bind_tools([color_picker]).invoke(messages) + + def test_tool_message_error_status(self, model: BaseChatModel) -> None: + """Test that ToolMessage with status='error' can be handled.""" + if not self.has_tool_calling: + pytest.skip("Test requires tool calling.") + model_with_tools = model.bind_tools([my_adder_tool]) + messages = [ + HumanMessage("What is 1 + 2"), + AIMessage( + "", + tool_calls=[ + { + "name": "my_adder_tool", + "args": {"a": 1}, + "id": "abc123", + "type": "tool_call", + }, + ], + ), + ToolMessage( + "Error: Missing required argument 'b'.", + name="my_adder_tool", + tool_call_id="abc123", + status="error", + ), + ] + result = model_with_tools.invoke(messages) + assert isinstance(result, AIMessage)