FilePart
.
Quickstart
1
Enable file uploads in your agent (optional)
Add the
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.2
Inject the Platform API extension
Import and use the
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.3
Process uploaded files
Iterate through message parts to find
FilePart
objects and load their content using load_file
helper.4
Generate new files
Use the
File.create()
method to generate new files and yield them as FilePart
objects.Example of File Processing
Here’s how to build an agent that can accept and modify files:How to work with files
Here’s what you need to know to add file processing capabilities to your agent: Enable file uploads: Adddefault_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.
File Upload Configuration
Thedefault_input_modes
parameter controls which file types users can upload:
default_output_modes
parameter controls which file agent can produce:
- Text files:
text/plain
,text/markdown
,text/csv
- Documents:
application/pdf
,application/msword
,application/vnd.openxmlformats-officedocument.wordprocessingml.document
- Images:
image/jpeg
,image/png
,image/gif
,image/svg+xml
- Data:
application/json
,application/xml
,text/xml