@@ -478,19 +478,27 @@ async def _get_agent_for_eval(
478478 module_path = f"{ module_name } "
479479 agent_module = importlib .import_module (module_path )
480480 print (dir (agent_module ))
481- if hasattr (agent_module , "agent" ):
482- if hasattr (agent_module .agent , "root_agent" ):
483- root_agent = agent_module .agent .root_agent
484- elif hasattr (agent_module .agent , "get_agent_async" ):
485- root_agent , _ = await agent_module .agent .get_agent_async ()
486- else :
487- raise ValueError (
488- f"Module { module_name } does not have a root_agent or"
489- " get_agent_async method."
490- )
481+
482+ # One of the two things should be satisfied, either the module should have
483+ # an "agent" as a member in it or the module name itself should end with
484+ # ".agent".
485+ if not (hasattr (agent_module , "agent" ) or module_name .endswith (".agent" )):
486+ raise ValueError (
487+ f"Module { module_name } does not have a member named `agent` or the"
488+ " name should endwith `.agent`."
489+ )
490+
491+ agent_module_with_agent = (
492+ agent_module .agent if hasattr (agent_module , "agent" ) else agent_module
493+ )
494+ if hasattr (agent_module_with_agent , "root_agent" ):
495+ root_agent = agent_module_with_agent .root_agent
496+ elif hasattr (agent_module_with_agent , "get_agent_async" ):
497+ root_agent , _ = await agent_module_with_agent .get_agent_async ()
491498 else :
492499 raise ValueError (
493- f"Module { module_name } does not have a member named `agent`."
500+ f"Module { module_name } does not have a root_agent or"
501+ " get_agent_async method."
494502 )
495503
496504 agent_for_eval = root_agent
0 commit comments