44from unittest .mock import AsyncMock , Mock , patch
55
66import pytest
7- from langchain_core .messages import AIMessage
7+ from langchain_core .messages import AIMessage , HumanMessage
88from pydantic import BaseModel , ConfigDict , Field
99from uipath .agent .models .agent import (
1010 AgentInternalToolProperties ,
@@ -76,15 +76,15 @@ def resource_config(self):
7676 "uipath_langchain.agent.wrappers.job_attachment_wrapper.get_job_attachment_wrapper"
7777 )
7878 @patch (
79- "uipath_langchain.agent.tools.internal_tools.analyze_files_tool.llm_call_with_files "
79+ "uipath_langchain.agent.tools.internal_tools.analyze_files_tool.add_files_to_message "
8080 )
8181 @patch (
8282 "uipath_langchain.agent.tools.internal_tools.analyze_files_tool._resolve_job_attachment_arguments"
8383 )
8484 async def test_create_analyze_file_tool_success (
8585 self ,
8686 mock_resolve_attachments ,
87- mock_llm_call ,
87+ mock_add_files ,
8888 mock_get_wrapper ,
8989 resource_config ,
9090 mock_llm ,
@@ -98,7 +98,16 @@ async def test_create_analyze_file_tool_success(
9898 mime_type = "application/pdf" ,
9999 )
100100 ]
101- mock_llm_call .return_value = "Analysis complete"
101+
102+ # mock add_files_to_message to return a message with files added
103+ mock_message_with_files = HumanMessage (
104+ content = [
105+ {"type" : "text" , "text" : "Summarize the document" },
106+ {"type" : "file" , "url" : "https://example.com/file.pdf" },
107+ ]
108+ )
109+ mock_add_files .return_value = mock_message_with_files
110+
102111 mock_wrapper = Mock ()
103112 mock_get_wrapper .return_value = mock_wrapper
104113
@@ -121,18 +130,29 @@ async def test_create_analyze_file_tool_success(
121130 )
122131
123132 # Verify calls
124- assert result == "Analysis complete "
133+ assert result == "Analyzed result "
125134 mock_resolve_attachments .assert_called_once ()
126- mock_llm_call .assert_called_once ()
127-
128- # Verify LLM call arguments
129- call_args = mock_llm_call .call_args
130- messages , files , llm = call_args [0 ]
131- assert len (messages ) == 2
132- assert messages [0 ].content == ANALYZE_FILES_SYSTEM_MESSAGE
133- assert messages [1 ].content == "Summarize the document"
134- assert len (files ) == 1
135- assert files [0 ].url == "https://example.com/file.pdf"
135+ mock_add_files .assert_called_once ()
136+ mock_llm .ainvoke .assert_called_once ()
137+
138+ # Verify add_files_to_message was called correctly
139+ add_files_call_args = mock_add_files .call_args
140+ message_arg = add_files_call_args [0 ][0 ]
141+ files_arg = add_files_call_args [0 ][1 ]
142+ llm_arg = add_files_call_args [0 ][2 ]
143+
144+ assert isinstance (message_arg , HumanMessage )
145+ assert message_arg .content == "Summarize the document"
146+ assert len (files_arg ) == 1
147+ assert files_arg [0 ].url == "https://example.com/file.pdf"
148+ assert llm_arg == mock_llm
149+
150+ # Verify llm.ainvoke was called with correct messages
151+ ainvoke_call_args = mock_llm .ainvoke .call_args
152+ messages_arg = ainvoke_call_args [0 ][0 ]
153+ assert len (messages_arg ) == 2
154+ assert messages_arg [0 ].content == ANALYZE_FILES_SYSTEM_MESSAGE
155+ assert messages_arg [1 ] == mock_message_with_files
136156
137157 @patch (
138158 "uipath_langchain.agent.wrappers.job_attachment_wrapper.get_job_attachment_wrapper"
@@ -176,15 +196,15 @@ async def test_create_analyze_file_tool_missing_attachments(
176196 "uipath_langchain.agent.wrappers.job_attachment_wrapper.get_job_attachment_wrapper"
177197 )
178198 @patch (
179- "uipath_langchain.agent.tools.internal_tools.analyze_files_tool.llm_call_with_files "
199+ "uipath_langchain.agent.tools.internal_tools.analyze_files_tool.add_files_to_message "
180200 )
181201 @patch (
182202 "uipath_langchain.agent.tools.internal_tools.analyze_files_tool._resolve_job_attachment_arguments"
183203 )
184204 async def test_create_analyze_file_tool_with_multiple_attachments (
185205 self ,
186206 mock_resolve_attachments ,
187- mock_llm_call ,
207+ mock_add_files ,
188208 mock_get_wrapper ,
189209 resource_config ,
190210 mock_llm ,
@@ -202,10 +222,25 @@ async def test_create_analyze_file_tool_with_multiple_attachments(
202222 mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ,
203223 ),
204224 ]
205- mock_llm_call .return_value = "Multiple files analyzed"
225+
226+ # mock add_files_to_message to return a message with multiple files
227+ mock_message_with_files = HumanMessage (
228+ content = [
229+ {"type" : "text" , "text" : "Compare these documents" },
230+ {"type" : "file" , "url" : "https://example.com/file1.pdf" },
231+ {"type" : "file" , "url" : "https://example.com/file2.docx" },
232+ ]
233+ )
234+ mock_add_files .return_value = mock_message_with_files
235+
206236 mock_wrapper = Mock ()
207237 mock_get_wrapper .return_value = mock_wrapper
208238
239+ # setup llm to return analyzed result
240+ mock_llm .ainvoke = AsyncMock (
241+ return_value = AIMessage (content = "Multiple files analyzed" )
242+ )
243+
209244 tool = create_analyze_file_tool (resource_config , mock_llm )
210245
211246 mock_attachments = [
@@ -227,8 +262,8 @@ async def test_create_analyze_file_tool_with_multiple_attachments(
227262 assert result == "Multiple files analyzed"
228263 mock_resolve_attachments .assert_called_once ()
229264
230- # Verify LLM received both files
231- call_args = mock_llm_call .call_args
265+ # Verify add_files_to_message received both files
266+ call_args = mock_add_files .call_args
232267 files = call_args [0 ][1 ]
233268 assert len (files ) == 2
234269
0 commit comments