#!/usr/bin/env python3 """ Test script for composed agent functionality """ import asyncio import os from pathlib import Path import sys # Add the source directory to the path sys.path.insert(0, str(Path(__file__).parent / "src")) from agent_mcp_server.server import AgentLibrary async def test_composed_agents(): """Test the composed agent functionality""" print("๐Ÿงช Testing Composed Agent Functionality") print("=" * 50) # Initialize agent library with local templates templates_path = Path(__file__).parent / "agent_templates" library = AgentLibrary(templates_path) await library.initialize() print(f"\n๐Ÿ“Š Total agents loaded: {len(library.agents)}") # Analyze agent types individual = composed = sub_agents = 0 for agent in library.agents.values(): if agent.agent_type == "individual": individual += 1 elif agent.agent_type == "composed": composed += 1 elif agent.agent_type == "sub": sub_agents += 1 print(f" โ€ข Individual agents: {individual}") print(f" โ€ข Composed agents: {composed}") print(f" โ€ข Sub-agents: {sub_agents}") # Test composed agent detection print(f"\n๐ŸŽฏ Testing Composed Agent Structure") for name, agent in library.agents.items(): if agent.agent_type == "composed": print(f"\n๐Ÿ“‹ Composed Agent: {agent.emoji} {agent.name}") print(f" Type: {agent.agent_type}") print(f" Sub-agents: {len(agent.sub_agents)}") for sub_name in agent.sub_agents: if sub_name in library.agents: sub_agent = library.agents[sub_name] print(f" โ””โ”€ {sub_agent.emoji} {sub_agent.name} (parent: {sub_agent.parent_agent})") # Test hierarchical recommendations print(f"\n๐Ÿ”ง Testing Hierarchical Recommendations") test_tasks = [ "I need help with Python testing framework development", "How do I create beautiful HTML reports?", "Help me with testing in general", "I need a testing architecture overview" ] for task in test_tasks: print(f"\n๐Ÿ“ Task: \"{task}\"") recommendations = await library.recommend_agents(task, "", 3) for i, rec in enumerate(recommendations, 1): agent_type_desc = rec.get('agent_type', 'unknown') parent_info = f" (part of {rec.get('parent_agent', 'N/A')})" if rec.get('parent_agent') else "" print(f" {i}. {rec['emoji']} {rec['name']} - {agent_type_desc}{parent_info}") print(f" Confidence: {rec['confidence']:.2f} | Reason: {rec['reason']}") # Test agent content enhancement print(f"\n๐Ÿ“„ Testing Agent Content Enhancement") # Test composed agent content composed_agent_name = None sub_agent_name = None for name, agent in library.agents.items(): if agent.agent_type == "composed": composed_agent_name = name elif agent.agent_type == "sub": sub_agent_name = name if composed_agent_name: print(f"\n๐Ÿ—๏ธ Composed Agent Content: {composed_agent_name}") content_result = await library.get_agent_content(composed_agent_name) if content_result["success"]: print(" โœ… Content includes specialist team references") if "My Specialist Team" in content_result["content"]: print(" โœ… Found 'My Specialist Team' section") else: print(" โŒ Missing 'My Specialist Team' section") if sub_agent_name: print(f"\n๐Ÿ”ฌ Sub-Agent Content: {sub_agent_name}") content_result = await library.get_agent_content(sub_agent_name) if content_result["success"]: print(" โœ… Content includes parent framework context") if "Framework" in content_result["content"]: print(" โœ… Found parent framework reference") else: print(" โŒ Missing parent framework reference") # Test flat structure maintenance print(f"\n๐Ÿ“‹ Testing Flat Structure Maintenance") all_agents = await library.list_agents() print(f" Total agents in flat list: {len(all_agents)}") # Verify all agents are accessible accessible_individual = accessible_composed = accessible_sub = 0 for agent_data in all_agents: agent = library.agents[agent_data["name"]] if agent.agent_type == "individual": accessible_individual += 1 elif agent.agent_type == "composed": accessible_composed += 1 elif agent.agent_type == "sub": accessible_sub += 1 print(f" โœ… Individual accessible: {accessible_individual}") print(f" โœ… Composed accessible: {accessible_composed}") print(f" โœ… Sub-agents accessible: {accessible_sub}") print(f" ๐Ÿ“Š Claude Code sees ALL {len(all_agents)} agents in flat list") print(f"\nโœ… Composed Agent Testing Complete!") print(f"๐Ÿ“‹ Summary:") print(f" โ€ข Flat structure maintained: All {len(all_agents)} agents accessible") print(f" โ€ข Hierarchical intelligence: Sub-agents prioritized for specialized tasks") print(f" โ€ข Content enhancement: Dynamic cross-references added") print(f" โ€ข Backward compatibility: Individual agents work unchanged") if __name__ == "__main__": asyncio.run(test_composed_agents())