7272from humanloop .types import PromptKernelRequest as Prompt
7373from humanloop .types import ToolKernelRequest as Tool
7474from humanloop .types .agent_response import AgentResponse
75+ from humanloop .types .agent_kernel_request import AgentKernelRequest as Agent
7576from humanloop .types .datapoint_response import DatapointResponse
7677from humanloop .types .dataset_response import DatasetResponse
7778from humanloop .types .evaluation_run_response import EvaluationRunResponse
@@ -402,7 +403,7 @@ def _get_subclient(client: "BaseHumanloop", file_config: FileEvalConfig) -> Huma
402403
403404
404405def _safe_get_default_file_version (client : "BaseHumanloop" , file_config : FileEvalConfig ) -> EvaluatedFile :
405- """Get default version of a File from online workspace.
406+ """Get default version of a File from remote workspace.
406407
407408 Uses either the File path or id from the config.
408409
@@ -421,13 +422,13 @@ def _safe_get_default_file_version(client: "BaseHumanloop", file_config: FileEva
421422 raise HumanloopRuntimeError (
422423 f"File in Humanloop workspace at { path } is not of type { type } , but { hl_file .type } ."
423424 )
424- # cast is safe, we can only fetch Files allowed by FileType
425+ # cast is safe, we can only fetch Files that can be evaluated
425426 return typing .cast (EvaluatedFile , hl_file )
426427 elif file_id is not None :
427428 subclient = _get_subclient (client = client , file_config = file_config )
428429 return subclient .get (id = file_id )
429430 else :
430- raise HumanloopRuntimeError ("You must provide a path or id in your `file` config." )
431+ raise HumanloopRuntimeError ("You must provide either the path or the id in your `file` config." )
431432
432433
433434def _resolve_file (client : "BaseHumanloop" , file_config : FileEvalConfig ) -> tuple [EvaluatedFile , Optional [Callable ]]:
@@ -447,7 +448,14 @@ def _resolve_file(client: "BaseHumanloop", file_config: FileEvalConfig) -> tuple
447448 "You are trying to create a new version of the File by passing the `version` argument. "
448449 "You must pass either the `file.path` or `file.id` argument and provider proper `file.version` for upserting the File."
449450 )
450- hl_file = _safe_get_default_file_version (client = client , file_config = file_config )
451+ try :
452+ hl_file = _safe_get_default_file_version (client = client , file_config = file_config )
453+ except ApiError :
454+ if not version or not path or file_id :
455+ raise HumanloopRuntimeError (
456+ "File does not exist on Humanloop. Please provide a `file.path` and a version to create a new version." ,
457+ )
458+ return _upsert_file (file_config = file_config , client = client ), callable or None
451459
452460 if (version_id or environment ) and (callable or version ):
453461 raise HumanloopRuntimeError (
@@ -683,6 +691,9 @@ def _upsert_file(client: "BaseHumanloop", file_config: FileEvalConfig) -> Evalua
683691 elif type_ == "tool" :
684692 # Will throw error if version is invalid
685693 Tool .model_validate (version )
694+ elif type_ == "agent" :
695+ # Will throw error if version is invalid
696+ Agent .model_validate (version )
686697 else :
687698 raise NotImplementedError (f"Unsupported File type: { type_ } " )
688699
0 commit comments