@@ -91,7 +91,23 @@ def _handle_local_files(
9191 client : Any ,
9292 sync_client : SyncClient ,
9393) -> Dict [str , Any ]:
94- """Handle local file loading."""
94+ """Load prompt/agent file content from local filesystem into API request.
95+
96+ Retrieves the file content at the specified path and adds it to kwargs
97+ under the appropriate field ('prompt' or 'agent'), allowing local files
98+ to be used in API calls instead of fetching from Humanloop API.
99+
100+ Args:
101+ kwargs: API call arguments
102+ client: Client instance making the call
103+ sync_client: SyncClient handling local file operations
104+
105+ Returns:
106+ Updated kwargs with file content in prompt/agent field
107+
108+ Raises:
109+ HumanloopRuntimeError: On validation or file loading failures
110+ """
95111 if "id" in kwargs :
96112 raise HumanloopRuntimeError ("Can only specify one of `id` or `path`" )
97113
@@ -170,11 +186,19 @@ def _overload_log(self: Any, sync_client: Optional[SyncClient], use_local_files:
170186
171187 kwargs = _handle_tracing_context (kwargs , self )
172188
173- # Handle local files for Prompts and Agents clients
189+ # Handle loading files from local filesystem when using Prompts and Agents clients
190+ # This enables users to define prompts/agents in local files rather than fetching from the Humanloop API
174191 if use_local_files and _get_file_type_from_client (self ) in SyncClient .SERIALIZABLE_FILE_TYPES :
192+ # Developer note: sync_client should always be provided during SDK initialization when
193+ # use_local_files=True. If we hit this error, there's likely an initialization issue
194+ # in Humanloop.__init__ where the sync_client wasn't properly created or passed to the
195+ # overload_client function.
175196 if sync_client is None :
176197 logger .error ("sync_client is None but client has log method and use_local_files=%s" , use_local_files )
177- raise HumanloopRuntimeError ("sync_client is required for clients that support local file operations" )
198+ raise HumanloopRuntimeError (
199+ "SDK initialization error: sync_client is missing but required for local file operations. "
200+ "This is likely a bug in the SDK initialization - please report this issue to the Humanloop team."
201+ )
178202 kwargs = _handle_local_files (kwargs , self , sync_client )
179203
180204 kwargs , eval_callback = _handle_evaluation_context (kwargs )
@@ -194,6 +218,7 @@ def _overload_call(self: Any, sync_client: Optional[SyncClient], use_local_files
194218 try :
195219 kwargs = _handle_tracing_context (kwargs , self )
196220 if use_local_files and _get_file_type_from_client (self ) in SyncClient .SERIALIZABLE_FILE_TYPES :
221+ # Same sync_client requirement as in _overload_log - see developer note there
197222 if sync_client is None :
198223 logger .error ("sync_client is None but client has call method and use_local_files=%s" , use_local_files )
199224 raise HumanloopRuntimeError ("sync_client is required for clients that support call operations" )
0 commit comments