-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Add @persist decorator with FlowPersistence interface #1892
Open
devin-ai-integration
wants to merge
21
commits into
main
Choose a base branch
from
devin/1736848480-persist-decorator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,064
−141
Open
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
aeacbbf
Add @persist decorator with SQLite persistence
devin-ai-integration[bot] 668e195
Resolve merge conflicts integrating FlowState with new persistence
devin-ai-integration[bot] 6d08831
Fix remaining merge conflicts in uv.lock
devin-ai-integration[bot] cc87e08
Fix final CUDA dependency conflicts in uv.lock
devin-ai-integration[bot] 357ca68
Fix nvidia-cusparse-cu12 dependency conflicts in uv.lock
devin-ai-integration[bot] 59e9afa
Fix triton filelock dependency conflicts in uv.lock
devin-ai-integration[bot] 3c0101f
Fix merge conflict in crew_test.py
devin-ai-integration[bot] 6f5e73d
Clean up trailing merge conflict marker in crew_test.py
devin-ai-integration[bot] e3e7e67
Improve type safety in persistence implementation and resolve merge c…
devin-ai-integration[bot] 4e0a7ba
fix: Add explicit type casting in _create_initial_state method
devin-ai-integration[bot] 212e60f
fix: Improve type safety in flow state handling with proper validation
devin-ai-integration[bot] 9625630
fix: Improve type system with proper TypeVar scoping and validation
devin-ai-integration[bot] 785e97a
fix: Improve state restoration logic and add comprehensive tests
devin-ai-integration[bot] 1b6207d
fix: Initialize FlowState instances without passing id to constructor
devin-ai-integration[bot] 2271447
Merge branch 'main' into devin/1736848480-persist-decorator
joaomdmoura 37dc5ee
feat: Add class-level flow persistence decorator with SQLite default
devin-ai-integration[bot] 7cd11f5
fix: Sort imports in decorators.py to fix lint error
devin-ai-integration[bot] 40afbb9
style: Organize imports according to PEP 8 standard
devin-ai-integration[bot] 1ab8fe3
style: Format typing imports with line breaks for better readability
devin-ai-integration[bot] 8396f6e
style: Simplify import organization to fix lint error
devin-ai-integration[bot] a4bc624
style: Fix import sorting using Ruff auto-fix
devin-ai-integration[bot] 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 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 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,18 @@ | ||
""" | ||
CrewAI Flow Persistence. | ||
|
||
This module provides interfaces and implementations for persisting flow states. | ||
""" | ||
|
||
from typing import Any, Dict, TypeVar, Union | ||
|
||
from pydantic import BaseModel | ||
|
||
from crewai.flow.persistence.base import FlowPersistence | ||
from crewai.flow.persistence.decorators import persist | ||
from crewai.flow.persistence.sqlite import SQLiteFlowPersistence | ||
|
||
__all__ = ["FlowPersistence", "persist", "SQLiteFlowPersistence"] | ||
|
||
StateType = TypeVar('StateType', bound=Union[Dict[str, Any], BaseModel]) | ||
DictStateType = Dict[str, Any] |
This file contains 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,53 @@ | ||
"""Base class for flow state persistence.""" | ||
|
||
import abc | ||
from typing import Any, Dict, Optional, Union | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class FlowPersistence(abc.ABC): | ||
"""Abstract base class for flow state persistence. | ||
|
||
This class defines the interface that all persistence implementations must follow. | ||
It supports both structured (Pydantic BaseModel) and unstructured (dict) states. | ||
""" | ||
|
||
@abc.abstractmethod | ||
def init_db(self) -> None: | ||
"""Initialize the persistence backend. | ||
|
||
This method should handle any necessary setup, such as: | ||
- Creating tables | ||
- Establishing connections | ||
- Setting up indexes | ||
""" | ||
pass | ||
|
||
@abc.abstractmethod | ||
def save_state( | ||
self, | ||
flow_uuid: str, | ||
method_name: str, | ||
state_data: Union[Dict[str, Any], BaseModel] | ||
) -> None: | ||
"""Persist the flow state after method completion. | ||
|
||
Args: | ||
flow_uuid: Unique identifier for the flow instance | ||
method_name: Name of the method that just completed | ||
state_data: Current state data (either dict or Pydantic model) | ||
""" | ||
pass | ||
|
||
@abc.abstractmethod | ||
def load_state(self, flow_uuid: str) -> Optional[Dict[str, Any]]: | ||
"""Load the most recent state for a given flow UUID. | ||
|
||
Args: | ||
flow_uuid: Unique identifier for the flow instance | ||
|
||
Returns: | ||
The most recent state as a dictionary, or None if no state exists | ||
""" | ||
pass |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow this, the logic is that if an id is passed the flow should load the state from the persistency layer, and override just new fields being sent, but before overriding it shoudl reload all the state fields based on the id