You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In LangGraph Python, the recommended way to set up state is to either use MessagesState or to manually set it up. For example the Python quick start describes setting up state like this:
classState(TypedDict):
# Messages have the type "list". The `add_messages` function# in the annotation defines how this state key should be updated# (in this case, it appends messages to the list, rather than overwriting them)messages: Annotated[list, add_messages]
This is how the JS quickstart recommends to set up state:
// Define the graph state// See here for more info: https://langchain-ai.github.io/langgraphjs/how-tos/define-state/constStateAnnotation=Annotation.Root({messages: Annotation<BaseMessage[]>({reducer: (x,y)=>x.concat(y),})})
These two methods behave fundamentally different, i.e.:
In LangGraph Python, the recommended way to set up state is to either use
MessagesState
or to manually set it up. For example the Python quick start describes setting up state like this:This is how the JS quickstart recommends to set up state:
These two methods behave fundamentally different, i.e.:
If
state.messages
was[A,B,C]
it would be[A,B,C,D]
in Python and[A,B,C,A,B,C,D]
in Javascript.In addition, the "Define State" docs do not mention
MessagesAnnotation
and this method to get the equivalent of the Python behavior:To make it easier for users and to make LangGraph work more alike on Python and JS, I suggest these changes:
...MessagesAnnotation.spec
instead ofreducer: (x, y) => x.concat(y)
MessagesAnnotation
The text was updated successfully, but these errors were encountered: