@@ -350,6 +350,102 @@ async def test_create_structured_plan(self):
350350 print (f"\n Created technical webinar plan with { len (steps )} steps" )
351351 print (f"Steps assigned to: { ', ' .join (set (step .agent for step in steps ))} " )
352352
353+ async def test_hr_agent_selection (self ):
354+ """Test that the planner correctly assigns employee onboarding tasks to the HR agent."""
355+ # Initialize components
356+ await self .initialize_planner_agent ()
357+
358+ # Create an onboarding task
359+ input_task = InputTask (
360+ session_id = self .session_id ,
361+ user_id = self .user_id ,
362+ description = "Onboard a new employee, Jessica Smith."
363+ )
364+
365+ print ("\n \n ==== TESTING HR AGENT SELECTION FOR ONBOARDING ====" )
366+ print (f"Task: '{ input_task .description } '" )
367+
368+ # Call handle_input_task
369+ args = KernelArguments (input_task_json = input_task .json ())
370+ result = await self .planner_agent .handle_input_task (args )
371+
372+ # Check that result contains a success message
373+ self .assertIn ("created successfully" , result )
374+
375+ # Verify plan was created in memory store
376+ plan = await self .memory_store .get_plan_by_session (self .session_id )
377+ self .assertIsNotNone (plan )
378+
379+ # Verify steps were created
380+ steps = await self .memory_store .get_steps_for_plan (plan .id , self .session_id )
381+ self .assertGreater (len (steps ), 0 )
382+
383+ # Log plan details
384+ print (f"\n 📋 Created onboarding plan with ID: { plan .id } " )
385+ print (f"🎯 Goal: { plan .initial_goal } " )
386+ print (f"📝 Summary: { plan .summary } " )
387+
388+ print ("\n 📝 Steps:" )
389+ for i , step in enumerate (steps ):
390+ print (f" { i + 1 } . 👤 Agent: { step .agent } , 🔧 Action: { step .action } " )
391+
392+ # Count agents used in the plan
393+ agent_counts = {}
394+ for step in steps :
395+ agent_counts [step .agent ] = agent_counts .get (step .agent , 0 ) + 1
396+
397+ print ("\n 📊 Agent Distribution:" )
398+ for agent , count in agent_counts .items ():
399+ print (f" { agent } : { count } step(s)" )
400+
401+ # The critical test: verify that at least one step is assigned to HrAgent
402+ hr_steps = [step for step in steps if step .agent == "HrAgent" ]
403+ has_hr_steps = len (hr_steps ) > 0
404+ self .assertTrue (has_hr_steps , "No steps assigned to HrAgent for an onboarding task" )
405+
406+ if has_hr_steps :
407+ print ("\n ✅ TEST PASSED: HrAgent is used for onboarding task" )
408+ else :
409+ print ("\n ❌ TEST FAILED: HrAgent is not used for onboarding task" )
410+
411+ # Verify that no steps are incorrectly assigned to MarketingAgent
412+ marketing_steps = [step for step in steps if step .agent == "MarketingAgent" ]
413+ no_marketing_steps = len (marketing_steps ) == 0
414+ self .assertEqual (len (marketing_steps ), 0 ,
415+ f"Found { len (marketing_steps )} steps incorrectly assigned to MarketingAgent for an onboarding task" )
416+
417+ if no_marketing_steps :
418+ print ("✅ TEST PASSED: No MarketingAgent steps for onboarding task" )
419+ else :
420+ print (f"❌ TEST FAILED: Found { len (marketing_steps )} steps incorrectly assigned to MarketingAgent" )
421+
422+ # Verify that the first step or a step containing "onboard" is assigned to HrAgent
423+ first_agent = steps [0 ].agent if steps else None
424+ onboarding_steps = [step for step in steps if "onboard" in step .action .lower ()]
425+
426+ if onboarding_steps :
427+ onboard_correct = onboarding_steps [0 ].agent == "HrAgent"
428+ self .assertEqual (onboarding_steps [0 ].agent , "HrAgent" ,
429+ "The step containing 'onboard' was not assigned to HrAgent" )
430+ if onboard_correct :
431+ print ("✅ TEST PASSED: Steps containing 'onboard' are assigned to HrAgent" )
432+ else :
433+ print (f"❌ TEST FAILED: Step containing 'onboard' assigned to { onboarding_steps [0 ].agent } , not HrAgent" )
434+
435+ # If no specific "onboard" step but we have steps, the first should likely be HrAgent
436+ elif steps and "hr" not in first_agent .lower ():
437+ first_step_correct = first_agent == "HrAgent"
438+ self .assertEqual (first_agent , "HrAgent" ,
439+ f"The first step was assigned to { first_agent } , not HrAgent" )
440+ if first_step_correct :
441+ print ("✅ TEST PASSED: First step is assigned to HrAgent" )
442+ else :
443+ print (f"❌ TEST FAILED: First step assigned to { first_agent } , not HrAgent" )
444+
445+ print ("\n ==== END HR AGENT SELECTION TEST ====\n " )
446+
447+ return plan , steps
448+
353449 async def run_all_tests (self ):
354450 """Run all tests in sequence."""
355451 # Call setUp explicitly to ensure environment is properly initialized
@@ -372,6 +468,10 @@ async def run_all_tests(self):
372468 print ("\n ===== Testing _create_structured_plan directly =====" )
373469 await self .test_create_structured_plan ()
374470
471+ # Test 5: Verify HR agent selection for onboarding tasks
472+ print ("\n ===== Testing HR agent selection =====" )
473+ await self .test_hr_agent_selection ()
474+
375475 print ("\n All tests completed successfully!" )
376476
377477 except Exception as e :
0 commit comments