mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-29 11:19:54 +02:00
Fixes https://github.com/langchain-ai/langgraph/issues/5784 * Removes usage of `is_last_step`, no longer needed with `remaining_steps` * Make `remaining_steps` `NotRequired` so that json schema doesn't suggest need for user input * Move `PregelScratchpad` to shared utils file to prevent circular import issue (it's used from `channels/managed` and other pregel files). * Ensures that managed values wrapped in `NotRequired` or `Required` are still recognized!
28 lines
683 B
Python
28 lines
683 B
Python
from typing_extensions import NotRequired, Required, TypedDict
|
|
|
|
from langgraph.graph import StateGraph
|
|
from langgraph.managed import RemainingSteps
|
|
|
|
|
|
class StatePlain(TypedDict):
|
|
remaining_steps: RemainingSteps
|
|
|
|
|
|
class StateNotRequired(TypedDict):
|
|
remaining_steps: NotRequired[RemainingSteps]
|
|
|
|
|
|
class StateRequired(TypedDict):
|
|
remaining_steps: Required[RemainingSteps]
|
|
|
|
|
|
def test_managed_values_recognized() -> None:
|
|
graph = StateGraph(StatePlain)
|
|
assert "remaining_steps" in graph.managed
|
|
|
|
graph = StateGraph(StateNotRequired)
|
|
assert "remaining_steps" in graph.managed
|
|
|
|
graph = StateGraph(StateRequired)
|
|
assert "remaining_steps" in graph.managed
|