2424from ..utils .feature_decorator import working_in_progress
2525from .agent_config import AgentConfig
2626from .base_agent import BaseAgent
27- from .base_agent_config import SubAgentConfig
27+ from .common_configs import AgentRefConfig
2828from .common_configs import CodeConfig
2929from .llm_agent import LlmAgent
3030from .llm_agent_config import LlmAgentConfig
@@ -90,44 +90,48 @@ def _load_config_from_path(config_path: str) -> AgentConfig:
9090 return AgentConfig .model_validate (config_data )
9191
9292
93- @working_in_progress ("build_sub_agent is not ready for use." )
94- def build_sub_agent (
95- sub_config : SubAgentConfig , parent_agent_folder_path : str
93+ @working_in_progress ("resolve_agent_reference is not ready for use." )
94+ def resolve_agent_reference (
95+ ref_config : AgentRefConfig , referencing_agent_config_abs_path : str
9696) -> BaseAgent :
97- """Build a sub- agent from configuration .
97+ """Build an agent from a reference .
9898
9999 Args:
100- sub_config: The sub-agent configuration (SubAgentConfig).
101- parent_agent_folder_path: The folder path to the parent agent's YAML config.
100+ ref_config: The agent reference configuration (AgentRefConfig).
101+ referencing_agent_config_abs_path: The absolute path to the agent config
102+ that contains the reference.
102103
103104 Returns:
104- The created sub- agent instance.
105+ The created agent instance.
105106 """
106- if sub_config . config :
107- if os .path .isabs (sub_config . config ):
108- return from_config (sub_config . config )
107+ if ref_config . config_path :
108+ if os .path .isabs (ref_config . config_path ):
109+ return from_config (ref_config . config_path )
109110 else :
110111 return from_config (
111- os .path .join (parent_agent_folder_path , sub_config .config )
112+ os .path .join (
113+ referencing_agent_config_abs_path .rsplit ("/" , 1 )[0 ],
114+ ref_config .config_path ,
115+ )
112116 )
113- elif sub_config .code :
114- return _resolve_sub_agent_code_reference ( sub_config .code )
117+ elif ref_config .code :
118+ return _resolve_agent_code_reference ( ref_config .code )
115119 else :
116- raise ValueError ("SubAgentConfig must have either 'code' or 'config '" )
120+ raise ValueError ("AgentRefConfig must have either 'code' or 'config_path '" )
117121
118122
119- @working_in_progress ("_resolve_sub_agent_code_reference is not ready for use." )
120- def _resolve_sub_agent_code_reference (code : str ) -> Any :
121- """Resolve a code reference to an actual agent object .
123+ @working_in_progress ("_resolve_agent_code_reference is not ready for use." )
124+ def _resolve_agent_code_reference (code : str ) -> Any :
125+ """Resolve a code reference to an actual agent instance .
122126
123127 Args:
124- code: The code reference to the sub- agent.
128+ code: The fully-qualified path to an agent instance .
125129
126130 Returns:
127- The resolved agent object .
131+ The resolved agent instance .
128132
129133 Raises:
130- ValueError: If the code reference cannot be resolved.
134+ ValueError: If the agent reference cannot be resolved.
131135 """
132136 if "." not in code :
133137 raise ValueError (f"Invalid code reference: { code } " )
@@ -137,7 +141,10 @@ def _resolve_sub_agent_code_reference(code: str) -> Any:
137141 obj = getattr (module , obj_name )
138142
139143 if callable (obj ):
140- raise ValueError (f"Invalid code reference to a callable: { code } " )
144+ raise ValueError (f"Invalid agent reference to a callable: { code } " )
145+
146+ if not isinstance (obj , BaseAgent ):
147+ raise ValueError (f"Invalid agent reference to a non-agent instance: { code } " )
141148
142149 return obj
143150
0 commit comments