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.
Persistent storage lets plugins keep data within the same workspace across interactions, enabling stateful applications and memory features.
Dify currently provides a key-value (KV) storage system for plugins; more flexible and powerful storage interfaces are planned 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