@@ -402,3 +402,70 @@ async def test_agent_loop_stop_conditions_timeout(self):
402402 )
403403 ]
404404 )
405+
406+ @pytest .mark .asyncio
407+ async def test_duplicated_subagent_name (self ) -> None :
408+ pytest .importorskip ("langchain_openai" )
409+
410+ async with (
411+ Agent (
412+ model = (await self .model ()),
413+ system_prompt = "" ,
414+ service = self .service ,
415+ name = "subagent_name" ,
416+ ) as subagent1 ,
417+ Agent (
418+ model = (await self .model ()),
419+ system_prompt = "" ,
420+ service = self .service ,
421+ name = "subagent_name" ,
422+ ) as subagent2 ,
423+ Agent (
424+ model = (await self .model ()),
425+ system_prompt = "" ,
426+ service = self .service ,
427+ name = "" ,
428+ ) as subagent1_empty_name ,
429+ Agent (
430+ model = (await self .model ()),
431+ system_prompt = "" ,
432+ service = self .service ,
433+ name = "" ,
434+ ) as subagent2_empty_name ,
435+ ):
436+ with pytest .raises (
437+ AssertionError , match = "Subagents share the same name: subagent_name"
438+ ):
439+ async with Agent (
440+ model = (await self .model ()),
441+ system_prompt = "" ,
442+ service = self .service ,
443+ agents = [subagent1 , subagent2 ],
444+ ):
445+ pass
446+
447+ # Also make sure, that because of this check we have, we will not
448+ # mistakenely accept same subagent (since they also share the same name).
449+ with pytest .raises (
450+ AssertionError , match = "Subagents share the same name: subagent_name"
451+ ):
452+ async with Agent (
453+ model = (await self .model ()),
454+ system_prompt = "" ,
455+ service = self .service ,
456+ agents = [subagent1 , subagent1 ],
457+ ):
458+ pass
459+
460+ # Make sure that the subagent is validated before the name uniqueness check.
461+ with pytest .raises (
462+ AssertionError ,
463+ match = "Agent must have a name to be used by other Agents" ,
464+ ):
465+ async with Agent (
466+ model = (await self .model ()),
467+ system_prompt = "" ,
468+ service = self .service ,
469+ agents = [subagent1_empty_name , subagent2_empty_name ],
470+ ):
471+ pass
0 commit comments