Most plugin tools and endpoints operate in a stateless, single-round interaction model:
Receive a request
Process data
Return a response
End the interaction
However, many real-world applications require maintaining state across multiple interactions. This is where persistent storage becomes essential.
The persistent storage mechanism allows plugins to store data persistently within the same workspace, enabling stateful applications and memory features.
Dify currently provides a key-value (KV) storage system for plugins, with plans to introduce more flexible and powerful storage interfaces in the future based on developer needs.
def set(self, key: str, val: bytes) -> None: """ Store data in persistent storage Parameters: key: Unique identifier for your data val: Binary data to store (bytes) """ pass
The value must be in bytes format. This provides flexibility to store various types of data, including files.
def get(self, key: str) -> bytes: """ Retrieve data from persistent storage Parameters: key: Unique identifier for your data Returns: The stored data as bytes, or None if key doesn't exist """ pass