Files
langgraph/libs/langgraph/tests/test_managed_values.py
T
Sydney RunkleandGitHub 2920a9dd19 fix(langgraph): Tidy up AgentState (#5801)
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!
2025-08-03 07:12:53 -04:00

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