@@ -47,13 +47,23 @@ class SaveFilesAsArtifactsPlugin(BasePlugin):
4747 tool to the agent, or load the artifacts in your own tool to use the files.
4848 """
4949
50- def __init__ (self , name : str = 'save_files_as_artifacts_plugin' ):
50+ def __init__ (
51+ self ,
52+ name : str = 'save_files_as_artifacts_plugin' ,
53+ * ,
54+ attach_file_reference : bool = True ,
55+ ):
5156 """Initialize the save files as artifacts plugin.
5257
5358 Args:
5459 name: The name of the plugin instance.
60+ attach_file_reference: Whether to attach a file reference to the
61+ user message. If False, only save the files as artifacts without
62+ adding a file reference, and the files will not be directly
63+ accessible to the model.
5564 """
5665 super ().__init__ (name )
66+ self ._attach_file_reference = attach_file_reference
5767
5868 async def on_user_message_callback (
5969 self ,
@@ -108,15 +118,16 @@ async def on_user_message_callback(
108118 )
109119 new_parts .append (placeholder_part )
110120
111- file_part = await self ._build_file_reference_part (
112- invocation_context = invocation_context ,
113- filename = file_name ,
114- version = version ,
115- mime_type = inline_data .mime_type ,
116- display_name = display_name ,
117- )
118- if file_part :
119- new_parts .append (file_part )
121+ if self ._attach_file_reference :
122+ file_part = await self ._build_file_reference_part (
123+ invocation_context = invocation_context ,
124+ filename = file_name ,
125+ version = version ,
126+ mime_type = inline_data .mime_type ,
127+ display_name = display_name ,
128+ )
129+ if file_part :
130+ new_parts .append (file_part )
120131 pending_delta [file_name ] = version
121132
122133 modified = True
0 commit comments