fix(sdk-python): merge partial state with current_graph_state in emit_state#3139
Open
Valen-C12 wants to merge 1 commit intoCopilotKit:mainfrom
Open
fix(sdk-python): merge partial state with current_graph_state in emit_state#3139Valen-C12 wants to merge 1 commit intoCopilotKit:mainfrom
Valen-C12 wants to merge 1 commit intoCopilotKit:mainfrom
Conversation
…_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
|
Contributor
|
@ValenW is attempting to deploy a commit to the CopilotKit Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When using
copilotkit_emit_state()to emit intermediate state, the emittedSTATE_SNAPSHOTevent only contained the partial state passed to the function, not merged with the existingcurrent_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 onlyrun_titles, causingthinking_stepsto temporarily disappear until the next full state sync.Solution
Merge the partial state with
current_graph_statebefore emitting, ensuring the snapshot always contains the complete state:Note
This fix only addresses
copilotkit/langgraph_agui_agent.py. The same bug also exists inag_ui_langgraph/agent.py(the parentLangGraphAgentclass), which may need a similar fix in that package.Fixes #3138