Learn how to handle file uploads from users and generate downloadable files as outputs in your agents.
FilePart
.
Enable file uploads in your agent (optional)
default_input_modes
parameter to your agent decorator only if you want users to upload files to your agent. This specifies which file types users can upload.Inject the Platform API extension
PlatformApiExtensionServer
to access file creation capabilities. This extension provides your agent with the proper context and authentication needed to use the BeeAI platform API for creating and managing files. If not provided, your agent will receive unauthorized responses when working with files.Process uploaded files
FilePart
objects and load their content using load_file
helper.Generate new files
File.create()
method to generate new files and yield them as FilePart
objects.default_input_modes
to your agent decorator with a list of MIME types you want to accept (e.g., ["text/plain", "application/pdf", "image/jpeg"]
).
Enable producing of files: Add default_output_modes
to your agent decorator with a list of MIME types that your agent can potentially produce (e.g., ["text/plain", "application/pdf", "image/jpeg"]
).
Access the Platform API: Import and use PlatformApiExtensionServer
to get access to file manipulation capabilities.
Process message parts: Iterate through input.parts
to find FilePart objects that represent uploaded files.
Load file content: Use load_file()
with an async context manager to safely access file content.
Create new files: Use File.create()
to generate new files with custom names, content types, and content.
Yield file outputs: The File
object created by the SDK can be easily converted to a FilePart
using the to_file_part()
method and then yielded as agent outputs.
default_input_modes
parameter controls which file types users can upload:
default_output_modes
parameter controls which file agent can produce:
text/plain
, text/markdown
, text/csv
application/pdf
, application/msword
, application/vnd.openxmlformats-officedocument.wordprocessingml.document
image/jpeg
, image/png
, image/gif
, image/svg+xml
application/json
, application/xml
, text/xml