Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discrepancy in docs between Python and JS #695

Open
mme opened this issue Nov 28, 2024 · 0 comments
Open

Discrepancy in docs between Python and JS #695

mme opened this issue Nov 28, 2024 · 0 comments

Comments

@mme
Copy link

mme commented Nov 28, 2024

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:

class State(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/
const StateAnnotation = Annotation.Root({
  messages: Annotation<BaseMessage[]>({
    reducer: (x, y) => x.concat(y),
  })
})

These two methods behave fundamentally different, i.e.:

# pseudo code
def some_node(state):
   state["messages"].append(AIMessages("D"))
   return state

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:

export const SomeState = Annotation.Root({
  aProperty: Annotation<string>,
  ...MessagesAnnotation.spec,
});

To make it easier for users and to make LangGraph work more alike on Python and JS, I suggest these changes:

  • In the docs, recommend to set up state via ...MessagesAnnotation.spec instead of reducer: (x, y) => x.concat(y)
  • In the "Define State" section, mention MessagesAnnotation
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

No branches or pull requests

1 participant