Skip to main content

Overview

The Attachment class handles file attachments on messages, supporting various file types with automatic processing for text extraction, MIME type detection, and integration with FileStore for persistence.

Creating Attachments

From Raw Content

From File Path

From Data URLs

Key properties

string
required
Name of the file
bytes | str
File content as bytes or base64-encoded string
string
MIME type of the file (auto-detected if not provided)
Dict[str, Any]
Processed content and metadata (e.g., extracted text, image info)
string
Unique identifier when stored in FileStore
string
Path where file is stored in FileStore
Literal['pending', 'stored', 'failed']
default:"pending"
Current processing status
string
Auto-generated unique ID based on content hash

Processing and Storage

Attachments can be processed to extract content and stored persistently:

Content Processing

Different file types are automatically processed:

Text Files

PDFs

Images

JSON Files

Audio Files

Retrieving Content

Serialization

File Size and Type Validation

When used with FileStore, attachments are validated:

Example: Document Processing Pipeline

Integration with Messages

Attachments are designed to work seamlessly with messages: