Skip to content

Commit 35ee689

Browse files
committed
fix: preserve graph-owned state keys during frontend state merge (CopilotKit#2893)
1 parent 9686a71 commit 35ee689

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

sdk-python/copilotkit/langgraph_agent.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,12 @@ async def prepare_stream( # pylint: disable=too-many-arguments
236236
actions=actions,
237237
agent_name=self.name
238238
)
239-
current_graph_state.update(state)
239+
# Only update graph state with keys that merge_state explicitly produced,
240+
# not keys that were simply passed through from state_input unchanged.
241+
# This preserves graph-owned state keys that the frontend may have sent stale values for.
242+
for key, value in state.items():
243+
if key not in state_input or value is not state_input.get(key):
244+
current_graph_state[key] = value
240245
lg_interrupt_meta_event = next((ev for ev in (meta_events or []) if ev.get("name") == "LangGraphInterruptEvent"), None)
241246
has_active_interrupts = active_interrupts is not None and len(active_interrupts) > 0
242247

0 commit comments

Comments
 (0)