diff --git a/src/cleveragents/langgraph/nodes.py b/src/cleveragents/langgraph/nodes.py index 7e3cde120..1d4d626ac 100644 --- a/src/cleveragents/langgraph/nodes.py +++ b/src/cleveragents/langgraph/nodes.py @@ -223,8 +223,11 @@ class Node: # pylint: disable=too-many-instance-attributes full_history_enabled = self.config.metadata.get("full_history", False) if full_history_enabled: trimmed_history = list(state.messages) + history_truncated = False else: - trimmed_history, _ = self._prepare_conversation_history(state.messages) + trimmed_history, history_truncated = self._prepare_conversation_history( + state.messages + ) # Build a node config that explicitly contains conversation history # so the executor layer can pass it to the agent process_message call. @@ -255,6 +258,9 @@ class Node: # pylint: disable=too-many-instance-attributes "full_context": True, "node_config": config_with_history.model_dump(), } + if history_truncated: + context["_history_truncated"] = True + context["_history_original_length"] = len(state.messages) if state.metadata: context.update(state.metadata) nested_context = context.get("context") diff --git a/src/cleveragents/langgraph/state.py b/src/cleveragents/langgraph/state.py index 4ea94d5b0..8e43d1889 100644 --- a/src/cleveragents/langgraph/state.py +++ b/src/cleveragents/langgraph/state.py @@ -245,6 +245,16 @@ class ConversationStateManager: # pylint: disable=too-many-instance-attributes if self.is_closed: raise RuntimeError("StateManager is closed") + if self.enable_time_travel: + snapshot = StateSnapshot( + state=self._full_state().to_dict(), + timestamp=datetime.now(), + node_id=node_id, + ) + self._snapshots.append(snapshot) + if len(self._snapshots) > self.max_history_size: + self._snapshots = self._snapshots[-self.max_history_size :] + self._execution_state.execution_count += 1 self.update_count += 1 @@ -273,16 +283,6 @@ class ConversationStateManager: # pylint: disable=too-many-instance-attributes else: # APPEND setattr(self._execution_state, exec_field, value) - if self.enable_time_travel: - snapshot = StateSnapshot( - state=self._full_state().to_dict(), - timestamp=datetime.now(), - node_id=node_id, - ) - self._snapshots.append(snapshot) - if len(self._snapshots) > self.max_history_size: - self._snapshots = self._snapshots[-self.max_history_size :] - checkpoint_data_to_save: dict[str, Any] | None = None if ( self.checkpoint_dir