1212 is_transcripts_enabled ,
1313 construct_transcripts_path ,
1414 store_transcript ,
15+ get_rag_toolgroups ,
1516)
1617from models .requests import QueryRequest , Attachment
1718from models .config import ModelContextProtocolServer
@@ -277,12 +278,45 @@ def test_validate_attachments_metadata_invalid_content_type():
277278 )
278279
279280
281+ def test_retrieve_response_vector_db_available (mocker ):
282+ """Test the retrieve_response function."""
283+ mock_agent = mocker .Mock ()
284+ mock_agent .create_turn .return_value .output_message .content = "LLM answer"
285+ mock_client = mocker .Mock ()
286+ mock_client .shields .list .return_value = []
287+ mock_vector_db = mocker .Mock ()
288+ mock_vector_db .identifier = "VectorDB-1"
289+ mock_client .vector_dbs .list .return_value = [mock_vector_db ]
290+
291+ # Mock configuration with empty MCP servers
292+ mock_config = mocker .Mock ()
293+ mock_config .mcp_servers = []
294+ mocker .patch ("app.endpoints.query.configuration" , mock_config )
295+ mocker .patch ("app.endpoints.query.Agent" , return_value = mock_agent )
296+
297+ query_request = QueryRequest (query = "What is OpenStack?" )
298+ model_id = "fake_model_id"
299+ access_token = "test_token"
300+
301+ response = retrieve_response (mock_client , model_id , query_request , access_token )
302+
303+ assert response == "LLM answer"
304+ mock_agent .create_turn .assert_called_once_with (
305+ messages = [UserMessage (content = "What is OpenStack?" , role = "user" , context = None )],
306+ session_id = mocker .ANY ,
307+ documents = [],
308+ stream = False ,
309+ toolgroups = get_rag_toolgroups (["VectorDB-1" ]),
310+ )
311+
312+
280313def test_retrieve_response_no_available_shields (mocker ):
281314 """Test the retrieve_response function."""
282315 mock_agent = mocker .Mock ()
283316 mock_agent .create_turn .return_value .output_message .content = "LLM answer"
284317 mock_client = mocker .Mock ()
285318 mock_client .shields .list .return_value = []
319+ mock_client .vector_dbs .list .return_value = []
286320
287321 # Mock configuration with empty MCP servers
288322 mock_config = mocker .Mock ()
@@ -302,6 +336,7 @@ def test_retrieve_response_no_available_shields(mocker):
302336 session_id = mocker .ANY ,
303337 documents = [],
304338 stream = False ,
339+ toolgroups = None ,
305340 )
306341
307342
@@ -319,6 +354,7 @@ def identifier(self):
319354 mock_agent .create_turn .return_value .output_message .content = "LLM answer"
320355 mock_client = mocker .Mock ()
321356 mock_client .shields .list .return_value = [MockShield ("shield1" )]
357+ mock_client .vector_dbs .list .return_value = []
322358
323359 # Mock configuration with empty MCP servers
324360 mock_config = mocker .Mock ()
@@ -338,6 +374,7 @@ def identifier(self):
338374 session_id = mocker .ANY ,
339375 documents = [],
340376 stream = False ,
377+ toolgroups = None ,
341378 )
342379
343380
@@ -358,6 +395,7 @@ def identifier(self):
358395 MockShield ("shield1" ),
359396 MockShield ("shield2" ),
360397 ]
398+ mock_client .vector_dbs .list .return_value = []
361399
362400 # Mock configuration with empty MCP servers
363401 mock_config = mocker .Mock ()
@@ -377,6 +415,7 @@ def identifier(self):
377415 session_id = mocker .ANY ,
378416 documents = [],
379417 stream = False ,
418+ toolgroups = None ,
380419 )
381420
382421
@@ -386,6 +425,7 @@ def test_retrieve_response_with_one_attachment(mocker):
386425 mock_agent .create_turn .return_value .output_message .content = "LLM answer"
387426 mock_client = mocker .Mock ()
388427 mock_client .shields .list .return_value = []
428+ mock_client .vector_dbs .list .return_value = []
389429
390430 # Mock configuration with empty MCP servers
391431 mock_config = mocker .Mock ()
@@ -418,6 +458,7 @@ def test_retrieve_response_with_one_attachment(mocker):
418458 "mime_type" : "text/plain" ,
419459 },
420460 ],
461+ toolgroups = None ,
421462 )
422463
423464
@@ -427,6 +468,7 @@ def test_retrieve_response_with_two_attachments(mocker):
427468 mock_agent .create_turn .return_value .output_message .content = "LLM answer"
428469 mock_client = mocker .Mock ()
429470 mock_client .shields .list .return_value = []
471+ mock_client .vector_dbs .list .return_value = []
430472
431473 # Mock configuration with empty MCP servers
432474 mock_config = mocker .Mock ()
@@ -468,6 +510,7 @@ def test_retrieve_response_with_two_attachments(mocker):
468510 "mime_type" : "application/yaml" ,
469511 },
470512 ],
513+ toolgroups = None ,
471514 )
472515
473516
@@ -477,6 +520,7 @@ def test_retrieve_response_with_mcp_servers(mocker):
477520 mock_agent .create_turn .return_value .output_message .content = "LLM answer"
478521 mock_client = mocker .Mock ()
479522 mock_client .shields .list .return_value = []
523+ mock_client .vector_dbs .list .return_value = []
480524
481525 # Mock configuration with MCP servers
482526 mcp_servers = [
@@ -536,6 +580,7 @@ def test_retrieve_response_with_mcp_servers_empty_token(mocker):
536580 mock_agent .create_turn .return_value .output_message .content = "LLM answer"
537581 mock_client = mocker .Mock ()
538582 mock_client .shields .list .return_value = []
583+ mock_client .vector_dbs .list .return_value = []
539584
540585 # Mock configuration with MCP servers
541586 mcp_servers = [
@@ -646,3 +691,16 @@ def test_store_transcript(mocker):
646691 },
647692 mocker .ANY ,
648693 )
694+
695+
696+ def test_get_rag_toolgroups (mocker ):
697+ """Test get_rag_toolgroups function."""
698+ vector_db_ids = []
699+ result = get_rag_toolgroups (vector_db_ids )
700+ assert result is None
701+
702+ vector_db_ids = ["Vector-DB-1" , "Vector-DB-2" ]
703+ result = get_rag_toolgroups (vector_db_ids )
704+ assert len (result ) == 1
705+ assert result [0 ]["name" ] == "builtin::rag/knowledge_search"
706+ assert result [0 ]["args" ]["vector_db_ids" ] == vector_db_ids
0 commit comments