mirror of
https://github.com/langgenius/dify.git
synced 2026-03-04 15:26:21 +08:00
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
import abc
|
|
from typing import Protocol
|
|
|
|
from dify_graph.variables import VariableBase
|
|
|
|
|
|
class ConversationVariableUpdater(Protocol):
|
|
"""
|
|
ConversationVariableUpdater defines an abstraction for updating conversation variable values.
|
|
|
|
It is intended for use by `v1.VariableAssignerNode` and `v2.VariableAssignerNode` when updating
|
|
conversation variables.
|
|
|
|
Implementations may choose to batch updates. If batching is used, the `flush` method
|
|
should be implemented to persist buffered changes, and `update`
|
|
should handle buffering accordingly.
|
|
|
|
Note: Since implementations may buffer updates, instances of ConversationVariableUpdater
|
|
are not thread-safe. Each VariableAssignerNode should create its own instance during execution.
|
|
"""
|
|
|
|
@abc.abstractmethod
|
|
def update(self, conversation_id: str, variable: "VariableBase"):
|
|
"""
|
|
Updates the value of the specified conversation variable in the underlying storage.
|
|
|
|
:param conversation_id: The ID of the conversation to update. Typically references `ConversationVariable.id`.
|
|
:param variable: The `VariableBase` instance containing the updated value.
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def flush(self):
|
|
"""
|
|
Flushes all pending updates to the underlying storage system.
|
|
|
|
If the implementation does not buffer updates, this method can be a no-op.
|
|
"""
|
|
pass
|