fix(langgraph): preserve state history coverage semantics
This commit is contained in:
committed by
Forgejo
parent
fcf1306817
commit
4b6547b114
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user