diff --git a/typescript-sdk/integrations/langgraph/python/ag_ui_langgraph/agent.py b/typescript-sdk/integrations/langgraph/python/ag_ui_langgraph/agent.py index 686f7bbec..493fbbf4b 100644 --- a/typescript-sdk/integrations/langgraph/python/ag_ui_langgraph/agent.py +++ b/typescript-sdk/integrations/langgraph/python/ag_ui_langgraph/agent.py @@ -685,7 +685,15 @@ async def get_checkpoint_before_message(self, message_id: str, thread_id: str): empty_snapshot = snapshot empty_snapshot.values["messages"] = [] return empty_snapshot - return history_list[idx - 1] # return one snapshot *before* the one that includes the message + + snapshot_values_without_messages = snapshot.values.copy() + del snapshot_values_without_messages["messages"] + checkpoint = history_list[idx - 1] + + merged_values = {**checkpoint.values, **snapshot_values_without_messages} + checkpoint = checkpoint._replace(values=merged_values) + + return checkpoint raise ValueError("Message ID not found in history") diff --git a/typescript-sdk/integrations/langgraph/python/pyproject.toml b/typescript-sdk/integrations/langgraph/python/pyproject.toml index 136120639..9b7a8d93a 100644 --- a/typescript-sdk/integrations/langgraph/python/pyproject.toml +++ b/typescript-sdk/integrations/langgraph/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ag-ui-langgraph" -version = "0.0.5" +version = "0.0.6" description = "Implementation of the AG-UI protocol for LangGraph." authors = ["Ran Shem Tov "] readme = "README.md" diff --git a/typescript-sdk/integrations/langgraph/src/agent.ts b/typescript-sdk/integrations/langgraph/src/agent.ts index f43eb957e..07c37efcf 100644 --- a/typescript-sdk/integrations/langgraph/src/agent.ts +++ b/typescript-sdk/integrations/langgraph/src/agent.ts @@ -992,7 +992,9 @@ export class LangGraphAgent extends AbstractAgent { const targetStateIndex = reversed.indexOf(targetState); - return reversed[targetStateIndex - 1] ?? { ...targetState, values: {} }; + const { messages, ...targetStateValuesWithoutMessages } = targetState.values as State + const selectedCheckpoint = reversed[targetStateIndex - 1] ?? { ...targetState, values: {} } + return { ...selectedCheckpoint, values: { ...selectedCheckpoint.values, ...targetStateValuesWithoutMessages } }; } }