Skip to content

Add a LangGraph option to keep 0.1.0 context behavior - #127

Draft
campoy wants to merge 2 commits into
mainfrom
langgraph-context-compat
Draft

campoy wants to merge 2 commits into
mainfrom
langgraph-context-compat

Conversation

@campoy

@campoy campoy commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

#126 made Activity nodes and tasks rebuild class-based contexts by default. That breaks apps upgrading from 0.1.0 in three ways. I checked each by running 0.1.0 and #126 against a local server:

  • Code that reads a dataclass or Pydantic context as a dictionary (runtime.context["user_id"]) now fails with TypeError.
  • A context whose class isn't declared as a context_schema now fails the Workflow task. Workflows started on 0.1.0 fail the same way when they replay.
  • context_schema=dict[str, Any] now fails when the plugin is created.

This adds restore_context_types to LangGraphPlugin. The default stays True. With False:

  • Activity nodes and tasks receive the context as decoded by the payload converter, as in 0.1.0.
  • Contexts of undeclared classes are allowed.
  • Workflows still attach schema IDs for declared classes. Workers with either setting can run side by side, so turning restoration on later is a rolling deploy.

Schemas that aren't classes are now accepted with either setting.

How compatibility holds

  • Preserve typed context in LangGraph Activity nodes and tasks #126 didn't change Workflow commands, so 0.1.0 histories replay without patching. New tests replay saved 0.1.0 histories with both settings. With restoration on, an undeclared class still fails replay, and the README says to declare classes before turning it on.
  • 0.1.0 workers ignore the new schema ID in the Activity input, and new workers accept input without it.
  • A Functional API task scheduled by a 0.1.0 worker has no schema ID, so a worker with restoration on gives it a dictionary. The README's upgrade steps avoid this by upgrading with restoration off first.

Not included: aliases for renamed context classes.

Testing

The 0.1.0 histories were recorded by running this branch's TwoNodesWorkflow with the 0.1.0 plugin source. The worker identity is replaced with recorder.

Locally, from source against a dev server with cached SDK 1.34.0 and LangGraph 1.2.9: all graph context cases, both replay tests, the Functional API context test and the validation tests pass. ruff 0.15.22, mypy 1.18.2, basedpyright 1.34.0, pydocstyle and the conventions check pass. make lint, make test and make build can't run locally because the installed uv is 0.11.21 and the repo needs >=0.12.5, so CI runs the supported matrix.

Add restore_context_types to LangGraphPlugin. Setting it to False keeps the
0.1.0 behavior: Activity nodes and tasks receive class-based contexts as
decoded dictionaries, and contexts of undeclared classes are allowed.
Workflows still attach schema IDs for declared classes, so turning
restoration on later is a rolling deploy.

Also accept context schemas that are not classes, such as dict[str, Any],
which 0.1.0 accepted.

Replay saved 0.1.0 histories with both settings, and document the upgrade
path in the README.

@campoy campoy left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move python/langgraph/CONTEXT-RESTORATION-PLAN.md to python/langgraph/docs/CONTEXT-RESTORATION-PLAN.md

This branch has not been deployed

No deployments
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.

1 participant