[PR #3025] functional api: Add ability to request previous output #3034

Closed
opened 2026-02-20 17:47:58 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/3025

State: closed
Merged: Yes


  1. The inputs into foo do not affect any state behavior
  2. previous always reflects the previous return value from the function
  3. Anything can be returned and that will be the new state for the function on the next iteration
  4. This API is not meant to support reducers in the inputs/state
  from langgraph.func import entrypoint

  states = []

  # In this version reducers do not work
  @entrypoint(checkpointer=MemorySaver())
  def foo(inputs, *, previous: Any) -> Any:
      states.append(previous)
      return {"previous": previous, "current": inputs}

  config = {"configurable": {"thread_id": "1"}}

  foo.invoke({"a": "1"}, config)
  foo.invoke({"a": "2"}, config)
  foo.invoke({"a": "3"}, config)
  assert states == [
      None,
      {"current": {"a": "1"}, "previous": None},
      {"current": {"a": "2"}, "previous": {"current": {"a": "1"}, "previous": None}},
  ]
**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/3025 **State:** closed **Merged:** Yes --- 1. The inputs into foo do not affect any state behavior 2. `previous` always reflects the previous return value from the function 3. Anything can be returned and that will be the new state for the function on the next iteration 4. This API is not meant to support reducers in the inputs/state ```python from langgraph.func import entrypoint states = [] # In this version reducers do not work @entrypoint(checkpointer=MemorySaver()) def foo(inputs, *, previous: Any) -> Any: states.append(previous) return {"previous": previous, "current": inputs} config = {"configurable": {"thread_id": "1"}} foo.invoke({"a": "1"}, config) foo.invoke({"a": "2"}, config) foo.invoke({"a": "3"}, config) assert states == [ None, {"current": {"a": "1"}, "previous": None}, {"current": {"a": "2"}, "previous": {"current": {"a": "1"}, "previous": None}}, ] ```
yindo added the pull-request label 2026-02-20 17:47:58 -05:00
yindo closed this issue 2026-02-20 17:47:58 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#3034