Skip to content

fix(sdk-python): merge partial state with current_graph_state in emit_state#3139

Open
Valen-C12 wants to merge 1 commit intoCopilotKit:mainfrom
Valen-C12:fix/emit-state-merge-partial-state
Open

fix(sdk-python): merge partial state with current_graph_state in emit_state#3139
Valen-C12 wants to merge 1 commit intoCopilotKit:mainfrom
Valen-C12:fix/emit-state-merge-partial-state

Conversation

@Valen-C12
Copy link

Summary

When using copilotkit_emit_state() to emit intermediate state, the emitted STATE_SNAPSHOT event only contained the partial state passed to the function, not merged with the existing current_graph_state.

This caused state fields to "disappear" on the frontend when other fields were updated via copilotkit_emit_state().

Problem

For example, if the state had:

{
    "thinking_steps": [...],
    "run_titles": {...}
}

And copilotkit_emit_state({"run_titles": {...}}) was called, the frontend would receive a snapshot with only run_titles, causing thinking_steps to temporarily disappear until the next full state sync.

Solution

Merge the partial state with current_graph_state before emitting, ensuring the snapshot always contains the complete state:

partial_state = custom_event.value
current_graph_state = self.active_run.get("current_graph_state", {})
merged_state = {**current_graph_state, **partial_state}
self.active_run["current_graph_state"].update(partial_state)
self.active_run["manually_emitted_state"] = merged_state

Note

This fix only addresses copilotkit/langgraph_agui_agent.py. The same bug also exists in ag_ui_langgraph/agent.py (the parent LangGraphAgent class), which may need a similar fix in that package.

Fixes #3138

…_state

When using `copilotkit_emit_state()` to emit intermediate state, the
emitted `STATE_SNAPSHOT` event only contained the partial state passed
to the function, not merged with the existing `current_graph_state`.

This caused state fields to "disappear" on the frontend when other
fields were updated via `copilotkit_emit_state()`.

For example, if the state had `{thinking_steps: [...], run_titles: {...}}`,
and `copilotkit_emit_state({"run_titles": {...}})` was called, the
frontend would receive a snapshot with only `run_titles`, causing
`thinking_steps` to temporarily disappear.

The fix merges the partial state with `current_graph_state` before
emitting, ensuring the snapshot always contains the complete state.

Fixes CopilotKit#3138
@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2026

⚠️ No Changeset found

Latest commit: 0bb3dc5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Contributor

vercel bot commented Feb 2, 2026

@ValenW is attempting to deploy a commit to the CopilotKit Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug: copilotkit_emit_state partial state not merged with current_graph_state in STATE_SNAPSHOT

2 participants