-
Notifications
You must be signed in to change notification settings - Fork 20k
feat: Add conversation variable persistence layer #30531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
335bf83
Added constructor-based DI for VariableAssigner v2 and wired the node…
laipz8200 0fd225a
Updated to avoid the dict path and let the type checker enforce const…
laipz8200 67007f6
A new command for updating variables. (vibe-kanban 00377ffe)
laipz8200 43fefe8
Add a new persistent storage for handling Conversation Variables. (v…
laipz8200 89e644f
- fix(lint): replace `outputs.keys()` iteration in `api/core/app/laye…
laipz8200 3edd525
- feat(graph-engine): enforce variable update value types with Segmen…
laipz8200 638b0ef
- refactor(variable-assigner-v1): inline updated variable payload and…
laipz8200 5ebc87a
- refactor(graph-engine): switch VariableUpdate.value to VariableUnio…
laipz8200 89d292e
- refactor(variable-assigner): restore common_helpers updated-variabl…
laipz8200 8505033
- refactor(variable-assigner): drop updated outputs now that persiste…
laipz8200 36b4a6e
- chore(lint): run `make lint` (fails: dotenv-linter module missing a…
laipz8200 99509eb
Revert "- refactor(graph-engine): switch VariableUpdate.value to Vari…
laipz8200 2b044dd
Revert "- feat(graph-engine): enforce variable update value types wit…
laipz8200 2831694
Revert "A new command for updating variables. (vibe-kanban 00377ffe)"
laipz8200 b083fa2
- refactor(services): move ConversationVariableUpdaterImpl and factor…
laipz8200 deeebb8
- chore(lint): run `make lint` (fails: import linter error and dotenv…
laipz8200 1192648
- chore(import-linter): remove obsolete ignore for variable_assigner …
laipz8200 7c30854
fix(core): guard conversation variable flush when no updates
laipz8200 09b7aed
fix(core): use system variable conversation_id and add custom updater…
laipz8200 7b19f20
fix(services): use Exception for conversation variable not found
laipz8200 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
api/core/app/layers/conversation_variable_persist_layer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import logging | ||
|
|
||
| from core.variables import Variable | ||
| from core.workflow.constants import CONVERSATION_VARIABLE_NODE_ID | ||
| from core.workflow.conversation_variable_updater import ConversationVariableUpdater | ||
| from core.workflow.enums import NodeType | ||
| from core.workflow.graph_engine.layers.base import GraphEngineLayer | ||
| from core.workflow.graph_events import GraphEngineEvent, NodeRunSucceededEvent | ||
| from core.workflow.nodes.variable_assigner.common import helpers as common_helpers | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class ConversationVariablePersistenceLayer(GraphEngineLayer): | ||
| def __init__(self, conversation_variable_updater: ConversationVariableUpdater) -> None: | ||
| super().__init__() | ||
| self._conversation_variable_updater = conversation_variable_updater | ||
|
|
||
| def on_graph_start(self) -> None: | ||
| pass | ||
|
|
||
| def on_event(self, event: GraphEngineEvent) -> None: | ||
| if not isinstance(event, NodeRunSucceededEvent): | ||
| return | ||
| if event.node_type != NodeType.VARIABLE_ASSIGNER: | ||
| return | ||
| if self.graph_runtime_state is None: | ||
| return | ||
|
|
||
| updated_variables = common_helpers.get_updated_variables(event.node_run_result.process_data) or [] | ||
| if not updated_variables: | ||
| return | ||
|
|
||
| conversation_id = self.graph_runtime_state.system_variable.conversation_id | ||
| if conversation_id is None: | ||
| return | ||
|
|
||
| updated_any = False | ||
| for item in updated_variables: | ||
| selector = item.selector | ||
| if len(selector) < 2: | ||
| logger.warning("Conversation variable selector invalid. selector=%s", selector) | ||
| continue | ||
| if selector[0] != CONVERSATION_VARIABLE_NODE_ID: | ||
| continue | ||
| variable = self.graph_runtime_state.variable_pool.get(selector) | ||
| if not isinstance(variable, Variable): | ||
| logger.warning( | ||
| "Conversation variable not found in variable pool. selector=%s", | ||
| selector, | ||
| ) | ||
| continue | ||
| self._conversation_variable_updater.update(conversation_id=conversation_id, variable=variable) | ||
| updated_any = True | ||
|
|
||
| if updated_any: | ||
| self._conversation_variable_updater.flush() | ||
|
|
||
| def on_graph_end(self, error: Exception | None) -> None: | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.