@@ -55,7 +55,9 @@ def _reconcile_workflow_statuses(self) -> None:
5555 updated_instances .append (instance_id )
5656
5757 # Save the updated instance back to Redis
58- instance_key = self .memory_store ._get_instance_key (instance_id )
58+ instance_key = self .memory_store ._get_instance_key (
59+ instance_id
60+ )
5961 self .memory_store ._save_state_with_metadata (
6062 instance_key , instance_data
6163 )
@@ -70,7 +72,9 @@ def _reconcile_workflow_statuses(self) -> None:
7072 updated_instances .append (instance_id )
7173
7274 # Save the updated instance
73- instance_key = self .memory_store ._get_instance_key (instance_id )
75+ instance_key = self .memory_store ._get_instance_key (
76+ instance_id
77+ )
7478 self .memory_store ._save_state_with_metadata (
7579 instance_key , instance_data
7680 )
@@ -170,7 +174,9 @@ def initialize_state(self) -> None:
170174 logger .debug (
171175 "User provided a state as a Pydantic model. Converting to dict."
172176 )
173- self .memory_store ._current_state = self .memory_store ._current_state .model_dump ()
177+ self .memory_store ._current_state = (
178+ self .memory_store ._current_state .model_dump ()
179+ )
174180
175181 if not isinstance (self .memory_store ._current_state , dict ):
176182 raise TypeError (
@@ -209,8 +215,7 @@ def load_state(self) -> dict:
209215
210216 # For durable agents, always load from database to ensure it's the source of truth
211217 response = self ._dapr_client .get_state (
212- self .memory_store .name ,
213- self .memory_store ._key
218+ self .memory_store .name , self .memory_store ._key
214219 )
215220 if response .data :
216221 state_data = self ._deserialize_state (response .data )
@@ -227,8 +232,7 @@ def load_state(self) -> dict:
227232 # Get all sessions for this agent
228233 sessions_index_key = self .memory_store ._get_sessions_index_key ()
229234 response = self ._dapr_client .get_state (
230- self .memory_store .name ,
231- sessions_index_key
235+ self .memory_store .name , sessions_index_key
232236 )
233237
234238 if response .data :
@@ -242,8 +246,7 @@ def load_state(self) -> dict:
242246 for session_id in session_ids :
243247 session_key = self .memory_store ._get_session_key (session_id )
244248 response = self ._dapr_client .get_state (
245- self .memory_store .name ,
246- session_key
249+ self .memory_store .name , session_key
247250 )
248251
249252 if response .data :
@@ -256,8 +259,12 @@ def load_state(self) -> dict:
256259
257260 # Load each instance
258261 for instance_id in instance_ids :
259- instance_key = self .memory_store ._get_instance_key (instance_id )
260- response = self ._dapr_client .get_state (self .memory_store .name , instance_key )
262+ instance_key = self .memory_store ._get_instance_key (
263+ instance_id
264+ )
265+ response = self ._dapr_client .get_state (
266+ self .memory_store .name , instance_key
267+ )
261268 if response .data :
262269 instance_data = self ._deserialize_state (response .data )
263270
@@ -293,7 +300,9 @@ def load_state(self) -> dict:
293300 )
294301 return self .memory_store ._current_state
295302 except Exception as e :
296- logger .error (f"Failed to load state for key '{ self .memory_store ._key } ': { e } " )
303+ logger .error (
304+ f"Failed to load state for key '{ self .memory_store ._key } ': { e } "
305+ )
297306 raise RuntimeError (f"Error loading workflow state: { e } " ) from e
298307
299308 def get_local_state_file_path (self ) -> str :
@@ -428,19 +437,27 @@ def save_state(
428437 instance_json = instance_data
429438 else :
430439 instance_json = json .dumps (instance_data )
431- self ._dapr_client .save_state (self .memory_store .name , instance_key , instance_json )
440+ self ._dapr_client .save_state (
441+ self .memory_store .name , instance_key , instance_json
442+ )
432443 logger .debug (
433444 f"Saved workflow instance { instance_id } to key '{ instance_key } '"
434445 )
435446
436447 # Save other state data (like chat_history) to main key
437448 other_state = {
438- k : v for k , v in self .memory_store ._current_state .items () if k != "instances"
449+ k : v
450+ for k , v in self .memory_store ._current_state .items ()
451+ if k != "instances"
439452 }
440453 if other_state :
441454 other_state_json = json .dumps (other_state )
442- self ._dapr_client .save_state (self .memory_store .name , self .memory_store ._key , other_state_json )
443- logger .debug (f"Saved non-instance state to key '{ self .memory_store ._key } '" )
455+ self ._dapr_client .save_state (
456+ self .memory_store .name , self .memory_store ._key , other_state_json
457+ )
458+ logger .debug (
459+ f"Saved non-instance state to key '{ self .memory_store ._key } '"
460+ )
444461
445462 if self .memory_store .local_directory is not None :
446463 self .save_state_to_disk (state_data = state_to_save )
@@ -451,7 +468,9 @@ def save_state(
451468 f"State reloaded after saving for key '{ self .memory_store ._key } '."
452469 )
453470 except Exception as e :
454- logger .error (f"Failed to save state for key '{ self .memory_store ._key } ': { e } " )
471+ logger .error (
472+ f"Failed to save state for key '{ self .memory_store ._key } ': { e } "
473+ )
455474 raise
456475
457476 def _deserialize_state (self , raw : Union [bytes , str , dict ]) -> dict :
@@ -474,4 +493,4 @@ def _deserialize_state(self, raw: Union[bytes, str, dict]) -> dict:
474493 except json .JSONDecodeError as exc :
475494 raise ValueError (f"State is not valid JSON: { exc } " ) from exc
476495
477- raise TypeError (f"Unsupported state type { type (raw )!r} " )
496+ raise TypeError (f"Unsupported state type { type (raw )!r} " )
0 commit comments